这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
41 changes: 0 additions & 41 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down
Loading