Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java][Client] Support annotationLibrary=none #12422

Closed
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b287a95
Support annotationLibrary=none in JavaClientCodegen
cachescrubber May 21, 2022
bd50836
Add example using annotationLibrary=swagger1
cachescrubber May 21, 2022
cd576ac
Generate Samples
cachescrubber May 21, 2022
b24d24d
Generate Docs
cachescrubber May 21, 2022
815425a
Merge branch 'master' into java_annotation_library
cachescrubber May 21, 2022
ab4c1c5
Support annotationLibrary=none in libraries
cachescrubber May 21, 2022
ffa6027
Generate Samples
cachescrubber May 21, 2022
4598460
Fix missing brace - Generate Samples
cachescrubber May 21, 2022
1265428
fix if statement condition
cachescrubber May 21, 2022
ade7e1e
Re-generate all model tests
cachescrubber May 21, 2022
195786d
Support {{#swagger1AnnotationLibrary}} in java/rest-assured
cachescrubber May 21, 2022
0cc9da0
Delete stale sample classes
cachescrubber May 21, 2022
1b81f84
Delete stale sample classes
cachescrubber May 21, 2022
a005fac
Adopt JavaModelTest
cachescrubber May 21, 2022
39a2aeb
Model Tests are skipped again
cachescrubber May 21, 2022
7460821
Delete stale sample classes
cachescrubber May 21, 2022
90f2b7a
Delete stale sample classes...
cachescrubber May 21, 2022
b2cc43a
Delete stale sample classes - jersey3
cachescrubber May 21, 2022
3e05756
Delete stale sample classes - okhttp
cachescrubber May 21, 2022
42efa7c
Merge branch 'master' into java_annotation_library
cachescrubber Aug 24, 2022
7a4bb19
Generate Samples
cachescrubber Aug 24, 2022
9816408
Regenerate stale Test classes for java/okhttp-gson
cachescrubber Aug 24, 2022
e2e3413
Regenerate stale Test classes for java/okhttp-gson (second pass)
cachescrubber Aug 24, 2022
12fb636
Merge branch 'master' into java_annotation_library
cachescrubber Oct 28, 2022
0efd042
Merge branch 'master' into java_annotation_library
cachescrubber Oct 28, 2022
0053b71
Re-generate samples
cachescrubber Oct 28, 2022
6b471c6
Re-generate docs
cachescrubber Oct 28, 2022
7687155
Re-generate samples/client/petstore/java/okhttp-gson/
cachescrubber Oct 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
10 changes: 10 additions & 0 deletions bin/configs/java-resttemplate-swagger1.yaml
@@ -0,0 +1,10 @@
generatorName: java
outputDir: samples/client/petstore/java/resttemplate-swagger1
library: resttemplate
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-resttemplate
hideGenerationTimestamp: "true"
annotationLibrary: "swagger1"
java8: true
2 changes: 2 additions & 0 deletions docs/generators/java.md
Expand Up @@ -21,6 +21,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|additionalEnumTypeAnnotations|Additional annotations for enum type(class level annotations)| |null|
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|annotationLibrary|Select the complementary documentation annotation library.|<dl><dt>**none**</dt><dd>Do not annotate Model and Api with complementary annotations.</dd><dt>**swagger1**</dt><dd>Annotate Model and Api using the Swagger Annotations 1.x library.</dd></dl>|none|
|apiPackage|package for generated api classes| |org.openapitools.client.api|
|artifactDescription|artifact description in generated pom.xml| |OpenAPI Java|
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-client|
Expand All @@ -39,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false|
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true|
|documentationProvider|Select the OpenAPI documentation provider.|<dl><dt>**none**</dt><dd>Do not publish an OpenAPI specification.</dd><dt>**source**</dt><dd>Publish the original input OpenAPI specification.</dd></dl>|source|
|dynamicOperations|Generate operations dynamically at runtime from an OAS| |false|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
Expand Down
Expand Up @@ -135,6 +135,27 @@ public MpRestClientVersion(String rootPackage, String pomTemplate) {
}
}

@Override
public DocumentationProvider defaultDocumentationProvider() {
return DocumentationProvider.SOURCE;
}

@Override
public List<DocumentationProvider> supportedDocumentationProvider() {
List<DocumentationProvider> documentationProviders = new ArrayList<>();
documentationProviders.add(DocumentationProvider.NONE);
documentationProviders.add(DocumentationProvider.SOURCE);
return documentationProviders;
}

@Override
public List<AnnotationLibrary> supportedAnnotationLibraries() {
List<AnnotationLibrary> annotationLibraries = new ArrayList<>();
annotationLibraries.add(AnnotationLibrary.NONE);
annotationLibraries.add(AnnotationLibrary.SWAGGER1);
return annotationLibraries;
}

public JavaClientCodegen() {
super();

Expand Down Expand Up @@ -867,6 +888,14 @@ public CodegenModel fromModel(String name, Schema model) {
codegenModel.imports.remove("ApiModel");
}
}

// TODO: inverse logic. Do not add the imports unconditionally in the first place.
if (! AnnotationLibrary.SWAGGER1.equals(getAnnotationLibrary())) {
// Remove io.swagger.annotations.* imports
codegenModel.imports.remove("ApiModel");
codegenModel.imports.remove("ApiModelProperty");
}

return codegenModel;
}

