You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for selective generation of APIs has been updated to
specify the API names are the sanitized UpperCamelCase versions of the
tags in the spec.
The sanitization rules have been documented in a separate section.
Copy file name to clipboardExpand all lines: docs/customization.md
+29-7Lines changed: 29 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ Excluding `SupportingFiles`, each of the above options may result in multiple fi
75
75
Note that user-defined templates will merge with built-in template definitions. If a supporting file with the sample template file path exists, it will be replaced with the user-defined template, otherwise the user-defined template will be added to the list of template files to compile. If the generator's built-in template is `model_docs.mustache` and you define `model-docs.mustache`, this will result in duplicated model docs (if `destinationFilename` differs) or undefined behavior as whichever template compiles last will overwrite the previous model docs (if `destinationFilename` matches the extension or suffix in the generator's code).
76
76
77
77
## Custom Generator (and Template)
78
-
78
+
79
79
<aid="creating-a-new-template"></a> If none of the built-in generators suit your needs and you need to do more than just modify the mustache templates to tweak generated code, you can create a brand new generator and its associated templates. OpenAPI Generator can help with this, using the `meta` command:
80
80
81
81
```sh
@@ -95,7 +95,7 @@ To compile your library, enter the `out/generators/my-codegen` directory, run `m
95
95
96
96
**NOTE** Running your custom generator requires adding it to the classpath. This differs on [Windows](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html) slightly from [unix](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/classpath.html).
97
97
If you are running a Windows Subsystem for Linux or a shell such as gitbash, and have issues with the unix variant, try the Windows syntax below.
98
-
98
+
99
99
Now, execute the generator:
100
100
101
101
```sh
@@ -187,13 +187,21 @@ The default is to generate *everything* supported by the specific library. Once
187
187
188
188
To control the specific files being generated, you can pass a CSV list of what you want:
189
189
```sh
190
+
# generate the User and Pet APIs only
191
+
--global-property apis="User:Pet"
192
+
190
193
# generate the User and Pet models only
191
194
--global-property models="User:Pet"
192
195
193
196
# generate the User model and the supportingFile `StringUtil.java`:
The names of the apis are the _sanitized_ tags converted to _UpperCamelCase_ and are generated by the following steps:
201
+
- Execute the general [sanitization rules](#sanitization-rules)
202
+
- Prepend the word `Class` if the tag starts with numbers: `123_pet => Class123Pet`
203
+
- Convert the resulting string to upper camel case: `pet_store => PetStore`
204
+
197
205
To control generation of docs and tests for api and models, pass false to the option. For api, these options are `--global-property apiTests=false,apiDocs=false`. For models, `--global-property modelTests=false,modelDocs=false`.
198
206
These options default to true and don't limit the generation of the feature options listed above (like `--global-property api`):
199
207
@@ -447,7 +455,7 @@ will name the API method as `returnPetById` instead of `getPetById` obtained fro
447
455
448
456
## Schema Mapping
449
457
450
-
One can map the schema to something else (e.g. external objects/models outside of the package) using the `schemaMappings` option, e.g. in CLI
458
+
One can map the schema to something else (e.g. external objects/models outside the package) using the `schemaMappings` option, e.g. in CLI
@@ -510,7 +518,7 @@ Another useful option is `inlineSchemaOptions`, which allows you to customize ho
510
518
511
519
OpenAPI Normalizer transforms the input OpenAPI doc/spec (which may not perfectly conform to the specification) to make it workable with OpenAPI Generator. A few rules are switched on by default since 7.0.0 release:
512
520
513
-
- SIMPLIFY_ONEOF_ANYOF
521
+
- SIMPLIFY_ONEOF_ANYOF
514
522
- SIMPLIFY_BOOLEAN_ENUM
515
523
516
524
(One can use `DISABLE_ALL=true` to disable all the rules)
@@ -607,13 +615,13 @@ The `FILTER` parameter allows selective inclusion of API operations based on spe
607
615
608
616
### Available Filters
609
617
610
-
- **`operationId`**
618
+
- **`operationId`**
611
619
When set to `operationId:addPet|getPetById`, operations **not** matching `addPet` or `getPetById` will be marked as internal (`x-internal: true`), and excluded from generation. Matching operations will have `x-internal: false`.
612
620
613
-
- **`method`**
621
+
- **`method`**
614
622
When set to `method:get|post`, operations **not** using `GET` or `POST` methods will be marked as internal (`x-internal: true`), preventing their generation.
615
623
616
-
- **`tag`**
624
+
- **`tag`**
617
625
When set to `tag:person|basic`, operations **not** tagged with `person` or `basic` will be marked as internal (`x-internal: true`), and will not be generated.
618
626
619
627
### Example Usage
@@ -670,3 +678,17 @@ Into this securityScheme:
670
678
scheme: bearer
671
679
type: http
672
680
```
681
+
682
+
## Sanitization Rules
683
+
684
+
Various identifiers have to go through a set of sanitization rules to remove invalid characters. This is performed by [DefaultCodeGen#sanitizeName](https://github.com/OpenAPITools/openapi-generator/blob/3ab495a0aa094eb9b1c7a46aea0adca8de8deeb6/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L6538C19-L6538C107).
685
+
686
+
Whenever an identifier is said to be sanitized, the following rules are being performed:
687
+
- Removes any occurrences of the substring `[]`: `input[] => input`
688
+
- Replaces indexing with underscores: `input[a][b] => input_a_b`
689
+
- Replaces parenthesized substrings with underscores: `input(a)(b) => input_a_b`
690
+
- Replaces dots, colons, and hyphens with underscores: `input.name, input:name, input-name => input_name`
691
+
- Replaces pipes with underscores: `a|b => a_b`
692
+
- Replaces spaces with underscores: `input name and age => input_name_and_age`
693
+
- Replaces forward and backward slashes with underscores: `/api/films/get, \api\films\get => _api_films_get`
694
+
- Removes all remaining non-word characters. Unicode characters are allowed if the `allowUnicodeIdentifiers`[config option](https://openapi-generator.tech/docs/configuration/) is true.
0 commit comments