diff --git a/docs/generators/jaxrs-resteasy.md b/docs/generators/jaxrs-resteasy.md index 4be73c6a6d1a4149d59fa59d12139275e15d1783..0d7c86dfa13db1c97827ba2e05d9290159d99bb1 100644 --- a/docs/generators/jaxrs-resteasy.md +++ b/docs/generators/jaxrs-resteasy.md @@ -52,6 +52,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| |sourceFolder|source folder for generated code| |src/main/java| +|swaggerAnnotations|Whether to generate Swagger annotations.| |true| |title|a title describing the application| |OpenAPI Server| |useBeanValidation|Use BeanValidation API annotations| |true| |useTags|use tags for creating interface and controller classnames| |false| diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties index 8b65b3b4572dcc49e8eeccdae211b328a726fe62..abf7b9c56260467b5b05a292855ed27e94e6def6 100644 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties @@ -1,3 +1,3 @@ # RELEASE_VERSION -openApiGeneratorVersion=5.2.0-SNAPSHOT +openApiGeneratorVersion=5.2.1-SNAPSHOT # /RELEASE_VERSION diff --git a/modules/openapi-generator-maven-plugin/examples/kotlin.xml b/modules/openapi-generator-maven-plugin/examples/kotlin.xml index 32f2e2627419e622fde814a8416928ebd6df8963..6db0f049f2a0d01893b3a3a29fefd34c16b7d3e9 100644 --- a/modules/openapi-generator-maven-plugin/examples/kotlin.xml +++ b/modules/openapi-generator-maven-plugin/examples/kotlin.xml @@ -15,7 +15,7 @@ <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <!-- RELEASE_VERSION --> - <version>5.2.0-SNAPSHOT</version> + <version>5.2.1-SNAPSHOT</version> <!-- /RELEASE_VERSION --> <executions> <execution> diff --git a/modules/openapi-generator-maven-plugin/examples/spring.xml b/modules/openapi-generator-maven-plugin/examples/spring.xml index c0932d04dd091b51eaeddaf85dd71ab8437dce77..79b8942ae57a490a2f27ec8773ad1e5a7d769391 100644 --- a/modules/openapi-generator-maven-plugin/examples/spring.xml +++ b/modules/openapi-generator-maven-plugin/examples/spring.xml @@ -20,7 +20,7 @@ <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <!-- RELEASE_VERSION --> - <version>5.2.0-SNAPSHOT</version> + <version>5.2.1-SNAPSHOT</version> <!-- /RELEASE_VERSION --> <executions> <execution> diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaResteasyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaResteasyServerCodegen.java index 0970e975b965601b755c344172f879b232ee5f24..22f82e88605e165b93a303bbc4602d675eeff76c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaResteasyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaResteasyServerCodegen.java @@ -17,20 +17,28 @@ package org.openapitools.codegen.languages; -import org.apache.commons.lang3.BooleanUtils; -import org.openapitools.codegen.*; -import org.openapitools.codegen.languages.features.JbossFeature; -import org.openapitools.codegen.meta.features.DocumentationFeature; - import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.BooleanUtils; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.languages.features.JbossFeature; +import org.openapitools.codegen.meta.features.DocumentationFeature; + public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen implements JbossFeature { protected boolean generateJbossDeploymentDescriptor = true; + private static final String SWAGGER_ANNOTATIONS = "swaggerAnnotations"; + + private boolean swaggerAnnotations = true; + public JavaResteasyServerCodegen() { super(); @@ -56,6 +64,7 @@ public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen im cliOptions.add( CliOption.newBoolean(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, "Generate Jboss Deployment Descriptor")); + cliOptions.add(CliOption.newBoolean(SWAGGER_ANNOTATIONS, "Whether to generate Swagger annotations.", swaggerAnnotations)); } @Override @@ -73,11 +82,16 @@ public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen im super.processOpts(); if (additionalProperties.containsKey(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) { - boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack( + final boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack( GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR); this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp); } + if (additionalProperties.containsKey(SWAGGER_ANNOTATIONS)) { + swaggerAnnotations = Boolean.parseBoolean(additionalProperties.get(SWAGGER_ANNOTATIONS).toString()); + } + writePropertyBack(SWAGGER_ANNOTATIONS, swaggerAnnotations); + supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml") .doNotOverwrite()); supportingFiles.add(new SupportingFile("gradle.mustache", "", "build.gradle") @@ -129,12 +143,12 @@ public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen im } @Override - public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) { + public Map<String, Object> postProcessOperationsWithModels(final Map<String, Object> objs, final List<Object> allModels) { return super.postProcessOperationsWithModels(objs, allModels); } @Override - public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + public void postProcessModelProperty(final CodegenModel model, final CodegenProperty property) { super.postProcessModelProperty(model, property); //Add imports for Jackson if (!BooleanUtils.toBoolean(model.isEnum)) { @@ -151,15 +165,15 @@ public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen im objs = super.postProcessModelsEnum(objs); //Add imports for Jackson - List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports"); - List<Object> models = (List<Object>) objs.get("models"); - for (Object _mo : models) { - Map<String, Object> mo = (Map<String, Object>) _mo; - CodegenModel cm = (CodegenModel) mo.get("model"); + final List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports"); + final List<Object> models = (List<Object>) objs.get("models"); + for (final Object _mo : models) { + final Map<String, Object> mo = (Map<String, Object>) _mo; + final CodegenModel cm = (CodegenModel) mo.get("model"); // for enum model - if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) { + if (Boolean.TRUE.equals(cm.isEnum) && (cm.allowableValues != null)) { cm.imports.add(importMapping.get("JsonValue")); - Map<String, String> item = new HashMap<String, String>(); + final Map<String, String> item = new HashMap<>(); item.put("import", importMapping.get("JsonValue")); imports.add(item); } @@ -168,7 +182,8 @@ public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen im return objs; } - public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor) { + @Override + public void setGenerateJbossDeploymentDescriptor(final boolean generateJbossDeploymentDescriptor) { this.generateJbossDeploymentDescriptor = generateJbossDeploymentDescriptor; } } diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/api.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/api.mustache index 4b4575440beb7df9108ed259d5eac478af6a8b28..216a274e708850095e92e13f4aeda82c254e317d 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/api.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/api.mustache @@ -3,8 +3,8 @@ package {{package}}; import {{modelPackage}}.*; import {{package}}.{{classname}}Service; -import io.swagger.annotations.ApiParam; -import io.swagger.jaxrs.*; +{{#swaggerAnnotations}}import io.swagger.annotations.ApiParam; +import io.swagger.jaxrs.*;{{/swaggerAnnotations}} {{#imports}}import {{import}}; {{/imports}} @@ -29,8 +29,8 @@ import javax.validation.Valid; {{/isMultipart}}{{/operation}}{{/operations}} @Path("{{commonPath}}") {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}} -{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} -@io.swagger.annotations.Api(description = "the {{{baseName}}} API") +{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}}{{#swaggerAnnotations}} +@io.swagger.annotations.Api(description = "the {{{baseName}}} API"){{/swaggerAnnotations}} {{>generatedAnnotation}} {{#operations}} public class {{classname}} { @@ -41,7 +41,7 @@ public class {{classname}} { @{{httpMethod}} {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}} - {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} + {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}}{{#swaggerAnnotations}} @io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { {{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { {{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, @@ -51,7 +51,7 @@ public class {{classname}} { }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) @io.swagger.annotations.ApiResponses(value = { {{#responses}} @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{^-last}}, - {{/-last}}{{/responses}} }) + {{/-last}}{{/responses}} }){{/swaggerAnnotations}} public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{^isMultipart}}{{>formParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}@Context SecurityContext securityContext) throws NotFoundException { return service.{{nickname}}({{#isMultipart}}input,{{/isMultipart}}{{#allParams}}{{^isMultipart}}{{paramName}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{paramName}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}securityContext); diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/bodyParams.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/bodyParams.mustache index eec07e9062da6e17f33955325750347eab570e35..8a39ecc568c2080d00c83ddcff402497b499c352 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/bodyParams.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/bodyParams.mustache @@ -1 +1 @@ -{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#useBeanValidation}}{{#required}} @NotNull{{/required}} @Valid{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}}{{#useBeanValidation}}{{#required}} @NotNull{{/required}} @Valid{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/formParams.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/formParams.mustache index 79d5e482e3d0d787caa47ee7dd2a8a80d9579258..b7aa1b6f35f00759d5e11c49fc17d2f4fb99d0c1 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/formParams.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/formParams.mustache @@ -1 +1 @@ -{{#isFormParam}}{{^isFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{^isFile}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/headerParams.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/headerParams.mustache index 6dafce8fe79bfda1633eecb4d4b8a607176021a6..3f422dc7ee2adef0eba948fbccd869754c3ba91e 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/headerParams.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/headerParams.mustache @@ -1 +1 @@ -{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationHeaderParams}}{{/useBeanValidation}} @ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationHeaderParams}}{{/useBeanValidation}} {{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} @HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}} \ No newline at end of file