openapi-ts / openapi-typescript

Generate TypeScript types from OpenAPI 3 specs
https://openapi-ts.dev
MIT License
5.99k stars 473 forks source link

CLI option to validate existing file #1738

Open markedwards opened 5 months ago

markedwards commented 5 months ago

Description

There's no apparent way to validate that the existing generated types in the target file match the current schema. This is useful in a CI pipeline.

Proposal

A validation mode triggered by a --validate should do the trick. This would change the behavior from updating the file at the output path, to validating that its contents match the output that would be generated from the current schema. If the file doesn't exist, or if there is any difference, an error should be emitted.

Checklist

markedwards commented 5 months ago

It's easy to get a rudimentary variant of this functionality running using the API. I would be willing to assist with this feature, but I don't know all of the complexity involved in rolling it in to the CLI at this point.

markedwards commented 5 months ago

If this is as straightforward as it seems to me, after doing my own implementation, then I'm happy to do a PR for it. As I envision it, the --validate flag would require either:

  1. a valid redocly.yaml (in which case all defined apis will be validated and any failure would throw an error)
  2. the --output flag to be specified
drwpow commented 5 months ago

I’d love a PR for this! @markedwards I agree with your take on this.

markedwards commented 4 months ago

Thanks @drwpow, I'll open one when I get a chance.

markedwards commented 4 months ago

I notice that there is a new --check flag in the latest release, which I guess is supposed to do what I describe above? However, it does not appear to work for me. If I do openapi-typescript --check it passes regardless of whether there is even a file in the output location.

Does this feature not work with the redocly.yaml file?

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

markedwards commented 1 month ago

Pinging on this. Should I open a separate issue for the --check feature apparently not working?