File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main
java/org/openapitools/codegen/languages
resources/typescript-nestjs-server
samples/server/petstore/typescript-nestjs-server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,6 +278,14 @@ private boolean isLanguagePrimitive(String type) {
278278 return languageSpecificPrimitives .contains (type ) || isInlineUnion (type );
279279 }
280280
281+ /**
282+ * <p>
283+ * Determines if the given type is an inline union of strings, described as an enum without being an explicit component in OpenAPI spec.
284+ * </p>
285+ * Example input that matches: {@code "'A' | 'B'" }
286+ *
287+ * @param type The Typescript type to evaluate.
288+ */
281289 private boolean isInlineUnion (String type ) {
282290 return Arrays .stream (type .split ("\\ |" ))
283291 .map (String ::trim )
@@ -301,7 +309,7 @@ private boolean isRecordType(String type) {
301309 public void postProcessParameter (CodegenParameter parameter ) {
302310 super .postProcessParameter (parameter );
303311 parameter .dataType = applyLocalTypeMapping (parameter .dataType );
304- if ("undefined" .equals (parameter .defaultValue )) {
312+ if ("undefined" .equals (parameter .defaultValue )) {
305313 parameter .defaultValue = null ;
306314 }
307315 }
Original file line number Diff line number Diff line change 11import { createParamDecorator, ExecutionContext } from '@nestjs/common';
22
3+ /**
4+ * A decorator function for retrieving cookies from the request object in an HTTP context.
5+ *
6+ * This decorator only works, if the framework specific cookie middleware is installed and enabled.
7+ * - For Express, you need to use the `cookie-parser` middleware.
8+ * - For Fastify, you need to use the `@fastify/cookie` plugin.
9+ *
10+ * Consult https://docs.nestjs.com/techniques/cookies for further information
11+ *
12+ * Usage:
13+ * ```
14+ * @Get()
15+ * findAll(@Cookies('name') name: string) { }
16+ * ```
17+ */
318export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => {
4- const request = ctx.switchToHttp().getRequest();
5- return data ? request.cookies?.[data] : request.cookies;
19+ const request = ctx.switchToHttp().getRequest();
20+ return data ? request.cookies?.[data] : request.cookies;
621} );
Original file line number Diff line number Diff line change 11import { createParamDecorator , ExecutionContext } from '@nestjs/common' ;
22
3+ /**
4+ * A decorator function for retrieving cookies from the request object in an HTTP context.
5+ *
6+ * This decorator only works, if the framework specific cookie middleware is installed and enabled.
7+ * - For Express, you need to use the `cookie-parser` middleware.
8+ * - For Fastify, you need to use the `@fastify/cookie` plugin.
9+ *
10+ * Consult https://docs.nestjs.com/techniques/cookies for further information
11+ *
12+ * Usage:
13+ * ```
14+ * @Get ()
15+ * findAll(@Cookies('name') name: string) {}
16+ * ```
17+ */
318export const Cookies = createParamDecorator ( ( data : string , ctx : ExecutionContext ) => {
4- const request = ctx . switchToHttp ( ) . getRequest ( ) ;
5- return data ? request . cookies ?. [ data ] : request . cookies ;
19+ const request = ctx . switchToHttp ( ) . getRequest ( ) ;
20+ return data ? request . cookies ?. [ data ] : request . cookies ;
621} ) ;
Original file line number Diff line number Diff line change 11import { createParamDecorator , ExecutionContext } from '@nestjs/common' ;
22
3+ /**
4+ * A decorator function for retrieving cookies from the request object in an HTTP context.
5+ *
6+ * This decorator only works, if the framework specific cookie middleware is installed and enabled.
7+ * - For Express, you need to use the `cookie-parser` middleware.
8+ * - For Fastify, you need to use the `@fastify/cookie` plugin.
9+ *
10+ * Consult https://docs.nestjs.com/techniques/cookies for further information
11+ *
12+ * Usage:
13+ * ```
14+ * @Get ()
15+ * findAll(@Cookies('name') name: string) {}
16+ * ```
17+ */
318export const Cookies = createParamDecorator ( ( data : string , ctx : ExecutionContext ) => {
4- const request = ctx . switchToHttp ( ) . getRequest ( ) ;
5- return data ? request . cookies ?. [ data ] : request . cookies ;
19+ const request = ctx . switchToHttp ( ) . getRequest ( ) ;
20+ return data ? request . cookies ?. [ data ] : request . cookies ;
621} ) ;
Original file line number Diff line number Diff line change @@ -58,9 +58,10 @@ describe('AppModule (e2e)', () => {
5858 it ( 'should set default parameters' , ( ) => {
5959 let defaultService : DefaultService = app . get ( DefaultApi ) ;
6060
61- request ( app . getHttpServer ( ) )
61+ return request ( app . getHttpServer ( ) )
6262 . get ( '/test/parameters/path_a/path_b' )
63- . expect ( 200 , ( ) => {
63+ . expect ( 200 )
64+ . then ( ( ) => {
6465 expect ( defaultService . lastRequestParams ) . toEqual ( {
6566 pathDefault : 'path_a' ,
6667 pathNullable : 'path_b' ,
@@ -84,7 +85,7 @@ describe('AppModule (e2e)', () => {
8485 it ( 'should receive request parameters' , ( ) => {
8586 let defaultService : DefaultService = app . get ( DefaultApi ) ;
8687
87- request ( app . getHttpServer ( ) )
88+ return request ( app . getHttpServer ( ) )
8889 . get ( '/test/parameters/path_a/path_b' )
8990 . query ( {
9091 query_default : 'custom_query' ,
@@ -101,7 +102,8 @@ describe('AppModule (e2e)', () => {
101102 'Cookie' ,
102103 'cookie_default=custom_cookie; cookie_default_enum=C; cookie_default_int=7; cookie_nullable=a_cookie' ,
103104 )
104- . expect ( 200 , ( ) => {
105+ . expect ( 200 )
106+ . then ( ( ) => {
105107 expect ( defaultService . lastRequestParams ) . toEqual ( {
106108 pathDefault : 'path_a' ,
107109 pathNullable : 'path_b' ,
You can’t perform that action at this time.
0 commit comments