Feature Request: Support relative $ref in different file
wolthers opened this issue · comments
Thanks for a great library. I have a feature request:
It's pretty common to structure one's api so that common types are kept in a different spec and reused across.
Example:
....
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/SomeLocalSchema'
"401":
description: Unauthorized
content:
application/json:
schema:
$ref: "./common-types.yaml#/components/schemas/Error"
Is there any plan to support this any time soon?
Or if you could provide guidance, then I could take a stab at it, although I think it might be a bit of a mouthful as a first contribution.
Hello 👋
This can be achieved with some parsing tools before sending the file to this tool. You can use this as example https://www.npmjs.com/package/swagger-parser.
Usually, I do prefer to have this tool part of the CI flow, and versioned a "compiled" version of the specs so it's easy to consume.
I hope this help!
(for the record, I did consider to integrate this feature, but lack of time and easy workaround 😃)
I'm curious how that setup looks? I guess download specs, parse and save to disk and then using source: "file" in openapi-codegen.config from.source
? I guess source: "github" wouldn't work and source: "url" would only work if the url points to a compiled version. Can you share your setup or elaborate?
It would definitely be very nice to have this feature baked in.
The setup is quite straight forward since I push this compile step on the specs part.
The workflow looks like this (let's assume the specs are own by the backend):
- [backend] Update the specs
- [backend] Compile all the specs in one file -> part of the PR
- [frontend] Generate the specs from github
If you can't do this, you can have a little script that download the specs, compile it and use file
as from.source
.