Closed fredbi closed 6 years ago
skip schemas only exists for this flattening use case, but lack of rebasing seems like a bug in that implementation
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.
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,
$ref
s 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:SkipRemoteSchemas: false
: remote$ref
in schemas are expanded, even thoughSkipSchemas
is true. This ensures that anExpandSpec()
withSkipSchemas: true
does not leave remote $ref's behind.SkipRemoteSchemas: true
: remote$ref
in schemas are rebased to the current root, but not expanded. This adheres to a trueSkipSchemas; true
(no expansion at all in schemas)