Skip to content

Commit 1c7f435

Browse files
committed
Improve documentation for customization
The documentation for selective generation of APIs has been updated to specify the API names are the UpperCamelCase versions of the tags in the spec. The documentation for use of operationIdNameMappings has been updated to specify that the operationIds have already been sanitized and converted to lowerCamelCase before they are compared with the specified operationIdNameMappings.
1 parent 0e34d39 commit 1c7f435

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

docs/customization.md

Lines changed: 39 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_. The sanitization and camelization process performs the following steps:
201+
- Follows the general [sanitization rules](#sanitization-rules)
202+
- Prepends the word `Class` if the tag starts with numbers: `123_pet => Class123Pet`
203+
- Converts 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

@@ -445,9 +453,27 @@ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generat
445453
```
446454
will name the API method as `returnPetById` instead of `getPetById` obtained from OpenAPI doc/spec.
447455

456+
The `operationId` has had some transformations performed on it prior to being looked up in the operation id name mappings. The following transformations have been performed:
457+
- If the operationId is blank, the path is used to generate an operationId as follows:
458+
- If the path is just the root path (/), it is replaced with the word `root`: `/ => root`
459+
- All curly braces for path template parameters are removed: `/pets/{pet-name} => /pets/pet-name`
460+
- The HTTP method is appended to the path: `/pets/pet-name/get`
461+
- The resulting string is split on `/`
462+
- The parts are joined together to form a lowerCamelCase string: `/pets/pet-name/get => petsPet-nameGet`
463+
- The resulting operationId has the general [sanitization rules](#sanitization-rules) applied: `petsPet-nameGet => petsPetNameGet`
464+
- If the operationId is not blank, it is used unmodified
465+
- If the `removeOperationIdPrefix` [config option](https://openapi-generator.tech/docs/configuration/) is true:
466+
- The operationId is split on the `removeOperationIdPrefixDelimiter` character (default: `_`)
467+
- The `removeOperationIdPrefixCount` parts are discarded (default: `1`)
468+
- The remaining parts are joined using `removeOperationIdPrefixDelimiter`: `data_pets_get => pets_get`
469+
- The `removeOperationIdPrefixDelimiter` and the `-_:;#` characters are removed after capitalizing the subsequent character
470+
- The first character is converted to lowercase to yield a lowerCamcelCase operationId
471+
472+
The lowerCamelCase operationId generated from the above transformations is the value that must be configured as the key in the operationIdNameMappings.
473+
448474
## Schema Mapping
449475

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
476+
One can map the schema to something else (e.g. external objects/models outside the package) using the `schemaMappings` option, e.g. in CLI
451477
```sh
452478
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
453479
```
@@ -646,3 +672,15 @@ Example:
646672
```
647673
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
648674
```
675+
676+
## Sanitization Rules
677+
678+
Various identifiers have to go through a set of sanitization rules to remove invalid characters. Whenever an identifier is said to be sanitized, the following rules are being performed:
679+
- Removes any occurrences of the substring `[]`: `input[] => input`
680+
- Replaces indexing with underscores: `input[a][b] => input_a_b`
681+
- Replaces parenthesized substrings with underscores: `input(a)(b) => input_a_b`
682+
- Replaces dots, colons, and hyphens with underscores: `input.name, input:name, input-name => input_name`
683+
- Replaces pipes with underscores: `a|b => a_b`
684+
- Replaces spaces with underscores: `input name and age => input_name_and_age`
685+
- Replaces forward and backward slashes with underscores: `/api/films/get, \api\films\get => _api_films_get`
686+
- 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)