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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,13 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
schemas.put(opId, requestSchema);
}
// process all response bodies
for (Map.Entry<String, ApiResponse> ar : op.getValue().getResponses().entrySet()) {
ApiResponse a = ModelUtils.getReferencedApiResponse(openAPI, ar.getValue());
Schema responseSchema = ModelUtils.getSchemaFromResponse(a);
if (responseSchema != null) {
schemas.put(opId + ar.getKey(), responseSchema);
if (op.getValue().getResponses() != null) {
for (Map.Entry<String, ApiResponse> ar : op.getValue().getResponses().entrySet()) {
ApiResponse a = ModelUtils.getReferencedApiResponse(openAPI, ar.getValue());
Schema responseSchema = ModelUtils.getSchemaFromResponse(a);
if (responseSchema != null) {
schemas.put(opId + ar.getKey(), responseSchema);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,17 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
}
}

// add implements for serializable/parcelable to all models
List<Map<String, Object>> models = (List<Map<String, Object>>) objs.get("models");
for (Map<String, Object> mo : models) {
CodegenModel cm = (CodegenModel) mo.get("model");
cm.getVendorExtensions().putIfAbsent("implements", new ArrayList<String>()); // TODO: 5.0 Remove
cm.getVendorExtensions().putIfAbsent("x-implements", cm.getVendorExtensions().get("implements"));
if (this.serializableModel) {
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Serializable");
}
}

return postProcessModelsEnum(objs);
}

Expand Down Expand Up @@ -1214,6 +1225,17 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}
}

@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo")) {
Map<String, String> oneImport = new HashMap<>();
oneImport.put("import", importMapping.get(i));
if (!imports.contains(oneImport)) {
imports.add(oneImport);
}
}
}

private static String getAccept(OpenAPI openAPI, Operation operation) {
String accepts = null;
String defaultContentType = "application/json";
Expand Down Expand Up @@ -1727,7 +1749,7 @@ public void setAdditionalModelTypeAnnotations(final List<String> additionalModel
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
if (!supportsAdditionalPropertiesWithComposedSchema) {
// The additional (undeclared) propertiees are modeled in Java as a HashMap.
//
//
// 1. supportsAdditionalPropertiesWithComposedSchema is set to false:
// The generated model class extends from the HashMap. That does not work
// with composed schemas that also use a discriminator because the model class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,4 @@ public String toApiVarName(String name) {
}
return apiVarName;
}

@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo")) {
Map<String, String> oneImport = new HashMap<>();
oneImport.put("import", importMapping.get(i));
if (!imports.contains(oneImport)) {
imports.add(oneImport);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public void processOpts() {
} else if(KUMULUZEE_LIBRARY.equals(library)) {
supportingFiles.add(new SupportingFile("config.yaml.mustache", "src/main/resources", "config.yaml"));
}

if(useJackson) {
useOneOfInterfaces = true;
addOneOfInterfaceImports = true;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import javax.validation.Valid;
{{#isEnum}}
{{>enumOuterClass}}
{{/isEnum}}
{{^isEnum}}{{>pojo}}{{/isEnum}}
{{^isEnum}}
{{#vendorExtensions.x-is-one-of-interface}}{{>oneof_interface}}{{/vendorExtensions.x-is-one-of-interface}}{{^vendorExtensions.x-is-one-of-interface}}{{>pojo}}{{/vendorExtensions.x-is-one-of-interface}}
{{/isEnum}}

{{/model}}
{{/models}}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}
public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
{{#discriminator}}
public {{propertyType}} {{propertyGetter}}();
{{/discriminator}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import com.fasterxml.jackson.annotation.JsonValue;
* {{description}}
**/{{/description}}
{{#useSwaggerAnnotations}}{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}{{/useSwaggerAnnotations}}
{{>generatedAnnotation}}{{>additionalModelTypeAnnotations}}public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
{{>generatedAnnotation}}{{>additionalModelTypeAnnotations}}public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}{
{{#vars}}{{#isEnum}}{{^isContainer}}

{{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}}

{{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}}
private {{#useBeanValidation}}@Valid {{/useBeanValidation}}{{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};{{/vars}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openapitools.codegen.java.jaxrs;

import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.ArraySchema;
Expand Down Expand Up @@ -51,8 +52,7 @@ public void testInitialConfigValues() throws Exception {
final JavaJAXRSSpecServerCodegen codegen = new JavaJAXRSSpecServerCodegen();
codegen.processOpts();

OpenAPI openAPI = new OpenAPI();
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
final OpenAPI openAPI = createOpenApiWithServerUrl();
codegen.preprocessOpenAPI(openAPI);

Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
Expand Down Expand Up @@ -101,8 +101,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
codegen.additionalProperties().put(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "openapi.yml");
codegen.processOpts();

OpenAPI openAPI = new OpenAPI();
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
OpenAPI openAPI = createOpenApiWithServerUrl();
codegen.preprocessOpenAPI(openAPI);

Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
Expand Down Expand Up @@ -396,4 +395,15 @@ public void addsImportForSetResponse() throws IOException {

assertFileContains(path, "\nimport java.util.Set;\n");
}

private OpenAPI createOpenApiWithServerUrl() {
final OpenAPI openAPI = new OpenAPI();
final Components components = new Components();
components.schemas(new HashMap<>());
openAPI.setComponents(components);

openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));

return openAPI;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class AdditionalPropertiesClass implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class AdditionalPropertiesClass implements Serializable {

private @Valid Map<String, String> mapString = new HashMap<String, String>();
private @Valid Map<String, BigDecimal> mapNumber = new HashMap<String, BigDecimal>();
Expand Down Expand Up @@ -293,3 +293,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
})


@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Animal implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Animal implements Serializable {

private @Valid String className;
private @Valid String color = "red";
Expand Down Expand Up @@ -109,3 +109,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ArrayOfArrayOfNumberOnly implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ArrayOfArrayOfNumberOnly implements Serializable {

private @Valid List<List<BigDecimal>> arrayArrayNumber = new ArrayList<List<BigDecimal>>();

Expand Down Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ArrayOfNumberOnly implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ArrayOfNumberOnly implements Serializable {

private @Valid List<BigDecimal> arrayNumber = new ArrayList<BigDecimal>();

Expand Down Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ArrayTest implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ArrayTest implements Serializable {

private @Valid List<String> arrayOfString = new ArrayList<String>();
private @Valid List<List<Long>> arrayArrayOfInteger = new ArrayList<List<Long>>();
Expand Down Expand Up @@ -124,3 +124,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class BigCatAllOf implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class BigCatAllOf implements Serializable {


public enum KindEnum {
Expand Down Expand Up @@ -112,3 +112,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Capitalization implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Capitalization implements Serializable {

private @Valid String smallCamel;
private @Valid String capitalCamel;
Expand Down Expand Up @@ -185,3 +185,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class CatAllOf implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class CatAllOf implements Serializable {

private @Valid Boolean declawed;

Expand Down Expand Up @@ -79,3 +79,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Category implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Category implements Serializable {

private @Valid Long id;
private @Valid String name = "default-name";
Expand Down Expand Up @@ -101,3 +101,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Model for testing model with \&quot;_class\&quot; property
**/
@ApiModel(description = "Model for testing model with \"_class\" property")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ClassModel implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class ClassModel implements Serializable {

private @Valid String propertyClass;

Expand Down Expand Up @@ -81,3 +81,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Client implements Serializable {
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")public class Client implements Serializable {

private @Valid String client;

Expand Down Expand Up @@ -79,3 +79,5 @@ private String toIndentedString(Object o) {

}



Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ private String toIndentedString(Object o) {

}



Loading