-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[typescript-nestjs-server] #22928 improve request parameter handling #22960
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
Open
aryobenholzner
wants to merge
7
commits into
OpenAPITools:master
Choose a base branch
from
aryobenholzner:bugfix/22928-parameter-handling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+694
−47
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39b0eaf
[typescript-nestjs-server] #22928 exclude inline union strings from g…
aryobenholzner 1fae8c2
[typescript-nestjs-server] #22928 add optional type hints
aryobenholzner 617a8f6
[typescript-nestjs-server] #22928 add/improve support for various par…
aryobenholzner cd3b9a1
[typescript-nestjs-server] #22928 add docs, fix indentations and test…
aryobenholzner f3b4491
[typescript-nestjs-server] #22928 correctly parse numeric parameters,…
aryobenholzner bb85c06
[typescript-nestjs-server] #22928 lowercase header access, check each…
aryobenholzner 57ec23f
[typescript-nestjs-server] #22928 allow optional parameters for numbe…
aryobenholzner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| generatorName: typescript-nestjs-server | ||
| outputDir: samples/server/petstore/typescript-nestjs-server/builds/parameters | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/parameter-test-spec.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs-server | ||
| additionalProperties: | ||
| "useSingleRequestParameter" : true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../openapi-generator/src/main/resources/typescript-nestjs-server/cookies-decorator.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
|
||
| /** | ||
| * A decorator function for retrieving cookies from the request object in an HTTP context. | ||
| * | ||
| * This decorator only works, if the framework specific cookie middleware is installed and enabled. | ||
| * - For Express, you need to use the `cookie-parser` middleware. | ||
| * - For Fastify, you need to use the `@fastify/cookie` plugin. | ||
| * | ||
| * Consult https://docs.nestjs.com/techniques/cookies for further information | ||
| * | ||
| * Usage: | ||
| * ``` | ||
| * @Get() | ||
| * findAll(@Cookies('name') name: string) {} | ||
| * ``` | ||
| */ | ||
| export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => { | ||
aryobenholzner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const request = ctx.switchToHttp().getRequest(); | ||
| if (!data) { | ||
| return { ...request.cookies, ...request.signedCookies }; | ||
| } | ||
| return request.cookies?.[data] ?? request.signedCookies?.[data]; | ||
| }); | ||
2 changes: 2 additions & 0 deletions
2
modules/openapi-generator/src/main/resources/typescript-nestjs-server/decorators.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './cookies-decorator'; | ||
| export * from './headers-decorator'; |
16 changes: 16 additions & 0 deletions
16
.../openapi-generator/src/main/resources/typescript-nestjs-server/headers-decorator.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
|
||
| /** | ||
| * A decorator function for retrieving headers from the request object in an HTTP context. | ||
| * Workaround for enabling PipeTransformers on Headers (see https://github.com/nestjs/nest/issues/356) | ||
| * | ||
| * Usage: | ||
| * ``` | ||
| * @Get() | ||
| * findAll(@Headers('name') name: string) {} | ||
| * ``` | ||
| */ | ||
| export const Headers = createParamDecorator((data: string, ctx: ExecutionContext) => { | ||
| const request = ctx.switchToHttp().getRequest(); | ||
| return data ? request.headers?.[data.toLowerCase()] : request.headers; | ||
| }); |
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/main/resources/typescript-nestjs-server/paramPipe.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#defaultValue}}, new DefaultValuePipe({{{defaultValue}}}){{/defaultValue}}{{#isNumber}}, new {{#isFloat}}ParseFloatPipe({{/isFloat}}{{^isFloat}}ParseIntPipe({{/isFloat}}{{^isRequired}}{optional: true}{{/isRequired}}{{#isNullable}}{optional: true}{{/isNullable}}){{/isNumber}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { Body, Controller, Delete, Get, Post, Put, Param, Query, Req } from '@nestjs/common'; | ||
| import { Body, Controller, DefaultValuePipe, Delete, Get, Post, Put, Param, ParseIntPipe, ParseFloatPipe, Query, Req } from '@nestjs/common'; | ||
| import { Observable } from 'rxjs'; | ||
| import { Cookies, Headers } from '../decorators'; | ||
| import { PetApi } from '../api'; | ||
| import { ApiResponse, Pet, } from '../models'; | ||
|
|
||
|
|
@@ -13,7 +14,7 @@ export class PetApiController { | |
| } | ||
|
|
||
| @Delete('/pet/:petId') | ||
| deletePet(@Param('petId') petId: number, apiKey: string, @Req() request: Request): void | Promise<void> | Observable<void> { | ||
| deletePet(@Param('petId') petId: number, @Headers('api_key') apiKey: string | undefined, @Req() request: Request): void | Promise<void> | Observable<void> { | ||
| return this.petApi.deletePet(petId, apiKey, request); | ||
| } | ||
|
|
||
|
|
@@ -38,12 +39,12 @@ export class PetApiController { | |
| } | ||
|
|
||
| @Post('/pet/:petId') | ||
| updatePetWithForm(@Param('petId') petId: number, name: string, status: string, @Req() request: Request): void | Promise<void> | Observable<void> { | ||
| updatePetWithForm(@Param('petId') petId: number, name: string | undefined, status: string | undefined, @Req() request: Request): void | Promise<void> | Observable<void> { | ||
| return this.petApi.updatePetWithForm(petId, name, status, request); | ||
| } | ||
|
|
||
| @Post('/pet/:petId/uploadImage') | ||
| uploadFile(@Param('petId') petId: number, additionalMetadata: string, file: Blob, @Req() request: Request): ApiResponse | Promise<ApiResponse> | Observable<ApiResponse> { | ||
| uploadFile(@Param('petId') petId: number, additionalMetadata: string | undefined, file: Blob | undefined, @Req() request: Request): ApiResponse | Promise<ApiResponse> | Observable<ApiResponse> { | ||
|
Contributor
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. P2: Upload endpoint defines a Prompt for AI agents |
||
| return this.petApi.uploadFile(petId, additionalMetadata, file, request); | ||
| } | ||
|
|
||
|
|
||
3 changes: 2 additions & 1 deletion
3
...erver/petstore/typescript-nestjs-server/builds/default/controllers/StoreApi.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...server/petstore/typescript-nestjs-server/builds/default/controllers/UserApi.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...s/server/petstore/typescript-nestjs-server/builds/default/decorators/cookies-decorator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
|
||
| /** | ||
| * A decorator function for retrieving cookies from the request object in an HTTP context. | ||
| * | ||
| * This decorator only works, if the framework specific cookie middleware is installed and enabled. | ||
| * - For Express, you need to use the `cookie-parser` middleware. | ||
| * - For Fastify, you need to use the `@fastify/cookie` plugin. | ||
| * | ||
| * Consult https://docs.nestjs.com/techniques/cookies for further information | ||
| * | ||
| * Usage: | ||
| * ``` | ||
| * @Get() | ||
| * findAll(@Cookies('name') name: string) {} | ||
| * ``` | ||
| */ | ||
| export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => { | ||
| const request = ctx.switchToHttp().getRequest(); | ||
| if (!data) { | ||
| return { ...request.cookies, ...request.signedCookies }; | ||
| } | ||
| return request.cookies?.[data] ?? request.signedCookies?.[data]; | ||
| }); |
16 changes: 16 additions & 0 deletions
16
...s/server/petstore/typescript-nestjs-server/builds/default/decorators/headers-decorator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
|
||
| /** | ||
| * A decorator function for retrieving headers from the request object in an HTTP context. | ||
| * Workaround for enabling PipeTransformers on Headers (see https://github.com/nestjs/nest/issues/356) | ||
| * | ||
| * Usage: | ||
| * ``` | ||
| * @Get() | ||
| * findAll(@Headers('name') name: string) {} | ||
| * ``` | ||
| */ | ||
| export const Headers = createParamDecorator((data: string, ctx: ExecutionContext) => { | ||
| const request = ctx.switchToHttp().getRequest(); | ||
| return data ? request.headers?.[data.toLowerCase()] : request.headers; | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.