You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in the process of building some of the more complex schemas for an OpenAPI-based API and running into some new issues. I have an example that looks something like this:
funcmain() {
x:= controller.V1{}
// It is still possible to access the contents of commonElemsx.Inner="Hello"registry:=huma.NewMapRegistry("#/prefix", huma.DefaultSchemaNamer)
t:=reflect.TypeOf(controller.V1{})
schema:=huma.SchemaFromType(registry, t)
fmt.Printf("Schema: %v\n", schema)
}
The output only contains the outer field
Schema: &{object false <nil> [] <nil> false map[a:0x140001f6008] [] <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> false [a] <nil> <nil> false false false map[] map[] [] [] [] <nil> <nil> <nil> map[a:true] [a] expected value to be one of "" map[a:expected required property a to be present] map[]}
Changing commonElems to CommonElems so the embedded struct is exported, the output contains both expected fields:
Schema: &{object false <nil> [] <nil> false map[a:0x14000254008 inner:0x14000254308] [] <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> false [a inner] <nil> <nil> false false false map[] map[] [] [] [] <nil> <nil> <nil> map[a:true inner:true] [a inner] expected value to be one of "" map[a:expected required property a to be present inner:expected required property inner to be present] map[]}
Unfortunately, unlike the example, the structs V1 and V2 are located in another library that I don't have easy control over. But furthermore, I think the second output should be the default, since in Go we can still access exported fields inside of unexported embedded structs (as seen in the code example) and JSON marshalling/unmarshalling works the same. What are others thoughts?
The text was updated successfully, but these errors were encountered:
@srilman thanks for the issue! I believe this was done on purpose because Go can't use reflection to access private fields from other packages, so it would be inconsistent to allow access from within your package but disallow it from imported packages. I can dig a bit deeper just to confirm this is the case with embedded private fields.
Currently in the process of building some of the more complex schemas for an OpenAPI-based API and running into some new issues. I have an example that looks something like this:
In models.go
In main.go:
The output only contains the outer field
Changing
commonElems
toCommonElems
so the embedded struct is exported, the output contains both expected fields:Unfortunately, unlike the example, the structs V1 and V2 are located in another library that I don't have easy control over. But furthermore, I think the second output should be the default, since in Go we can still access exported fields inside of unexported embedded structs (as seen in the code example) and JSON marshalling/unmarshalling works the same. What are others thoughts?
The text was updated successfully, but these errors were encountered: