-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[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
Changes from 4 commits
39b0eaf
1fae8c2
617a8f6
cd3b9a1
f3b4491
bb85c06
57ec23f
702fa69
0f46899
b6d0a1a
387123d
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-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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 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.
Outdated
aryobenholzner marked this conversation as resolved.
Outdated
|
||
| const request = ctx.switchToHttp().getRequest(); | ||
| return data ? request.cookies?.[data] : request.cookies; | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| }); | ||
| 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, Delete, Get, Post, Put, Param, Query, Headers, Req } from '@nestjs/common'; | ||
|
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: Form and file parameters are missing NestJS parameter decorators, so these values will be undefined at runtime and the API handlers receive no form/file data. Prompt for AI agents |
||
| import { Observable } from 'rxjs'; | ||
| import { Cookies } from '../cookies-decorator'; | ||
| 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); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 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(); | ||
| return data ? request.cookies?.[data] : request.cookies; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # compiled output | ||
| /dist | ||
| /node_modules | ||
| /build | ||
|
|
||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| pnpm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| lerna-debug.log* | ||
|
|
||
| # OS | ||
| .DS_Store | ||
|
|
||
| # Tests | ||
| /coverage | ||
| /.nyc_output | ||
|
|
||
| # IDEs and editors | ||
| /.idea | ||
| .project | ||
| .classpath | ||
| .c9/ | ||
| *.launch | ||
| .settings/ | ||
| *.sublime-workspace | ||
|
|
||
| # IDE - VSCode | ||
| .vscode/* | ||
| !.vscode/settings.json | ||
| !.vscode/tasks.json | ||
| !.vscode/launch.json | ||
| !.vscode/extensions.json | ||
|
|
||
| # dotenv environment variable files | ||
| .env | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .env.local | ||
|
|
||
| # temp directory | ||
| .temp | ||
| .tmp | ||
|
|
||
| # Runtime data | ||
| pids | ||
| *.pid | ||
| *.seed | ||
| *.pid.lock | ||
|
|
||
| # Diagnostic reports (https://nodejs.org/api/report.html) | ||
| report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json |
| 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 |
Uh oh!
There was an error while loading. Please reload this page.