Skip to content

Commit e5fa153

Browse files
Merge pull request #848 from danielgtaylor/revert-822-unexported-embed
Revert "fix: export of embed properties when struct type is not exported"
2 parents 179328f + fb41f02 commit e5fa153

File tree

2 files changed

+3
-45
lines changed

2 files changed

+3
-45
lines changed

schema.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,15 +636,14 @@ func getFields(typ reflect.Type, visited map[reflect.Type]struct{}) []fieldInfo
636636

637637
for i := 0; i < typ.NumField(); i++ {
638638
f := typ.Field(i)
639+
if !f.IsExported() {
640+
continue
641+
}
639642

640643
if f.Anonymous {
641644
embedded = append(embedded, f)
642645
continue
643646
}
644-
// embeds can have exported fields
645-
if !f.IsExported() {
646-
continue
647-
}
648647

649648
fields = append(fields, fieldInfo{typ, f})
650649
}

schema_test.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ type EmbeddedChild struct {
4242
Value string `json:"value" doc:"old doc"`
4343
}
4444

45-
type embedWithExported struct {
46-
Value string `json:"value" doc:"embed doc"`
47-
}
48-
4945
type Embedded struct {
5046
EmbeddedChild
5147
Value string `json:"value" doc:"new doc"`
@@ -698,28 +694,6 @@ func TestSchema(t *testing.T) {
698694
}
699695
}`,
700696
},
701-
{
702-
name: "field-embed-unexported",
703-
input: struct {
704-
// the embed is an unexported type, but it can contribute exported properties that will be in the JSON
705-
*embedWithExported
706-
Value2 string `json:"value2"`
707-
}{},
708-
expected: `{
709-
"type": "object",
710-
"additionalProperties": false,
711-
"required": ["value2", "value"],
712-
"properties": {
713-
"value": {
714-
"type": "string",
715-
"description": "embed doc"
716-
},
717-
"value2": {
718-
"type": "string"
719-
}
720-
}
721-
}`,
722-
},
723697
{
724698
name: "field-embed-override",
725699
input: struct {
@@ -1329,21 +1303,6 @@ func (o OmittableNullable[T]) Schema(r huma.Registry) *huma.Schema {
13291303
return s
13301304
}
13311305

1332-
func TestUnexportedEmbed(t *testing.T) {
1333-
// shows value is serialized in the JSON
1334-
j, err := json.Marshal(struct {
1335-
*embedWithExported
1336-
Value2 string `json:"value2"`
1337-
}{
1338-
embedWithExported: &embedWithExported{
1339-
Value: "foo",
1340-
},
1341-
Value2: "bar",
1342-
})
1343-
require.NoError(t, err)
1344-
assert.JSONEq(t, `{"value":"foo","value2":"bar"}`, string(j))
1345-
}
1346-
13471306
func TestCustomUnmarshalType(t *testing.T) {
13481307
type O struct {
13491308
Field OmittableNullable[int] `json:"field" maximum:"10" example:"5"`

0 commit comments

Comments
 (0)