-
-
Notifications
You must be signed in to change notification settings - Fork 544
Nullable fields not respected in intercom schema? #1422
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
Comments
Taking a quick glance at your schema, I think it’s because you have |
Also |
Hey, thanks so much for being so helpful. I've created a repo showing my problem here https://github.com/cipriancaba/openapi-typescript This is the schema for the specific
I can see indeed it is missing the required property as |
Yes that’s the behavior that’s consistent in OpenAPI 3 (and 2) and JSONSchema (there are only a couple exceptions, such as |
I see, that would be amazing if I actually had control over the schema. The problem seems to be with more of the schemas I am using integrating different services. Do you think it might be helpful to add a flag that treats non-required fields as required if the nullable is present? If you're open to the idea and point me in the right direction, would be more than happy to open a PR |
I’d rather not add a flag to support this because it would encourage going against using OpenAPI as it’s designed, and how it’s worked for a long time. The real fix here is using valid schemas that adhere to the OpenAPI specification as-written. But I understand that’s beyond your control. Because this is a unique scenario that few people encounter, I’d recommend using the transform API to override generated types based on the schema logic. Or you could simply fork the API schema and make the changes yourself (which for a public API that can’t introduce breaking changes, you won’t have to update this very much if at all). |
Thanks again @drwpow . I totally understand your reasoning, however this api is just one of those that we use, and keeping updated copies of every single one is not going to work in the long run. I've gave the transform API a shot, but not sure how I can access the default transform, I am trying to achieve something like this:
I don't want to rewrite the entire transformer, just update the schemaObject to actually include |
Oh shoot yeah that’s just a bad example; will fix that. It’s more meant to represent “if a node meets condition A then I want to override the type; otherwise, transform as normal.” But you could just return literal Also in the current version (6.x), you can use
Yes that sounds like it. That would be outside the purpose of this library, as this only translates a valid schema into TS and won’t give you any tools to modify your schema. I’d look at Redocly—this sounds like you’d want to create a plugin to modify your schema on-the-fly (also fun fact: the upcoming 7.x version bundles Redocly core for validation & extra features). |
I am on version 7 currently, figured I'd get a head start on it anyway :) Let me see if I got this clear, in the Which basically means that there is no way to update the result of the transform (remove the Is there a way to access the redocly plugin directly from openapi-typescript in v7? |
Basically you’re modifying your schema—you are changing the contract that the API server has with its consumers. This is in “bad practice” territory and is nonstandard (I know you don’t have control, but the root issue is an unreliable schema, and the real fix). I’ve been suggesting “hacks” in openapi-typescript as a shortcut for you if it’s simple enough to work, but you should treat this problem as what it is—a consumer modifying the original schema ad-hoc. And there’s no standard support or happy path for that. But if you are in that territory, I’d suggest looking into Redocly’s plugins as it’s built exactly for that purpose, and I’m confident that approach will last (and 7.x isn’t quite ready yet, so even if using Redocly in a specific way in 7.x works in the beta version don’t take that as a guarantee it will in the stable release). |
Thanks @drwpow, really appreciate the help and thanks for the amazing library |
Yeah it’s a tricky problem and not one many people face! But again, Redocly almost certainly has the suite of tools you need if you run it before openapi-typescript. Good luck! 🙂 |
Uh oh!
There was an error while loading. Please reload this page.
Description
This is my first time using this library, it's absolutely amazing, thank you so much 🙏
I'm having a bit of trouble with the
| undefined
parts of the generated types. It seems that absolutely everything is| undefined
For example, in this call to GET/tags
, it correctly discriminates the non error nature of the response, but the generated type is:And here is my code
Been playing around with the --default-non-nullable but it doesn't seem to do the trick. I'm sure it's an obvious problem, but I can't figure it out.
Thanks for the help
openapi-typescript
7.0.0-next.2
18.20
macOS Sonoma
Reproduction
https://gist.github.com/cipriancaba/790b7366794640779f0ca662f759ef8e
npx openapi-typescript@next intercom.yaml -o intercom.d.ts
Expected result
Generated data type shouldn't be
| undefined
, unless nullable is specified in the yaml schema eg:Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: