Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void processOpts() {
convertPropertyToStringAndWriteBack(CodegenConstants.IMPL_FOLDER, this::setImplFolder);
convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION, this::setUseBeanValidation);
convertPropertyToBooleanAndWriteBack(USE_TAGS, this::setUseTags);
convertPropertyToBooleanAndWriteBack(JACKSON, this::setJackson);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about defaulting this option to true instead?

(I can do it in another PR instead)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the value is set to default true here

I assumed the property, if not explicitly configured, would not be present (and this method does not set anything if the property is not present). Is this okay or is this an incrrect assumption?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. I was not expecting so many changes to the samples if the option is default to true but it turns out most changes are just removing empty lines

i'll test the option locally and merge if no question from me.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,22 @@ public void processOpts() {
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")
.doNotOverwrite());
supportingFiles.add(new SupportingFile("RestResourceRoot.mustache",
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestResourceRoot.java")
.doNotOverwrite());

if (!interfaceOnly) {
supportingFiles.add(new SupportingFile("RestResourceRoot.mustache",
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestResourceRoot.java")
.doNotOverwrite());

supportingFiles.add(new SupportingFile("RestApplication.mustache",
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java")
.doNotOverwrite());
}

if (generatePom) {
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")
.doNotOverwrite());
}

supportingFiles.add(new SupportingFile("RestApplication.mustache",
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java")
.doNotOverwrite());

if (StringUtils.isNotEmpty(openApiSpecFileLocation)) {
int index = openApiSpecFileLocation.lastIndexOf('/');
String fileFolder;
Expand Down Expand Up @@ -276,6 +279,7 @@ public CodegenModel fromModel(String name, Schema model) {
if (!jackson) {
codegenModel.imports.remove("JsonValue");
codegenModel.imports.remove("JsonProperty");
codegenModel.imports.remove("JsonTypeName");
}
return codegenModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {{javaxPackage}}.validation.Valid;{{/useBeanValidation}}
/**
* Represents a collection of functions to interact with the API endpoints.
*/
@Path("{{commonPath}}"){{#useSwaggerAnnotations}}
{{^interfaceOnly}}
@Path("{{commonPath}}")
{{/interfaceOnly}}
{{#useSwaggerAnnotations}}
@Api(description = "the {{{baseName}}} API"){{/useSwaggerAnnotations}}{{#hasConsumes}}
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}}
@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @return {{{message}}}
{{/responses}}
*/
@{{httpMethod}}{{#subresourceOperation}}
@Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}}
@{{httpMethod}}
@Path("{{commonPath}}{{{path}}}"){{#hasConsumes}}
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}}
@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}}{{#useSwaggerAnnotations}}
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}"{{#hasAuthMethods}}, authorizations = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
}

@Override
{{#jackson}}
@JsonValue
{{/jackson}}
public String toString() {
return String.valueOf(value);
}
Expand All @@ -40,6 +42,7 @@
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected string value '" + s + "'");{{/isNullable}}
}

{{#jackson}}
@JsonCreator
public static {{datatypeWithEnum}} fromValue({{dataType}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
Expand All @@ -49,4 +52,5 @@
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
}
{{/jackson}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ import com.fasterxml.jackson.annotation.JsonValue;
}

@Override
{{#jackson}}
@JsonValue
{{/jackson}}
public String toString() {
return String.valueOf(value);
}

{{#jackson}}
@JsonCreator
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
Expand All @@ -55,4 +58,5 @@ import com.fasterxml.jackson.annotation.JsonValue;
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
}
{{/jackson}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import io.swagger.annotations.*;
{{/useSwaggerAnnotations}}
import java.util.Objects;
{{#jackson}}
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonTypeName;

{{/jackson}}
{{#withXml}}
import {{javaxPackage}}.xml.bind.annotation.XmlElement;
import {{javaxPackage}}.xml.bind.annotation.XmlRootElement;
Expand All @@ -22,7 +23,7 @@ import {{javaxPackage}}.xml.bind.annotation.XmlEnumValue;
**/{{/description}}
{{#useSwaggerAnnotations}}{{#description}}@ApiModel(description = "{{{.}}}"){{/description}}{{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#title}}title="{{{.}}}", {{/title}}{{#description}}description="{{{.}}}"{{/description}}{{^description}}description=""{{/description}}){{/useMicroProfileOpenAPIAnnotations}}
@JsonTypeName("{{name}}")
{{#jackson}}@JsonTypeName("{{name}}"){{/jackson}}
{{>generatedAnnotation}}{{>additionalModelTypeAnnotations}}{{>xmlPojoAnnotation}}
{{#vendorExtensions.x-class-extra-annotation}}
{{{vendorExtensions.x-class-extra-annotation}}}
Expand Down Expand Up @@ -61,6 +62,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
public {{classname}}() {
}

{{#jackson}}
{{#generateJsonCreator}}
{{#hasRequired}}
@JsonCreator
Expand All @@ -85,6 +87,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens

{{/hasRequired}}
{{/generateJsonCreator}}
{{/jackson}}
{{#vars}}
/**
{{#description}}
Expand All @@ -108,12 +111,14 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
{{#vendorExtensions.x-extra-annotation}}{{{vendorExtensions.x-extra-annotation}}}{{/vendorExtensions.x-extra-annotation}}{{#useSwaggerAnnotations}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useMicroProfileOpenAPIAnnotations}}
@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}")
{{#jackson}}@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}"){{/jackson}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}public {{>beanValidatedType}} {{getter}}() {
return {{name}};
}

{{#jackson}}
@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}")
{{/jackson}}
{{#vendorExtensions.x-setter-extra-annotation}}{{{vendorExtensions.x-setter-extra-annotation}}}
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ src/gen/java/org/openapitools/api/AnotherFakeApi.java
src/gen/java/org/openapitools/api/FakeApi.java
src/gen/java/org/openapitools/api/FakeClassnameTestApi.java
src/gen/java/org/openapitools/api/PetApi.java
src/gen/java/org/openapitools/api/RestApplication.java
src/gen/java/org/openapitools/api/RestResourceRoot.java
src/gen/java/org/openapitools/api/StoreApi.java
src/gen/java/org/openapitools/api/UserApi.java
src/gen/java/org/openapitools/model/AdditionalPropertiesAnyType.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/**
* Represents a collection of functions to interact with the API endpoints.
*/
@Path("/another-fake/dummy")
@Api(description = "the another-fake API")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.17.0-SNAPSHOT")
public interface AnotherFakeApi {
Expand All @@ -30,6 +29,7 @@ public interface AnotherFakeApi {
* @return successful operation
*/
@PATCH
@Path("/another-fake/dummy")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "To test special tags", notes = "To test special tags and operation ID starting with number", tags={ "$another-fake?" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/**
* Represents a collection of functions to interact with the API endpoints.
*/
@Path("/fake")
@Api(description = "the fake API")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.17.0-SNAPSHOT")
public interface FakeApi {
Expand All @@ -38,7 +37,7 @@ public interface FakeApi {
* @return successful operation
*/
@POST
@Path("/create_xml_item")
@Path("/fake/create_xml_item")
@Consumes({ "application/xml", "application/xml; charset=utf-8", "application/xml; charset=utf-16", "text/xml", "text/xml; charset=utf-8", "text/xml; charset=utf-16" })
@ApiOperation(value = "creates an XmlItem", notes = "this route creates an XmlItem", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -53,7 +52,7 @@ public interface FakeApi {
* @return Output boolean
*/
@POST
@Path("/outer/boolean")
@Path("/fake/outer/boolean")
@Produces({ "*/*" })
@ApiOperation(value = "", notes = "Test serialization of outer boolean types", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -68,7 +67,7 @@ public interface FakeApi {
* @return Output composite
*/
@POST
@Path("/outer/composite")
@Path("/fake/outer/composite")
@Produces({ "*/*" })
@ApiOperation(value = "", notes = "Test serialization of object with outer number type", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -83,7 +82,7 @@ public interface FakeApi {
* @return Output number
*/
@POST
@Path("/outer/number")
@Path("/fake/outer/number")
@Produces({ "*/*" })
@ApiOperation(value = "", notes = "Test serialization of outer number types", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -98,7 +97,7 @@ public interface FakeApi {
* @return Output string
*/
@POST
@Path("/outer/string")
@Path("/fake/outer/string")
@Produces({ "*/*" })
@ApiOperation(value = "", notes = "Test serialization of outer string types", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -113,7 +112,7 @@ public interface FakeApi {
* @return Success
*/
@PUT
@Path("/body-with-file-schema")
@Path("/fake/body-with-file-schema")
@Consumes({ "application/json" })
@ApiOperation(value = "", notes = "For this test, the body for this request much reference a schema named `File`.", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -129,7 +128,7 @@ public interface FakeApi {
* @return Success
*/
@PUT
@Path("/body-with-query-params")
@Path("/fake/body-with-query-params")
@Consumes({ "application/json" })
@ApiOperation(value = "", notes = "", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -144,6 +143,7 @@ public interface FakeApi {
* @return successful operation
*/
@PATCH
@Path("/fake")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "To test \"client\" model", notes = "To test \"client\" model", tags={ "fake" })
Expand Down Expand Up @@ -173,6 +173,7 @@ public interface FakeApi {
* @return User not found
*/
@POST
@Path("/fake")
@Consumes({ "application/x-www-form-urlencoded" })
@ApiOperation(value = "Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트", notes = "Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트", authorizations = {

Expand All @@ -199,6 +200,7 @@ public interface FakeApi {
* @return Not found
*/
@GET
@Path("/fake")
@Consumes({ "application/x-www-form-urlencoded" })
@ApiOperation(value = "To test enum parameters", notes = "To test enum parameters", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -219,6 +221,7 @@ public interface FakeApi {
* @return Something wrong
*/
@DELETE
@Path("/fake")
@ApiOperation(value = "Fake endpoint to test group parameters (optional)", notes = "Fake endpoint to test group parameters (optional)", tags={ "fake" })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Something wrong", response = Void.class) })
Expand All @@ -232,7 +235,7 @@ public interface FakeApi {
* @return successful operation
*/
@POST
@Path("/inline-additionalProperties")
@Path("/fake/inline-additionalProperties")
@Consumes({ "application/json" })
@ApiOperation(value = "test inline additionalProperties", notes = "", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -248,7 +251,7 @@ public interface FakeApi {
* @return successful operation
*/
@GET
@Path("/jsonFormData")
@Path("/fake/jsonFormData")
@Consumes({ "application/x-www-form-urlencoded" })
@ApiOperation(value = "test json serialization of form data", notes = "", tags={ "fake" })
@ApiResponses(value = {
Expand All @@ -267,7 +270,7 @@ public interface FakeApi {
* @return Success
*/
@PUT
@Path("/test-query-parameters")
@Path("/fake/test-query-parameters")
@ApiOperation(value = "", notes = "To test the collection format in query parameters", tags={ "fake" })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = Void.class) })
Expand All @@ -283,7 +286,7 @@ public interface FakeApi {
* @return successful operation
*/
@POST
@Path("/{petId}/uploadImageWithRequiredFile")
@Path("/fake/{petId}/uploadImageWithRequiredFile")
@Consumes({ "multipart/form-data" })
@Produces({ "application/json" })
@ApiOperation(value = "uploads an image (required)", notes = "", authorizations = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/**
* Represents a collection of functions to interact with the API endpoints.
*/
@Path("/fake_classname_test")
@Api(description = "the fake_classname_test API")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.17.0-SNAPSHOT")
public interface FakeClassnameTestApi {
Expand All @@ -28,6 +27,7 @@ public interface FakeClassnameTestApi {
* @return successful operation
*/
@PATCH
@Path("/fake_classname_test")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "To test class name in snake case", notes = "To test class name in snake case", authorizations = {
Expand Down
Loading
Loading