Skip to content

Commit fcc83db

Browse files
NestJS server codegen (#21494)
* setup basic codegen for nestjs server * set up generated file structure * adapted moustache files * fixed imports * adapted templates * added module bootstrap * added model generation * fixed error with generic type * added README * added usage clarification to README, introduced module index.ts * Update modules/openapi-generator/src/main/resources/typescript-nestjs-server/api.module.mustache Co-authored-by: Esteban Gehring <[email protected]> * cleaned up package.mustache, added parameters for versions * cleaned up unneeded boilerplate templates * fixed indentations from templates * implemented useSingleRequestParameter * fixed parameter handling * added samples with tests * added docs * fixed samples * corrected docs * updated docs after merge of master * fixed samples build * fixed workflow --------- Co-authored-by: Esteban Gehring <[email protected]>
1 parent 3fbf52f commit fcc83db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+14303
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: TypeScript NestJS Server
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- samples/server/petstore/typescript-nestjs-server/**
7+
- .github/workflows/samples-typescript-nestjs-server.yaml
8+
jobs:
9+
build:
10+
name: Test TypeScript NestJS Server
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
sample:
16+
# clients
17+
- samples/server/petstore/typescript-nestjs-server
18+
node-version:
19+
- 20
20+
- 22
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
- name: Install
29+
working-directory: ${{ matrix.sample }}
30+
run: |
31+
npm i
32+
33+
- name: Test
34+
working-directory: ${{ matrix.sample }}
35+
run: npm run test

CI/circle_parallel.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ elif [ "$NODE_INDEX" = "3" ]; then
115115
(cd samples/client/petstore/javascript-flowtyped && mvn integration-test)
116116
(cd samples/client/petstore/javascript-es6 && mvn integration-test)
117117
(cd samples/client/petstore/javascript-promise-es6 && mvn integration-test)
118+
(cd samples/server/petstore/typescript-nestjs-server && mvn integration-test)
118119

119120
else
120121
echo "Running node $NODE_INDEX ..."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
generatorName: typescript-nestjs-server
2+
outputDir: samples/server/petstore/typescript-nestjs-server/builds/default
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs-server

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ The following generators are available:
152152
* [scala-play-server](generators/scala-play-server.md)
153153
* [scalatra](generators/scalatra.md)
154154
* [spring](generators/spring.md)
155+
* [typescript-nestjs-server (beta)](generators/typescript-nestjs-server.md)
155156

156157

157158
## DOCUMENTATION generators
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
---
2+
title: Documentation for the typescript-nestjs-server Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | typescript-nestjs-server | pass this to the generate command after -g |
10+
| generator stability | BETA | |
11+
| generator type | SERVER | |
12+
| generator language | Typescript | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a TypeScript NestJS server stub. | |
15+
16+
## CONFIG OPTIONS
17+
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
18+
19+
| Option | Description | Values | Default |
20+
| ------ | ----------- | ------ | ------- |
21+
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
22+
|apiFileSuffix|The suffix of the file of the generated API class (api&lt;suffix&gt;.ts).| |.api|
23+
|apiSuffix|The suffix of the generated API class| |Api|
24+
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
25+
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
26+
|enumNameSuffix|Suffix that will be appended to all enum names.| |Enum|
27+
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase|
28+
|enumPropertyNamingReplaceSpecialChar|Set to true to replace '-' and '+' symbols with 'minus_' and 'plus_' in enum of type string| |false|
29+
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
30+
|fileNaming|Naming convention for the output files: 'camelCase', 'kebab-case'.| |kebab-case|
31+
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
32+
|licenseName|The name of the license| |Unlicense|
33+
|modelFileSuffix|The suffix of the file of the generated model (model&lt;suffix&gt;.ts).| |null|
34+
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original|
35+
|modelSuffix|The suffix of the generated model.| |null|
36+
|nestVersion|The version of Nestjs. (At least 10.0.0)| |10.0.0|
37+
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
38+
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
39+
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|
40+
|nullSafeAdditionalProps|Set to make additional properties types declare that their indexer may return undefined| |false|
41+
|paramNaming|Naming convention for parameters: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
42+
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
43+
|rxjsVersion|The version of RxJS compatible with Angular (see ngVersion option).| |null|
44+
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
45+
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
46+
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
47+
|stringEnums|Generate string enums instead of objects for enum values.| |false|
48+
|supportsES6|Generate code that conforms to ES6.| |false|
49+
|taggedUnions|Use discriminators to create tagged unions instead of extending interfaces.| |false|
50+
|tsVersion|The version of typescript compatible with Angular (see ngVersion option).| |null|
51+
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
52+
53+
## IMPORT MAPPING
54+
55+
| Type/Alias | Imports |
56+
| ---------- | ------- |
57+
58+
59+
## INSTANTIATION TYPES
60+
61+
| Type/Alias | Instantiated By |
62+
| ---------- | --------------- |
63+
|array|Array|
64+
65+
66+
## LANGUAGE PRIMITIVES
67+
68+
<ul class="column-ul">
69+
<li>Array</li>
70+
<li>Awaited</li>
71+
<li>Blob</li>
72+
<li>Boolean</li>
73+
<li>Capitalize</li>
74+
<li>ConstructorParameters</li>
75+
<li>Date</li>
76+
<li>Double</li>
77+
<li>Error</li>
78+
<li>Exclude</li>
79+
<li>Extract</li>
80+
<li>File</li>
81+
<li>Float</li>
82+
<li>InstanceType</li>
83+
<li>Integer</li>
84+
<li>Long</li>
85+
<li>Lowercase</li>
86+
<li>Map</li>
87+
<li>NoInfer</li>
88+
<li>NonNullable</li>
89+
<li>Object</li>
90+
<li>Omit</li>
91+
<li>OmitThisParameter</li>
92+
<li>Parameters</li>
93+
<li>Partial</li>
94+
<li>Pick</li>
95+
<li>Readonly</li>
96+
<li>ReadonlyArray</li>
97+
<li>Record</li>
98+
<li>Required</li>
99+
<li>ReturnType</li>
100+
<li>Set</li>
101+
<li>String</li>
102+
<li>ThisParameterType</li>
103+
<li>ThisType</li>
104+
<li>Uncapitalize</li>
105+
<li>Uppercase</li>
106+
<li>any</li>
107+
<li>boolean</li>
108+
<li>number</li>
109+
<li>object</li>
110+
<li>string</li>
111+
</ul>
112+
113+
## RESERVED WORDS
114+
115+
<ul class="column-ul">
116+
<li>abstract</li>
117+
<li>await</li>
118+
<li>boolean</li>
119+
<li>break</li>
120+
<li>byte</li>
121+
<li>case</li>
122+
<li>catch</li>
123+
<li>char</li>
124+
<li>class</li>
125+
<li>const</li>
126+
<li>continue</li>
127+
<li>debugger</li>
128+
<li>default</li>
129+
<li>delete</li>
130+
<li>do</li>
131+
<li>double</li>
132+
<li>else</li>
133+
<li>enum</li>
134+
<li>export</li>
135+
<li>extends</li>
136+
<li>false</li>
137+
<li>final</li>
138+
<li>finally</li>
139+
<li>float</li>
140+
<li>for</li>
141+
<li>formParams</li>
142+
<li>from</li>
143+
<li>function</li>
144+
<li>goto</li>
145+
<li>headerParams</li>
146+
<li>headers</li>
147+
<li>if</li>
148+
<li>implements</li>
149+
<li>import</li>
150+
<li>in</li>
151+
<li>instanceof</li>
152+
<li>int</li>
153+
<li>interface</li>
154+
<li>let</li>
155+
<li>long</li>
156+
<li>native</li>
157+
<li>new</li>
158+
<li>null</li>
159+
<li>package</li>
160+
<li>private</li>
161+
<li>protected</li>
162+
<li>public</li>
163+
<li>queryParameters</li>
164+
<li>requestOptions</li>
165+
<li>return</li>
166+
<li>short</li>
167+
<li>static</li>
168+
<li>super</li>
169+
<li>switch</li>
170+
<li>synchronized</li>
171+
<li>this</li>
172+
<li>throw</li>
173+
<li>transient</li>
174+
<li>true</li>
175+
<li>try</li>
176+
<li>typeof</li>
177+
<li>useFormData</li>
178+
<li>var</li>
179+
<li>varLocalDeferred</li>
180+
<li>varLocalPath</li>
181+
<li>void</li>
182+
<li>volatile</li>
183+
<li>while</li>
184+
<li>with</li>
185+
<li>yield</li>
186+
</ul>
187+
188+
## FEATURE SET
189+
190+
191+
### Client Modification Feature
192+
| Name | Supported | Defined By |
193+
| ---- | --------- | ---------- |
194+
|BasePath|✓|ToolingExtension
195+
|Authorizations|✗|ToolingExtension
196+
|UserAgent|✗|ToolingExtension
197+
|MockServer|✗|ToolingExtension
198+
199+
### Data Type Feature
200+
| Name | Supported | Defined By |
201+
| ---- | --------- | ---------- |
202+
|Custom|✗|OAS2,OAS3
203+
|Int32|✓|OAS2,OAS3
204+
|Int64|✓|OAS2,OAS3
205+
|Float|✓|OAS2,OAS3
206+
|Double|✓|OAS2,OAS3
207+
|Decimal|✓|ToolingExtension
208+
|String|✓|OAS2,OAS3
209+
|Byte|✓|OAS2,OAS3
210+
|Binary|✓|OAS2,OAS3
211+
|Boolean|✓|OAS2,OAS3
212+
|Date|✓|OAS2,OAS3
213+
|DateTime|✓|OAS2,OAS3
214+
|Password|✓|OAS2,OAS3
215+
|File|✓|OAS2
216+
|Uuid||
217+
|Array|✓|OAS2,OAS3
218+
|Null|✗|OAS3
219+
|AnyType|✗|OAS2,OAS3
220+
|Object|✓|OAS2,OAS3
221+
|Maps|✓|ToolingExtension
222+
|CollectionFormat|✓|OAS2
223+
|CollectionFormatMulti|✓|OAS2
224+
|Enum|✓|OAS2,OAS3
225+
|ArrayOfEnum|✓|ToolingExtension
226+
|ArrayOfModel|✓|ToolingExtension
227+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
228+
|ArrayOfCollectionOfModel|✓|ToolingExtension
229+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
230+
|MapOfEnum|✓|ToolingExtension
231+
|MapOfModel|✓|ToolingExtension
232+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
233+
|MapOfCollectionOfModel|✓|ToolingExtension
234+
|MapOfCollectionOfEnum|✓|ToolingExtension
235+
236+
### Documentation Feature
237+
| Name | Supported | Defined By |
238+
| ---- | --------- | ---------- |
239+
|Readme|✓|ToolingExtension
240+
|Model|✓|ToolingExtension
241+
|Api|✓|ToolingExtension
242+
243+
### Global Feature
244+
| Name | Supported | Defined By |
245+
| ---- | --------- | ---------- |
246+
|Host|✓|OAS2,OAS3
247+
|BasePath|✓|OAS2,OAS3
248+
|Info|✓|OAS2,OAS3
249+
|Schemes|✗|OAS2,OAS3
250+
|PartialSchemes|✓|OAS2,OAS3
251+
|Consumes|✓|OAS2
252+
|Produces|✓|OAS2
253+
|ExternalDocumentation|✓|OAS2,OAS3
254+
|Examples|✓|OAS2,OAS3
255+
|XMLStructureDefinitions|✗|OAS2,OAS3
256+
|MultiServer|✗|OAS3
257+
|ParameterizedServer|✗|OAS3
258+
|ParameterStyling|✗|OAS3
259+
|Callbacks|✗|OAS3
260+
|LinkObjects|✗|OAS3
261+
262+
### Parameter Feature
263+
| Name | Supported | Defined By |
264+
| ---- | --------- | ---------- |
265+
|Path|✓|OAS2,OAS3
266+
|Query|✓|OAS2,OAS3
267+
|Header|✓|OAS2,OAS3
268+
|Body|✓|OAS2
269+
|FormUnencoded|✓|OAS2
270+
|FormMultipart|✓|OAS2
271+
|Cookie|✓|OAS3
272+
273+
### Schema Support Feature
274+
| Name | Supported | Defined By |
275+
| ---- | --------- | ---------- |
276+
|Simple|✓|OAS2,OAS3
277+
|Composite|✗|OAS2,OAS3
278+
|Polymorphism|✗|OAS2,OAS3
279+
|Union|✗|OAS3
280+
|allOf|✗|OAS2,OAS3
281+
|anyOf|✗|OAS3
282+
|oneOf|✓|OAS3
283+
|not|✗|OAS3
284+
285+
### Security Feature
286+
| Name | Supported | Defined By |
287+
| ---- | --------- | ---------- |
288+
|BasicAuth|✓|OAS2,OAS3
289+
|ApiKey|✓|OAS2,OAS3
290+
|OpenIDConnect|✗|OAS3
291+
|BearerToken|✗|OAS3
292+
|OAuth2_Implicit|✓|OAS2,OAS3
293+
|OAuth2_Password|✗|OAS2,OAS3
294+
|OAuth2_ClientCredentials|✗|OAS2,OAS3
295+
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
296+
|SignatureAuth|✗|OAS3
297+
|AWSV4Signature|✗|ToolingExtension
298+
299+
### Wire Format Feature
300+
| Name | Supported | Defined By |
301+
| ---- | --------- | ---------- |
302+
|JSON|✓|OAS2,OAS3
303+
|XML|✓|OAS2,OAS3
304+
|PROTOBUF|✗|ToolingExtension
305+
|Custom|✗|OAS2,OAS3

0 commit comments

Comments
 (0)