Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with self-referencing entites #89

Closed
Fifi31 opened this issue Nov 9, 2023 · 1 comment · Fixed by swaggest/jsonschema-go#100
Closed

Issue with self-referencing entites #89

Fifi31 opened this issue Nov 9, 2023 · 1 comment · Fixed by swaggest/jsonschema-go#100

Comments

@Fifi31
Copy link

Fifi31 commented Nov 9, 2023

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'.

Also SubEntity.self has nullable set as true but I am not sure if it is normal, as Req.self has not.

@vearutop
Copy link
Member

vearutop commented Dec 2, 2023

Now should be fixed in master, thanks for reporting this!

@vearutop vearutop closed this as completed Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants