-
Notifications
You must be signed in to change notification settings - Fork 6k
Typescript node discriminator fixes #7824
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
Typescript node discriminator fixes #7824
Conversation
To get rid of the `[ts] Member 'discriminator' implicitly has an 'any' type.` error message from the TypeScript compiler when `noImplicitAny` is set to true.
Otherwise the code wouldn't work probably and the TypeScript compiler didn't even compile it without errors. The Petstore client sample only contains undefined discriminators so this change does not affect the code generation of the Petstore client sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
| {{/discriminator}} | ||
| {{^discriminator}} | ||
| static discriminator = undefined; | ||
| static discriminator : any = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove the space before :? Just to keep the code style consistent.
Would defining the type as string be correct? IIRC the discriminator is just a string denoting the property name. I would prefer a more specific type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TiFu Yes type string is correct. I've updated the PR to according to your comments.
|
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @bjarnij Any chance we can get this to merge into 2.4? Its blocking our ability to use discriminators in our current workflow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor tweaks for CI purposes.
| {{/discriminator}} | ||
| {{^discriminator}} | ||
| static discriminator = undefined; | ||
| static discriminator: string = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be
static discriminator: string | undefined = undefined;
so that it can pass CI. The same with all the rest of the spots with undefined assignments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjarnij I checked this locally and it in fact does fix the issue:
{{#discriminator}}
static discriminator: string | undefined = "{{discriminator}}";
{{/discriminator}}
{{^discriminator}}
static discriminator: string | undefined = undefined;
{{/discriminator}}
|
@wing328 do you know who is responsible for updating this? https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/ I'd love to get this latest changed into that image. |
|
@gbrown-ce I'll look into that... |
|
@wing328 you're awesome, thank you! |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.3.0.0branch for changes related to OpenAPI spec 3.0. Default:master.Description of the PR
The generated code for discriminators that are not
undefined discriminators, lacked quotes around the name of the property containing the discriminator causing the generated code not to compile.Also I explicitly defined the undefined discriminator as any to get rid of the
[ts] Member 'discriminator' implicitly has an 'any' type.error message from the TypeScript compiler when the compiler optionnoImplicitAnyis set to true.@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny