go-openapi / spec

openapi specification object model
Apache License 2.0
389 stars 98 forks source link

Expander: the expanded spec is unusable to resolve circular $ref #180

Open fredbi opened 8 months ago

fredbi commented 8 months ago

This is a nasty bug: so far I've failed to nail it.

When expanding schemas in a spec for further use (e.g. validating the spec, flattening it with the expand option), circular $ref are left in a unusable state in the $ref cache, leading to jsonpointer errors (e.g. "xxx has no key yyy") when attempting to resolve.

This is for example the root cause for go-swagger/go-swagger#2346. In go-swagger, it is possible to work around this issue by reloading the spec as a fresh go-openapi/loads.Document, but this is not ideal. This workaround is used on 2 occasions in go-swagger: