diff --git a/schema.go b/schema.go index e17362ee..94b4530d 100644 --- a/schema.go +++ b/schema.go @@ -636,15 +636,14 @@ func getFields(typ reflect.Type, visited map[reflect.Type]struct{}) []fieldInfo for i := 0; i < typ.NumField(); i++ { f := typ.Field(i) + if !f.IsExported() { + continue + } if f.Anonymous { embedded = append(embedded, f) continue } - // embeds can have exported fields - if !f.IsExported() { - continue - } fields = append(fields, fieldInfo{typ, f}) } diff --git a/schema_test.go b/schema_test.go index 08c3e1b3..18ab17a1 100644 --- a/schema_test.go +++ b/schema_test.go @@ -42,10 +42,6 @@ type EmbeddedChild struct { Value string `json:"value" doc:"old doc"` } -type embedWithExported struct { - Value string `json:"value" doc:"embed doc"` -} - type Embedded struct { EmbeddedChild Value string `json:"value" doc:"new doc"` @@ -698,28 +694,6 @@ func TestSchema(t *testing.T) { } }`, }, - { - name: "field-embed-unexported", - input: struct { - // the embed is an unexported type, but it can contribute exported properties that will be in the JSON - *embedWithExported - Value2 string `json:"value2"` - }{}, - expected: `{ - "type": "object", - "additionalProperties": false, - "required": ["value2", "value"], - "properties": { - "value": { - "type": "string", - "description": "embed doc" - }, - "value2": { - "type": "string" - } - } - }`, - }, { name: "field-embed-override", input: struct { @@ -1329,21 +1303,6 @@ func (o OmittableNullable[T]) Schema(r huma.Registry) *huma.Schema { return s } -func TestUnexportedEmbed(t *testing.T) { - // shows value is serialized in the JSON - j, err := json.Marshal(struct { - *embedWithExported - Value2 string `json:"value2"` - }{ - embedWithExported: &embedWithExported{ - Value: "foo", - }, - Value2: "bar", - }) - require.NoError(t, err) - assert.JSONEq(t, `{"value":"foo","value2":"bar"}`, string(j)) -} - func TestCustomUnmarshalType(t *testing.T) { type O struct { Field OmittableNullable[int] `json:"field" maximum:"10" example:"5"`