-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull all schemas instead of just those linked to paths #11
Comments
Also, I should note that I managed to hack something together for this, but I'd prefer it if a less shitty version could be added to spec2ts. I'm trying to get more people in my organization to use openapi, and having a good tool for tasks like this would help me do that. The core of what I did was just this
and
and then just some |
Here's some real-world use-cases for this:
What you'd like to do is just keep both S and SS around, and even though no endpoints point to S anymore, you still generate T from it and continue to use that in your domain code. Eventually you get rid of SS and nothing really changes. You might say that the correct answer here is "don't use types generated from openapi yaml in your domain code." And this is not necessarily wrong, but it doesn't really help me at the moment. Also, the slightly longer term plan for the project involves replacing that same response schema S with another schema R, and in that case changing the generated type across my codebase is exactly what I want. |
This enhancement could make sense. |
This is a feature request.
The way spec2ts (and most comparable tools) work to generate types from schemas is:
This is probably what the tool should do by default.
However, from my perspective, there are times when I'd rather just say: for every schema in
components.schemas
, emit a type. I can explain more about the cases where this is useful if desired.For example, you could add a flag
--all-schemas
which would say to just emit a type for every schema in the target file, instead of trying to follow the paths.If you were to do this, it would also be potentially useful to add the ability to not validate that the input file is valid openapi, although this is something that users could work around in the short term. The reason is that I would want to write a fragment with just my schemas and have the main file refer to it with jsonschema refs. But if I want to pass the file with just the schemas into
spec2ts
, i would have to writethe main problem with this is that I'm repeating
info.version
(and I guess the openapi version) multiple times, so if I bump my api's version, I have to change it in multiple places. This is merely kind of ugly though, and not a major problem.Another possible improvement would be for the user to specify the prefix under which all entries would be assumed to be schemas, which by default would be
components.schemas
. That way, the user could have a fragment with just a schema and no prefix (i think people do this a lot), and set the prefix to empty. This is also not very important. Personally, I always make my fragments start with thecomponents.schemas
prefix like the above example because it makes it obvious what these things are, but not everybody does this.So, to summarize: I would find it very handy if there was a flag
--all-schemas
so I could runand have it just emit whatever was in
components.schemas
in that file. There are also some ways you could improve this & make it more flexible.The text was updated successfully, but these errors were encountered: