Skip to content

Commit bfc4bdb

Browse files
committed
update doc
1 parent d7e33ef commit bfc4bdb

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

docs/customization.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,32 @@ or
401401
--import-mappings Pet=my.models.MyPet --import-mappings Order=my.models.MyOrder
402402
```
403403
404+
## Default Values
405+
406+
To customize the default values for containers, one can leverage the option `defaultToEmptyContainer` to customize what to initalize for array/set/map by respecting the default values in the spec
407+
408+
Set optional array and map default value to an empty container
409+
```
410+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/output --additional-properties defaultToEmptyContainer="array?|map?"
411+
```
412+
413+
Set nullable array (required) default value to an empty container
414+
```
415+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/output --additional-properties defaultToEmptyContainer="?array"
416+
```
417+
418+
Set nullable array (optional) default value to an empty container
419+
```
420+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/output --additional-properties defaultToEmptyContainer="?array?"
421+
```
422+
423+
To simply enable this option to respect default values in the specification (basically null if not specified):
424+
```
425+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/output --additional-properties defaultToEmptyContainer=""
426+
```
427+
428+
Note: not all generators support this generator's option (e.g. --additional-properties defaultToEmptyContainer="?array" in CLI) so please test to confirm. Java generators are the first to implement this feature. We welcome PRs to support this option in other generators. Related PR: https://github.com/OpenAPITools/openapi-generator/pull/21269
429+
404430
## Name Mapping
405431
406432
One can map the property name using `nameMappings` option and parameter name using `parameterNameMappings` option to something else. Consider the following schema:

0 commit comments

Comments
 (0)