Expand Down
Expand Up @@ -214,11 +214,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}

<!-- @Nullable annotation -->
<dependency>
Expand Down Expand Up @@ -325,7 +327,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.5.21</swagger-annotations-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<httpclient-version>4.5.13</httpclient-version>
<jackson-version>2.12.6</jackson-version>
<jackson-databind-version>2.12.6.1</jackson-databind-version>
Expand Down
Expand Up @@ -213,11 +213,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}

<!-- @Nullable annotation -->
<dependency>
Expand Down Expand Up @@ -351,7 +353,7 @@
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<swagger-annotations-version>1.5.24</swagger-annotations-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<feign-version>10.11</feign-version>
<feign-form-version>3.8.0</feign-form-version>
<jackson-version>2.10.3</jackson-version>
Expand Down
Expand Up @@ -206,11 +206,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down Expand Up @@ -294,7 +296,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.5.22</swagger-annotations-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<google-api-client-version>1.32.2</google-api-client-version>
<jersey-common-version>2.25.1</jersey-common-version>
<jackson-version>2.12.1</jackson-version>
Expand Down
Expand Up @@ -2,8 +2,12 @@
* {{description}}{{^description}}{{classname}}{{/description}}{{#isDeprecated}}
* @deprecated{{/isDeprecated}}
*/{{#isDeprecated}}
@Deprecated{{/isDeprecated}}{{#description}}
@ApiModel(description = "{{{.}}}"){{/description}}
@Deprecated{{/isDeprecated}}
{{#swagger1AnnotationLibrary}}
{{#description}}
@ApiModel(description = "{{{.}}}")
{{/description}}
{{/swagger1AnnotationLibrary}}
{{#jackson}}
@JsonPropertyOrder({
{{#vars}}
Expand Down Expand Up @@ -211,7 +215,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{^required}}
@javax.annotation.Nullable
{{/required}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{#useBeanValidation}}
{{>beanValidation}}
{{/useBeanValidation}}
{{#swagger1AnnotationLibrary}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{/swagger1AnnotationLibrary}}
{{#vendorExtensions.x-extra-annotation}}
{{{vendorExtensions.x-extra-annotation}}}
{{/vendorExtensions.x-extra-annotation}}
Expand Down
Expand Up @@ -258,11 +258,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}

<!-- @Nullable annotation -->
<dependency>
Expand Down Expand Up @@ -380,7 +382,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.6.5</swagger-annotations-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<jersey-version>2.35</jersey-version>
<jackson-version>2.13.2</jackson-version>
<jackson-databind-version>2.13.2.2</jackson-databind-version>
Expand Down
Expand Up @@ -2,8 +2,12 @@
* {{description}}{{^description}}{{classname}}{{/description}}{{#isDeprecated}}
* @deprecated{{/isDeprecated}}
*/{{#isDeprecated}}
@Deprecated{{/isDeprecated}}{{#description}}
@ApiModel(description = "{{{.}}}"){{/description}}
@Deprecated{{/isDeprecated}}
{{#swagger1AnnotationLibrary}}
{{#description}}
@ApiModel(description = "{{{.}}}")
{{/description}}
{{/swagger1AnnotationLibrary}}
{{#jackson}}
@JsonPropertyOrder({
{{#vars}}
Expand Down Expand Up @@ -211,7 +215,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{^required}}
@jakarta.annotation.Nullable
{{/required}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{#useBeanValidation}}
{{>beanValidation}}
{{/useBeanValidation}}
{{#swagger1AnnotationLibrary}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{/swagger1AnnotationLibrary}}
{{#vendorExtensions.x-extra-annotation}}
{{{vendorExtensions.x-extra-annotation}}}
{{/vendorExtensions.x-extra-annotation}}
Expand Down
Expand Up @@ -258,11 +258,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}

<!-- @Nullable annotation -->
<dependency>
Expand Down Expand Up @@ -380,7 +382,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.6.5</swagger-annotations-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<jersey-version>3.0.4</jersey-version>
<jackson-version>2.13.2</jackson-version>
<jackson-databind-version>2.13.2</jackson-databind-version>
Expand Down
Expand Up @@ -5,8 +5,12 @@ import {{invokerPackage}}.JSON;
* {{description}}{{^description}}{{classname}}{{/description}}{{#isDeprecated}}
* @deprecated{{/isDeprecated}}
*/{{#isDeprecated}}
@Deprecated{{/isDeprecated}}{{#description}}
@ApiModel(description = "{{{.}}}"){{/description}}
@Deprecated{{/isDeprecated}}
{{#swagger1AnnotationLibrary}}
{{#description}}
@ApiModel(description = "{{{.}}}")
{{/description}}
{{/swagger1AnnotationLibrary}}
{{#jackson}}
@JsonPropertyOrder({
{{#vars}}
Expand Down Expand Up @@ -211,7 +215,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{^required}}
@javax.annotation.Nullable
{{/required}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{#useBeanValidation}}
{{>beanValidation}}
{{/useBeanValidation}}
{{#swagger1AnnotationLibrary}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{/swagger1AnnotationLibrary}}
{{#vendorExtensions.x-extra-annotation}}
{{{vendorExtensions.x-extra-annotation}}}
{{/vendorExtensions.x-extra-annotation}}
Expand Down
Expand Up @@ -161,11 +161,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}

<!-- JSON processing: jackson -->
<dependency>
Expand Down Expand Up @@ -218,7 +220,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.5.22</swagger-annotations-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jackson-version>2.13.0</jackson-version>
Expand Down
Expand Up @@ -22,8 +22,12 @@ import {{invokerPackage}}.JSON;
* {{description}}{{^description}}{{classname}}{{/description}}{{#isDeprecated}}
* @deprecated{{/isDeprecated}}
*/{{#isDeprecated}}
@Deprecated{{/isDeprecated}}{{#description}}
@ApiModel(description = "{{{.}}}"){{/description}}
@Deprecated{{/isDeprecated}}
{{#swagger1AnnotationLibrary}}
{{#description}}
@ApiModel(description = "{{{.}}}")
{{/description}}
{{/swagger1AnnotationLibrary}}
{{#jackson}}
@JsonPropertyOrder({
{{#vars}}
Expand Down Expand Up @@ -216,7 +220,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{#jsonb}}
@JsonbProperty("{{baseName}}")
{{/jsonb}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{#useBeanValidation}}
{{>beanValidation}}
{{/useBeanValidation}}
{{#swagger1AnnotationLibrary}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{/swagger1AnnotationLibrary}}
{{#vendorExtensions.x-extra-annotation}}
{{{vendorExtensions.x-extra-annotation}}}
{{/vendorExtensions.x-extra-annotation}}
Expand Down
Expand Up @@ -256,11 +256,13 @@
</profiles>

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-core-version}</version>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down Expand Up @@ -386,7 +388,7 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.8.5</gson-fire-version>
<swagger-core-version>1.6.5</swagger-core-version>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<okhttp-version>4.9.3</okhttp-version>
<gson-version>2.9.0</gson-version>
<commons-lang3-version>3.12.0</commons-lang3-version>
Expand Down
Expand Up @@ -22,7 +22,9 @@ import io.restassured.common.mapper.TypeRef;
{{/jackson}}
import io.restassured.http.Method;
import io.restassured.response.Response;
{{#swagger1AnnotationLibrary}}
import io.swagger.annotations.*;
{{/swagger1AnnotationLibrary}}

import java.lang.reflect.Type;
import java.util.function.Consumer;
Expand All @@ -34,7 +36,9 @@ import {{invokerPackage}}.JSON;
{{/gson}}
import static io.restassured.http.Method.*;

{{#swagger1AnnotationLibrary}}
@Api(value = "{{{baseName}}}")
{{/swagger1AnnotationLibrary}}
public class {{classname}} {

private Supplier<RequestSpecBuilder> reqSpecSupplier;
Expand Down Expand Up @@ -68,12 +72,14 @@ public class {{classname}} {
{{#operations}}
{{#operation}}

{{#swagger1AnnotationLibrary}}
@ApiOperation(value = "{{{summary}}}",
notes = "{{{notes}}}",
nickname = "{{{operationId}}}",
tags = { {{#tags}}{{#name}}"{{{.}}}"{{/name}}{{^-last}}, {{/-last}}{{/tags}} })
@ApiResponses(value = { {{#responses}}
@ApiResponse(code = {{{code}}}, message = "{{{message}}}") {{^-last}},{{/-last}}{{/responses}} })
{{/swagger1AnnotationLibrary}}
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
Expand Down
Expand Up @@ -219,11 +219,13 @@
{{/jackson}}

<dependencies>
{{#swagger1AnnotationLibrary}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
{{/swagger1AnnotationLibrary}}
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down