go-openapi / spec

openapi specification object model
Apache License 2.0
394 stars 100 forks source link

spec ExpandSpec with SkipSchemas: true leaves inconsistent remote $ref in schema #77

Closed fredbi closed 6 years ago

fredbi commented 6 years ago

Following the study of go-swagger/go-swagger#1429, I found out that expanding a spec with SkipSchemas: true wrongly resolves remote $refs in schemas.

The problem is that when skipping schemas, $refs in parameters and responses are properly resolved, but if the expanded parameter or response has a schema with a $ref (relative to another root), it is simply resolved "as is" without rebasing this ref to the current root. This results in a schema with unresolvable $ref, since the root is lost.

I added a testcase derived from go-swagger/go-swagger#1429 to illustrate this.

Main spec: swagger.yaml.txt Remote file: responses.yaml.txt

This is especially annoying for spec flattening in go-swagger, since it is relying on the SkipSchema feature.

I think that another SkipRemoteSchemas option should be made available to tune the expand behavior:

casualjim commented 6 years ago

skip schemas only exists for this flattening use case, but lack of rebasing seems like a bug in that implementation

fredbi commented 6 years ago

Managed to fix this. More thorough testing is ongoing. Actually, the proposal above for some optional behavior is unnecessary: it suffices to relocate $ref properly.