Closed Fifi31 closed 6 months ago
Describe the bug When a sub-entity of a request has a field of its own type, the resulting schema doesn't reference itself. It works well if the request (the top-level type) references itself, but not for sub-entities.
To Reproduce Playground
type SubEntity struct { Self *SubEntity `json:"self"` } type Req struct { SubEntity *SubEntity `json:"subentity"` Self *Req `json:"self"` } func main() { reflector := openapi3.Reflector{} reflector.Spec = &openapi3.Spec{Openapi: "3.1.0"} putOp := openapi3.Operation{} reflector.SetRequest(&putOp, Req{}, http.MethodPut) reflector.Spec.AddOperation(http.MethodPut, "/things/{id}", putOp) schema, err := reflector.Spec.MarshalYAML() if err != nil { log.Fatal(err) } // Req schema references itself on self field, but SubEntity schema has no reference on self field fmt.Println(string(schema)) }
Expected behavior components.schemas.SubEntity.properties.self should have a $ref field with the value '#/components/schemas/SubEntity'.
components.schemas.SubEntity.properties.self
$ref
'#/components/schemas/SubEntity'
Also SubEntity.self has nullable set as true but I am not sure if it is normal, as Req.self has not.
SubEntity.self
nullable
true
Req.self
Now should be fixed in master, thanks for reporting this!
master
Describe the bug When a sub-entity of a request has a field of its own type, the resulting schema doesn't reference itself. It works well if the request (the top-level type) references itself, but not for sub-entities.
To Reproduce Playground
Expected behavior
components.schemas.SubEntity.properties.self
should have a$ref
field with the value'#/components/schemas/SubEntity'
.Also
SubEntity.self
hasnullable
set astrue
but I am not sure if it is normal, asReq.self
has not.