openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Generated types causes compiler errors

Open tonyxiao opened this issue 1 year ago • 2 comments

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 CleanShot 2023-12-10 at 00 47 48@2x

Discord https://raw.githubusercontent.com/discord/discord-api-spec/main/specs/openapi.json image

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)

tonyxiao avatar Dec 10 '23 08:12 tonyxiao

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.

drwpow avatar Dec 14 '23 23:12 drwpow

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.

drwpow avatar Dec 14 '23 23:12 drwpow

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.

github-actions[bot] avatar Aug 06 '24 12:08 github-actions[bot]

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.

github-actions[bot] avatar Aug 14 '24 02:08 github-actions[bot]