Open will-banked opened 2 years ago
I ran across the same issue. It seems to me that kin-openapi prefers the Ref when marshalling the T back into JSON/YAML. The loader does resolve internal references by default (it calls .ResolveRefsIn(doc, nil)
), but leaves the .Ref
fields intact.
I was able to work around this like so (in a super dirty way that will blow up if your spec has circular references) https://gist.github.com/xrstf/cdfb3bfae8cc40aae32ea6b1b3270225
I've got an OpenAPI Spec file that looks like this
The actual real spec is a lot longer with a lot more in-file references, but hopefully this is an example enough for now. In code I'm doing something like:
However, when Marshalling to JSON and printing it, all the refs are in output. I was under the impression that when loading in a file, references would be resolved. My assumption was that, at the very least, in-file refs would resolve, and any external files might then need a bit of additional work to sort out. But yeah, definitely expecting in-file ones to resolve, and not sure if they're not or if I'm doing something wrong.
I obviously have spotted the
resolveRefsIn()
function, but it seems like it takes a URL to what I assume is a location of external refs, which I'm not using.Am I misunderstanding what Loader should resolve?
I've got a Go Playground there which uses a string instead of a .json file, and that actually does return an error in the console saying it can't resolve the ref, but I'm not getting any such errors when loading in the file itself.
Go playground: https://go.dev/play/p/Nds_KeSWGwd