-
-
Notifications
You must be signed in to change notification settings - Fork 528
Transform nullable returns | null instead of optional ? #1411
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
Ah that’s a really good question! You can’t. Because the way the TS AST works, the For most cases, 🤔 I wonder if to fix this, const ast = await openapiTS(mySchema, {
transform(schemaObject, metadata) {
if (schemaObject.format === "binary") {
return {
schema: BLOB, // the root schema
questionToken: true, // set `?`
// some other options…
};
}
},
}); This format would allow us to add additional options, if any, of which |
Yes I was thinking the same thing while messing around with the transform function! Those options would be great. I can try and create a starting point and hack something together in my spare time, but I have no experience with TS AST/TS compiler API. So there is a bit of a learning curve 😛 |
Yeah I’d welcome a PR if you have time and interest. This task is also fairly easy, and a good introduction to the TS AST. The best way to start is TDD: first write a failing test that outlines the API you want, then just throw code around until it passes. For this particular problem, I’d like to keep the original API in tact, but also accept this “expanded” syntax as a secondary format. I’ve seen this pattern in other libraries that let you omit metadata because it just cuts down on boilerplate for most people. But you should be able to get by with: const result = options.ctx.transform(schemaObject, options);
if (result) {
// expanded syntax
if (typeof result === 'object' && result.schema) {
// (new code)
}
// original syntax
else {
// (existing code) Simply checking for The rest of the code should be pretty lightweight and straightforward; it’s just familiarizing yourself with the TS API and finding the right places to plug in. However, the one final “trick” is we may need to move the |
Thanks for the detailed explanation! Will take a look when I got some spare time this week 😄 |
Description
I'm following the example from https://openapi-ts.pages.dev/node/, but the type becomes
file: Blob | null
instead offile?: Blob
. Maybe this is the desired result, in that case, how can I make it optional with the question mark notation? I tried appending undefined as well, but that results infile: Blob | undefined
which is also not what I'm looking for 😄openapi-typescript
7.0.0-next.2
18.x.x
Windows 11
Reproduction
Expected result
file?: Blob
Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: