asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
997 stars 61 forks source link

Non-local $refs #170

Open rhysdoliver opened 1 year ago

rhysdoliver commented 1 year ago

Problem

I'm currently working on a project where I have an openAPI spec which is organised as a folder. I've been experimenting with using this library to generate schemas only, which has been working great for my use case! But I have found the $ref is hardcoded to assume the spec is only using local references, meaning i currently have to manually update each file.

Proposal

I thought it might be good to have a argument on generateComponents that controls the reference type (local/remote/server), as per the swagger guidance Using $ref. Scope may be wider to make it compatible with the whole library? Happy to make a PR myself

AGalabov commented 1 year ago

@rhysdoliver thank you for the suggestion. I do think this makes sense. I think we've thought about providing a "base path" of where documents are being stored. I.e not necessarily under /components or /schemas.

And yes such a task should ideally be done for the whole library - meaning both v3 and v3.1 and also for generateComponents and generateDocument. One thing that comes to mind is that this can be done with an optional second parameter to the Generator constructor and it would influence both behaviors.

Feel free to open up a PR for us