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

Java generator changed to stable status, version updated to 4.2.0 #422

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ so developers can use all of those features.
Currently, the following languages/frameworks are supported:

- python (Stability: Stable)
- java (Stability: Experimental)
- java (Stability: Stable)

## Join Our Community
We use a Discord server as a place to ask questions and help each other. It offers functionality very similar to Slack.
Expand Down Expand Up @@ -49,7 +49,7 @@ You can join us here: https://discord.gg/mHB8WEQuYQ
- Invalid (in python) property names supported like `from`, `1var`, `hi-there` etc in
- schema property names
- endpoint parameter names
- Payload values are not coerced when validated, so a datetime value can pass other validations that describe the payload only as type string
- 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
- types are generated for enums of type string/integer/boolean using typing.Literal
- String transmission of numbers supported with type: string, format: number, value can be accessed as a Decimal with schemas.as_decimal(inst)
- Multiple content types supported for request and response bodies
Expand All @@ -67,11 +67,9 @@ And many more!

## Reasons To Use the Java Generator

- v3.0.0 - [v3.1.0](docs/generators/java.md#schema-feature) OpenAPI Specification support for component schemas
- Very [thorough documentation generated in the style of javadocs, includes code samples](samples/client/petstore/java/docs/components/schemas/Money.md#money)
- Sealed classes used to define different endpoint responses.
Sealed classes used to define different response body classes.
Endpoint code samples include exhaustive handling of the sealed classes.
- v3.0.0 - [v3.1.0](docs/generators/java.md#schema-feature) OpenAPI Specification support
- Documentation generated in the style of javadocs. Examples: [Money schema](samples/client/petstore/java/docs/components/schemas/Money.md#money1) [Pet.addPet endpoint](samples/client/petstore/java/docs/apis/tags/Pet.md#addpet)
- Sealed classes used to define endpoint responses/response bodies/validated schema payloads/request bodies
- Input types constrained for a Schema in SomeSchema.validate
- validate method can accept arbitrary List/Map/null/int/long/double/float/String json data
- Immutable List output classes generated and returned by validate for List<?> input
Expand All @@ -95,8 +93,8 @@ And many more!
- Generated interfaces are largely consistent with the python code
- Openapi spec inline schemas supported at any depth in any location
- Format support for: int32, int64, float, double, date, datetime, uuid
- Payload values are not coerced when validated, so a datetime value can pass other validations that describe the payload only as type string
- types are generated for enums of type string/number/integer/boolean/null
- 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
- enum types are generated for enums of type string/integer/number/boolean/null
- String transmission of numbers supported with type: string, format: number
- [Autogenerated thorough testing of json schema keyword features in models and endpoints](samples/client/3_0_3_unit_test/java/src/test/java/org/openapijsonschematools/client/components/schemas) which come from the [json schema test suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite)
- [Tests are passing in CI](https://app.circleci.com/pipelines/github/openapi-json-schema-tools/openapi-json-schema-generator?branch=master)
Expand Down
8 changes: 4 additions & 4 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ title: Documentation for the java generator
| Property | Value | Notes |
| -------- | ----- | ----- |
| generator name | java | pass this to the generate command after -g |
| generator stability | EXPERIMENTAL | |
| generator stability | STABLE | |
| generator type | CLIENT | |
| generator language | Java | |
| generator language version | 17 | |
| generator default templating engine | handlebars | |
| helpTxt | Generates a Java client library<br /><br />Features in this generator:<br />- v3.0.0 - [v3.0.3](#schema-feature) OpenAPI Specification support for component schemas<br />- Very [thorough documentation generated in the style of javadocs, includes code samples](samples/client/petstore/java/docs/components/schemas/Money.md#money)<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 datetime value can pass other validations that describe the payload only as type string<br />- types are generated for enums of type string/integer/boolean using typing.Literal<br />- String transmission of numbers supported with type: string, format: number | |
| 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 | |

## CONFIG OPTIONS
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.
Expand Down Expand Up @@ -218,7 +218,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ---- | --------- | ---------- |
|Readme|✓|ToolingExtension
|Servers|✓|OAS3
|Security||OAS2,OAS3
|Security||OAS2,OAS3
|ComponentSchemas|✓|OAS3
|ComponentResponses|✓|OAS3
|ComponentParameters|✓|OAS3
Expand All @@ -228,7 +228,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|ComponentLinks|✗|OAS3
|ComponentCallbacks|✗|OAS3
|ComponentPathItems|✗|OAS3
|Api||ToolingExtension
|Api||ToolingExtension

### Global Feature
| Name | Supported | Defined By |
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
</dependencies>
<properties>
<!-- RELEASE_VERSION -->
<revision>4.1.3</revision>
<revision>4.2.0</revision>
<!-- /RELEASE_VERSION -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class JavaClientGenerator extends DefaultGenerator implements Generator {
private final Map<String, String> schemaKeyToModelNameCache = new HashMap<>();

protected Stability getStability() {
return Stability.EXPERIMENTAL;
return Stability.STABLE;
}

@Override
Expand Down Expand Up @@ -259,87 +259,89 @@ public JavaClientGenerator() {
instantiationTypes.put("null", "Void (null)");

modifyFeatureSet(features -> features
.includeDocumentationFeatures(
DocumentationFeature.Readme,
DocumentationFeature.Servers,
DocumentationFeature.ComponentSchemas,
DocumentationFeature.ComponentSecuritySchemes,
DocumentationFeature.ComponentRequestBodies,
DocumentationFeature.ComponentResponses,
DocumentationFeature.ComponentHeaders,
DocumentationFeature.ComponentParameters
)
.includeGlobalFeatures(
GlobalFeature.Components,
GlobalFeature.Servers,
GlobalFeature.Security,
GlobalFeature.Paths
)
.includeComponentsFeatures(
ComponentsFeature.schemas,
ComponentsFeature.securitySchemes,
ComponentsFeature.requestBodies,
ComponentsFeature.responses,
ComponentsFeature.headers,
ComponentsFeature.parameters
)
.includeSecurityFeatures(
SecurityFeature.ApiKey,
SecurityFeature.HTTP_Basic,
SecurityFeature.HTTP_Bearer
)
.includeOperationFeatures(
OperationFeature.Security,
OperationFeature.Servers,
OperationFeature.Responses_Default,
OperationFeature.Responses_HttpStatusCode,
OperationFeature.Responses_RangedResponseCodes,
OperationFeature.Responses_RedirectionResponse
)
.includeSchemaFeatures(
SchemaFeature.AdditionalProperties,
SchemaFeature.AllOf,
SchemaFeature.AnyOf,
SchemaFeature.Const,
SchemaFeature.Contains,
SchemaFeature.Default,
SchemaFeature.DependentRequired,
SchemaFeature.DependentSchemas,
// SchemaFeature.Discriminator,
SchemaFeature.Else,
SchemaFeature.Enum,
SchemaFeature.ExclusiveMaximum,
SchemaFeature.ExclusiveMinimum,
SchemaFeature.Format,
SchemaFeature.If,
SchemaFeature.Items,
SchemaFeature.MaxContains,
SchemaFeature.MaxItems,
SchemaFeature.MaxLength,
SchemaFeature.MaxProperties,
SchemaFeature.Maximum,
SchemaFeature.MinContains,
SchemaFeature.MinItems,
SchemaFeature.MinLength,
SchemaFeature.MinProperties,
SchemaFeature.Minimum,
SchemaFeature.MultipleOf,
SchemaFeature.Not,
SchemaFeature.Nullable,
SchemaFeature.OneOf,
SchemaFeature.Pattern,
SchemaFeature.PatternProperties,
SchemaFeature.PrefixItems,
SchemaFeature.Properties,
SchemaFeature.PropertyNames,
SchemaFeature.Ref,
SchemaFeature.Required,
SchemaFeature.Then,
SchemaFeature.Type,
SchemaFeature.UnevaluatedItems,
SchemaFeature.UnevaluatedProperties,
SchemaFeature.UniqueItems
)
.includeDocumentationFeatures(
DocumentationFeature.Readme,
DocumentationFeature.Servers,
DocumentationFeature.Security,
DocumentationFeature.ComponentSchemas,
DocumentationFeature.ComponentSecuritySchemes,
DocumentationFeature.ComponentRequestBodies,
DocumentationFeature.ComponentResponses,
DocumentationFeature.ComponentHeaders,
DocumentationFeature.ComponentParameters,
DocumentationFeature.Api
)
.includeGlobalFeatures(
GlobalFeature.Components,
GlobalFeature.Servers,
GlobalFeature.Security,
GlobalFeature.Paths
)
.includeComponentsFeatures(
ComponentsFeature.schemas,
ComponentsFeature.securitySchemes,
ComponentsFeature.requestBodies,
ComponentsFeature.responses,
ComponentsFeature.headers,
ComponentsFeature.parameters
)
.includeSecurityFeatures(
SecurityFeature.ApiKey,
SecurityFeature.HTTP_Basic,
SecurityFeature.HTTP_Bearer
)
.includeOperationFeatures(
OperationFeature.Security,
OperationFeature.Servers,
OperationFeature.Responses_Default,
OperationFeature.Responses_HttpStatusCode,
OperationFeature.Responses_RangedResponseCodes,
OperationFeature.Responses_RedirectionResponse
)
.includeSchemaFeatures(
SchemaFeature.AdditionalProperties,
SchemaFeature.AllOf,
SchemaFeature.AnyOf,
SchemaFeature.Const,
SchemaFeature.Contains,
SchemaFeature.Default,
SchemaFeature.DependentRequired,
SchemaFeature.DependentSchemas,
// SchemaFeature.Discriminator,
SchemaFeature.Else,
SchemaFeature.Enum,
SchemaFeature.ExclusiveMaximum,
SchemaFeature.ExclusiveMinimum,
SchemaFeature.Format,
SchemaFeature.If,
SchemaFeature.Items,
SchemaFeature.MaxContains,
SchemaFeature.MaxItems,
SchemaFeature.MaxLength,
SchemaFeature.MaxProperties,
SchemaFeature.Maximum,
SchemaFeature.MinContains,
SchemaFeature.MinItems,
SchemaFeature.MinLength,
SchemaFeature.MinProperties,
SchemaFeature.Minimum,
SchemaFeature.MultipleOf,
SchemaFeature.Not,
SchemaFeature.Nullable,
SchemaFeature.OneOf,
SchemaFeature.Pattern,
SchemaFeature.PatternProperties,
SchemaFeature.PrefixItems,
SchemaFeature.Properties,
SchemaFeature.PropertyNames,
SchemaFeature.Ref,
SchemaFeature.Required,
SchemaFeature.Then,
SchemaFeature.Type,
SchemaFeature.UnevaluatedItems,
SchemaFeature.UnevaluatedProperties,
SchemaFeature.UniqueItems
)
);

outputFolder = "generated-code" + File.separator + "java";
Expand Down Expand Up @@ -378,8 +380,8 @@ public String getHelp() {
"Generates a Java client library",
"",
"Features in this generator:",
"- v3.0.0 - [v3.0.3](#schema-feature) OpenAPI Specification support for component schemas",
"- Very [thorough documentation generated in the style of javadocs, includes code samples](samples/client/petstore/java/docs/components/schemas/Money.md#money)",
"- v3.0.0 - [v3.1.0](#schema-feature) OpenAPI Specification support",
"- Very thorough documentation generated in the style of javadocs",
"- Input types constrained for a Schema in SomeSchema.validate",
" - validate method can accept arbitrary List/Map/null/int/long/double/float/String json data",
"- Immutable List output classes generated and returned by validate for List&lt;?&gt; input",
Expand All @@ -403,8 +405,8 @@ public String getHelp() {
"- Generated interfaces are largely consistent with the python code",
"- Openapi spec inline schemas supported at any depth in any location",
"- Format support for: int32, int64, float, double, date, datetime, uuid",
"- Payload values are not coerced when validated, so a datetime value can pass other validations that describe the payload only as type string",
"- types are generated for enums of type string/integer/boolean using typing.Literal",
"- 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",
"- enum types are generated for enums of type string/integer/number/boolean/null",
"- String transmission of numbers supported with type: string, format: number"
);
}
Expand Down