-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Fix dangerous destructuration in typescript-nestjs services #20157
Changes from 4 commits
3a8800e
9d9259e
eabc989
9c7fcfa
d87f086
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
generatorName: typescript-nestjs | ||
outputDir: samples/client/petstore/typescript-nestjs/builds/reservedParamNames | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-nestjs/reserved-param-names.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs | ||
additionalProperties: | ||
"useSingleRequestParameter" : true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ export interface {{classname}}{{operationIdCamelCase}}Request { | |
* @type {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> | ||
* @memberof {{classname}}{{operationIdCamelCase}} | ||
*/ | ||
readonly {{paramName}}{{^required}}?{{/required}}: {{{dataType}}} | ||
readonly {{#hasSanitizedName}}'{{{baseName}}}'{{/hasSanitizedName}}{{^hasSanitizedName}}{{{paramName}}}{{/hasSanitizedName}}{{^required}}?{{/required}}: {{{dataType}}} | ||
{{^-last}} | ||
|
||
{{/-last}} | ||
|
@@ -106,7 +106,7 @@ export class {{classname}} { | |
{{#useSingleRequestParameter}} | ||
const { | ||
{{#allParams}} | ||
{{paramName}}, | ||
{{#hasSanitizedName}}'{{{baseName}}}': {{/hasSanitizedName}}{{paramName}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not an object, but destructuring the request parameters, please revert this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, it's to keep the request parameter with the original names while renaming the params in this method to avoid conflicts with existing properties. const {
notReserved,
'from': _from,
'headers': _headers,
} = requestParameters; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i see, i didnt know this is possible |
||
{{/allParams}} | ||
} = requestParameters; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
openapi: 3.0.0 | ||
info: | ||
description: Test reserved param names | ||
version: 1.0.0 | ||
title: Reserved param names | ||
paths: | ||
/test: | ||
post: | ||
security: | ||
- bearerAuth: [] | ||
summary: Test reserved param names | ||
description: '' | ||
operationId: testReservedParamNames | ||
parameters: | ||
- name: notReserved | ||
in: query | ||
description: Should not be treated as a reserved param name | ||
required: true | ||
schema: | ||
type: string | ||
- name: from | ||
in: query | ||
description: Might conflict with rxjs import | ||
required: true | ||
schema: | ||
type: string | ||
- name: headers | ||
in: header | ||
description: Might conflict with headers const | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: successful operation | ||
'405': | ||
description: Invalid input | ||
components: | ||
securitySchemes: | ||
bearerAuth: | ||
type: http | ||
scheme: bearer | ||
bearerFormat: JWT |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
wwwroot/*.js | ||
node_modules | ||
typings | ||
dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.gitignore | ||
README.md | ||
api.module.ts | ||
api/api.ts | ||
api/default.service.ts | ||
configuration.ts | ||
git_push.sh | ||
index.ts | ||
model/models.ts | ||
variables.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.11.0-SNAPSHOT |
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.
please separate this change of parameters into a separate PR. also, is there an easier way than to
extends CodegenParameter
?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 was inpired by the typescript-fetch generator. If you know a better way to do it I can make the changes
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.
ah i see. the risk is just that whenever new properties are added to the CodegenParameter, we will probably forget to add them here. can this be automated/avoided somehow?
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 see uses of
param.vendorExtensions
in others generators:openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java
Line 204 in ed21105
Do you think it would be a better approach as it doesn't require to extend
CodegenParameter
?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.
oh that sounds compelling, yes please try if that works!
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 ! It works as well 😃
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.
thanks!
are you motivated to also do that for the typescript-fetch generator in 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.
You mean using
vendorExtensions
instead of extendingCodegenParameter
? Or keeping original names in requestParameters interfaces ? Or both maybe ? 😃