Skip to content

Commit 0f46899

Browse files
[typescript-nestjs-server] #22928 updated README, additional PR feedback
1 parent 702fa69 commit 0f46899

10 files changed

Lines changed: 103 additions & 28 deletions

File tree

modules/openapi-generator/src/main/resources/typescript-nestjs-server/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Usage: The generated output is intended to be its own module, that can be imported into your NestJS App Module. You do not need to change generated files, just import the module and implement the API
44

5+
Currently, only Express is supported.
6+
57
Example usage (with the openapi sample `petstore.yaml`):
68

79
1. Invoke openapi-generator
@@ -28,7 +30,7 @@ Example usage (with the openapi sample `petstore.yaml`):
2830

2931
...
3032
```
31-
3. Import the generated `ApiModule` with `ApiModule.forRoot` and provide a instance of `ApiImplementations` with a reference to your implementation
33+
3. Import the generated `ApiModule` with `ApiModule.forRoot` and provide an instance of `ApiImplementations` with a reference to your implementation
3234
`app.module.ts`
3335
```typescript
3436
import { Module } from "@nestjs/common";
@@ -45,12 +47,35 @@ Example usage (with the openapi sample `petstore.yaml`):
4547

4648
@Module({
4749
imports: [
48-
ApiModule.forRoot(apiImplementations),
50+
ApiModule.forRoot({
51+
apiImplementations: apiImplementations,
52+
providers: [
53+
// additional providers for services injected into apiImplementations
54+
]
55+
}),
4956
],
5057
controllers: [],
5158
providers: [],
5259
})
5360
export class AppModule {}
5461
```
5562
56-
You now can regenerate the API module as often as you want without overriding your implementation.
63+
You now can regenerate the API module as often as you want without overriding your implementation.
64+
65+
## Using Cookie parameters
66+
67+
In order for cookie parameters to work, the the framework specific cookie middleware must be enabled.
68+
69+
For Express, the `cookie-parser` middleware must be installed and enabled.
70+
71+
```
72+
npm install cookie-parser
73+
```
74+
75+
in `main.ts`
76+
77+
```
78+
import * as cookieParser from 'cookie-parser';
79+
80+
app.use(cookieParser());
81+
```

modules/openapi-generator/src/main/resources/typescript-nestjs-server/cookies-decorator.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
1515
* findAll(@Cookies('name') name: string) {}
1616
* ```
1717
*/
18-
export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => {
18+
export const Cookies = createParamDecorator((cookieName: string, ctx: ExecutionContext) => {
1919
const request = ctx.switchToHttp().getRequest();
20-
if (!data) {
20+
if (!cookieName) {
2121
return { ...request.cookies, ...request.signedCookies };
2222
}
23-
return request.cookies?.[data] ?? request.signedCookies?.[data];
23+
return request.cookies?.[cookieName] ?? request.signedCookies?.[cookieName];
2424
});

modules/openapi-generator/src/main/resources/typescript-nestjs-server/headers-decorator.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
1010
* findAll(@Headers('name') name: string) {}
1111
* ```
1212
*/
13-
export const Headers = createParamDecorator((data: string, ctx: ExecutionContext) => {
14-
const request = ctx.switchToHttp().getRequest();
15-
return data ? request.headers?.[data.toLowerCase()] : request.headers;
13+
export const Headers = createParamDecorator((headerName: string, ctx: ExecutionContext) => {
14+
const request = ctx.switchToHttp().getRequest();
15+
return headerName ? request.headers?.[headerName.toLowerCase()] : request.headers;
1616
});

samples/server/petstore/typescript-nestjs-server/builds/default/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Usage: The generated output is intended to be its own module, that can be imported into your NestJS App Module. You do not need to change generated files, just import the module and implement the API
44

5+
Currently, only Express is supported.
6+
57
Example usage (with the openapi sample `petstore.yaml`):
68

79
1. Invoke openapi-generator
@@ -28,7 +30,7 @@ Example usage (with the openapi sample `petstore.yaml`):
2830

2931
...
3032
```
31-
3. Import the generated `ApiModule` with `ApiModule.forRoot` and provide a instance of `ApiImplementations` with a reference to your implementation
33+
3. Import the generated `ApiModule` with `ApiModule.forRoot` and provide an instance of `ApiImplementations` with a reference to your implementation
3234
`app.module.ts`
3335
```typescript
3436
import { Module } from "@nestjs/common";
@@ -45,12 +47,35 @@ Example usage (with the openapi sample `petstore.yaml`):
4547

4648
@Module({
4749
imports: [
48-
ApiModule.forRoot(apiImplementations),
50+
ApiModule.forRoot({
51+
apiImplementations: apiImplementations,
52+
providers: [
53+
// additional providers for services injected into apiImplementations
54+
]
55+
}),
4956
],
5057
controllers: [],
5158
providers: [],
5259
})
5360
export class AppModule {}
5461
```
5562
56-
You now can regenerate the API module as often as you want without overriding your implementation.
63+
You now can regenerate the API module as often as you want without overriding your implementation.
64+
65+
## Using Cookie parameters
66+
67+
In order for cookie parameters to work, the the framework specific cookie middleware must be enabled.
68+
69+
For Express, the `cookie-parser` middleware must be installed and enabled.
70+
71+
```
72+
npm install cookie-parser
73+
```
74+
75+
in `main.ts`
76+
77+
```
78+
import * as cookieParser from 'cookie-parser';
79+
80+
app.use(cookieParser());
81+
```

samples/server/petstore/typescript-nestjs-server/builds/default/decorators/cookies-decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
1515
* findAll(@Cookies('name') name: string) {}
1616
* ```
1717
*/
18-
export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => {
18+
export const Cookies = createParamDecorator((cookieName: string, ctx: ExecutionContext) => {
1919
const request = ctx.switchToHttp().getRequest();
20-
if (!data) {
20+
if (!cookieName) {
2121
return { ...request.cookies, ...request.signedCookies };
2222
}
23-
return request.cookies?.[data] ?? request.signedCookies?.[data];
23+
return request.cookies?.[cookieName] ?? request.signedCookies?.[cookieName];
2424
});

samples/server/petstore/typescript-nestjs-server/builds/default/decorators/headers-decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
1010
* findAll(@Headers('name') name: string) {}
1111
* ```
1212
*/
13-
export const Headers = createParamDecorator((data: string, ctx: ExecutionContext) => {
14-
const request = ctx.switchToHttp().getRequest();
15-
return data ? request.headers?.[data.toLowerCase()] : request.headers;
13+
export const Headers = createParamDecorator((headerName: string, ctx: ExecutionContext) => {
14+
const request = ctx.switchToHttp().getRequest();
15+
return headerName ? request.headers?.[headerName.toLowerCase()] : request.headers;
1616
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.20.0-SNAPSHOT
1+
7.21.0-SNAPSHOT

samples/server/petstore/typescript-nestjs-server/builds/parameters/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Usage: The generated output is intended to be its own module, that can be imported into your NestJS App Module. You do not need to change generated files, just import the module and implement the API
44

5+
Currently, only Express is supported.
6+
57
Example usage (with the openapi sample `petstore.yaml`):
68

79
1. Invoke openapi-generator
@@ -28,7 +30,7 @@ Example usage (with the openapi sample `petstore.yaml`):
2830

2931
...
3032
```
31-
3. Import the generated `ApiModule` with `ApiModule.forRoot` and provide a instance of `ApiImplementations` with a reference to your implementation
33+
3. Import the generated `ApiModule` with `ApiModule.forRoot` and provide an instance of `ApiImplementations` with a reference to your implementation
3234
`app.module.ts`
3335
```typescript
3436
import { Module } from "@nestjs/common";
@@ -45,12 +47,35 @@ Example usage (with the openapi sample `petstore.yaml`):
4547

4648
@Module({
4749
imports: [
48-
ApiModule.forRoot(apiImplementations),
50+
ApiModule.forRoot({
51+
apiImplementations: apiImplementations,
52+
providers: [
53+
// additional providers for services injected into apiImplementations
54+
]
55+
}),
4956
],
5057
controllers: [],
5158
providers: [],
5259
})
5360
export class AppModule {}
5461
```
5562
56-
You now can regenerate the API module as often as you want without overriding your implementation.
63+
You now can regenerate the API module as often as you want without overriding your implementation.
64+
65+
## Using Cookie parameters
66+
67+
In order for cookie parameters to work, the the framework specific cookie middleware must be enabled.
68+
69+
For Express, the `cookie-parser` middleware must be installed and enabled.
70+
71+
```
72+
npm install cookie-parser
73+
```
74+
75+
in `main.ts`
76+
77+
```
78+
import * as cookieParser from 'cookie-parser';
79+
80+
app.use(cookieParser());
81+
```

samples/server/petstore/typescript-nestjs-server/builds/parameters/decorators/cookies-decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
1515
* findAll(@Cookies('name') name: string) {}
1616
* ```
1717
*/
18-
export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => {
18+
export const Cookies = createParamDecorator((cookieName: string, ctx: ExecutionContext) => {
1919
const request = ctx.switchToHttp().getRequest();
20-
if (!data) {
20+
if (!cookieName) {
2121
return { ...request.cookies, ...request.signedCookies };
2222
}
23-
return request.cookies?.[data] ?? request.signedCookies?.[data];
23+
return request.cookies?.[cookieName] ?? request.signedCookies?.[cookieName];
2424
});

samples/server/petstore/typescript-nestjs-server/builds/parameters/decorators/headers-decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
1010
* findAll(@Headers('name') name: string) {}
1111
* ```
1212
*/
13-
export const Headers = createParamDecorator((data: string, ctx: ExecutionContext) => {
14-
const request = ctx.switchToHttp().getRequest();
15-
return data ? request.headers?.[data.toLowerCase()] : request.headers;
13+
export const Headers = createParamDecorator((headerName: string, ctx: ExecutionContext) => {
14+
const request = ctx.switchToHttp().getRequest();
15+
return headerName ? request.headers?.[headerName.toLowerCase()] : request.headers;
1616
});

0 commit comments

Comments
 (0)