Skip to content

Commit 4408bbf

Browse files
committed
Improve documentation for customization
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.
1 parent 3ab495a commit 4408bbf

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

docs/customization.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,21 @@ The default is to generate *everything* supported by the specific library. Once
187187

188188
To control the specific files being generated, you can pass a CSV list of what you want:
189189
```sh
190+
# generate the User and Pet APIs only
191+
--global-property apis="User:Pet"
192+
190193
# generate the User and Pet models only
191194
--global-property models="User:Pet"
192195

193196
# generate the User model and the supportingFile `StringUtil.java`:
194197
--global-property models=User,supportingFiles=StringUtil.java
195198
```
196199

200+
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+
197205
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`.
198206
These options default to true and don't limit the generation of the feature options listed above (like `--global-property api`):
199207

@@ -447,7 +455,7 @@ will name the API method as `returnPetById` instead of `getPetById` obtained fro
447455

448456
## Schema Mapping
449457

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
451459
```sh
452460
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/type-alias.yaml -o /tmp/java2/ --schema-mappings TypeAlias=foo.bar.TypeAlias
453461
```
@@ -646,3 +654,17 @@ Example:
646654
```
647655
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml -o /tmp/java-okhttp/ --openapi-normalizer FIX_DUPLICATED_OPERATIONID=true
648656
```
657+
658+
## Sanitization Rules
659+
660+
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).
661+
662+
Whenever an identifier is said to be sanitized, the following rules are being performed:
663+
- Removes any occurrences of the substring `[]`: `input[] => input`
664+
- Replaces indexing with underscores: `input[a][b] => input_a_b`
665+
- Replaces parenthesized substrings with underscores: `input(a)(b) => input_a_b`
666+
- Replaces dots, colons, and hyphens with underscores: `input.name, input:name, input-name => input_name`
667+
- Replaces pipes with underscores: `a|b => a_b`
668+
- Replaces spaces with underscores: `input name and age => input_name_and_age`
669+
- Replaces forward and backward slashes with underscores: `/api/films/get, \api\films\get => _api_films_get`
670+
- 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

Comments
 (0)