Check/verify functionality for CLI
Description
Sometimes, for example as part of CI workflows, one might want to check that types generated by this library are up to date rather than actually write them to a file. For example, this could ensure that noone made changes to an OpenAPI specification and forgot to re-generate the types for it. This could for example be done by running the generator and inspecting the git status before and after doing so, however that approach seems clunky. It would be convenient if this library provided an easy way to do this.
Proposal
A similar workflow is supported by some other codegen tools including graphql-codegen and kysely-codegen. Here is a concrete implementation suggestion for this project.
Add a flag called check to the CLI. This could be specified as follows:
"Instead of writing the types to the output destination, compare the output with the file at the destination. Exit with exit code 0 if the destination file exists and its content is equal to the output, and exit code 1 otherwise. If this flag is used, the --output option must also be specified."
Checklist
- [ ] I’m willing to open a PR for this (see CONTRIBUTING.md)
I guess I could open a PR, but I don't know if I'll be able to work on it and this is intended as a feature request/suggestion.
That makes sense! I’d be in support of this. The idea of linting schemas is something I’ve had good luck with Redocly with, which is why 7.x has it built-in. But this is something beyond linting, and something only openapi-typescript could do.
Also in 7.x with the improved Node.js API this should be easier to compare 2 outputs as well
Thanks for implementing this! Looks like we could close this issue now, right?
Yes, in the other issue specified there is a bug. But we can track it there and don’t need this open still.