-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[TS][Angular] Avoid strictNullChecks errors for apiKeys #1611
Conversation
- ./bin/typescript-angular-petstore-all.sh - ./bin/typescript-inversify-petstore.sh
- ./bin/security/typescript-angular.sh - ./bin/security/typescript-angular2.sh - ./bin/security/typescript-inversify.sh
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
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>; | ||
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>; | ||
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> { | ||
public testCodeInjectEndRnNR(UNKNOWN_BASE_TYPE?: UNKNOWN_BASE_TYPE, observe?: 'body', reportProgress?: boolean): Observable<any>; |
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.
any idea why UNKNOWN_BASE_TYPE
occurs here?
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.
./bin/security/typescript-angular.sh
had warned:
[main] WARN o.o.codegen.DefaultCodegen - The following schema has undefined (null) baseType. It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. A correct 'consumes' for form parameters should be 'application/x-www-form-urlencoded' or 'mul
tipart/form-data'
And I changed modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml:
consumes:
- - application/json
- - "*/ ' \" =end -- \r\n \n \r"
+ - application/x-www-form-urlencoded
But invalid identifier was generated:
- public testCodeInjectEndRnNR(UNKNOWN_BASE_TYPE?: UNKNOWN_BASE_TYPE, observe?: 'body', reportProgress?: boolean): Observable<any>;
- public testCodeInjectEndRnNR(UNKNOWN_BASE_TYPE?: UNKNOWN_BASE_TYPE, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
- public testCodeInjectEndRnNR(UNKNOWN_BASE_TYPE?: UNKNOWN_BASE_TYPE, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
- public testCodeInjectEndRnNR(UNKNOWN_BASE_TYPE?: UNKNOWN_BASE_TYPE, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
+ public testCodeInjectEndRnNR(testCodeInject*#39;"=endRnNR?: string, observe?: 'body', reportProgress?: boolean): Observable<any>;
+ public testCodeInjectEndRnNR(testCodeInject*'"=endRnNR?: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
+ public testCodeInjectEndRnNR(testCodeInject*'"=endRnNR?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
+ public testCodeInjectEndRnNR(testCodeInject*'"=endRnNR?: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
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 think AbstractTypeScriptClientCodegen#toParamName is broken:
- name = sanitizeName(name, "\\W-[\\$]");
+ name = sanitizeName(name, "[^\\w$]");
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.
@grktsh can you include this fix, too?
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.
@macjohnny I will!
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.
@macjohnny Done. Could you review again?
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.
"*/ ' \" =end -- \r\n \n \r"
is for detecting code injection (malicious input in consumes
). I'll add it back with a separate PR.
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.
Done via d57009d
50dc4f2
to
28b06ff
Compare
@grktsh @macjohnny Do we need the similar fix for other TS generators? (this is not to say either one of you will need to submit the fix or own the issue. Just want to know if other TS generators have a similar bug) |
@grktsh thanks for the contribution, which has been included in the 4.0.0-beta release: https://twitter.com/oas_generator/status/1079727020374806529. Happy New Year and looking forward to more collaboration and contributions in 2019! |
…#1611) * [typescript] Avoid strictNullChecks errors for apiKeys fix OpenAPITools#1607 * Run ./bin/{LANG}-petstore.sh - ./bin/typescript-angular-petstore-all.sh - ./bin/typescript-inversify-petstore.sh * Run ./bin/security/{LANG}-petstore.sh - ./bin/security/typescript-angular.sh - ./bin/security/typescript-angular2.sh - ./bin/security/typescript-inversify.sh * [typescript] Fix parameter name sanitization * Fix invalid consumes of petstore-security-test.yaml * Run ./bin/security/typescript-*.sh
fix #1607
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if 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\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
I'd like to add
this.configuration.apiKeys &&
to the following conditions to avoid strictNullChecks errors for apiKeys:from typescript-angular/api.service.mustache@master
from typescript-inversify/api.service.mustache@master
@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10)