openapi-typescript
openapi-typescript copied to clipboard
Generated types causes compiler errors
When generating types for Slack & Discord I'm getting the following issue
Slack
https://api.apis.guru/v2/specs/slack.com/1.7.0/openapi.json
Discord
https://raw.githubusercontent.com/discord/discord-api-spec/main/specs/openapi.json
I checked neither specs pass the redocly linter. However I wonder if there is a way for us to still generate types that doesn't cause typescript to completely error out and user has to manually resort to @ts-ignore
Checklist
- [ ] My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint) Does not pass unfortunately - [ ] I’m willing to open a PR (see CONTRIBUTING.md)
Will take a look. I think in the Slack one, that can be fixed as we can just prevent [key: string]: Record<string, never> from being generated—that’s just noise (that should only happen if there are no other properties)
The Discord one is less straightforward, but it’s also worth looking into. Will look at what that specific schema object is, and see if there’s a better way to generate that.
With the Slack schema, Swagger 2.0 is no longer supported with more recent versions of openapi-typescript. We can push security patches to 5.x and older versions, but not introducing breaking changes to how those generate.
Unfortunately, with the Discord error, that is a circular reference which is unresolvable. There’s not really a way to fix that in openapi-typescript. But with a tool like Redocly custom plugins, you can import a schema, apply modifications, and then openapi-typescript can operate on the transformed result (when it comes to rewriting a schema, that’s something Redocly is better suited for than this library).
I see you referenced one error per schema for both; if there are other more specific errors you find in those examples I can investigate further.
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.
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.