Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 9b468b3

Browse files
authored
Generator refactoring (#425)
* Extracts OpenapApiProcessor interface out of Generator * Deprecates more generator methods * Deprecates toResponseModuleName * Deprecates toParamName * Deprecates more methods, removes packagePath from generator interface * Adjusts generator instantiation * Deprecates getOutputDir * Deprecates outputFolder * Deprecates templateDir * Deprecates embeddedTemplateDir * Deprecates packageName * Passes strict spec behaviort in generator new * Deprecates isEnableMinimalUpdate * Removes setRemoveOperationIdPrefix * Updates IgnoreFilePathOverride * Handles isSkipOperationExample * Updates 2 more generator settings * Saves input spec location in new * Stops using serviceloader for generators * Fixes java test testRemoveOperationIdPrefix * Fixes smokeTestAuthorTemplateCommand * Fixes java tests * Moves reservedWords into generator metadata * Moves instantiationTypes into metadata * Reprecates languageSpecificPrimitives * Adds hide genration timestamp option * Removes defaultIncludes * Fixes referencing issue * Docs regen * Fixes java docs * Fixes setting package name * Samples regen * Updates batch to watn about deprecated additional properties * Samples regen * Samples regen with fixed java config file inputs * Changes generatorMetadata usages to use the getGeneratorMetadata method * Samples regen * Removes lingering unused folder * Removes other unsed folder * Removes not files from python 303 * Removes not files from python 310 * Removes files generated from when reservedWords was not integrated correctly * Fixes java tests, adjusts where logging is done for deprecated additionalProperties * Fixes hideGenerationTimestamp conversion
1 parent 43eb428 commit 9b468b3

File tree

58 files changed

+1735
-2200
lines changed

Some content is hidden

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

58 files changed

+1735
-2200
lines changed

bin/generate-samples.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if [ ! -f "$executable" ]; then
1010
(cd "${root}" && mvn -B --no-snapshot-updates clean package -DskipTests=true -Dmaven.javadoc.skip=true -Djacoco.skip=true)
1111
fi
1212

13+
# -ea -> enable assertions
14+
# -server -> server version of the VM which has more complex optimizations, + is tuned to maximize performance
1315
export JAVA_OPTS="${JAVA_OPTS} -ea -server -Duser.timezone=UTC"
1416
export BATCH_OPTS="${BATCH_OPTS:-}"
1517

@@ -53,10 +55,10 @@ if [[ ${#files[@]} -eq 1 && "${files[0]}" != *'*'* ]]; then
5355
java ${JAVA_OPTS} -jar "$executable" generate -c ${files[0]} ${args[@]}
5456
else
5557
echo "Please press CTRL+C to stop or the script will continue in 5 seconds."
56-
sleep 5
5758
if [ ${#files[@]} -eq 0 ]; then
5859
files=("${root}"/bin/generate_samples_configs/*.yaml)
5960
fi
61+
sleep 5
6062

6163
# shellcheck disable=SC2086
6264
# shellcheck disable=SC2068

bin/generate_samples_configs/java_3_0_3_unit_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ generatorName: java
22
outputDir: samples/client/3_0_3_unit_test/java
33
inputSpec: src/test/resources/3_0/unit_test_spec/3_0_3_unit_test_spec_nopaths.yaml
44
additionalProperties:
5-
artifactId: petstore
5+
artifactId: unit-test-api
66
hideGenerationTimestamp: "true"

bin/generate_samples_configs/java_3_1_0_unit_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ generatorName: java
22
outputDir: samples/client/3_1_0_unit_test/java
33
inputSpec: src/test/resources/3_1/unit_test_spec/3_1_0_unit_test_spec_nopaths.yaml
44
additionalProperties:
5-
packageName: unit_test_api
5+
artifactId: unit-test-api

docs/generators/java.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,22 @@ title: Documentation for the java generator
1212
| generator language | Java | |
1313
| generator language version | 17 | |
1414
| generator default templating engine | handlebars | |
15-
| helpTxt | Generates a Java client library<br /><br />Features in this generator:<br />- v3.0.0 - [v3.1.0](#schema-feature) OpenAPI Specification support<br />- Very thorough documentation generated in the style of javadocs<br />- Input types constrained for a Schema in SomeSchema.validate<br /> - validate method can accept arbitrary List/Map/null/int/long/double/float/String json data<br />- Immutable List output classes generated and returned by validate for List&lt;?&gt; input<br />- Immutable Map output classes generated and returned by validate for Map&lt;?, ?&gt; input<br />- Strictly typed list input can be instantiated in client code using generated ListBuilders<br />- Strictly typed map input can be instantiated in client code using generated MapBuilders<br /> - Sequential map builders are generated ensuring that required properties are set before build is invoked. Looks like:<br /> - `new MapBuilder().requiredA("a").requiredB("b").build()`<br /> - `new MapBuilder().requiredA("a").requiredB("b").optionalProp("c").additionalProperty("someAddProp", "d").build()`<br />- Run time type checking and validation when<br /> - validating schema payloads<br /> - instantiating List output class (validation run)<br /> - instantiating Map output class (validation run)<br /> - Note: if needed, validation of json schema keywords can be deactivated via a SchemaConfiguration class<br />- Enums classes are generated and may be input into Schema.validate or the List/MapBuilder add/setter methods<br />- The [Checker-Framework's](https://github.com/typetools/checker-framework) NullnessChecker and @Nullable annotations are used in the java client<br /> - ensuring that null pointer exceptions will not happen<br />- Invalid (in java) property names supported like `class`, `1var`, `hi-there` etc in<br /> - component schema names<br /> - schema property names (a fallback setter is written in the MapBuilder)<br />- Generated interfaces are largely consistent with the python code<br />- Openapi spec inline schemas supported at any depth in any location<br />- Format support for: int32, int64, float, double, date, datetime, uuid<br />- Payload values are not coerced when validated, so a date/date-time value can pass other validations that describe the payload only as type string<br />- enum types are generated for enums of type string/integer/number/boolean/null<br />- String transmission of numbers supported with type: string, format: number | |
15+
| helpMsg | Generates a Java client library<br /><br />Features in this generator:<br />- v3.0.0 - [v3.1.0](#schema-feature) OpenAPI Specification support<br />- Very thorough documentation generated in the style of javadocs<br />- Input types constrained for a Schema in SomeSchema.validate<br /> - validate method can accept arbitrary List/Map/null/int/long/double/float/String json data<br />- Immutable List output classes generated and returned by validate for List&lt;?&gt; input<br />- Immutable Map output classes generated and returned by validate for Map&lt;?, ?&gt; input<br />- Strictly typed list input can be instantiated in client code using generated ListBuilders<br />- Strictly typed map input can be instantiated in client code using generated MapBuilders<br /> - Sequential map builders are generated ensuring that required properties are set before build is invoked. Looks like:<br /> - `new MapBuilder().requiredA("a").requiredB("b").build()`<br /> - `new MapBuilder().requiredA("a").requiredB("b").optionalProp("c").additionalProperty("someAddProp", "d").build()`<br />- Run time type checking and validation when<br /> - validating schema payloads<br /> - instantiating List output class (validation run)<br /> - instantiating Map output class (validation run)<br /> - Note: if needed, validation of json schema keywords can be deactivated via a SchemaConfiguration class<br />- Enums classes are generated and may be input into Schema.validate or the List/MapBuilder add/setter methods<br />- The [Checker-Framework's](https://github.com/typetools/checker-framework) NullnessChecker and @Nullable annotations are used in the java client<br /> - ensuring that null pointer exceptions will not happen<br />- Invalid (in java) property names supported like `class`, `1var`, `hi-there` etc in<br /> - component schema names<br /> - schema property names (a fallback setter is written in the MapBuilder)<br />- Generated interfaces are largely consistent with the python code<br />- Openapi spec inline schemas supported at any depth in any location<br />- Format support for: int32, int64, float, double, date, datetime, uuid<br />- Payload values are not coerced when validated, so a date/date-time value can pass other validations that describe the payload only as type string<br />- enum types are generated for enums of type string/integer/number/boolean/null<br />- String transmission of numbers supported with type: string, format: number | |
1616

1717
## CONFIG OPTIONS
1818
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.
1919

2020
| Option | Description | Values | Default |
2121
| ------ | ----------- | ------ | ------- |
2222
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
23-
|apiPackage|package for generated api classes| |apis|
2423
|artifactDescription|artifact description in generated pom.xml| |OpenAPI Java|
25-
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-client|
2624
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapi-json-schema-tools/openapi-json-schema-generator|
2725
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
2826
|developerEmail|developer email in generated pom.xml| |[email protected]|
2927
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
3028
|developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org|
3129
|developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapijsonschematools.org|
3230
|groupId|groupId in generated pom.xml| |org.openapijsonschematools|
33-
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false|
3431
|invokerPackage|root package for generated code| |org.openapijsonschematools.client|
3532
|licenseName|The name of the license| |Unlicense|
3633
|licenseUrl|The URL of the license| |http://unlicense.org|

docs/generators/python.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ title: Documentation for the python generator
1212
| generator language | Python | |
1313
| generator language version | >=3.8 | |
1414
| generator default templating engine | handlebars | |
15-
| helpTxt | Generates a Python client library<br /><br />Features in this generator:<br />- type hints on endpoints and model creation<br />- model parameter names use the spec defined keys and cases<br />- robust composition (oneOf/anyOf/allOf/not) where payload data is stored in one instance only<br />- endpoint parameter names use the spec defined keys and cases<br />- inline schemas are supported at any location including composition<br />- multiple content types supported in request body and response bodies<br />- run time type checking + json schema validation<br />- json schema keyword validation may be selectively disabled with SchemaConfiguration<br />- enums of type string/integer/boolean typed using typing.Literal<br />- mypy static type checking run on generated sample<br />- Sending/receiving decimals as strings supported with type:string format: number -> DecimalSchema<br />- Sending/receiving uuids as strings supported with type:string format: uuid -> UUIDSchema<br />- quicker load time for python modules (a single endpoint can be imported and used without loading others)<br />- composed schemas with type constraints supported (type:object + oneOf/anyOf/allOf)<br />- schemas are not coerced/cast. For example string + date are both stored as string, and there is a date accessor | |
15+
| helpMsg | Generates a Python client library<br /><br />Features in this generator:<br />- type hints on endpoints and model creation<br />- model parameter names use the spec defined keys and cases<br />- robust composition (oneOf/anyOf/allOf/not) where payload data is stored in one instance only<br />- endpoint parameter names use the spec defined keys and cases<br />- inline schemas are supported at any location including composition<br />- multiple content types supported in request body and response bodies<br />- run time type checking + json schema validation<br />- json schema keyword validation may be selectively disabled with SchemaConfiguration<br />- enums of type string/integer/boolean typed using typing.Literal<br />- mypy static type checking run on generated sample<br />- Sending/receiving decimals as strings supported with type:string format: number -> DecimalSchema<br />- Sending/receiving uuids as strings supported with type:string format: uuid -> UUIDSchema<br />- quicker load time for python modules (a single endpoint can be imported and used without loading others)<br />- composed schemas with type constraints supported (type:object + oneOf/anyOf/allOf)<br />- schemas are not coerced/cast. For example string + date are both stored as string, and there is a date accessor | |
1616

1717
## CONFIG OPTIONS
1818
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.
@@ -22,12 +22,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2222
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
2323
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
2424
|nonCompliantUseDiscriminatorIfCompositionFails|When true, If the payload fails to validate against composed schemas (allOf/anyOf/oneOf/not) and a discriminator is present, then ignore the composition validation errors and attempt to use the discriminator to validate the payload.<br />Note: setting this to true makes the generated client not comply with json schema because it ignores composition validation errors. Please consider making your schemas more restrictive rather than setting this to true. You can do that by:<ul><li>defining the propertyName as an enum with only one value in the schemas that are in your discriminator map</li><li>setting additionalProperties: false in your schemas</li></ul>|<dl><dt>**true**</dt><dd>If composition fails and a discriminator exists, the composition errors will be ignored and validation will be attempted with the discriminator</dd><dt>**false**</dt><dd>Composition validation must succeed. Discriminator validation must succeed.</dd></dl>|false|
25-
|packageName|python package name (convention: snake_case).| |openapi_client|
2625
|packageUrl|python package URL.| |null|
2726
|packageVersion|python package version.| |1.0.0|
2827
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
2928
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
30-
|templatingEngine|template engine|<dl><dt>**handlebars**</dt><dd>handlebars templating engine</dd></dl>|handlebars|
3129
|useNose|use the nose test framework| |false|
3230

3331
## SUPPORTED VENDOR EXTENSIONS
@@ -54,24 +52,24 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5452
## LANGUAGE PRIMITIVES
5553

5654
<ul class="column-ul">
55+
<li>None</li>
5756
<li>bool</li>
5857
<li>bytes</li>
5958
<li>date</li>
6059
<li>datetime</li>
6160
<li>dict</li>
6261
<li>file</li>
63-
<li>file_type</li>
6462
<li>float</li>
6563
<li>int</li>
6664
<li>list</li>
67-
<li>none_type</li>
6865
<li>object</li>
6966
<li>str</li>
7067
</ul>
7168

7269
## RESERVED WORDS
7370

7471
<ul class="column-ul">
72+
<li>@property</li>
7573
<li>and</li>
7674
<li>as</li>
7775
<li>assert</li>
@@ -81,6 +79,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8179
<li>break</li>
8280
<li>class</li>
8381
<li>continue</li>
82+
<li>cookie_params</li>
83+
<li>datetime</li>
84+
<li>decimal</li>
8485
<li>def</li>
8586
<li>del</li>
8687
<li>dict</li>
@@ -93,12 +94,15 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9394
<li>float</li>
9495
<li>for</li>
9596
<li>from</li>
97+
<li>functools</li>
9698
<li>global</li>
99+
<li>header_params</li>
97100
<li>if</li>
98101
<li>immutabledict</li>
99102
<li>import</li>
100103
<li>in</li>
101104
<li>int</li>
105+
<li>io</li>
102106
<li>is</li>
103107
<li>lambda</li>
104108
<li>list</li>
@@ -107,15 +111,23 @@ These options may be applied as additional-properties (cli) or configOptions (pl
107111
<li>not</li>
108112
<li>or</li>
109113
<li>pass</li>
114+
<li>path_params</li>
110115
<li>print</li>
111116
<li>property</li>
117+
<li>query_params</li>
112118
<li>raise</li>
119+
<li>re</li>
120+
<li>resource_path</li>
113121
<li>return</li>
122+
<li>schemas</li>
114123
<li>self</li>
115124
<li>str</li>
116125
<li>true</li>
117126
<li>try</li>
118127
<li>tuple</li>
128+
<li>typing</li>
129+
<li>typing_extensions</li>
130+
<li>uuid</li>
119131
<li>while</li>
120132
<li>with</li>
121133
<li>yield</li>

samples/client/3_0_3_unit_test/java/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# petstore
1+
# unit-test-api
22
sample spec for testing openapi functionality, built from json schema tests for draft6
33

44
This Java package is automatically generated by the [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) project:
@@ -35,7 +35,7 @@ Add this dependency to your project's POM:
3535
```xml
3636
<dependency>
3737
<groupId>org.openapijsonschematools</groupId>
38-
<artifactId>petstore</artifactId>
38+
<artifactId>unit-test-api</artifactId>
3939
<version>0.0.1</version>
4040
<scope>compile</scope>
4141
</dependency>
@@ -51,7 +51,7 @@ mvn clean package
5151

5252
Then manually install the following JARs:
5353

54-
- `target/petstore-0.0.1.jar`
54+
- `target/unit-test-api-0.0.1.jar`
5555
- `target/lib/*.jar`
5656

5757

samples/client/3_0_3_unit_test/java/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.openapijsonschematools</groupId>
5-
<artifactId>petstore</artifactId>
5+
<artifactId>unit-test-api</artifactId>
66
<packaging>jar</packaging>
7-
<name>petstore</name>
7+
<name>unit-test-api</name>
88
<version>0.0.1</version>
99
<url>https://github.com/openapi-json-schema-tools/openapi-json-schema-generator</url>
1010
<description>OpenAPI Java</description>

samples/client/3_1_0_unit_test/java/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# openapi-java-client
1+
# unit-test-api
22
sample spec for testing openapi functionality, built from json schema tests for draft2020-12
33

44
This Java package is automatically generated by the [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) project:
@@ -35,7 +35,7 @@ Add this dependency to your project's POM:
3535
```xml
3636
<dependency>
3737
<groupId>org.openapijsonschematools</groupId>
38-
<artifactId>openapi-java-client</artifactId>
38+
<artifactId>unit-test-api</artifactId>
3939
<version>0.0.1</version>
4040
<scope>compile</scope>
4141
</dependency>
@@ -51,7 +51,7 @@ mvn clean package
5151

5252
Then manually install the following JARs:
5353

54-
- `target/openapi-java-client-0.0.1.jar`
54+
- `target/unit-test-api-0.0.1.jar`
5555
- `target/lib/*.jar`
5656

5757

samples/client/3_1_0_unit_test/java/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.openapijsonschematools</groupId>
5-
<artifactId>openapi-java-client</artifactId>
5+
<artifactId>unit-test-api</artifactId>
66
<packaging>jar</packaging>
7-
<name>openapi-java-client</name>
7+
<name>unit-test-api</name>
88
<version>0.0.1</version>
99
<url>https://github.com/openapi-json-schema-tools/openapi-json-schema-generator</url>
1010
<description>OpenAPI Java</description>

samples/client/petstore/python/docs/components/schema/any_type_and_format.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ base class: schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]
3434
### &lowbar;&lowbar;new&lowbar;&lowbar; method
3535
Keyword Argument | Type | Description | Notes
3636
---------------- | ---- | ----------- | -----
37-
**uuid** | dict, schemas.immutabledict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, schemas.Unset | | [optional] value must be a uuid
3837
**date** | dict, schemas.immutabledict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, schemas.Unset | | [optional] value must conform to RFC-3339 full-date YYYY-MM-DD
3938
**number** | dict, schemas.immutabledict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, schemas.Unset | | [optional] value must be int or float numeric
4039
**binary** | dict, schemas.immutabledict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, schemas.Unset | | [optional]
@@ -46,7 +45,6 @@ Keyword Argument | Type | Description | Notes
4645
### properties
4746
Property | Type | Description | Notes
4847
-------- | ---- | ----------- | -----
49-
**uuid** | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO, schemas.Unset | | [optional] value must be a uuid
5048
**date** | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO, schemas.Unset | | [optional] value must conform to RFC-3339 full-date YYYY-MM-DD
5149
**number** | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO, schemas.Unset | | [optional] value must be int or float numeric
5250
**binary** | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO, schemas.Unset | | [optional]
@@ -58,7 +56,7 @@ Property | Type | Description | Notes
5856
Method | Input Type | Return Type | Notes
5957
------ | ---------- | ----------- | ------
6058
from_dict_ | [AnyTypeAndFormatDictInput](#anytypeandformatdictinput), [AnyTypeAndFormatDict](#anytypeandformatdict) | [AnyTypeAndFormatDict](#anytypeandformatdict) | a constructor
61-
&lowbar;&lowbar;getitem&lowbar;&lowbar; | str | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO | This model has invalid python names so this method is used under the hood when you access instance["date-time"], instance["float"],
59+
&lowbar;&lowbar;getitem&lowbar;&lowbar; | str | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO | This model has invalid python names so this method is used under the hood when you access instance["uuid"], instance["date-time"], instance["float"],
6260
get_additional_property_ | str | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO, schemas.Unset | provides type safety for additional properties
6361

6462
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)

0 commit comments

Comments
 (0)