forked from loafle/openapi-generator-original
update tests, generators and more
This commit is contained in:
parent
8c06f96529
commit
4a275b24f7
@ -111,8 +111,8 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
/**
|
/**
|
||||||
* True if this property is an array of items or a map container.
|
* True if this property is an array of items or a map container.
|
||||||
* See:
|
* See:
|
||||||
* - ModelUtils.isArraySchema()
|
* - modelUtils.isArraySchema()
|
||||||
* - ModelUtils.isMapSchema()
|
* - modelUtils.isMapSchema()
|
||||||
*/
|
*/
|
||||||
public boolean isContainer;
|
public boolean isContainer;
|
||||||
public boolean isString;
|
public boolean isString;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@
|
|||||||
package org.openapitools.codegen;
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import io.swagger.models.Model;
|
||||||
import io.swagger.v3.core.util.Json;
|
import io.swagger.v3.core.util.Json;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.Operation;
|
import io.swagger.v3.oas.models.Operation;
|
||||||
@ -76,6 +77,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
protected CodegenConfig config;
|
protected CodegenConfig config;
|
||||||
protected ClientOptInput opts;
|
protected ClientOptInput opts;
|
||||||
protected OpenAPI openAPI;
|
protected OpenAPI openAPI;
|
||||||
|
protected ModelUtils modelUtils;
|
||||||
protected CodegenIgnoreProcessor ignoreProcessor;
|
protected CodegenIgnoreProcessor ignoreProcessor;
|
||||||
private Boolean generateApis = null;
|
private Boolean generateApis = null;
|
||||||
private Boolean generateModels = null;
|
private Boolean generateModels = null;
|
||||||
@ -108,6 +110,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
public Generator opts(ClientOptInput opts) {
|
public Generator opts(ClientOptInput opts) {
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.openAPI = opts.getOpenAPI();
|
this.openAPI = opts.getOpenAPI();
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
this.config = opts.getConfig();
|
this.config = opts.getConfig();
|
||||||
List<TemplateDefinition> userFiles = opts.getUserDefinedTemplates();
|
List<TemplateDefinition> userFiles = opts.getUserDefinedTemplates();
|
||||||
if (userFiles != null) {
|
if (userFiles != null) {
|
||||||
@ -152,6 +155,10 @@ public class DefaultGenerator implements Generator {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModelUtils getModelUtils() {
|
||||||
|
return modelUtils;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an instance to the configured template processor, available after user-defined options are
|
* Retrieves an instance to the configured template processor, available after user-defined options are
|
||||||
* applied via {@link DefaultGenerator#opts(ClientOptInput)}.
|
* applied via {@link DefaultGenerator#opts(ClientOptInput)}.
|
||||||
@ -397,7 +404,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, Schema> schemas = ModelUtils.getSchemas(this.openAPI);
|
final Map<String, Schema> schemas = modelUtils.getSchemas();
|
||||||
if (schemas == null) {
|
if (schemas == null) {
|
||||||
LOGGER.warn("Skipping generation of models because specification document has no schemas.");
|
LOGGER.warn("Skipping generation of models because specification document has no schemas.");
|
||||||
return;
|
return;
|
||||||
@ -458,7 +465,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
|
|
||||||
Schema schema = schemas.get(name);
|
Schema schema = schemas.get(name);
|
||||||
|
|
||||||
if (ModelUtils.isFreeFormObject(this.openAPI, schema)) { // check to see if it'a a free-form object
|
if (modelUtils.isFreeFormObject(schema)) { // check to see if it'a a free-form object
|
||||||
// there are 3 free form use cases
|
// there are 3 free form use cases
|
||||||
// 1. free form with no validation that is not allOf included in any composed schemas
|
// 1. free form with no validation that is not allOf included in any composed schemas
|
||||||
// 2. free form with validation
|
// 2. free form with validation
|
||||||
@ -472,17 +479,17 @@ public class DefaultGenerator implements Generator {
|
|||||||
LOGGER.info("Model {} not generated since it's a free-form object", name);
|
LOGGER.info("Model {} not generated since it's a free-form object", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(schema)) { // check to see if it's a "map" model
|
} else if (modelUtils.isMapSchema(schema)) { // check to see if it's a "map" model
|
||||||
// A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
|
// A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
|
||||||
// for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
|
// for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
|
||||||
// in the inner schemas, and the outer schema does not have properties.
|
// in the inner schemas, and the outer schema does not have properties.
|
||||||
if (!ModelUtils.isGenerateAliasAsModel(schema) && !ModelUtils.isComposedSchema(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
if (!modelUtils.isGenerateAliasAsModel(schema) && !modelUtils.isComposedSchema(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
||||||
// schema without property, i.e. alias to map
|
// schema without property, i.e. alias to map
|
||||||
LOGGER.info("Model {} not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)", name);
|
LOGGER.info("Model {} not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
|
} else if (modelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
|
||||||
if (!ModelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
if (!modelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
|
||||||
// schema without property, i.e. alias to array
|
// schema without property, i.e. alias to array
|
||||||
LOGGER.info("Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)", name);
|
LOGGER.info("Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)", name);
|
||||||
continue;
|
continue;
|
||||||
@ -868,7 +875,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
|
|
||||||
List<File> files = new ArrayList<>();
|
List<File> files = new ArrayList<>();
|
||||||
// models
|
// models
|
||||||
List<String> filteredSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI);
|
List<String> filteredSchemas = modelUtils.getSchemasUsedOnlyInFormParam();
|
||||||
List<Object> allModels = new ArrayList<>();
|
List<Object> allModels = new ArrayList<>();
|
||||||
generateModels(files, allModels, filteredSchemas);
|
generateModels(files, allModels, filteredSchemas);
|
||||||
// apis
|
// apis
|
||||||
|
@ -39,6 +39,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class InlineModelResolver {
|
public class InlineModelResolver {
|
||||||
private OpenAPI openapi;
|
private OpenAPI openapi;
|
||||||
|
private ModelUtils modelUtils;
|
||||||
private Map<String, Schema> addedModels = new HashMap<String, Schema>();
|
private Map<String, Schema> addedModels = new HashMap<String, Schema>();
|
||||||
private Map<String, String> generatedSignature = new HashMap<String, String>();
|
private Map<String, String> generatedSignature = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
void flatten(OpenAPI openapi) {
|
void flatten(OpenAPI openapi) {
|
||||||
this.openapi = openapi;
|
this.openapi = openapi;
|
||||||
|
this.modelUtils = new ModelUtils(openapi);
|
||||||
|
|
||||||
if (openapi.getComponents() == null) {
|
if (openapi.getComponents() == null) {
|
||||||
openapi.setComponents(new Components());
|
openapi.setComponents(new Components());
|
||||||
@ -116,7 +118,7 @@ public class InlineModelResolver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Schema model = ModelUtils.getSchemaFromRequestBody(requestBody);
|
Schema model = modelUtils.getSchemaFromRequestBody(requestBody);
|
||||||
if (model instanceof ObjectSchema) {
|
if (model instanceof ObjectSchema) {
|
||||||
Schema obj = (Schema) model;
|
Schema obj = (Schema) model;
|
||||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||||
@ -266,11 +268,11 @@ public class InlineModelResolver {
|
|||||||
|
|
||||||
for (String key : responses.keySet()) {
|
for (String key : responses.keySet()) {
|
||||||
ApiResponse response = responses.get(key);
|
ApiResponse response = responses.get(key);
|
||||||
if (ModelUtils.getSchemaFromResponse(response) == null) {
|
if (modelUtils.getSchemaFromResponse(response) == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Schema property = ModelUtils.getSchemaFromResponse(response);
|
Schema property = modelUtils.getSchemaFromResponse(response);
|
||||||
if (property instanceof ObjectSchema) {
|
if (property instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) property;
|
ObjectSchema op = (ObjectSchema) property;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
@ -318,7 +320,7 @@ public class InlineModelResolver {
|
|||||||
}
|
}
|
||||||
} else if (property instanceof MapSchema) {
|
} else if (property instanceof MapSchema) {
|
||||||
MapSchema mp = (MapSchema) property;
|
MapSchema mp = (MapSchema) property;
|
||||||
Schema innerProperty = ModelUtils.getAdditionalProperties(openAPI, mp);
|
Schema innerProperty = modelUtils.getAdditionalProperties(mp);
|
||||||
if (innerProperty instanceof ObjectSchema) {
|
if (innerProperty instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) innerProperty;
|
ObjectSchema op = (ObjectSchema) innerProperty;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
@ -428,7 +430,7 @@ public class InlineModelResolver {
|
|||||||
List<String> modelNames = new ArrayList<String>(models.keySet());
|
List<String> modelNames = new ArrayList<String>(models.keySet());
|
||||||
for (String modelName : modelNames) {
|
for (String modelName : modelNames) {
|
||||||
Schema model = models.get(modelName);
|
Schema model = models.get(modelName);
|
||||||
if (ModelUtils.isComposedSchema(model)) {
|
if (modelUtils.isComposedSchema(model)) {
|
||||||
ComposedSchema m = (ComposedSchema) model;
|
ComposedSchema m = (ComposedSchema) model;
|
||||||
// inline child schemas
|
// inline child schemas
|
||||||
flattenComposedChildren(openAPI, modelName + "_allOf", m.getAllOf());
|
flattenComposedChildren(openAPI, modelName + "_allOf", m.getAllOf());
|
||||||
@ -439,7 +441,7 @@ public class InlineModelResolver {
|
|||||||
Map<String, Schema> properties = m.getProperties();
|
Map<String, Schema> properties = m.getProperties();
|
||||||
flattenProperties(openAPI, properties, modelName);
|
flattenProperties(openAPI, properties, modelName);
|
||||||
fixStringModel(m);
|
fixStringModel(m);
|
||||||
} else if (ModelUtils.isArraySchema(model)) {
|
} else if (modelUtils.isArraySchema(model)) {
|
||||||
ArraySchema m = (ArraySchema) model;
|
ArraySchema m = (ArraySchema) model;
|
||||||
Schema inner = m.getItems();
|
Schema inner = m.getItems();
|
||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
@ -602,8 +604,8 @@ public class InlineModelResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isMapSchema(property)) {
|
if (modelUtils.isMapSchema(property)) {
|
||||||
Schema inner = ModelUtils.getAdditionalProperties(openAPI, property);
|
Schema inner = modelUtils.getAdditionalProperties(property);
|
||||||
if (inner instanceof ObjectSchema) {
|
if (inner instanceof ObjectSchema) {
|
||||||
ObjectSchema op = (ObjectSchema) inner;
|
ObjectSchema op = (ObjectSchema) inner;
|
||||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||||
|
@ -264,7 +264,7 @@ public class CodegenConfigurator {
|
|||||||
|
|
||||||
public CodegenConfigurator setGenerateAliasAsModel(boolean generateAliasAsModel) {
|
public CodegenConfigurator setGenerateAliasAsModel(boolean generateAliasAsModel) {
|
||||||
workflowSettingsBuilder.withGenerateAliasAsModel(generateAliasAsModel);
|
workflowSettingsBuilder.withGenerateAliasAsModel(generateAliasAsModel);
|
||||||
ModelUtils.setGenerateAliasAsModel(generateAliasAsModel);
|
GlobalSettings.setProperty("generateAliasAsModelKey", String.valueOf(generateAliasAsModel));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,9 +508,6 @@ public class CodegenConfigurator {
|
|||||||
GlobalSettings.setProperty(entry.getKey(), entry.getValue());
|
GlobalSettings.setProperty(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if caller resets GlobalSettings, we'll need to reset generateAliasAsModel. As noted in this method, this should be moved.
|
|
||||||
ModelUtils.setGenerateAliasAsModel(workflowSettings.isGenerateAliasAsModel());
|
|
||||||
|
|
||||||
// TODO: Support custom spec loader implementations (https://github.com/OpenAPITools/openapi-generator/issues/844)
|
// TODO: Support custom spec loader implementations (https://github.com/OpenAPITools/openapi-generator/issues/844)
|
||||||
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
|
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
|
||||||
ParseOptions options = new ParseOptions();
|
ParseOptions options = new ParseOptions();
|
||||||
@ -523,13 +520,18 @@ public class CodegenConfigurator {
|
|||||||
// TODO: The line below could be removed when at least one of the issue below has been resolved.
|
// TODO: The line below could be removed when at least one of the issue below has been resolved.
|
||||||
// https://github.com/swagger-api/swagger-parser/issues/1369
|
// https://github.com/swagger-api/swagger-parser/issues/1369
|
||||||
// https://github.com/swagger-api/swagger-parser/pull/1374
|
// https://github.com/swagger-api/swagger-parser/pull/1374
|
||||||
//ModelUtils.getOpenApiVersion(specification, inputSpec, authorizationValues);
|
//modelUtils.getOpenApiVersion(specification, inputSpec, authorizationValues);
|
||||||
|
|
||||||
|
ModelUtils modelUtils = new ModelUtils(specification);
|
||||||
|
|
||||||
|
// if caller resets GlobalSettings, we'll need to reset generateAliasAsModel. As noted in this method, this should be moved.
|
||||||
|
modelUtils.setGenerateAliasAsModel(workflowSettings.isGenerateAliasAsModel());
|
||||||
|
|
||||||
// NOTE: We will only expose errors+warnings if there are already errors in the spec.
|
// NOTE: We will only expose errors+warnings if there are already errors in the spec.
|
||||||
if (validationMessages.size() > 0) {
|
if (validationMessages.size() > 0) {
|
||||||
Set<String> warnings = new HashSet<>();
|
Set<String> warnings = new HashSet<>();
|
||||||
if (specification != null) {
|
if (specification != null) {
|
||||||
List<String> unusedModels = ModelUtils.getUnusedSchemas(specification);
|
List<String> unusedModels = modelUtils.getUnusedSchemas();
|
||||||
if (unusedModels != null) {
|
if (unusedModels != null) {
|
||||||
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
|
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.examples;
|
package org.openapitools.codegen.examples;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xpath.internal.operations.Mod;
|
||||||
import io.swagger.v3.core.util.Json;
|
import io.swagger.v3.core.util.Json;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
@ -46,11 +47,13 @@ public class ExampleGenerator {
|
|||||||
|
|
||||||
protected Map<String, Schema> examples;
|
protected Map<String, Schema> examples;
|
||||||
private OpenAPI openAPI;
|
private OpenAPI openAPI;
|
||||||
|
private ModelUtils modelUtils;
|
||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
public ExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
public ExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
||||||
this.examples = examples;
|
this.examples = examples;
|
||||||
this.openAPI = openAPI;
|
this.openAPI = openAPI;
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
// use a fixed seed to make the "random" numbers reproducible.
|
// use a fixed seed to make the "random" numbers reproducible.
|
||||||
this.random = new Random("ExampleGenerator".hashCode());
|
this.random = new Random("ExampleGenerator".hashCode());
|
||||||
}
|
}
|
||||||
@ -69,7 +72,7 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Map<String, String>> generateFromResponseSchema(Schema responseSchema, Set<String> producesInfo) {
|
private List<Map<String, String>> generateFromResponseSchema(Schema responseSchema, Set<String> producesInfo) {
|
||||||
if (responseSchema.getExample() == null && StringUtils.isEmpty(responseSchema.get$ref()) && !ModelUtils.isArraySchema(responseSchema)) {
|
if (responseSchema.getExample() == null && StringUtils.isEmpty(responseSchema.get$ref()) && !modelUtils.isArraySchema(responseSchema)) {
|
||||||
// no example provided
|
// no example provided
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -78,14 +81,14 @@ public class ExampleGenerator {
|
|||||||
return generate(responseSchema.getExample(), new ArrayList<>(producesInfo));
|
return generate(responseSchema.getExample(), new ArrayList<>(producesInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(responseSchema)) { // array of schema
|
if (modelUtils.isArraySchema(responseSchema)) { // array of schema
|
||||||
ArraySchema as = (ArraySchema) responseSchema;
|
ArraySchema as = (ArraySchema) responseSchema;
|
||||||
if (as.getItems() != null && StringUtils.isEmpty(as.getItems().get$ref())) { // arary of primtive types
|
if (as.getItems() != null && StringUtils.isEmpty(as.getItems().get$ref())) { // arary of primtive types
|
||||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||||
new ArrayList<String>(producesInfo), as.getItems());
|
new ArrayList<String>(producesInfo), as.getItems());
|
||||||
} else if (as.getItems() != null && !StringUtils.isEmpty(as.getItems().get$ref())) { // array of model
|
} else if (as.getItems() != null && !StringUtils.isEmpty(as.getItems().get$ref())) { // array of model
|
||||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||||
new ArrayList<String>(producesInfo), ModelUtils.getSimpleRef(as.getItems().get$ref()));
|
new ArrayList<String>(producesInfo), modelUtils.getSimpleRef(as.getItems().get$ref()));
|
||||||
} else {
|
} else {
|
||||||
// TODO log warning message as such case is not handled at the moment
|
// TODO log warning message as such case is not handled at the moment
|
||||||
return null;
|
return null;
|
||||||
@ -95,7 +98,7 @@ public class ExampleGenerator {
|
|||||||
new ArrayList<String>(producesInfo), responseSchema);
|
new ArrayList<String>(producesInfo), responseSchema);
|
||||||
} else { // model
|
} else { // model
|
||||||
return generate((Map<String, Object>) responseSchema.getExample(),
|
return generate((Map<String, Object>) responseSchema.getExample(),
|
||||||
new ArrayList<String>(producesInfo), ModelUtils.getSimpleRef(responseSchema.get$ref()));
|
new ArrayList<String>(producesInfo), modelUtils.getSimpleRef(responseSchema.get$ref()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +121,7 @@ public class ExampleGenerator {
|
|||||||
output.add(kv);
|
output.add(kv);
|
||||||
}
|
}
|
||||||
} else if (property != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
} else if (property != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
||||||
String example = new XmlExampleGenerator(this.examples).toXml(property);
|
String example = new XmlExampleGenerator(this.examples, openAPI).toXml(property);
|
||||||
if (example != null) {
|
if (example != null) {
|
||||||
kv.put(EXAMPLE, example);
|
kv.put(EXAMPLE, example);
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
@ -165,7 +168,7 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
} else if (modelName != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
} else if (modelName != null && mediaType.startsWith(MIME_TYPE_XML)) {
|
||||||
final Schema schema = this.examples.get(modelName);
|
final Schema schema = this.examples.get(modelName);
|
||||||
String example = new XmlExampleGenerator(this.examples).toXml(schema, 0, Collections.<String>emptySet());
|
String example = new XmlExampleGenerator(this.examples, openAPI).toXml(schema, 0, Collections.<String>emptySet());
|
||||||
if (example != null) {
|
if (example != null) {
|
||||||
kv.put(EXAMPLE, example);
|
kv.put(EXAMPLE, example);
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
@ -222,13 +225,13 @@ public class ExampleGenerator {
|
|||||||
if (property.getExample() != null) {
|
if (property.getExample() != null) {
|
||||||
LOGGER.debug("Example set in openapi spec, returning example: '{}'", property.getExample().toString());
|
LOGGER.debug("Example set in openapi spec, returning example: '{}'", property.getExample().toString());
|
||||||
return property.getExample();
|
return property.getExample();
|
||||||
} else if (ModelUtils.isBooleanSchema(property)) {
|
} else if (modelUtils.isBooleanSchema(property)) {
|
||||||
Object defaultValue = property.getDefault();
|
Object defaultValue = property.getDefault();
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
} else if (ModelUtils.isArraySchema(property)) {
|
} else if (modelUtils.isArraySchema(property)) {
|
||||||
Schema innerType = ((ArraySchema) property).getItems();
|
Schema innerType = ((ArraySchema) property).getItems();
|
||||||
if (innerType != null) {
|
if (innerType != null) {
|
||||||
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
|
int arrayLength = null == ((ArraySchema) property).getMaxItems() ? 2 : ((ArraySchema) property).getMaxItems();
|
||||||
@ -241,45 +244,45 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
return objectProperties;
|
return objectProperties;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(property)) {
|
} else if (modelUtils.isDateSchema(property)) {
|
||||||
return "2000-01-23";
|
return "2000-01-23";
|
||||||
} else if (ModelUtils.isDateTimeSchema(property)) {
|
} else if (modelUtils.isDateTimeSchema(property)) {
|
||||||
return "2000-01-23T04:56:07.000+00:00";
|
return "2000-01-23T04:56:07.000+00:00";
|
||||||
} else if (ModelUtils.isNumberSchema(property)) {
|
} else if (modelUtils.isNumberSchema(property)) {
|
||||||
Double min = getPropertyValue(property.getMinimum());
|
Double min = getPropertyValue(property.getMinimum());
|
||||||
Double max = getPropertyValue(property.getMaximum());
|
Double max = getPropertyValue(property.getMaximum());
|
||||||
if (ModelUtils.isFloatSchema(property)) { // float
|
if (modelUtils.isFloatSchema(property)) { // float
|
||||||
return (float) randomNumber(min, max);
|
return (float) randomNumber(min, max);
|
||||||
} else if (ModelUtils.isDoubleSchema(property)) { // decimal/double
|
} else if (modelUtils.isDoubleSchema(property)) { // decimal/double
|
||||||
return BigDecimal.valueOf(randomNumber(min, max));
|
return BigDecimal.valueOf(randomNumber(min, max));
|
||||||
} else { // no format defined
|
} else { // no format defined
|
||||||
return randomNumber(min, max);
|
return randomNumber(min, max);
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isFileSchema(property)) {
|
} else if (modelUtils.isFileSchema(property)) {
|
||||||
return ""; // TODO
|
return ""; // TODO
|
||||||
|
|
||||||
} else if (ModelUtils.isIntegerSchema(property)) {
|
} else if (modelUtils.isIntegerSchema(property)) {
|
||||||
Double min = getPropertyValue(property.getMinimum());
|
Double min = getPropertyValue(property.getMinimum());
|
||||||
Double max = getPropertyValue(property.getMaximum());
|
Double max = getPropertyValue(property.getMaximum());
|
||||||
if (ModelUtils.isLongSchema(property)) {
|
if (modelUtils.isLongSchema(property)) {
|
||||||
return (long) randomNumber(min, max);
|
return (long) randomNumber(min, max);
|
||||||
}
|
}
|
||||||
return (int) randomNumber(min, max);
|
return (int) randomNumber(min, max);
|
||||||
} else if (ModelUtils.isMapSchema(property)) {
|
} else if (modelUtils.isMapSchema(property)) {
|
||||||
Map<String, Object> mp = new HashMap<String, Object>();
|
Map<String, Object> mp = new HashMap<String, Object>();
|
||||||
if (property.getName() != null) {
|
if (property.getName() != null) {
|
||||||
mp.put(property.getName(),
|
mp.put(property.getName(),
|
||||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(openAPI, property), processedModels));
|
resolvePropertyToExample(propertyName, mediaType, modelUtils.getAdditionalProperties(property), processedModels));
|
||||||
} else {
|
} else {
|
||||||
mp.put("key",
|
mp.put("key",
|
||||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(openAPI, property), processedModels));
|
resolvePropertyToExample(propertyName, mediaType, modelUtils.getAdditionalProperties(property), processedModels));
|
||||||
}
|
}
|
||||||
return mp;
|
return mp;
|
||||||
} else if (ModelUtils.isUUIDSchema(property)) {
|
} else if (modelUtils.isUUIDSchema(property)) {
|
||||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||||
} else if (ModelUtils.isURISchema(property)) {
|
} else if (modelUtils.isURISchema(property)) {
|
||||||
return "https://openapi-generator.tech";
|
return "https://openapi-generator.tech";
|
||||||
} else if (ModelUtils.isStringSchema(property)) {
|
} else if (modelUtils.isStringSchema(property)) {
|
||||||
LOGGER.debug("String property");
|
LOGGER.debug("String property");
|
||||||
String defaultValue = (String) property.getDefault();
|
String defaultValue = (String) property.getDefault();
|
||||||
if (defaultValue != null && !defaultValue.isEmpty()) {
|
if (defaultValue != null && !defaultValue.isEmpty()) {
|
||||||
@ -299,14 +302,14 @@ public class ExampleGenerator {
|
|||||||
LOGGER.debug("No values found, using property name " + propertyName + " as example");
|
LOGGER.debug("No values found, using property name " + propertyName + " as example");
|
||||||
return propertyName;
|
return propertyName;
|
||||||
} else if (!StringUtils.isEmpty(property.get$ref())) { // model
|
} else if (!StringUtils.isEmpty(property.get$ref())) { // model
|
||||||
String simpleName = ModelUtils.getSimpleRef(property.get$ref());
|
String simpleName = modelUtils.getSimpleRef(property.get$ref());
|
||||||
Schema schema = ModelUtils.getSchema(openAPI, simpleName);
|
Schema schema = modelUtils.getSchema(simpleName);
|
||||||
if (schema == null) { // couldn't find the model/schema
|
if (schema == null) { // couldn't find the model/schema
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
return resolveModelToExample(simpleName, mediaType, schema, processedModels);
|
return resolveModelToExample(simpleName, mediaType, schema, processedModels);
|
||||||
|
|
||||||
} else if (ModelUtils.isObjectSchema(property)) {
|
} else if (modelUtils.isObjectSchema(property)) {
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.examples;
|
package org.openapitools.codegen.examples;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import io.swagger.v3.oas.models.media.XML;
|
import io.swagger.v3.oas.models.media.XML;
|
||||||
@ -35,8 +36,12 @@ public class XmlExampleGenerator {
|
|||||||
public static String TAG_END = "</";
|
public static String TAG_END = "</";
|
||||||
private static String EMPTY = "";
|
private static String EMPTY = "";
|
||||||
protected Map<String, Schema> examples;
|
protected Map<String, Schema> examples;
|
||||||
|
protected OpenAPI openAPI;
|
||||||
|
protected ModelUtils modelUtils;
|
||||||
|
|
||||||
public XmlExampleGenerator(Map<String, Schema> examples) {
|
public XmlExampleGenerator(Map<String, Schema> examples, OpenAPI openAPI) {
|
||||||
|
this.openAPI = openAPI;
|
||||||
|
this.modelUtils = new ModelUtils(openAPI);
|
||||||
this.examples = examples;
|
this.examples = examples;
|
||||||
if (examples == null) {
|
if (examples == null) {
|
||||||
this.examples = new HashMap<String, Schema>();
|
this.examples = new HashMap<String, Schema>();
|
||||||
@ -124,7 +129,7 @@ public class XmlExampleGenerator {
|
|||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema as = (ArraySchema) schema;
|
ArraySchema as = (ArraySchema) schema;
|
||||||
Schema inner = as.getItems();
|
Schema inner = as.getItems();
|
||||||
boolean wrapped = false;
|
boolean wrapped = false;
|
||||||
@ -177,29 +182,29 @@ public class XmlExampleGenerator {
|
|||||||
protected String getExample(Schema schema) {
|
protected String getExample(Schema schema) {
|
||||||
if (schema.getExample() != null) {
|
if (schema.getExample() != null) {
|
||||||
return schema.getExample().toString();
|
return schema.getExample().toString();
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||||
return "2000-01-23T04:56:07.000Z";
|
return "2000-01-23T04:56:07.000Z";
|
||||||
} else if (ModelUtils.isDateSchema(schema)) {
|
} else if (modelUtils.isDateSchema(schema)) {
|
||||||
return "2000-01-23";
|
return "2000-01-23";
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
return "true";
|
return "true";
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (ModelUtils.isFloatSchema(schema)) { // float
|
if (modelUtils.isFloatSchema(schema)) { // float
|
||||||
return "1.3579";
|
return "1.3579";
|
||||||
} else { // double
|
} else { // double
|
||||||
return "3.149";
|
return "3.149";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isPasswordSchema(schema)) {
|
} else if (modelUtils.isPasswordSchema(schema)) {
|
||||||
return "********";
|
return "********";
|
||||||
} else if (ModelUtils.isUUIDSchema(schema)) {
|
} else if (modelUtils.isUUIDSchema(schema)) {
|
||||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||||
} else if (ModelUtils.isURISchema(schema)) {
|
} else if (modelUtils.isURISchema(schema)) {
|
||||||
return "https://openapi-generator.tech";
|
return "https://openapi-generator.tech";
|
||||||
// do these last in case the specific types above are derived from these classes
|
// do these last in case the specific types above are derived from these classes
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
return "aeiou";
|
return "aeiou";
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (ModelUtils.isLongSchema(schema)) { // long
|
if (modelUtils.isLongSchema(schema)) { // long
|
||||||
return "123456789";
|
return "123456789";
|
||||||
} else { //integer
|
} else { //integer
|
||||||
return "123";
|
return "123";
|
||||||
|
@ -410,12 +410,12 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
schemaType = schemaType.replace("-", "_");
|
schemaType = schemaType.replace("-", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner) + "_Vectors.Vector";
|
return getTypeDeclaration(inner) + "_Vectors.Vector";
|
||||||
}
|
}
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
String name = getTypeDeclaration(inner) + "_Map";
|
String name = getTypeDeclaration(inner) + "_Map";
|
||||||
if (name.startsWith("Swagger.")) {
|
if (name.startsWith("Swagger.")) {
|
||||||
@ -432,7 +432,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
return schemaType;
|
return schemaType;
|
||||||
}
|
}
|
||||||
String modelType = toModelName(schemaType).replace("-", "_");
|
String modelType = toModelName(schemaType).replace("-", "_");
|
||||||
if (ModelUtils.isStringSchema(p) || ModelUtils.isFileSchema(p)
|
if (modelUtils.isStringSchema(p) || modelUtils.isFileSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(modelType)) {
|
|| languageSpecificPrimitives.contains(modelType)) {
|
||||||
return modelType;
|
return modelType;
|
||||||
}
|
}
|
||||||
@ -526,8 +526,8 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
|
|
||||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||||
if (methodResponse != null && ModelUtils.getSchemaFromResponse(methodResponse) != null) {
|
if (methodResponse != null && modelUtils.getSchemaFromResponse(methodResponse) != null) {
|
||||||
CodegenProperty cm = fromProperty("response", ModelUtils.getSchemaFromResponse(methodResponse));
|
CodegenProperty cm = fromProperty("response", modelUtils.getSchemaFromResponse(methodResponse));
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
op.vendorExtensions.put("x-codegen-response", cm);
|
||||||
op.vendorExtensions.put("x-is-model-type", isModelType(cm));
|
op.vendorExtensions.put("x-is-model-type", isModelType(cm));
|
||||||
op.vendorExtensions.put("x-is-stream-type", isStreamType(cm));
|
op.vendorExtensions.put("x-is-stream-type", isStreamType(cm));
|
||||||
|
@ -185,7 +185,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -194,7 +194,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -217,7 +217,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
final ArraySchema ap = (ArraySchema) p;
|
final ArraySchema ap = (ArraySchema) p;
|
||||||
final String pattern = "new ArrayList<%s>()";
|
final String pattern = "new ArrayList<%s>()";
|
||||||
if (ap.getItems() == null) {
|
if (ap.getItems() == null) {
|
||||||
@ -225,7 +225,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, getTypeDeclaration(ap.getItems()));
|
return String.format(Locale.ROOT, pattern, getTypeDeclaration(ap.getItems()));
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
final MapSchema ap = (MapSchema) p;
|
final MapSchema ap = (MapSchema) p;
|
||||||
final String pattern = "new HashMap<%s>()";
|
final String pattern = "new HashMap<%s>()";
|
||||||
if (getAdditionalProperties(ap) == null) {
|
if (getAdditionalProperties(ap) == null) {
|
||||||
@ -233,32 +233,32 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, String.format(Locale.ROOT, "String, %s", getTypeDeclaration(getAdditionalProperties(ap))));
|
return String.format(Locale.ROOT, pattern, String.format(Locale.ROOT, "String, %s", getTypeDeclaration(getAdditionalProperties(ap))));
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "l";
|
return p.getDefault().toString() + "l";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isFloatSchema(p)) {
|
} else if (modelUtils.isFloatSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "f";
|
return p.getDefault().toString() + "f";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
} else if (modelUtils.isDoubleSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "d";
|
return p.getDefault().toString() + "d";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = (String) p.getDefault();
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
@ -314,18 +314,18 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
Object obj = p.getExample();
|
Object obj = p.getExample();
|
||||||
String example = obj == null ? "" : obj.toString();
|
String example = obj == null ? "" : obj.toString();
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
example = "new " + getTypeDeclaration(p) + "{" + toExampleValue(
|
||||||
((ArraySchema) p).getItems()) + "}";
|
((ArraySchema) p).getItems()) + "}";
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
example = String.valueOf(!"false".equals(example));
|
example = String.valueOf(!"false".equals(example));
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
if (example.isEmpty()) {
|
if (example.isEmpty()) {
|
||||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||||
}
|
}
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
example = "EncodingUtil.base64Decode('" + example + "')";
|
example = "EncodingUtil.base64Decode('" + example + "')";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
if (example.matches("^\\d{4}(-\\d{2}){2}")) {
|
||||||
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
example = example.substring(0, 10).replaceAll("-0?", ", ");
|
||||||
} else if (example.isEmpty()) {
|
} else if (example.isEmpty()) {
|
||||||
@ -336,7 +336,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
example = "2000, 1, 23";
|
example = "2000, 1, 23";
|
||||||
}
|
}
|
||||||
example = "Date.newInstance(" + example + ")";
|
example = "Date.newInstance(" + example + ")";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) {
|
||||||
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
example = example.substring(0, 19).replaceAll("[-T:]0?", ", ");
|
||||||
} else if (example.isEmpty()) {
|
} else if (example.isEmpty()) {
|
||||||
@ -347,31 +347,31 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
example = "2000, 1, 23, 4, 56, 7";
|
example = "2000, 1, 23, 4, 56, 7";
|
||||||
}
|
}
|
||||||
example = "Datetime.newInstanceGmt(" + example + ")";
|
example = "Datetime.newInstanceGmt(" + example + ")";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
example = example.replaceAll("[^-0-9.]", "");
|
example = example.replaceAll("[^-0-9.]", "");
|
||||||
example = example.isEmpty() ? "1.3579" : example;
|
example = example.isEmpty() ? "1.3579" : example;
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
if (example.isEmpty()) {
|
if (example.isEmpty()) {
|
||||||
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu";
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
}
|
}
|
||||||
example = "EncodingUtil.base64Decode(" + example + ")";
|
example = "EncodingUtil.base64Decode(" + example + ")";
|
||||||
} else if (ModelUtils.isEmailSchema(p)) {
|
} else if (modelUtils.isEmailSchema(p)) {
|
||||||
if (example.isEmpty()) {
|
if (example.isEmpty()) {
|
||||||
example = "example@example.com";
|
example = "example@example.com";
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
}
|
}
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
example = example.isEmpty() ? "123456789L" : example + "L";
|
example = example.isEmpty() ? "123456789L" : example + "L";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue(getAdditionalProperties(p)) + "}";
|
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue(getAdditionalProperties(p)) + "}";
|
||||||
|
|
||||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
} else if (modelUtils.isPasswordSchema(p)) {
|
||||||
example = example.isEmpty() ? "password123" : escapeText(example);
|
example = example.isEmpty() ? "password123" : escapeText(example);
|
||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
List<String> enums = p.getEnum();
|
List<String> enums = p.getEnum();
|
||||||
if (enums != null && example.isEmpty()) {
|
if (enums != null && example.isEmpty()) {
|
||||||
example = enums.get(0);
|
example = enums.get(0);
|
||||||
@ -383,13 +383,13 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
p.setExample(example);
|
p.setExample(example);
|
||||||
}
|
}
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
} else if (modelUtils.isUUIDSchema(p)) {
|
||||||
example = example.isEmpty()
|
example = example.isEmpty()
|
||||||
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'"
|
||||||
: "'" + escapeText(example) + "'";
|
: "'" + escapeText(example) + "'";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
example = example.matches("^-?\\d+$") ? example : "0";
|
example = example.matches("^-?\\d+$") ? example : "0";
|
||||||
} else if (ModelUtils.isObjectSchema(p)) {
|
} else if (modelUtils.isObjectSchema(p)) {
|
||||||
example = example.isEmpty() ? "null" : example;
|
example = example.isEmpty() ? "null" : example;
|
||||||
} else {
|
} else {
|
||||||
example = getTypeDeclaration(p) + ".getExample()";
|
example = getTypeDeclaration(p) + ".getExample()";
|
||||||
@ -571,7 +571,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
if (op.getHasExamples()) {
|
if (op.getHasExamples()) {
|
||||||
// prepare examples for Apex test classes
|
// prepare examples for Apex test classes
|
||||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||||
final Schema responseSchema = ModelUtils.getSchemaFromResponse(apiResponse);
|
final Schema responseSchema = modelUtils.getSchemaFromResponse(apiResponse);
|
||||||
String deserializedExample = toExampleValue(responseSchema);
|
String deserializedExample = toExampleValue(responseSchema);
|
||||||
for (Map<String, String> example : op.examples) {
|
for (Map<String, String> example : op.examples) {
|
||||||
example.put("example", escapeText(example.get("example")));
|
example.put("example", escapeText(example.get("example")));
|
||||||
|
@ -437,7 +437,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
private void postProcessEnumRefs(final Map<String, Object> models) {
|
private void postProcessEnumRefs(final Map<String, Object> models) {
|
||||||
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
CodegenModel model = ModelUtils.getModelByName(entry.getKey(), models);
|
CodegenModel model = modelUtils.getModelByName(entry.getKey(), models);
|
||||||
if (model.isEnum) {
|
if (model.isEnum) {
|
||||||
enumRefs.put(entry.getKey(), model);
|
enumRefs.put(entry.getKey(), model);
|
||||||
}
|
}
|
||||||
@ -445,7 +445,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.allVars) {
|
for (CodegenProperty var : model.allVars) {
|
||||||
if (enumRefs.containsKey(var.dataType)) {
|
if (enumRefs.containsKey(var.dataType)) {
|
||||||
@ -594,7 +594,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
protected void updateValueTypeProperty(Map<String, Object> models) {
|
protected void updateValueTypeProperty(Map<String, Object> models) {
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.vars) {
|
for (CodegenProperty var : model.vars) {
|
||||||
var.vendorExtensions.put("x-is-value-type", isValueType(var));
|
var.vendorExtensions.put("x-is-value-type", isValueType(var));
|
||||||
@ -611,7 +611,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
protected void updateNullableTypeProperty(Map<String, Object> models) {
|
protected void updateNullableTypeProperty(Map<String, Object> models) {
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.vars) {
|
for (CodegenProperty var : model.vars) {
|
||||||
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
|
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
|
||||||
@ -859,23 +859,23 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toExampleValue(Schema p) {
|
public String toExampleValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return "\"" + p.getExample().toString() + "\"";
|
return "\"" + p.getExample().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
@ -891,33 +891,33 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (modelUtils.isFloatSchema(p)) { // float
|
||||||
return p.getDefault().toString() + "F";
|
return p.getDefault().toString() + "F";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) { // double
|
} else if (modelUtils.isDoubleSchema(p)) { // double
|
||||||
return p.getDefault().toString() + "D";
|
return p.getDefault().toString() + "D";
|
||||||
} else { // decimal
|
} else { // decimal
|
||||||
return p.getDefault().toString() + "M";
|
return p.getDefault().toString() + "M";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = (String) p.getDefault();
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
@ -989,7 +989,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(p);
|
return super.toInstantiationType(p);
|
||||||
@ -997,9 +997,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
// Should we also support maps of maps?
|
// Should we also support maps of maps?
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||||
|
@ -362,7 +362,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
public Map<String, Object> postProcessAllModels(Map<String, Object> objs){
|
public Map<String, Object> postProcessAllModels(Map<String, Object> objs){
|
||||||
Map<String, Object> models = super.postProcessAllModels(objs);
|
Map<String, Object> models = super.postProcessAllModels(objs);
|
||||||
for (final Entry<String, Object> model : models.entrySet()) {
|
for (final Entry<String, Object> model : models.entrySet()) {
|
||||||
CodegenModel mo = ModelUtils.getModelByName(model.getKey(), models);
|
CodegenModel mo = modelUtils.getModelByName(model.getKey(), models);
|
||||||
addForwardDeclarations(mo, models);
|
addForwardDeclarations(mo, models);
|
||||||
}
|
}
|
||||||
return models;
|
return models;
|
||||||
@ -379,7 +379,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
}
|
}
|
||||||
String childPropertyType = property.isContainer? property.mostInnerItems.baseType : property.baseType;
|
String childPropertyType = property.isContainer? property.mostInnerItems.baseType : property.baseType;
|
||||||
for(final Entry<String, Object> mo : objs.entrySet()) {
|
for(final Entry<String, Object> mo : objs.entrySet()) {
|
||||||
CodegenModel childModel = ModelUtils.getModelByName(mo.getKey(), objs);
|
CodegenModel childModel = modelUtils.getModelByName(mo.getKey(), objs);
|
||||||
if( !childPropertyType.equals(childModel.classname) || childPropertyType.equals(parentModel.classname) || !childModel.hasVars ){
|
if( !childPropertyType.equals(childModel.classname) || childPropertyType.equals(parentModel.classname) || !childModel.hasVars ){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -292,11 +292,11 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "LIST [" + getTypeDeclaration(inner) + "]";
|
return "LIST [" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + " [" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + " [" + getTypeDeclaration(inner) + "]";
|
||||||
@ -463,7 +463,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
private void postProcessParentModels(final Map<String, Object> models) {
|
private void postProcessParentModels(final Map<String, Object> models) {
|
||||||
for (final String parent : parentModels) {
|
for (final String parent : parentModels) {
|
||||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||||
for (final CodegenModel child : childrenModels) {
|
for (final CodegenModel child : childrenModels) {
|
||||||
processParentPropertiesInChildModel(parentModel, child);
|
processParentPropertiesInChildModel(parentModel, child);
|
||||||
@ -492,7 +492,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
||||||
final Schema parentModel = allDefinitions.get(codegenModel.parentSchema);
|
final Schema parentModel = allDefinitions.get(codegenModel.parentSchema);
|
||||||
@ -571,7 +571,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
return getTypeDeclaration(p);
|
return getTypeDeclaration(p);
|
||||||
// if (ModelUtils.isMapSchema(p)) {
|
// if (modelUtils.isMapSchema(p)) {
|
||||||
// Schema additionalProperties2 = getAdditionalProperties(p);
|
// Schema additionalProperties2 = getAdditionalProperties(p);
|
||||||
// String type = additionalProperties2.getType();
|
// String type = additionalProperties2.getType();
|
||||||
// if (null == type) {
|
// if (null == type) {
|
||||||
@ -580,7 +580,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
|||||||
// }
|
// }
|
||||||
// String inner = toModelName(getSchemaType(additionalProperties2));
|
// String inner = toModelName(getSchemaType(additionalProperties2));
|
||||||
// return instantiationTypes.get("map") + " [" + inner + "]";
|
// return instantiationTypes.get("map") + " [" + inner + "]";
|
||||||
// } else if (ModelUtils.isArraySchema(p)) {
|
// } else if (modelUtils.isArraySchema(p)) {
|
||||||
// ArraySchema ap = (ArraySchema) p;
|
// ArraySchema ap = (ArraySchema) p;
|
||||||
// String inner = toModelName(getSchemaType(ap.getItems()));
|
// String inner = toModelName(getSchemaType(ap.getItems()));
|
||||||
// return instantiationTypes.get("array") + " [" + inner + "]";
|
// return instantiationTypes.get("array") + " [" + inner + "]";
|
||||||
|
@ -358,7 +358,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
List<String> classNames = new ArrayList<String>();
|
List<String> classNames = new ArrayList<String>();
|
||||||
|
|
||||||
for (String k : objs.keySet()) {
|
for (String k : objs.keySet()) {
|
||||||
CodegenModel model = ModelUtils.getModelByName(k, objs);
|
CodegenModel model = modelUtils.getModelByName(k, objs);
|
||||||
if (model == null || model.classname == null) {
|
if (model == null || model.classname == null) {
|
||||||
throw new RuntimeException("Null model encountered");
|
throw new RuntimeException("Null model encountered");
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
private void postProcessEnumRefs(final Map<String, Object> models) {
|
private void postProcessEnumRefs(final Map<String, Object> models) {
|
||||||
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
Map<String, CodegenModel> enumRefs = new HashMap<String, CodegenModel>();
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
CodegenModel model = ModelUtils.getModelByName(entry.getKey(), models);
|
CodegenModel model = modelUtils.getModelByName(entry.getKey(), models);
|
||||||
if (model.isEnum) {
|
if (model.isEnum) {
|
||||||
enumRefs.put(entry.getKey(), model);
|
enumRefs.put(entry.getKey(), model);
|
||||||
}
|
}
|
||||||
@ -413,7 +413,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
for (Map.Entry<String, Object> entry : models.entrySet()) {
|
||||||
String openAPIName = entry.getKey();
|
String openAPIName = entry.getKey();
|
||||||
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
|
CodegenModel model = modelUtils.getModelByName(openAPIName, models);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
for (CodegenProperty var : model.allVars) {
|
for (CodegenProperty var : model.allVars) {
|
||||||
if (enumRefs.containsKey(var.dataType)) {
|
if (enumRefs.containsKey(var.dataType)) {
|
||||||
@ -735,23 +735,23 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toExampleValue(Schema p) {
|
public String toExampleValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return "\"" + p.getExample().toString() + "\"";
|
return "\"" + p.getExample().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getExample() != null) {
|
if (p.getExample() != null) {
|
||||||
return p.getExample().toString();
|
return p.getExample().toString();
|
||||||
}
|
}
|
||||||
@ -768,33 +768,33 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (modelUtils.isFloatSchema(p)) { // float
|
||||||
return p.getDefault().toString() + "F";
|
return p.getDefault().toString() + "F";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) { // double
|
} else if (modelUtils.isDoubleSchema(p)) { // double
|
||||||
return p.getDefault().toString() + "D";
|
return p.getDefault().toString() + "D";
|
||||||
} else { // decimal
|
} else { // decimal
|
||||||
return p.getDefault().toString() + "M";
|
return p.getDefault().toString() + "M";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = (String) p.getDefault();
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
@ -817,7 +817,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + " option";
|
return type + " option";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
@ -869,7 +869,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(p);
|
return super.toInstantiationType(p);
|
||||||
@ -877,9 +877,9 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
return getArrayTypeDeclaration((ArraySchema) p);
|
return getArrayTypeDeclaration((ArraySchema) p);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
// Should we also support maps of maps?
|
// Should we also support maps of maps?
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||||
|
@ -331,7 +331,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
// In OAS 3.0.x, the array "items" attribute is required.
|
// In OAS 3.0.x, the array "items" attribute is required.
|
||||||
@ -339,7 +339,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
// specification is aligned with the JSON schema specification.
|
// specification is aligned with the JSON schema specification.
|
||||||
// When "items" is not specified, the elements of the array may be anything at all.
|
// When "items" is not specified, the elements of the array may be anything at all.
|
||||||
if (inner != null) {
|
if (inner != null) {
|
||||||
inner = ModelUtils.unaliasSchema(this.openAPI, inner);
|
inner = modelUtils.unaliasSchema(inner);
|
||||||
}
|
}
|
||||||
String typDecl;
|
String typDecl;
|
||||||
if (inner != null) {
|
if (inner != null) {
|
||||||
@ -348,9 +348,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
typDecl = "interface{}";
|
typDecl = "interface{}";
|
||||||
}
|
}
|
||||||
return "[]" + typDecl;
|
return "[]" + typDecl;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[string]" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner));
|
return getSchemaType(p) + "[string]" + getTypeDeclaration(modelUtils.unaliasSchema(inner));
|
||||||
}
|
}
|
||||||
//return super.getTypeDeclaration(p);
|
//return super.getTypeDeclaration(p);
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
|
|
||||||
if (ref != null && !ref.isEmpty()) {
|
if (ref != null && !ref.isEmpty()) {
|
||||||
type = openAPIType;
|
type = openAPIType;
|
||||||
} else if ("object".equals(openAPIType) && ModelUtils.isAnyTypeSchema(openAPI, p)) {
|
} else if ("object".equals(openAPIType) && modelUtils.isAnyTypeSchema(p)) {
|
||||||
// Arbitrary type. Note this is not the same thing as free-form object.
|
// Arbitrary type. Note this is not the same thing as free-form object.
|
||||||
type = "interface{}";
|
type = "interface{}";
|
||||||
} else if (typeMapping.containsKey(openAPIType)) {
|
} else if (typeMapping.containsKey(openAPIType)) {
|
||||||
@ -426,9 +426,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema property) {
|
public String toInstantiationType(Schema property) {
|
||||||
if (ModelUtils.isMapSchema(property)) {
|
if (modelUtils.isMapSchema(property)) {
|
||||||
return getTypeDeclaration(property);
|
return getTypeDeclaration(property);
|
||||||
} else if (ModelUtils.isArraySchema(property)) {
|
} else if (modelUtils.isArraySchema(property)) {
|
||||||
return getTypeDeclaration(property);
|
return getTypeDeclaration(property);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(property);
|
return super.toInstantiationType(property);
|
||||||
|
@ -266,11 +266,11 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = (Schema) p.getAdditionalProperties();
|
Schema inner = (Schema) p.getAdditionalProperties();
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
|||||||
// Not using the supertype invocation, because we want to UpperCamelize
|
// Not using the supertype invocation, because we want to UpperCamelize
|
||||||
// the type.
|
// the type.
|
||||||
String schemaType = getSchemaType(p);
|
String schemaType = getSchemaType(p);
|
||||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
String nullable = modelUtils.isNullable(p) ? "" : "!";
|
||||||
/*
|
/*
|
||||||
if (p != null && Boolean.TRUE.equals(p.getNullable())) {
|
if (p != null && Boolean.TRUE.equals(p.getNullable())) {
|
||||||
nullable = "";
|
nullable = "";
|
||||||
|
@ -794,13 +794,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
Schema<?> schema = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
|
Schema<?> schema = modelUtils.unaliasSchema(p, importMapping);
|
||||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
Schema<?> target = modelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||||
if (ModelUtils.isArraySchema(target)) {
|
if (modelUtils.isArraySchema(target)) {
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||||
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(target)) {
|
} else if (modelUtils.isMapSchema(target)) {
|
||||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
// Note: modelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||||
// additionalproperties: true
|
// additionalproperties: true
|
||||||
Schema<?> inner = getAdditionalProperties(target);
|
Schema<?> inner = getAdditionalProperties(target);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -823,10 +823,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
schema = modelUtils.getReferencedSchema(schema);
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
final String pattern;
|
final String pattern;
|
||||||
if (ModelUtils.isSet(schema)) {
|
if (modelUtils.isSet(schema)) {
|
||||||
String mapInstantiationType = instantiationTypes().getOrDefault("set", "LinkedHashSet");
|
String mapInstantiationType = instantiationTypes().getOrDefault("set", "LinkedHashSet");
|
||||||
pattern = "new " + mapInstantiationType + "<%s>()";
|
pattern = "new " + mapInstantiationType + "<%s>()";
|
||||||
} else {
|
} else {
|
||||||
@ -836,7 +836,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||||
|
|
||||||
String typeDeclaration = getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items));
|
String typeDeclaration = getTypeDeclaration(modelUtils.unaliasSchema(items));
|
||||||
Object java8obj = additionalProperties.get("java8");
|
Object java8obj = additionalProperties.get("java8");
|
||||||
if (java8obj != null) {
|
if (java8obj != null) {
|
||||||
Boolean java8 = Boolean.valueOf(java8obj.toString());
|
Boolean java8 = Boolean.valueOf(java8obj.toString());
|
||||||
@ -846,7 +846,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
||||||
} else if (ModelUtils.isMapSchema(schema) && !(schema instanceof ComposedSchema)) {
|
} else if (modelUtils.isMapSchema(schema) && !(schema instanceof ComposedSchema)) {
|
||||||
if (schema.getProperties() != null && schema.getProperties().size() > 0) {
|
if (schema.getProperties() != null && schema.getProperties().size() > 0) {
|
||||||
// object is complex object with free-form additional properties
|
// object is complex object with free-form additional properties
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
@ -872,7 +872,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
return String.format(Locale.ROOT, pattern, typeDeclaration);
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(schema.getFormat())) {
|
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "l";
|
return schema.getDefault().toString() + "l";
|
||||||
@ -881,7 +881,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "f";
|
return schema.getDefault().toString() + "f";
|
||||||
@ -892,17 +892,17 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isURISchema(schema)) {
|
} else if (modelUtils.isURISchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
return "URI.create(\"" + escapeText((String) schema.getDefault()) + "\")";
|
return "URI.create(\"" + escapeText((String) schema.getDefault()) + "\")";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
String _default;
|
String _default;
|
||||||
if (schema.getDefault() instanceof Date) {
|
if (schema.getDefault() instanceof Date) {
|
||||||
@ -923,7 +923,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
} else if (modelUtils.isObjectSchema(schema)) {
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
return super.toDefaultValue(schema);
|
return super.toDefaultValue(schema);
|
||||||
}
|
}
|
||||||
@ -1100,7 +1100,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (codegenModel.description != null) {
|
if (codegenModel.description != null) {
|
||||||
codegenModel.imports.add("ApiModel");
|
codegenModel.imports.add("ApiModel");
|
||||||
@ -1213,13 +1213,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
for (Operation operation : path.readOperations()) {
|
for (Operation operation : path.readOperations()) {
|
||||||
LOGGER.info("Processing operation " + operation.getOperationId());
|
LOGGER.info("Processing operation " + operation.getOperationId());
|
||||||
if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
|
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
|
||||||
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
|
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||||
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
|
List<String> consumes = new ArrayList<>(getConsumesInfo(operation));
|
||||||
String contentType = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
String contentType = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
||||||
operation.addExtension("x-contentType", contentType);
|
operation.addExtension("x-contentType", contentType);
|
||||||
}
|
}
|
||||||
String accepts = getAccept(openAPI, operation);
|
String accepts = getAccept(operation);
|
||||||
operation.addExtension("x-accepts", accepts);
|
operation.addExtension("x-accepts", accepts);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1271,10 +1271,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getAccept(OpenAPI openAPI, Operation operation) {
|
private String getAccept(Operation operation) {
|
||||||
String accepts = null;
|
String accepts = null;
|
||||||
String defaultContentType = "application/json";
|
String defaultContentType = "application/json";
|
||||||
Set<String> producesInfo = getProducesInfo(openAPI, operation);
|
Set<String> producesInfo = getProducesInfo(operation);
|
||||||
if (producesInfo != null && !producesInfo.isEmpty()) {
|
if (producesInfo != null && !producesInfo.isEmpty()) {
|
||||||
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -310,13 +310,13 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
Schema<?> schema = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
|
Schema<?> schema = modelUtils.unaliasSchema(p, importMapping);
|
||||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
Schema<?> target = modelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||||
if (ModelUtils.isArraySchema(target)) {
|
if (modelUtils.isArraySchema(target)) {
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
Schema<?> items = getSchemaItems((ArraySchema) schema);
|
||||||
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
return getSchemaType(target) + "<" + getTypeDeclaration(items) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(target)) {
|
} else if (modelUtils.isMapSchema(target)) {
|
||||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
// Note: modelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||||
// additionalproperties: true
|
// additionalproperties: true
|
||||||
Schema<?> inner = getAdditionalProperties(target);
|
Schema<?> inner = getAdditionalProperties(target);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -899,27 +899,27 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isURISchema(p)) {
|
} else if (modelUtils.isURISchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "URI.create('" + p.getDefault() + "')";
|
return "URI.create('" + p.getDefault() + "')";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault() + "\"";
|
return "\"" + p.getDefault() + "\"";
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -301,7 +301,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
inner = new StringSchema().description("TODO default missing array inner type to string");
|
inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||||
}
|
}
|
||||||
return getTypeDeclaration(inner) + "[]";
|
return getTypeDeclaration(inner) + "[]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
||||||
@ -514,23 +514,23 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
|
@ -345,11 +345,11 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@ -704,26 +704,26 @@ public abstract class AbstractPythonConnexionServerCodegen extends DefaultCodege
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||||
return "False";
|
return "False";
|
||||||
else
|
else
|
||||||
return "True";
|
return "True";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + (String) p.getDefault() + "'";
|
return "'" + (String) p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
|
@ -114,10 +114,10 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema schema) {
|
public String getTypeDeclaration(Schema schema) {
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
Schema inner = ((ArraySchema) schema).getItems();
|
Schema inner = ((ArraySchema) schema).getItems();
|
||||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema inner = getAdditionalProperties(schema);
|
Schema inner = getAdditionalProperties(schema);
|
||||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
@ -127,11 +127,11 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema schema) {
|
public String toInstantiationType(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return instantiationTypes.get("map");
|
return instantiationTypes.get("map");
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
String parentType;
|
String parentType;
|
||||||
if (ModelUtils.isSet(schema)) {
|
if (modelUtils.isSet(schema)) {
|
||||||
parentType = "set";
|
parentType = "set";
|
||||||
} else {
|
} else {
|
||||||
parentType = "array";
|
parentType = "array";
|
||||||
@ -143,12 +143,12 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
p = modelUtils.getReferencedSchema(p);
|
||||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault() instanceof Date) {
|
if (p.getDefault() instanceof Date) {
|
||||||
Date date = (Date) p.getDefault();
|
Date date = (Date) p.getDefault();
|
||||||
|
@ -320,11 +320,11 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
@ -335,7 +335,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getSchemaType(Schema p) {
|
public String getSchemaType(Schema p) {
|
||||||
String openAPIType = super.getSchemaType(p);
|
String openAPIType = super.getSchemaType(p);
|
||||||
if (ModelUtils.isSet(p)) {
|
if (modelUtils.isSet(p)) {
|
||||||
openAPIType = "set";
|
openAPIType = "set";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,13 +353,13 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return ( ModelUtils.isSet(ap) ? instantiationTypes.get("set") : instantiationTypes.get("array") ) + "[" + inner + "]";
|
return ( modelUtils.isSet(ap) ? instantiationTypes.get("set") : instantiationTypes.get("array") ) + "[" + inner + "]";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -372,24 +372,24 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// comment out the following as the default value is no handled differently
|
// comment out the following as the default value is no handled differently
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "new HashMap[String, " + inner + "]() ";
|
return "new HashMap[String, " + inner + "]() ";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
String genericType;
|
String genericType;
|
||||||
if (ModelUtils.isSet(ap)) {
|
if (modelUtils.isSet(ap)) {
|
||||||
genericType = instantiationTypes.get("set");
|
genericType = instantiationTypes.get("set");
|
||||||
} else {
|
} else {
|
||||||
genericType = instantiationTypes.get("array");
|
genericType = instantiationTypes.get("array");
|
||||||
@ -410,7 +410,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
// Assume that any other generic types can be new'd up.
|
// Assume that any other generic types can be new'd up.
|
||||||
return "new " + genericType + "[" + inner + "]() ";
|
return "new " + genericType + "[" + inner + "]() ";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -427,9 +427,9 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public CodegenProperty fromProperty(String name, Schema p) {
|
public CodegenProperty fromProperty(String name, Schema p) {
|
||||||
CodegenProperty prop = super.fromProperty(name, p);
|
CodegenProperty prop = super.fromProperty(name, p);
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema as = (ArraySchema) p;
|
ArraySchema as = (ArraySchema) p;
|
||||||
if (ModelUtils.isSet(as)) {
|
if (modelUtils.isSet(as)) {
|
||||||
prop.containerType = "set";
|
prop.containerType = "set";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,16 +413,16 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
Schema<?> items = getSchemaItems((ArraySchema) p);
|
Schema<?> items = getSchemaItems((ArraySchema) p);
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items)) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(modelUtils.unaliasSchema(items)) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema<?> inner = getSchemaAdditionalProperties(p);
|
Schema<?> inner = getSchemaAdditionalProperties(p);
|
||||||
String nullSafeSuffix = getNullSafeAdditionalProps() ? " | undefined" : "";
|
String nullSafeSuffix = getNullSafeAdditionalProps() ? " | undefined" : "";
|
||||||
return "{ [key: string]: " + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + nullSafeSuffix + "; }";
|
return "{ [key: string]: " + getTypeDeclaration(modelUtils.unaliasSchema(inner)) + nullSafeSuffix + "; }";
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return "any";
|
return "any";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "any";
|
return "any";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
@ -432,37 +432,37 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
protected String getParameterDataType(Parameter parameter, Schema p) {
|
protected String getParameterDataType(Parameter parameter, Schema p) {
|
||||||
// handle enums of various data types
|
// handle enums of various data types
|
||||||
Schema inner;
|
Schema inner;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema mp1 = (ArraySchema) p;
|
ArraySchema mp1 = (ArraySchema) p;
|
||||||
inner = mp1.getItems();
|
inner = mp1.getItems();
|
||||||
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
inner = getAdditionalProperties(p);
|
inner = getAdditionalProperties(p);
|
||||||
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
// Handle string enums
|
// Handle string enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
// Handle integer enums
|
// Handle integer enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
// Handle double enums
|
// Handle double enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO revise the logic below
|
/* TODO revise the logic below
|
||||||
else if (ModelUtils.isDateSchema(p)) {
|
else if (modelUtils.isDateSchema(p)) {
|
||||||
// Handle date enums
|
// Handle date enums
|
||||||
DateSchema sp = (DateSchema) p;
|
DateSchema sp = (DateSchema) p;
|
||||||
if (sp.getEnum() != null) {
|
if (sp.getEnum() != null) {
|
||||||
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
|
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// Handle datetime enums
|
// Handle datetime enums
|
||||||
DateTimeSchema sp = (DateTimeSchema) p;
|
DateTimeSchema sp = (DateTimeSchema) p;
|
||||||
if (sp.getEnum() != null) {
|
if (sp.getEnum() != null) {
|
||||||
@ -510,27 +510,27 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isNumberSchema(p) || ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p) || modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + (String) p.getDefault() + "'";
|
return "'" + (String) p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
@ -551,7 +551,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
public String getSchemaType(Schema p) {
|
public String getSchemaType(Schema p) {
|
||||||
String openAPIType = super.getSchemaType(p);
|
String openAPIType = super.getSchemaType(p);
|
||||||
String type = null;
|
String type = null;
|
||||||
if (ModelUtils.isComposedSchema(p)) {
|
if (modelUtils.isComposedSchema(p)) {
|
||||||
return openAPIType;
|
return openAPIType;
|
||||||
} else if (typeMapping.containsKey(openAPIType)) {
|
} else if (typeMapping.containsKey(openAPIType)) {
|
||||||
type = typeMapping.get(openAPIType);
|
type = typeMapping.get(openAPIType);
|
||||||
@ -898,7 +898,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
|
|
||||||
return filteredSchemas.stream().map(schema -> {
|
return filteredSchemas.stream().map(schema -> {
|
||||||
String schemaType = getSchemaType(schema);
|
String schemaType = getSchemaType(schema);
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema ap = (ArraySchema) schema;
|
ArraySchema ap = (ArraySchema) schema;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
|
||||||
|
@ -223,11 +223,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
|
@ -221,24 +221,24 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
String out = null;
|
String out = null;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
Schema inner = ((ArraySchema) p).getItems();
|
Schema inner = ((ArraySchema) p).getItems();
|
||||||
out = String.format(
|
out = String.format(
|
||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
"new List<%s>()",
|
"new List<%s>()",
|
||||||
inner == null ? "Object" : getTypeDeclaration(inner)
|
inner == null ? "Object" : getTypeDeclaration(inner)
|
||||||
);
|
);
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
// true => "true", false => "false", null => "null"
|
// true => "true", false => "false", null => "null"
|
||||||
out = String.valueOf(p.getDefault());
|
out = String.valueOf(p.getDefault());
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
Long def = (Long) p.getDefault();
|
Long def = (Long) p.getDefault();
|
||||||
out = def == null ? out : def.toString() + "L";
|
out = def == null ? out : def.toString() + "L";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
||||||
out = String.format(Locale.ROOT, "new Map<String, %s>()", s);
|
out = String.format(Locale.ROOT, "new Map<String, %s>()", s);
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String def = p.getDefault().toString();
|
String def = p.getDefault().toString();
|
||||||
if (def != null) {
|
if (def != null) {
|
||||||
|
@ -450,7 +450,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + "?";
|
return type + "?";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
|
@ -423,11 +423,11 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@ -619,7 +619,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
@Override
|
@Override
|
||||||
public CodegenOperation fromOperation(String path, String httpMethod,
|
public CodegenOperation fromOperation(String path, String httpMethod,
|
||||||
Operation operation, List<Server> servers) {
|
Operation operation, List<Server> servers) {
|
||||||
Map<String, Schema> definitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> definitions = modelUtils.getSchemas();
|
||||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -663,8 +663,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
* If the operation produces Json and has nonempty example
|
* If the operation produces Json and has nonempty example
|
||||||
* try to reformat it.
|
* try to reformat it.
|
||||||
*/
|
*/
|
||||||
if (getConsumesInfo(this.openAPI, operation) != null
|
if (getConsumesInfo(operation) != null
|
||||||
&& getConsumesInfo(this.openAPI, operation).contains("application/json")
|
&& getConsumesInfo(operation).contains("application/json")
|
||||||
&& definitions.get(p.dataType).getExample() != null) {
|
&& definitions.get(p.dataType).getExample() != null) {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
@ -296,10 +296,10 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema schema) {
|
public String getTypeDeclaration(Schema schema) {
|
||||||
/* comment out below as we'll do it in the template instead
|
/* comment out below as we'll do it in the template instead
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (modelUtils.isArraySchema(schema)) {
|
||||||
Schema inner = ((ArraySchema) schema).getItems();
|
Schema inner = ((ArraySchema) schema).getItems();
|
||||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
@ -310,11 +310,11 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + escapeText((String) p.getDefault()) + "'";
|
return "'" + escapeText((String) p.getDefault()) + "'";
|
||||||
}
|
}
|
||||||
@ -327,17 +327,17 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
public String toExampleValue(Schema schema) {
|
public String toExampleValue(Schema schema) {
|
||||||
String example = super.toExampleValue(schema);
|
String example = super.toExampleValue(schema);
|
||||||
|
|
||||||
if (ModelUtils.isNullType(schema) && null != example) {
|
if (modelUtils.isNullType(schema) && null != example) {
|
||||||
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
||||||
// though this tooling supports it.
|
// though this tooling supports it.
|
||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
// correct "'"s into "'"s after toString()
|
// correct "'"s into "'"s after toString()
|
||||||
if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) {
|
if (modelUtils.isStringSchema(schema) && schema.getDefault() != null) {
|
||||||
example = (String) schema.getDefault();
|
example = (String) schema.getDefault();
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "\"" + example + "\"";
|
example = "\"" + example + "\"";
|
||||||
}
|
}
|
||||||
return example;
|
return example;
|
||||||
@ -346,7 +346,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
||||||
// Enum case:
|
// Enum case:
|
||||||
example = schema.getEnum().get(0).toString();
|
example = schema.getEnum().get(0).toString();
|
||||||
/* if (ModelUtils.isStringSchema(schema)) {
|
/* if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "'" + escapeText(example) + "'";
|
example = "'" + escapeText(example) + "'";
|
||||||
}*/
|
}*/
|
||||||
if (null == example)
|
if (null == example)
|
||||||
@ -355,8 +355,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
return example;
|
return example;
|
||||||
} else if (null != schema.get$ref()) {
|
} else if (null != schema.get$ref()) {
|
||||||
// $ref case:
|
// $ref case:
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
String ref = ModelUtils.getSimpleRef(schema.get$ref());
|
String ref = modelUtils.getSimpleRef(schema.get$ref());
|
||||||
if (allDefinitions != null) {
|
if (allDefinitions != null) {
|
||||||
Schema refSchema = allDefinitions.get(ref);
|
Schema refSchema = allDefinitions.get(ref);
|
||||||
if (null == refSchema) {
|
if (null == refSchema) {
|
||||||
@ -372,18 +372,18 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isDateSchema(schema)) {
|
if (modelUtils.isDateSchema(schema)) {
|
||||||
example = "\"2013-10-20\"";
|
example = "\"2013-10-20\"";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||||
example = "\"2013-10-20T19:20:30+01:00\"";
|
example = "\"2013-10-20T19:20:30+01:00\"";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isBinarySchema(schema)) {
|
} else if (modelUtils.isBinarySchema(schema)) {
|
||||||
example = "instantiate_binary_t(\"blah\", 5)";
|
example = "instantiate_binary_t(\"blah\", 5)";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isByteArraySchema(schema)) {
|
} else if (modelUtils.isByteArraySchema(schema)) {
|
||||||
example = "YQ==";
|
example = "YQ==";
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
// decimal (type: string, format: decimal)
|
// decimal (type: string, format: decimal)
|
||||||
if ("number".equalsIgnoreCase(schema.getFormat())) {
|
if ("number".equalsIgnoreCase(schema.getFormat())) {
|
||||||
return "1";
|
return "1";
|
||||||
@ -398,29 +398,29 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
example = "";
|
example = "";
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
example += i;
|
example += i;
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (schema.getMinimum() != null)
|
if (schema.getMinimum() != null)
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
else
|
else
|
||||||
example = "56";
|
example = "56";
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (schema.getMinimum() != null)
|
if (schema.getMinimum() != null)
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
else
|
else
|
||||||
example = "1.337";
|
example = "1.337";
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
example = "1";
|
example = "1";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
example = "list_create()";
|
example = "list_create()";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
example = "list_create()";
|
example = "list_create()";
|
||||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
} else if (modelUtils.isObjectSchema(schema)) {
|
||||||
return null; // models are managed at moustache level
|
return null; // models are managed at moustache level
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "\"" + escapeText(example) + "\"";
|
example = "\"" + escapeText(example) + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,7 +744,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
@Override
|
@Override
|
||||||
public CodegenProperty fromProperty(String name, Schema p) {
|
public CodegenProperty fromProperty(String name, Schema p) {
|
||||||
CodegenProperty cm = super.fromProperty(name, p);
|
CodegenProperty cm = super.fromProperty(name, p);
|
||||||
Schema ref = ModelUtils.getReferencedSchema(openAPI, p);
|
Schema ref = modelUtils.getReferencedSchema(p);
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
if (ref.getEnum() != null) {
|
if (ref.getEnum() != null) {
|
||||||
cm.isEnum = true;
|
cm.isEnum = true;
|
||||||
|
@ -588,7 +588,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||||
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||||
@ -965,14 +965,14 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema schema) {
|
public String toInstantiationType(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema additionalProperties = getAdditionalProperties(schema);
|
Schema additionalProperties = getAdditionalProperties(schema);
|
||||||
String inner = getSchemaType(additionalProperties);
|
String inner = getSchemaType(additionalProperties);
|
||||||
if (ModelUtils.isMapSchema(additionalProperties)) {
|
if (modelUtils.isMapSchema(additionalProperties)) {
|
||||||
inner = toInstantiationType(additionalProperties);
|
inner = toInstantiationType(additionalProperties);
|
||||||
}
|
}
|
||||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String inner = getSchemaType(arraySchema.getItems());
|
String inner = getSchemaType(arraySchema.getItems());
|
||||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||||
@ -984,7 +984,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + "?";
|
return type + "?";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
|
@ -51,7 +51,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
private static final String PACKAGE_CONTEXT = "packageContext";
|
private static final String PACKAGE_CONTEXT = "packageContext";
|
||||||
private static final String ASYNC_SERVER = "asyncServer";
|
private static final String ASYNC_SERVER = "asyncServer";
|
||||||
|
|
||||||
private static final Map<String, Predicate<Schema>> propertyToOpenAPITypeMapping =
|
private final Map<String, Predicate<Schema>> propertyToOpenAPITypeMapping =
|
||||||
createPropertyToOpenAPITypeMapping();
|
createPropertyToOpenAPITypeMapping();
|
||||||
|
|
||||||
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
|
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
|
||||||
@ -270,7 +270,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
private void postProcessParentModels(final Map<String, Object> models) {
|
private void postProcessParentModels(final Map<String, Object> models) {
|
||||||
LOGGER.debug("Processing parents: " + parentModels);
|
LOGGER.debug("Processing parents: " + parentModels);
|
||||||
for (final String parent : parentModels) {
|
for (final String parent : parentModels) {
|
||||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||||
if (parentModel != null) {
|
if (parentModel != null) {
|
||||||
parentModel.hasChildren = true;
|
parentModel.hasChildren = true;
|
||||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||||
@ -397,17 +397,17 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen {
|
|||||||
return super.getSchemaType(property);
|
return super.getSchemaType(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Predicate<Schema>> createPropertyToOpenAPITypeMapping() {
|
private Map<String, Predicate<Schema>> createPropertyToOpenAPITypeMapping() {
|
||||||
final ImmutableMap.Builder<String, Predicate<Schema>> mapping = ImmutableMap.builder();
|
final ImmutableMap.Builder<String, Predicate<Schema>> mapping = ImmutableMap.builder();
|
||||||
mapping.put("time", timeProperty());
|
mapping.put("time", timeProperty());
|
||||||
return mapping.build();
|
return mapping.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Predicate<Schema> timeProperty() {
|
private Predicate<Schema> timeProperty() {
|
||||||
return new Predicate<Schema>() {
|
return new Predicate<Schema>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Schema property) {
|
public boolean apply(Schema property) {
|
||||||
return ModelUtils.isStringSchema(property) && "time".equalsIgnoreCase(property.getFormat());
|
return modelUtils.isStringSchema(property) && "time".equalsIgnoreCase(property.getFormat());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||||
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||||
@ -401,7 +401,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String getNullableType(Schema p, String type) {
|
public String getNullableType(Schema p, String type) {
|
||||||
if (languageSpecificPrimitives.contains(type)) {
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
if (isSupportNullable() && ModelUtils.isNullable(p) && nullableType.contains(type)) {
|
if (isSupportNullable() && modelUtils.isNullable(p) && nullableType.contains(type)) {
|
||||||
return type + "?";
|
return type + "?";
|
||||||
} else {
|
} else {
|
||||||
return type;
|
return type;
|
||||||
@ -968,14 +968,14 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema schema) {
|
public String toInstantiationType(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
Schema additionalProperties = getAdditionalProperties(schema);
|
Schema additionalProperties = getAdditionalProperties(schema);
|
||||||
String inner = getSchemaType(additionalProperties);
|
String inner = getSchemaType(additionalProperties);
|
||||||
if (ModelUtils.isMapSchema(additionalProperties)) {
|
if (modelUtils.isMapSchema(additionalProperties)) {
|
||||||
inner = toInstantiationType(additionalProperties);
|
inner = toInstantiationType(additionalProperties);
|
||||||
}
|
}
|
||||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String inner = getSchemaType(arraySchema.getItems());
|
String inner = getSchemaType(arraySchema.getItems());
|
||||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||||
|
@ -168,7 +168,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
|
|
||||||
return "(s/coll-of " + getTypeDeclaration(inner) + ")";
|
return "(s/coll-of " + getTypeDeclaration(inner) + ")";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = (Schema) p.getAdditionalProperties();
|
Schema inner = (Schema) p.getAdditionalProperties();
|
||||||
|
|
||||||
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
|
return "(s/map-of string? " + getTypeDeclaration(inner) + ")";
|
||||||
|
@ -102,11 +102,11 @@ public class ConfluenceWikiCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||||
|
|
||||||
if (apiResponse != null) {
|
if (apiResponse != null) {
|
||||||
Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
|
Schema response = modelUtils.getSchemaFromResponse(apiResponse);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
CodegenProperty cm = fromProperty("response", response);
|
CodegenProperty cm = fromProperty("response", response);
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
op.vendorExtensions.put("x-codegen-response", cm);
|
||||||
@ -350,20 +350,20 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "std::string";
|
return "std::string";
|
||||||
}
|
}
|
||||||
if (ModelUtils.isStringSchema(p)
|
if (modelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p)
|
|| modelUtils.isDateSchema(p)
|
||||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
|| modelUtils.isDateTimeSchema(p) || modelUtils.isFileSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
@ -373,34 +373,34 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (ModelUtils.isFloatSchema(p)) {
|
if (modelUtils.isFloatSchema(p)) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (ModelUtils.isLongSchema(p)) {
|
if (modelUtils.isLongSchema(p)) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "std::map<std::string, " + inner + ">()";
|
return "std::map<std::string, " + inner + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return "std::vector<" + inner + ">()";
|
return "std::vector<" + inner + ">()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
||||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,16 +181,16 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return getSchemaType(p);
|
return getSchemaType(p);
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return getSchemaType(p);
|
return getSchemaType(p);
|
||||||
}
|
}
|
||||||
if (foundationClasses.contains(openAPIType)) {
|
if (foundationClasses.contains(openAPIType)) {
|
||||||
@ -205,33 +205,33 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "NULL";
|
return "NULL";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "NULL";
|
return "NULL";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "QList<" + getTypeDeclaration(inner) + ">()";
|
return "QList<" + getTypeDeclaration(inner) + ">()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "QString(\"\")";
|
return "QString(\"\")";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
}
|
}
|
||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import io.swagger.v3.oas.models.servers.Server;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openapitools.codegen.*;
|
import org.openapitools.codegen.*;
|
||||||
import org.openapitools.codegen.meta.features.*;
|
import org.openapitools.codegen.meta.features.*;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -271,8 +270,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||||
|
|
||||||
if (methodResponse != null) {
|
if (methodResponse != null) {
|
||||||
Schema response = ModelUtils.getSchemaFromResponse(methodResponse);
|
Schema response = modelUtils.getSchemaFromResponse(methodResponse);
|
||||||
response = ModelUtils.unaliasSchema(this.openAPI, response, importMapping);
|
response = modelUtils.unaliasSchema(response, importMapping);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
CodegenProperty cm = fromProperty("response", response);
|
CodegenProperty cm = fromProperty("response", response);
|
||||||
op.vendorExtensions.put("x-codegen-response", cm);
|
op.vendorExtensions.put("x-codegen-response", cm);
|
||||||
@ -344,18 +343,18 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isFileSchema(p) || ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isFileSchema(p) || modelUtils.isBinarySchema(p)) {
|
||||||
return "std::shared_ptr<" + openAPIType + ">";
|
return "std::shared_ptr<" + openAPIType + ">";
|
||||||
} else if (ModelUtils.isStringSchema(p)
|
} else if (modelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)
|
|| modelUtils.isDateSchema(p) || modelUtils.isDateTimeSchema(p)
|
||||||
|| ModelUtils.isFileSchema(p) || ModelUtils.isUUIDSchema(p)
|
|| modelUtils.isFileSchema(p) || modelUtils.isUUIDSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
@ -365,26 +364,26 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "utility::datetime()";
|
return "utility::datetime()";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "utility::datetime()";
|
return "utility::datetime()";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (ModelUtils.isFloatSchema(p)) {
|
if (modelUtils.isFloatSchema(p)) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (ModelUtils.isLongSchema(p)) {
|
if (modelUtils.isLongSchema(p)) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "std::map<utility::string_t, " + inner + ">()";
|
return "std::map<utility::string_t, " + inner + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
if (!languageSpecificPrimitives.contains(inner)) {
|
if (!languageSpecificPrimitives.contains(inner)) {
|
||||||
@ -392,10 +391,10 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
}
|
}
|
||||||
return "std::vector<" + inner + ">()";
|
return "std::vector<" + inner + ">()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return "new " + toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "utility::conversions::to_string_t(\"\")";
|
return "utility::conversions::to_string_t(\"\")";
|
||||||
} else if (ModelUtils.isFreeFormObject(openAPI, p)) {
|
} else if (modelUtils.isFreeFormObject(p)) {
|
||||||
return "new Object()";
|
return "new Object()";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +445,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
private void postProcessParentModels(final Map<String, Object> models) {
|
private void postProcessParentModels(final Map<String, Object> models) {
|
||||||
for (final String parent : parentModels) {
|
for (final String parent : parentModels) {
|
||||||
final CodegenModel parentModel = ModelUtils.getModelByName(parent, models);
|
final CodegenModel parentModel = modelUtils.getModelByName(parent, models);
|
||||||
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
final Collection<CodegenModel> childrenModels = childrenByParent.get(parent);
|
||||||
for (final CodegenModel child : childrenModels) {
|
for (final CodegenModel child : childrenModels) {
|
||||||
processParentPropertiesInChildModel(parentModel, child);
|
processParentPropertiesInChildModel(parentModel, child);
|
||||||
|
@ -345,18 +345,18 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "std::string";
|
return "std::string";
|
||||||
} else if (ModelUtils.isStringSchema(p)
|
} else if (modelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p)
|
|| modelUtils.isDateSchema(p)
|
||||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
|| modelUtils.isDateTimeSchema(p) || modelUtils.isFileSchema(p)
|
||||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
@ -366,32 +366,32 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (modelUtils.isFloatSchema(p)) { // float
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "f";
|
return p.getDefault().toString() + "f";
|
||||||
} else {
|
} else {
|
||||||
@ -404,8 +404,8 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
return "0.0";
|
return "0.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (ModelUtils.isLongSchema(p)) { // long
|
if (modelUtils.isLongSchema(p)) { // long
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString() + "L";
|
return p.getDefault().toString() + "L";
|
||||||
} else {
|
} else {
|
||||||
@ -418,16 +418,16 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "std::map<std::string, " + inner + ">()";
|
return "std::map<std::string, " + inner + ">()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
if (!languageSpecificPrimitives.contains(inner)) {
|
if (!languageSpecificPrimitives.contains(inner)) {
|
||||||
@ -435,7 +435,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
|||||||
}
|
}
|
||||||
return "std::vector<" + inner + ">()";
|
return "std::vector<" + inner + ">()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return "std::make_shared<" + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + ">()";
|
return "std::make_shared<" + toModelName(modelUtils.getSimpleRef(p.get$ref())) + ">()";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "nullptr";
|
return "nullptr";
|
||||||
|
@ -161,9 +161,9 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
return instantiationTypes.get("map");
|
return instantiationTypes.get("map");
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return instantiationTypes.get("array");
|
return instantiationTypes.get("array");
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -232,28 +232,28 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
//Might not be needed
|
//Might not be needed
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "bool(false)";
|
return "bool(false)";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) {
|
||||||
return "float(0)";
|
return "float(0)";
|
||||||
}
|
}
|
||||||
return "double(0)";
|
return "double(0)";
|
||||||
|
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
|
||||||
return "long(0)";
|
return "long(0)";
|
||||||
}
|
}
|
||||||
return "int(0)";
|
return "int(0)";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
return "new std::map()";
|
return "new std::map()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return "new std::list()";
|
return "new std::list()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
return "new " + toModelName(modelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||||
} else if (ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateSchema(p) || modelUtils.isDateTimeSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "std::string()";
|
return "std::string()";
|
||||||
}
|
}
|
||||||
return "null";
|
return "null";
|
||||||
|
@ -379,11 +379,11 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
|||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
String openAPIType = getSchemaType(p);
|
String openAPIType = getSchemaType(p);
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return getSchemaType(p) + "<FString, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<FString, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
@ -404,41 +404,41 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "TEXT(\"" + p.getDefault().toString() + "\")";
|
return "TEXT(\"" + p.getDefault().toString() + "\")";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "FDateTime(0)";
|
return "FDateTime(0)";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "FDateTime(0)";
|
return "FDateTime(0)";
|
||||||
} else if (ModelUtils.isDoubleSchema(p)) {
|
} else if (modelUtils.isDoubleSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "0.0";
|
return "0.0";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isFloatSchema(p)) {
|
} else if (modelUtils.isFloatSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (modelUtils.isLongSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else {
|
} else {
|
||||||
|
@ -412,14 +412,14 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return "const {}";
|
return "const {}";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
return "const []";
|
return "const []";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||||
}
|
}
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
@ -430,11 +430,11 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
|
@ -118,14 +118,14 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return "const {}";
|
return "const {}";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
return "const []";
|
return "const []";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||||
}
|
}
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
|
@ -132,14 +132,14 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema schema) {
|
public String toDefaultValue(Schema schema) {
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (modelUtils.isMapSchema(schema)) {
|
||||||
return "const {}";
|
return "const {}";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
return "const []";
|
return "const []";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
|
||||||
}
|
}
|
||||||
return schema.getDefault().toString();
|
return schema.getDefault().toString();
|
||||||
|
@ -490,42 +490,42 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
|
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
|
||||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
} else if (modelUtils.isPasswordSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isEmailSchema(p)) {
|
} else if (modelUtils.isEmailSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (modelUtils.isByteArraySchema(p)) {
|
||||||
return "binary()";
|
return "binary()";
|
||||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
} else if (modelUtils.isUUIDSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "Date.t";
|
return "Date.t";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "DateTime.t";
|
return "DateTime.t";
|
||||||
} else if (ModelUtils.isObjectSchema(p)) {
|
} else if (modelUtils.isObjectSchema(p)) {
|
||||||
// TODO How to map it?
|
// TODO How to map it?
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return "integer()";
|
return "integer()";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return "float()";
|
return "float()";
|
||||||
} else if (ModelUtils.isBinarySchema(p) || ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isBinarySchema(p) || modelUtils.isFileSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "boolean()";
|
return "boolean()";
|
||||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
||||||
// How to map it?
|
// How to map it?
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "String.t";
|
return "String.t";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -238,7 +238,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return instantiationTypes.get("array") + " " + inner;
|
return instantiationTypes.get("array") + " " + inner;
|
||||||
@ -414,19 +414,19 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + p.getDefault().toString() + "\"";
|
return "\"" + p.getDefault().toString() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return Boolean.valueOf(p.getDefault().toString()) ? "True" : "False";
|
return Boolean.valueOf(p.getDefault().toString()) ? "True" : "False";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
@ -450,11 +450,11 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
CodegenModel cm = super.fromModel(name, model);
|
CodegenModel cm = super.fromModel(name, model);
|
||||||
if(ModelUtils.isArraySchema(model)) {
|
if(modelUtils.isArraySchema(model)) {
|
||||||
return new CodegenArrayModel(cm, (ArraySchema) model);
|
return new CodegenArrayModel(cm, (ArraySchema) model);
|
||||||
} else {
|
} else {
|
||||||
return cm;
|
return cm;
|
||||||
@ -152,7 +152,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema schema) {
|
public String getTypeDeclaration(Schema schema) {
|
||||||
String typeDeclaration = super.getSchemaType(schema);
|
String typeDeclaration = super.getSchemaType(schema);
|
||||||
if(ModelUtils.isArraySchema(schema)) {
|
if(modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String complexType = getSchemaType(arraySchema.getItems());
|
String complexType = getSchemaType(arraySchema.getItems());
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
@Override
|
@Override
|
||||||
public String getSchemaType(Schema schema) {
|
public String getSchemaType(Schema schema) {
|
||||||
String schemaType = super.getSchemaType(schema);
|
String schemaType = super.getSchemaType(schema);
|
||||||
if(ModelUtils.isArraySchema(schema)) {
|
if(modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
String complexType = getSchemaType(arraySchema.getItems());
|
String complexType = getSchemaType(arraySchema.getItems());
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if(minItems != null && maxItems != null) sb.append(", ").append(maxItems);
|
if(minItems != null && maxItems != null) sb.append(", ").append(maxItems);
|
||||||
|
|
||||||
return sb.append(")").toString();
|
return sb.append(")").toString();
|
||||||
} else if(ModelUtils.isIntegerSchema(schema)) {
|
} else if(modelUtils.isIntegerSchema(schema)) {
|
||||||
StringBuilder sb = new StringBuilder("integer(");
|
StringBuilder sb = new StringBuilder("integer(");
|
||||||
|
|
||||||
BigDecimal min = schema.getMinimum();
|
BigDecimal min = schema.getMinimum();
|
||||||
@ -192,9 +192,9 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if(min != null && max != null) sb.append(", ").append(max);
|
if(min != null && max != null) sb.append(", ").append(max);
|
||||||
|
|
||||||
return sb.append(")").toString();
|
return sb.append(")").toString();
|
||||||
} else if(ModelUtils.isDateSchema(schema) || ModelUtils.isDateTimeSchema(schema)) {
|
} else if(modelUtils.isDateSchema(schema) || modelUtils.isDateTimeSchema(schema)) {
|
||||||
return typeMapping.get(schemaType);
|
return typeMapping.get(schemaType);
|
||||||
} else if(ModelUtils.isStringSchema(schema)) {
|
} else if(modelUtils.isStringSchema(schema)) {
|
||||||
StringBuilder sb = new StringBuilder("binary(");
|
StringBuilder sb = new StringBuilder("binary(");
|
||||||
Integer min = schema.getMinLength();
|
Integer min = schema.getMinLength();
|
||||||
Integer max = schema.getMaxLength();
|
Integer max = schema.getMaxLength();
|
||||||
|
@ -235,7 +235,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p) || ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isArraySchema(p) || modelUtils.isMapSchema(p)) {
|
||||||
return getSchemaType(p);
|
return getSchemaType(p);
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
@ -258,27 +258,27 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "0.0";
|
return "0.0";
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return "0";
|
return "0";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
return "new Dictionary()";
|
return "new Dictionary()";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return "new Array()";
|
return "new Array()";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "null";
|
return "null";
|
||||||
} else {
|
} else {
|
||||||
return "NaN";
|
return "NaN";
|
||||||
|
@ -349,8 +349,8 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
p = ModelUtils.getReferencedSchema(this.openAPI, p);
|
p = modelUtils.getReferencedSchema(p);
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
|||||||
// between some specific types for GraphQL:
|
// between some specific types for GraphQL:
|
||||||
// return "[" + getTypeDeclaration(inner) + "]";
|
// return "[" + getTypeDeclaration(inner) + "]";
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = (Schema) p.getAdditionalProperties();
|
Schema inner = (Schema) p.getAdditionalProperties();
|
||||||
|
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
@ -139,7 +139,7 @@ public class GraphQLNodeJSExpressServerCodegen extends AbstractGraphQLCodegen im
|
|||||||
|
|
||||||
// IMPORANT NOTE Not using the supertype invocation, because we want to UpperCamelize the type:
|
// IMPORANT NOTE Not using the supertype invocation, because we want to UpperCamelize the type:
|
||||||
String schemaType = getSchemaType(p);
|
String schemaType = getSchemaType(p);
|
||||||
String nullable = ModelUtils.isNullable(p) ? "" : "!";
|
String nullable = modelUtils.isNullable(p) ? "" : "!";
|
||||||
|
|
||||||
if (typeMapping.containsKey(schemaType)) {
|
if (typeMapping.containsKey(schemaType)) {
|
||||||
return typeMapping.get(schemaType) + nullable;
|
return typeMapping.get(schemaType) + nullable;
|
||||||
|
@ -624,11 +624,11 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||||
}
|
}
|
||||||
@ -650,7 +650,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||||
String type = additionalProperties2.getType();
|
String type = additionalProperties2.getType();
|
||||||
if (null == type) {
|
if (null == type) {
|
||||||
@ -659,7 +659,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
String inner = getSchemaType(additionalProperties2);
|
String inner = getSchemaType(additionalProperties2);
|
||||||
return "(Map.Map Text " + inner + ")";
|
return "(Map.Map Text " + inner + ")";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
return getSchemaType(ap.getItems());
|
return getSchemaType(ap.getItems());
|
||||||
} else {
|
} else {
|
||||||
@ -1245,11 +1245,11 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||||
return "False";
|
return "False";
|
||||||
|
@ -368,11 +368,11 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema additionalProperties2 = getAdditionalProperties(p);
|
Schema additionalProperties2 = getAdditionalProperties(p);
|
||||||
String type = additionalProperties2.getType();
|
String type = additionalProperties2.getType();
|
||||||
if (null == type) {
|
if (null == type) {
|
||||||
@ -416,7 +416,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
}
|
}
|
||||||
String inner = getSchemaType(additionalProperties2);
|
String inner = getSchemaType(additionalProperties2);
|
||||||
return "(Map.Map Text " + inner + ")";
|
return "(Map.Map Text " + inner + ")";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
// Return only the inner type; the wrapping with QueryList is done
|
// Return only the inner type; the wrapping with QueryList is done
|
||||||
|
@ -201,11 +201,11 @@ public class JMeterClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
@ -1431,9 +1431,9 @@ public class JavaCXFExtServerCodegen extends JavaCXFServerCodegen implements CXF
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isGenerateAliasAsModel(p) && StringUtils.isNotEmpty(p.get$ref())) {
|
if (modelUtils.isGenerateAliasAsModel(p) && StringUtils.isNotEmpty(p.get$ref())) {
|
||||||
Schema<?> ref = ModelUtils.getReferencedSchema(this.openAPI, p);
|
Schema<?> ref = modelUtils.getReferencedSchema(p);
|
||||||
if (ModelUtils.isArraySchema(ref) || ModelUtils.isMapSchema(ref)) {
|
if (modelUtils.isArraySchema(ref) || modelUtils.isMapSchema(ref)) {
|
||||||
String typeDeclaration = getTypeDeclaration(p);
|
String typeDeclaration = getTypeDeclaration(p);
|
||||||
return String.format(Locale.ROOT, "new %s()", typeDeclaration);
|
return String.format(Locale.ROOT, "new %s()", typeDeclaration);
|
||||||
}
|
}
|
||||||
|
@ -560,11 +560,11 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "{String: " + getTypeDeclaration(inner) + "}";
|
return "{String: " + getTypeDeclaration(inner) + "}";
|
||||||
}
|
}
|
||||||
@ -573,23 +573,23 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
@ -814,7 +814,7 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
|||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
|
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
|
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||||
@ -822,14 +822,14 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
|||||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||||
codegenModel = JavascriptApolloClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
codegenModel = JavascriptApolloClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||||
}
|
}
|
||||||
if (ModelUtils.isArraySchema(model)) {
|
if (modelUtils.isArraySchema(model)) {
|
||||||
ArraySchema am = (ArraySchema) model;
|
ArraySchema am = (ArraySchema) model;
|
||||||
if (codegenModel != null && am.getItems() != null) {
|
if (codegenModel != null && am.getItems() != null) {
|
||||||
String itemType = getSchemaType(am.getItems());
|
String itemType = getSchemaType(am.getItems());
|
||||||
codegenModel.vendorExtensions.put("x-is-array", true);
|
codegenModel.vendorExtensions.put("x-is-array", true);
|
||||||
codegenModel.vendorExtensions.put("x-item-type", itemType);
|
codegenModel.vendorExtensions.put("x-item-type", itemType);
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(model)) {
|
} else if (modelUtils.isMapSchema(model)) {
|
||||||
if (codegenModel != null && getAdditionalProperties(model) != null) {
|
if (codegenModel != null && getAdditionalProperties(model) != null) {
|
||||||
String itemType = getSchemaType(getAdditionalProperties(model));
|
String itemType = getSchemaType(getAdditionalProperties(model));
|
||||||
codegenModel.vendorExtensions.put("x-is-map", true);
|
codegenModel.vendorExtensions.put("x-is-map", true);
|
||||||
|
@ -611,11 +611,11 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "{String: " + getTypeDeclaration(inner) + "}";
|
return "{String: " + getTypeDeclaration(inner) + "}";
|
||||||
}
|
}
|
||||||
@ -624,23 +624,23 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
@ -865,7 +865,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
|
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
|
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||||
@ -873,14 +873,14 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||||
codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||||
}
|
}
|
||||||
if (ModelUtils.isArraySchema(model)) {
|
if (modelUtils.isArraySchema(model)) {
|
||||||
ArraySchema am = (ArraySchema) model;
|
ArraySchema am = (ArraySchema) model;
|
||||||
if (codegenModel != null && am.getItems() != null) {
|
if (codegenModel != null && am.getItems() != null) {
|
||||||
String itemType = getSchemaType(am.getItems());
|
String itemType = getSchemaType(am.getItems());
|
||||||
codegenModel.vendorExtensions.put("x-is-array", true);
|
codegenModel.vendorExtensions.put("x-is-array", true);
|
||||||
codegenModel.vendorExtensions.put("x-item-type", itemType);
|
codegenModel.vendorExtensions.put("x-item-type", itemType);
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(model)) {
|
} else if (modelUtils.isMapSchema(model)) {
|
||||||
if (codegenModel != null && getAdditionalProperties(model) != null) {
|
if (codegenModel != null && getAdditionalProperties(model) != null) {
|
||||||
String itemType = getSchemaType(getAdditionalProperties(model));
|
String itemType = getSchemaType(getAdditionalProperties(model));
|
||||||
codegenModel.vendorExtensions.put("x-is-map", true);
|
codegenModel.vendorExtensions.put("x-is-map", true);
|
||||||
|
@ -220,14 +220,14 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "<!" + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<!" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "Object<!string, "+ getTypeDeclaration(inner) + ">";
|
return "Object<!string, "+ getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return "Object";
|
return "Object";
|
||||||
}
|
}
|
||||||
String type = super.getTypeDeclaration(p);
|
String type = super.getTypeDeclaration(p);
|
||||||
|
@ -325,16 +325,16 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
|
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
|
||||||
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
|
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
|
||||||
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
|
List<String> consumes = new ArrayList<>(getConsumesInfo(operation));
|
||||||
String contentTypeValue = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
String contentTypeValue = consumes == null || consumes.isEmpty() ? defaultContentType : consumes.get(0);
|
||||||
if (contentTypeValue.equals("*/*"))
|
if (contentTypeValue.equals("*/*"))
|
||||||
contentTypeValue = "application/json";
|
contentTypeValue = "application/json";
|
||||||
Parameter contentType = new Parameter("Content-Type", getDoubleQuotedString(contentTypeValue));
|
Parameter contentType = new Parameter("Content-Type", getDoubleQuotedString(contentTypeValue));
|
||||||
httpParams.add(contentType);
|
httpParams.add(contentType);
|
||||||
|
|
||||||
RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, operation.getRequestBody());
|
RequestBody requestBody = modelUtils.getReferencedRequestBody(operation.getRequestBody());
|
||||||
|
|
||||||
for (Map.Entry<String, ApiResponse> responseEntry : operation.getResponses().entrySet()) {
|
for (Map.Entry<String, ApiResponse> responseEntry : operation.getResponses().entrySet()) {
|
||||||
CodegenResponse r = fromResponse(responseEntry.getKey(), responseEntry.getValue());
|
CodegenResponse r = fromResponse(responseEntry.getKey(), responseEntry.getValue());
|
||||||
@ -349,7 +349,7 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
for (CodegenParameter parameter : formParameteres) {
|
for (CodegenParameter parameter : formParameteres) {
|
||||||
String reference = "";
|
String reference = "";
|
||||||
if (parameter.isModel) {
|
if (parameter.isModel) {
|
||||||
Schema nestedSchema = ModelUtils.getSchema(openAPI, parameter.baseType);
|
Schema nestedSchema = modelUtils.getSchema(parameter.baseType);
|
||||||
CodegenModel model = fromModel(parameter.paramName, nestedSchema);
|
CodegenModel model = fromModel(parameter.paramName, nestedSchema);
|
||||||
reference = generateNestedModelTemplate(model);
|
reference = generateNestedModelTemplate(model);
|
||||||
if (parameter.dataType.equals("List")) {
|
if (parameter.dataType.equals("List")) {
|
||||||
@ -369,7 +369,7 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
bodyOrFormParams.add(k6Parameter);
|
bodyOrFormParams.add(k6Parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String accepts = getAccept(openAPI, operation);
|
String accepts = getAccept(operation);
|
||||||
String responseType = getDoubleQuotedString(accepts);
|
String responseType = getDoubleQuotedString(accepts);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -602,10 +602,10 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getAccept(OpenAPI openAPI, Operation operation) {
|
private String getAccept(Operation operation) {
|
||||||
String accepts = null;
|
String accepts = null;
|
||||||
String defaultContentType = "application/json";
|
String defaultContentType = "application/json";
|
||||||
Set<String> producesInfo = getProducesInfo(openAPI, operation);
|
Set<String> producesInfo = getProducesInfo(operation);
|
||||||
if (producesInfo != null && !producesInfo.isEmpty()) {
|
if (producesInfo != null && !producesInfo.isEmpty()) {
|
||||||
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
ArrayList<String> produces = new ArrayList<>(producesInfo);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -362,11 +362,11 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
|
@ -270,14 +270,14 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return "seq[" + getTypeDeclaration(inner) + "]";
|
return "seq[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
inner = new StringSchema();
|
inner = new StringSchema();
|
||||||
|
@ -575,7 +575,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -583,7 +583,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
inner = new StringSchema().description("TODO default missing array inner type to string");
|
inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||||
}
|
}
|
||||||
return getTypeDeclaration(inner) + " list";
|
return getTypeDeclaration(inner) + " list";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
||||||
@ -596,7 +596,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
return enumUniqNames.get(h);
|
return enumUniqNames.get(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
Schema referencedSchema = ModelUtils.getReferencedSchema(openAPI, p);
|
Schema referencedSchema = modelUtils.getReferencedSchema(p);
|
||||||
if (referencedSchema != null && referencedSchema.getEnum() != null) {
|
if (referencedSchema != null && referencedSchema.getEnum() != null) {
|
||||||
String h = hashEnum(referencedSchema);
|
String h = hashEnum(referencedSchema);
|
||||||
return "Enums." + enumUniqNames.get(h);
|
return "Enums." + enumUniqNames.get(h);
|
||||||
|
@ -325,9 +325,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
return instantiationTypes.get("map");
|
return instantiationTypes.get("map");
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
return instantiationTypes.get("array");
|
return instantiationTypes.get("array");
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -366,7 +366,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||||
@ -388,7 +388,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
return getSchemaType(p) + "<" + innerTypeDeclaration + ">*";
|
return getSchemaType(p) + "<" + innerTypeDeclaration + ">*";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||||
@ -679,23 +679,23 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isDateSchema(p)) {
|
if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "@" + p.getDefault().toString();
|
return "@" + p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "@" + p.getDefault().toString();
|
return "@" + p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "@\"" + (String) p.getDefault() + "\"";
|
return "@\"" + (String) p.getDefault() + "\"";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||||
return "@(NO)";
|
return "@(NO)";
|
||||||
|
@ -252,11 +252,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@ -283,23 +283,23 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
|
@ -171,11 +171,11 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
@ -536,13 +536,13 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getTypeDeclaration(inner);
|
return getTypeDeclaration(inner);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
|
|||||||
if (parameter instanceof QueryParameter) {
|
if (parameter instanceof QueryParameter) {
|
||||||
QueryParameter queryParameter = (QueryParameter) parameter;
|
QueryParameter queryParameter = (QueryParameter) parameter;
|
||||||
// array
|
// array
|
||||||
if (ModelUtils.isArraySchema(queryParameter.getSchema())) {
|
if (modelUtils.isArraySchema(queryParameter.getSchema())) {
|
||||||
Schema inner = ((ArraySchema) queryParameter.getSchema()).getItems();
|
Schema inner = ((ArraySchema) queryParameter.getSchema()).getItems();
|
||||||
ArraySchema arraySchema = new ArraySchema();
|
ArraySchema arraySchema = new ArraySchema();
|
||||||
arraySchema.setMinItems(queryParameter.getSchema().getMinItems());
|
arraySchema.setMinItems(queryParameter.getSchema().getMinItems());
|
||||||
|
@ -906,11 +906,11 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getTypeDeclaration(inner) + "[]";
|
return getTypeDeclaration(inner) + "[]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
return "System.Collections.Hashtable";
|
return "System.Collections.Hashtable";
|
||||||
} else if (!languageSpecificPrimitives.contains(getSchemaType(p))) {
|
} else if (!languageSpecificPrimitives.contains(getSchemaType(p))) {
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
@ -1272,21 +1272,21 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (Boolean.valueOf(p.getDefault().toString())) {
|
if (Boolean.valueOf(p.getDefault().toString())) {
|
||||||
return "$true";
|
return "$true";
|
||||||
} else {
|
} else {
|
||||||
return "$false";
|
return "$false";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
LOGGER.warn("Default value for `date` not yet supported. Please open an issue with https://github.com/openapitools/openapi-generator");
|
LOGGER.warn("Default value for `date` not yet supported. Please open an issue with https://github.com/openapitools/openapi-generator");
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
LOGGER.warn("Default value for `datetime` not yet supported. Please open an issue with https://github.com/openapitools/openapi-generator");
|
LOGGER.warn("Default value for `datetime` not yet supported. Please open an issue with https://github.com/openapitools/openapi-generator");
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "\"" + p.getDefault() + "\"";
|
return "\"" + p.getDefault() + "\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,33 +300,33 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (Boolean.valueOf(p.getDefault().toString()) == false)
|
if (Boolean.valueOf(p.getDefault().toString()) == false)
|
||||||
return "false";
|
return "false";
|
||||||
else
|
else
|
||||||
return "true";
|
return "true";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||||
return "'''" + p.getDefault() + "'''";
|
return "'''" + p.getDefault() + "'''";
|
||||||
else
|
else
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
@ -484,11 +484,11 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default this to true so the python ModelSimple models will be generated
|
// default this to true so the python ModelSimple models will be generated
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
LOGGER.info(CodegenConstants.GENERATE_ALIAS_AS_MODEL + " is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums");
|
LOGGER.info(CodegenConstants.GENERATE_ALIAS_AS_MODEL + " is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums");
|
||||||
|
|
||||||
Boolean attrNoneIfUnset = false;
|
Boolean attrNoneIfUnset = false;
|
||||||
@ -170,7 +170,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings) {
|
public Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings) {
|
||||||
Map<String, Schema> allSchemas = ModelUtils.getSchemas(openAPI);
|
Map<String, Schema> allSchemas = modelUtils.getSchemas();
|
||||||
if (allSchemas == null || allSchemas.isEmpty()) {
|
if (allSchemas == null || allSchemas.isEmpty()) {
|
||||||
// skip the warning as the spec can have no model defined
|
// skip the warning as the spec can have no model defined
|
||||||
//LOGGER.warn("allSchemas cannot be null/empty in unaliasSchema. Returned 'schema'");
|
//LOGGER.warn("allSchemas cannot be null/empty in unaliasSchema. Returned 'schema'");
|
||||||
@ -178,7 +178,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) {
|
if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) {
|
||||||
String simpleRef = ModelUtils.getSimpleRef(schema.get$ref());
|
String simpleRef = modelUtils.getSimpleRef(schema.get$ref());
|
||||||
if (usedImportMappings.containsKey(simpleRef)) {
|
if (usedImportMappings.containsKey(simpleRef)) {
|
||||||
LOGGER.debug("Schema unaliasing of {} omitted because aliased class is to be mapped to {}", simpleRef, usedImportMappings.get(simpleRef));
|
LOGGER.debug("Schema unaliasing of {} omitted because aliased class is to be mapped to {}", simpleRef, usedImportMappings.get(simpleRef));
|
||||||
return schema;
|
return schema;
|
||||||
@ -190,41 +190,41 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
} else if (ref.getEnum() != null && !ref.getEnum().isEmpty()) {
|
} else if (ref.getEnum() != null && !ref.getEnum().isEmpty()) {
|
||||||
// top-level enum class
|
// top-level enum class
|
||||||
return schema;
|
return schema;
|
||||||
} else if (ModelUtils.isArraySchema(ref)) {
|
} else if (modelUtils.isArraySchema(ref)) {
|
||||||
if (ModelUtils.isGenerateAliasAsModel(ref)) {
|
if (modelUtils.isGenerateAliasAsModel(ref)) {
|
||||||
return schema; // generate a model extending array
|
return schema; // generate a model extending array
|
||||||
} else {
|
} else {
|
||||||
return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())),
|
return unaliasSchema(allSchemas.get(modelUtils.getSimpleRef(schema.get$ref())),
|
||||||
usedImportMappings);
|
usedImportMappings);
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isComposedSchema(ref)) {
|
} else if (modelUtils.isComposedSchema(ref)) {
|
||||||
return schema;
|
return schema;
|
||||||
} else if (ModelUtils.isMapSchema(ref)) {
|
} else if (modelUtils.isMapSchema(ref)) {
|
||||||
if (ref.getProperties() != null && !ref.getProperties().isEmpty()) // has at least one property
|
if (ref.getProperties() != null && !ref.getProperties().isEmpty()) // has at least one property
|
||||||
return schema; // treat it as model
|
return schema; // treat it as model
|
||||||
else {
|
else {
|
||||||
if (ModelUtils.isGenerateAliasAsModel(ref)) {
|
if (modelUtils.isGenerateAliasAsModel(ref)) {
|
||||||
return schema; // generate a model extending map
|
return schema; // generate a model extending map
|
||||||
} else {
|
} else {
|
||||||
// treat it as a typical map
|
// treat it as a typical map
|
||||||
return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())),
|
return unaliasSchema(allSchemas.get(modelUtils.getSimpleRef(schema.get$ref())),
|
||||||
usedImportMappings);
|
usedImportMappings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isObjectSchema(ref)) { // model
|
} else if (modelUtils.isObjectSchema(ref)) { // model
|
||||||
if (ref.getProperties() != null && !ref.getProperties().isEmpty()) { // has at least one property
|
if (ref.getProperties() != null && !ref.getProperties().isEmpty()) { // has at least one property
|
||||||
return schema;
|
return schema;
|
||||||
} else {
|
} else {
|
||||||
// free form object (type: object)
|
// free form object (type: object)
|
||||||
if (ModelUtils.hasValidation(ref)) {
|
if (modelUtils.hasValidation(ref)) {
|
||||||
return schema;
|
return schema;
|
||||||
} else if (getAllOfDescendants(simpleRef, openAPI).size() > 0) {
|
} else if (getAllOfDescendants(simpleRef, openAPI).size() > 0) {
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())),
|
return unaliasSchema(allSchemas.get(modelUtils.getSimpleRef(schema.get$ref())),
|
||||||
usedImportMappings);
|
usedImportMappings);
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.hasValidation(ref)) {
|
} else if (modelUtils.hasValidation(ref)) {
|
||||||
// non object non array non map schemas that have validations
|
// non object non array non map schemas that have validations
|
||||||
// are returned so we can generate those schemas as models
|
// are returned so we can generate those schemas as models
|
||||||
// we do this to:
|
// we do this to:
|
||||||
@ -232,7 +232,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
// - use those validations when we use this schema in composed oneOf schemas
|
// - use those validations when we use this schema in composed oneOf schemas
|
||||||
return schema;
|
return schema;
|
||||||
} else {
|
} else {
|
||||||
return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), usedImportMappings);
|
return unaliasSchema(allSchemas.get(modelUtils.getSimpleRef(schema.get$ref())), usedImportMappings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
@ -297,13 +297,13 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String defaultValue = defaultObject.toString();
|
String defaultValue = defaultObject.toString();
|
||||||
if (ModelUtils.isDateSchema(p)) {
|
if (modelUtils.isDateSchema(p)) {
|
||||||
defaultValue = pythonDate(defaultObject);
|
defaultValue = pythonDate(defaultObject);
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
defaultValue = pythonDateTime(defaultObject);
|
defaultValue = pythonDateTime(defaultObject);
|
||||||
} else if (ModelUtils.isStringSchema(p) && !ModelUtils.isByteArraySchema(p) && !ModelUtils.isBinarySchema(p) && !ModelUtils.isFileSchema(p) && !ModelUtils.isUUIDSchema(p) && !ModelUtils.isEmailSchema(p)) {
|
} else if (modelUtils.isStringSchema(p) && !modelUtils.isByteArraySchema(p) && !modelUtils.isBinarySchema(p) && !modelUtils.isFileSchema(p) && !modelUtils.isUUIDSchema(p) && !modelUtils.isEmailSchema(p)) {
|
||||||
defaultValue = ensureQuotes(defaultValue);
|
defaultValue = ensureQuotes(defaultValue);
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
} else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (Boolean.valueOf(defaultValue) == false) {
|
if (Boolean.valueOf(defaultValue) == false) {
|
||||||
defaultValue = "False";
|
defaultValue = "False";
|
||||||
} else {
|
} else {
|
||||||
@ -359,7 +359,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
super.postProcessAllModels(objs);
|
super.postProcessAllModels(objs);
|
||||||
|
|
||||||
List<String> modelsToRemove = new ArrayList<>();
|
List<String> modelsToRemove = new ArrayList<>();
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
for (String schemaName: allDefinitions.keySet()) {
|
for (String schemaName: allDefinitions.keySet()) {
|
||||||
Schema refSchema = new Schema().$ref("#/components/schemas/"+schemaName);
|
Schema refSchema = new Schema().$ref("#/components/schemas/"+schemaName);
|
||||||
Schema unaliasedSchema = unaliasSchema(refSchema, importMapping);
|
Schema unaliasedSchema = unaliasSchema(refSchema, importMapping);
|
||||||
@ -467,7 +467,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
|
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
|
||||||
CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName);
|
CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName);
|
||||||
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
|
Schema schema = modelUtils.getSchemaFromRequestBody(body);
|
||||||
if (schema.get$ref() == null) {
|
if (schema.get$ref() == null) {
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
@ -586,7 +586,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
oneOfanyOfSchemas.addAll(anyOf);
|
oneOfanyOfSchemas.addAll(anyOf);
|
||||||
}
|
}
|
||||||
for (Schema sc: oneOfanyOfSchemas) {
|
for (Schema sc: oneOfanyOfSchemas) {
|
||||||
Schema refSchema = ModelUtils.getReferencedSchema(this.openAPI, sc);
|
Schema refSchema = modelUtils.getReferencedSchema(sc);
|
||||||
addProperties(otherProperties, otherRequired, refSchema);
|
addProperties(otherProperties, otherRequired, refSchema);
|
||||||
}
|
}
|
||||||
Set<String> otherRequiredSet = new HashSet<String>(otherRequired);
|
Set<String> otherRequiredSet = new HashSet<String>(otherRequired);
|
||||||
@ -651,7 +651,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
postProcessModelProperty(cm, cp);
|
postProcessModelProperty(cm, cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Boolean isNotPythonModelSimpleModel = (ModelUtils.isComposedSchema(sc) || ModelUtils.isObjectSchema(sc) || ModelUtils.isMapSchema(sc));
|
Boolean isNotPythonModelSimpleModel = (modelUtils.isComposedSchema(sc) || modelUtils.isObjectSchema(sc) || modelUtils.isMapSchema(sc));
|
||||||
if (isNotPythonModelSimpleModel) {
|
if (isNotPythonModelSimpleModel) {
|
||||||
return cm;
|
return cm;
|
||||||
}
|
}
|
||||||
@ -703,7 +703,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
if (sc.get$ref() != null) {
|
if (sc.get$ref() != null) {
|
||||||
Schema unaliasedSchema = unaliasSchema(sc, importMapping);
|
Schema unaliasedSchema = unaliasSchema(sc, importMapping);
|
||||||
if (unaliasedSchema.get$ref() != null) {
|
if (unaliasedSchema.get$ref() != null) {
|
||||||
return toModelName(ModelUtils.getSimpleRef(sc.get$ref()));
|
return toModelName(modelUtils.getSimpleRef(sc.get$ref()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -740,27 +740,27 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
// a composed schema, convert the name to a Python class.
|
// a composed schema, convert the name to a Python class.
|
||||||
Schema unaliasedSchema = unaliasSchema(p, importMapping);
|
Schema unaliasedSchema = unaliasSchema(p, importMapping);
|
||||||
if (unaliasedSchema.get$ref() != null) {
|
if (unaliasedSchema.get$ref() != null) {
|
||||||
String modelName = toModelName(ModelUtils.getSimpleRef(p.get$ref()));
|
String modelName = toModelName(modelUtils.getSimpleRef(p.get$ref()));
|
||||||
if (referencedModelNames != null) {
|
if (referencedModelNames != null) {
|
||||||
referencedModelNames.add(modelName);
|
referencedModelNames.add(modelName);
|
||||||
}
|
}
|
||||||
return prefix + modelName + fullSuffix;
|
return prefix + modelName + fullSuffix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isAnyTypeSchema(openAPI, p)) {
|
if (modelUtils.isAnyTypeSchema(p)) {
|
||||||
return prefix + "bool, date, datetime, dict, float, int, list, str, none_type" + suffix;
|
return prefix + "bool, date, datetime, dict, float, int, list, str, none_type" + suffix;
|
||||||
}
|
}
|
||||||
// Resolve $ref because ModelUtils.isXYZ methods do not automatically resolve references.
|
// Resolve $ref because modelUtils.isXYZ methods do not automatically resolve references.
|
||||||
if (ModelUtils.isNullable(ModelUtils.getReferencedSchema(this.openAPI, p))) {
|
if (modelUtils.isNullable(modelUtils.getReferencedSchema(p))) {
|
||||||
fullSuffix = ", none_type" + suffix;
|
fullSuffix = ", none_type" + suffix;
|
||||||
}
|
}
|
||||||
if (ModelUtils.isFreeFormObject(openAPI, p) && getAdditionalProperties(p) == null) {
|
if (modelUtils.isFreeFormObject(p) && getAdditionalProperties(p) == null) {
|
||||||
return prefix + "bool, date, datetime, dict, float, int, list, str" + fullSuffix;
|
return prefix + "bool, date, datetime, dict, float, int, list, str" + fullSuffix;
|
||||||
}
|
}
|
||||||
if ((ModelUtils.isMapSchema(p) || "object".equals(p.getType())) && getAdditionalProperties(p) != null) {
|
if ((modelUtils.isMapSchema(p) || "object".equals(p.getType())) && getAdditionalProperties(p) != null) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return prefix + "{str: " + getTypeString(inner, "(", ")", referencedModelNames) + "}" + fullSuffix;
|
return prefix + "{str: " + getTypeString(inner, "(", ")", referencedModelNames) + "}" + fullSuffix;
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -777,7 +777,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
return prefix + getTypeString(inner, "[", "]", referencedModelNames) + fullSuffix;
|
return prefix + getTypeString(inner, "[", "]", referencedModelNames) + fullSuffix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isFileSchema(p)) {
|
if (modelUtils.isFileSchema(p)) {
|
||||||
return prefix + "file_type" + fullSuffix;
|
return prefix + "file_type" + fullSuffix;
|
||||||
}
|
}
|
||||||
String baseType = getSchemaType(p);
|
String baseType = getSchemaType(p);
|
||||||
@ -801,7 +801,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema property) {
|
public String toInstantiationType(Schema property) {
|
||||||
if (ModelUtils.isArraySchema(property) || ModelUtils.isMapSchema(property) || property.getAdditionalProperties() != null) {
|
if (modelUtils.isArraySchema(property) || modelUtils.isMapSchema(property) || property.getAdditionalProperties() != null) {
|
||||||
return getSchemaType(property);
|
return getSchemaType(property);
|
||||||
}
|
}
|
||||||
return super.toInstantiationType(property);
|
return super.toInstantiationType(property);
|
||||||
@ -837,10 +837,10 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
Schema schema = sc;
|
Schema schema = sc;
|
||||||
String ref = sc.get$ref();
|
String ref = sc.get$ref();
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
schema = ModelUtils.getSchema(this.openAPI, ModelUtils.getSimpleRef(ref));
|
schema = modelUtils.getSchema(modelUtils.getSimpleRef(ref));
|
||||||
}
|
}
|
||||||
// TODO handle examples in object models in the future
|
// TODO handle examples in object models in the future
|
||||||
Boolean objectModel = (ModelUtils.isObjectSchema(schema) || ModelUtils.isMapSchema(schema) || ModelUtils.isComposedSchema(schema));
|
Boolean objectModel = (modelUtils.isObjectSchema(schema) || modelUtils.isMapSchema(schema) || modelUtils.isComposedSchema(schema));
|
||||||
if (objectModel) {
|
if (objectModel) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -883,9 +883,9 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
Schema sc = schema;
|
Schema sc = schema;
|
||||||
String ref = schema.get$ref();
|
String ref = schema.get$ref();
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
sc = ModelUtils.getSchema(this.openAPI, ModelUtils.getSimpleRef(ref));
|
sc = modelUtils.getSchema(modelUtils.getSimpleRef(ref));
|
||||||
}
|
}
|
||||||
if (ModelUtils.isStringSchema(sc) && !ModelUtils.isDateSchema(sc) && !ModelUtils.isDateTimeSchema(sc) && !"Number".equalsIgnoreCase(sc.getFormat()) && !ModelUtils.isByteArraySchema(sc) && !ModelUtils.isBinarySchema(sc) && schema.getPattern() == null) {
|
if (modelUtils.isStringSchema(sc) && !modelUtils.isDateSchema(sc) && !modelUtils.isDateTimeSchema(sc) && !"Number".equalsIgnoreCase(sc.getFormat()) && !modelUtils.isByteArraySchema(sc) && !modelUtils.isBinarySchema(sc) && schema.getPattern() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -895,7 +895,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
for ( MappedModel mm : disc.getMappedModels() ) {
|
for ( MappedModel mm : disc.getMappedModels() ) {
|
||||||
String modelName = mm.getModelName();
|
String modelName = mm.getModelName();
|
||||||
Schema modelSchema = getModelNameToSchemaCache().get(modelName);
|
Schema modelSchema = getModelNameToSchemaCache().get(modelName);
|
||||||
if (ModelUtils.isObjectSchema(modelSchema)) {
|
if (modelUtils.isObjectSchema(modelSchema)) {
|
||||||
return mm;
|
return mm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -949,8 +949,8 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
example = objExample.toString();
|
example = objExample.toString();
|
||||||
}
|
}
|
||||||
if (null != schema.get$ref()) {
|
if (null != schema.get$ref()) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
String ref = ModelUtils.getSimpleRef(schema.get$ref());
|
String ref = modelUtils.getSimpleRef(schema.get$ref());
|
||||||
Schema refSchema = allDefinitions.get(ref);
|
Schema refSchema = allDefinitions.get(ref);
|
||||||
if (null == refSchema) {
|
if (null == refSchema) {
|
||||||
LOGGER.warn("Unable to find referenced schema "+schema.get$ref()+"\n");
|
LOGGER.warn("Unable to find referenced schema "+schema.get$ref()+"\n");
|
||||||
@ -958,11 +958,11 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
String refModelName = getModelName(schema);
|
String refModelName = getModelName(schema);
|
||||||
return toExampleValueRecursive(refModelName, refSchema, objExample, indentationLevel, prefix, exampleLine);
|
return toExampleValueRecursive(refModelName, refSchema, objExample, indentationLevel, prefix, exampleLine);
|
||||||
} else if (ModelUtils.isNullType(schema) || ModelUtils.isAnyTypeSchema(openAPI, schema)) {
|
} else if (modelUtils.isNullType(schema) || modelUtils.isAnyTypeSchema(schema)) {
|
||||||
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
||||||
// though this tooling supports it.
|
// though this tooling supports it.
|
||||||
return fullPrefix + "None" + closeChars;
|
return fullPrefix + "None" + closeChars;
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
example = "True";
|
example = "True";
|
||||||
} else {
|
} else {
|
||||||
@ -973,32 +973,32 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isDateSchema(schema)) {
|
} else if (modelUtils.isDateSchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
example = pythonDate("1970-01-01");
|
example = pythonDate("1970-01-01");
|
||||||
} else {
|
} else {
|
||||||
example = pythonDate(objExample);
|
example = pythonDate(objExample);
|
||||||
}
|
}
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
example = pythonDateTime("1970-01-01T00:00:00.00Z");
|
example = pythonDateTime("1970-01-01T00:00:00.00Z");
|
||||||
} else {
|
} else {
|
||||||
example = pythonDateTime(objExample);
|
example = pythonDateTime(objExample);
|
||||||
}
|
}
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isBinarySchema(schema)) {
|
} else if (modelUtils.isBinarySchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
example = "/path/to/file";
|
example = "/path/to/file";
|
||||||
}
|
}
|
||||||
example = "open('" + example + "', 'rb')";
|
example = "open('" + example + "', 'rb')";
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isByteArraySchema(schema)) {
|
} else if (modelUtils.isByteArraySchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
example = "'YQ=='";
|
example = "'YQ=='";
|
||||||
}
|
}
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
// a BigDecimal:
|
// a BigDecimal:
|
||||||
if ("Number".equalsIgnoreCase(schema.getFormat())) {
|
if ("Number".equalsIgnoreCase(schema.getFormat())) {
|
||||||
@ -1022,14 +1022,14 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
example = "";
|
example = "";
|
||||||
int len = schema.getMinLength().intValue();
|
int len = schema.getMinLength().intValue();
|
||||||
for (int i=0;i<len;i++) example += "a";
|
for (int i=0;i<len;i++) example += "a";
|
||||||
} else if (ModelUtils.isUUIDSchema(schema)) {
|
} else if (modelUtils.isUUIDSchema(schema)) {
|
||||||
example = "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
example = "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||||
} else {
|
} else {
|
||||||
example = "string_example";
|
example = "string_example";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fullPrefix + ensureQuotes(example) + closeChars;
|
return fullPrefix + ensureQuotes(example) + closeChars;
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
if (schema.getMinimum() != null) {
|
if (schema.getMinimum() != null) {
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
@ -1038,7 +1038,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (objExample == null) {
|
if (objExample == null) {
|
||||||
if (schema.getMinimum() != null) {
|
if (schema.getMinimum() != null) {
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
@ -1047,7 +1047,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fullPrefix + example + closeChars;
|
return fullPrefix + example + closeChars;
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
if (objExample instanceof Iterable) {
|
if (objExample instanceof Iterable) {
|
||||||
// If the example is already a list, return it directly instead of wrongly wrap it in another list
|
// If the example is already a list, return it directly instead of wrongly wrap it in another list
|
||||||
return fullPrefix + objExample.toString();
|
return fullPrefix + objExample.toString();
|
||||||
@ -1057,7 +1057,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
String itemModelName = getModelName(itemSchema);
|
String itemModelName = getModelName(itemSchema);
|
||||||
example = fullPrefix + "[" + "\n" + toExampleValueRecursive(itemModelName, itemSchema, objExample, indentationLevel+1, "", exampleLine+1) + ",\n" + closingIndentation + "]" + closeChars;
|
example = fullPrefix + "[" + "\n" + toExampleValueRecursive(itemModelName, itemSchema, objExample, indentationLevel+1, "", exampleLine+1) + ",\n" + closingIndentation + "]" + closeChars;
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
if (modelName == null) {
|
if (modelName == null) {
|
||||||
fullPrefix += "{";
|
fullPrefix += "{";
|
||||||
closeChars = "}";
|
closeChars = "}";
|
||||||
@ -1082,7 +1082,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
example = fullPrefix + closeChars;
|
example = fullPrefix + closeChars;
|
||||||
}
|
}
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
} else if (modelUtils.isObjectSchema(schema)) {
|
||||||
if (modelName == null) {
|
if (modelName == null) {
|
||||||
fullPrefix += "{";
|
fullPrefix += "{";
|
||||||
closeChars = "}";
|
closeChars = "}";
|
||||||
@ -1101,7 +1101,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exampleForObjectModel(schema, fullPrefix, closeChars, null, indentationLevel, exampleLine, closingIndentation);
|
return exampleForObjectModel(schema, fullPrefix, closeChars, null, indentationLevel, exampleLine, closingIndentation);
|
||||||
} else if (ModelUtils.isComposedSchema(schema)) {
|
} else if (modelUtils.isComposedSchema(schema)) {
|
||||||
// TODO add examples for composed schema models without discriminators
|
// TODO add examples for composed schema models without discriminators
|
||||||
|
|
||||||
CodegenDiscriminator disc = createDiscriminator(modelName, schema, openAPI);
|
CodegenDiscriminator disc = createDiscriminator(modelName, schema, openAPI);
|
||||||
@ -1161,14 +1161,14 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
Schema schema = sc;
|
Schema schema = sc;
|
||||||
String ref = sc.get$ref();
|
String ref = sc.get$ref();
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
schema = ModelUtils.getSchema(this.openAPI, ModelUtils.getSimpleRef(ref));
|
schema = modelUtils.getSchema(modelUtils.getSimpleRef(ref));
|
||||||
}
|
}
|
||||||
Object example = getObjectExample(schema);
|
Object example = getObjectExample(schema);
|
||||||
if (example != null) {
|
if (example != null) {
|
||||||
return example;
|
return example;
|
||||||
} else if (simpleStringSchema(schema)) {
|
} else if (simpleStringSchema(schema)) {
|
||||||
return propName + "_example";
|
return propName + "_example";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
ArraySchema arraySchema = (ArraySchema) schema;
|
ArraySchema arraySchema = (ArraySchema) schema;
|
||||||
Schema itemSchema = arraySchema.getItems();
|
Schema itemSchema = arraySchema.getItems();
|
||||||
example = getObjectExample(itemSchema);
|
example = getObjectExample(itemSchema);
|
||||||
@ -1228,7 +1228,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
Content content = requestBody.getContent();
|
Content content = requestBody.getContent();
|
||||||
|
|
||||||
if (content.size() > 1) {
|
if (content.size() > 1) {
|
||||||
// @see ModelUtils.getSchemaFromContent()
|
// @see modelUtils.getSchemaFromContent()
|
||||||
once(LOGGER).warn("Multiple MediaTypes found, using only the first one");
|
once(LOGGER).warn("Multiple MediaTypes found, using only the first one");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1283,7 +1283,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
|
|||||||
if (modelNameToSchemaCache == null) {
|
if (modelNameToSchemaCache == null) {
|
||||||
// Create a cache to efficiently lookup schema based on model name.
|
// Create a cache to efficiently lookup schema based on model name.
|
||||||
Map<String, Schema> m = new HashMap<String, Schema>();
|
Map<String, Schema> m = new HashMap<String, Schema>();
|
||||||
ModelUtils.getSchemas(openAPI).forEach((key, schema) -> {
|
modelUtils.getSchemas().forEach((key, schema) -> {
|
||||||
m.put(toModelName(key), schema);
|
m.put(toModelName(key), schema);
|
||||||
});
|
});
|
||||||
modelNameToSchemaCache = Collections.unmodifiableMap(m);
|
modelNameToSchemaCache = Collections.unmodifiableMap(m);
|
||||||
|
@ -469,11 +469,11 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "(str, " + getTypeDeclaration(inner) + ")";
|
return getSchemaType(p) + "(str, " + getTypeDeclaration(inner) + ")";
|
||||||
@ -673,33 +673,33 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (Boolean.valueOf(p.getDefault().toString()) == false)
|
if (Boolean.valueOf(p.getDefault().toString()) == false)
|
||||||
return "False";
|
return "False";
|
||||||
else
|
else
|
||||||
return "True";
|
return "True";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||||
return "'''" + p.getDefault() + "'''";
|
return "'''" + p.getDefault() + "'''";
|
||||||
else
|
else
|
||||||
return "'" + ((String) p.getDefault()).replaceAll("'", "\'") + "'";
|
return "'" + ((String) p.getDefault()).replaceAll("'", "\'") + "'";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
@ -726,24 +726,24 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
example = schema.getExample().toString();
|
example = schema.getExample().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isNullType(schema) && null != example) {
|
if (modelUtils.isNullType(schema) && null != example) {
|
||||||
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
|
||||||
// though this tooling supports it.
|
// though this tooling supports it.
|
||||||
return "None";
|
return "None";
|
||||||
}
|
}
|
||||||
// correct "true"s into "True"s, since super.toExampleValue uses "toString()" on Java booleans
|
// correct "true"s into "True"s, since super.toExampleValue uses "toString()" on Java booleans
|
||||||
if (ModelUtils.isBooleanSchema(schema) && null!=example) {
|
if (modelUtils.isBooleanSchema(schema) && null!=example) {
|
||||||
if ("false".equalsIgnoreCase(example)) example = "False";
|
if ("false".equalsIgnoreCase(example)) example = "False";
|
||||||
else example = "True";
|
else example = "True";
|
||||||
}
|
}
|
||||||
|
|
||||||
// correct "'"s into "'"s after toString()
|
// correct "'"s into "'"s after toString()
|
||||||
if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null && !ModelUtils.isDateSchema(schema) && !ModelUtils.isDateTimeSchema(schema)) {
|
if (modelUtils.isStringSchema(schema) && schema.getDefault() != null && !modelUtils.isDateSchema(schema) && !modelUtils.isDateTimeSchema(schema)) {
|
||||||
example = (String) schema.getDefault();
|
example = (String) schema.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "'" + example + "'";
|
example = "'" + example + "'";
|
||||||
}
|
}
|
||||||
return example;
|
return example;
|
||||||
@ -752,7 +752,7 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
|
||||||
// Enum case:
|
// Enum case:
|
||||||
example = schema.getEnum().get(0).toString();
|
example = schema.getEnum().get(0).toString();
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "'" + escapeText(example) + "'";
|
example = "'" + escapeText(example) + "'";
|
||||||
}
|
}
|
||||||
if (null == example)
|
if (null == example)
|
||||||
@ -761,8 +761,8 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
return example;
|
return example;
|
||||||
} else if (null != schema.get$ref()) {
|
} else if (null != schema.get$ref()) {
|
||||||
// $ref case:
|
// $ref case:
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
String ref = ModelUtils.getSimpleRef(schema.get$ref());
|
String ref = modelUtils.getSimpleRef(schema.get$ref());
|
||||||
if (allDefinitions != null) {
|
if (allDefinitions != null) {
|
||||||
Schema refSchema = allDefinitions.get(ref);
|
Schema refSchema = allDefinitions.get(ref);
|
||||||
if (null == refSchema) {
|
if (null == refSchema) {
|
||||||
@ -781,18 +781,18 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
LOGGER.warn("allDefinitions not defined in toExampleValue!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isDateSchema(schema)) {
|
if (modelUtils.isDateSchema(schema)) {
|
||||||
example = "datetime.datetime.strptime('1975-12-30', '%Y-%m-%d').date()";
|
example = "datetime.datetime.strptime('1975-12-30', '%Y-%m-%d').date()";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (modelUtils.isDateTimeSchema(schema)) {
|
||||||
example = "datetime.datetime.strptime('2013-10-20 19:20:30.00', '%Y-%m-%d %H:%M:%S.%f')";
|
example = "datetime.datetime.strptime('2013-10-20 19:20:30.00', '%Y-%m-%d %H:%M:%S.%f')";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isBinarySchema(schema)) {
|
} else if (modelUtils.isBinarySchema(schema)) {
|
||||||
example = "bytes(b'blah')";
|
example = "bytes(b'blah')";
|
||||||
return example;
|
return example;
|
||||||
} else if (ModelUtils.isByteArraySchema(schema)) {
|
} else if (modelUtils.isByteArraySchema(schema)) {
|
||||||
example = "YQ==";
|
example = "YQ==";
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (modelUtils.isStringSchema(schema)) {
|
||||||
// a BigDecimal:
|
// a BigDecimal:
|
||||||
if ("Number".equalsIgnoreCase(schema.getFormat())) {return "1";}
|
if ("Number".equalsIgnoreCase(schema.getFormat())) {return "1";}
|
||||||
if (StringUtils.isNotBlank(schema.getPattern())) {
|
if (StringUtils.isNotBlank(schema.getPattern())) {
|
||||||
@ -822,25 +822,25 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
for (int i=0;i<len;i++) example += i;
|
for (int i=0;i<len;i++) example += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (modelUtils.isIntegerSchema(schema)) {
|
||||||
if (schema.getMinimum() != null)
|
if (schema.getMinimum() != null)
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
else
|
else
|
||||||
example = "56";
|
example = "56";
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (modelUtils.isNumberSchema(schema)) {
|
||||||
if (schema.getMinimum() != null)
|
if (schema.getMinimum() != null)
|
||||||
example = schema.getMinimum().toString();
|
example = schema.getMinimum().toString();
|
||||||
else
|
else
|
||||||
example = "1.337";
|
example = "1.337";
|
||||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
} else if (modelUtils.isBooleanSchema(schema)) {
|
||||||
example = "True";
|
example = "True";
|
||||||
} else if (ModelUtils.isArraySchema(schema)) {
|
} else if (modelUtils.isArraySchema(schema)) {
|
||||||
if (StringUtils.isNotBlank(schema.getTitle()) && !"null".equals(schema.getTitle())) {
|
if (StringUtils.isNotBlank(schema.getTitle()) && !"null".equals(schema.getTitle())) {
|
||||||
included_schemas.add(schema.getTitle());
|
included_schemas.add(schema.getTitle());
|
||||||
}
|
}
|
||||||
ArraySchema arrayschema = (ArraySchema) schema;
|
ArraySchema arrayschema = (ArraySchema) schema;
|
||||||
example = "[\n" + indentation_string + toExampleValueRecursive(arrayschema.getItems(), included_schemas, indentation+1) + "\n" + indentation_string + "]";
|
example = "[\n" + indentation_string + toExampleValueRecursive(arrayschema.getItems(), included_schemas, indentation+1) + "\n" + indentation_string + "]";
|
||||||
} else if (ModelUtils.isMapSchema(schema)) {
|
} else if (modelUtils.isMapSchema(schema)) {
|
||||||
if (StringUtils.isNotBlank(schema.getTitle()) && !"null".equals(schema.getTitle())) {
|
if (StringUtils.isNotBlank(schema.getTitle()) && !"null".equals(schema.getTitle())) {
|
||||||
included_schemas.add(schema.getTitle());
|
included_schemas.add(schema.getTitle());
|
||||||
}
|
}
|
||||||
@ -850,7 +850,7 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
String the_key = "'key'";
|
String the_key = "'key'";
|
||||||
if (additional.getEnum() != null && !additional.getEnum().isEmpty()) {
|
if (additional.getEnum() != null && !additional.getEnum().isEmpty()) {
|
||||||
the_key = additional.getEnum().get(0).toString();
|
the_key = additional.getEnum().get(0).toString();
|
||||||
if (ModelUtils.isStringSchema(additional)) {
|
if (modelUtils.isStringSchema(additional)) {
|
||||||
the_key = "'" + escapeText(the_key) + "'";
|
the_key = "'" + escapeText(the_key) + "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -858,7 +858,7 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
} else {
|
} else {
|
||||||
example = "{ }";
|
example = "{ }";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isObjectSchema(schema)) {
|
} else if (modelUtils.isObjectSchema(schema)) {
|
||||||
if (StringUtils.isBlank(schema.getTitle())) {
|
if (StringUtils.isBlank(schema.getTitle())) {
|
||||||
example = "None";
|
example = "None";
|
||||||
return example;
|
return example;
|
||||||
@ -916,7 +916,7 @@ public class PythonLegacyClientCodegen extends DefaultCodegen implements Codegen
|
|||||||
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isStringSchema(schema)) {
|
if (modelUtils.isStringSchema(schema)) {
|
||||||
example = "'" + escapeText(example) + "'";
|
example = "'" + escapeText(example) + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,11 +355,11 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner)+ "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner)+ "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "(" + getTypeDeclaration(inner) + ")";
|
return getSchemaType(p) + "(" + getTypeDeclaration(inner) + ")";
|
||||||
}
|
}
|
||||||
@ -629,33 +629,33 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (Boolean.valueOf(p.getDefault().toString()) == false)
|
if (Boolean.valueOf(p.getDefault().toString()) == false)
|
||||||
return "FALSE";
|
return "FALSE";
|
||||||
else
|
else
|
||||||
return "TRUE";
|
return "TRUE";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||||
return "'''" + p.getDefault() + "'''";
|
return "'''" + p.getDefault() + "'''";
|
||||||
else
|
else
|
||||||
return "'" + ((String) p.getDefault()).replaceAll("'","\'") + "'";
|
return "'" + ((String) p.getDefault()).replaceAll("'","\'") + "'";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
@ -448,7 +448,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
inner = new StringSchema().description("TODO default missing array inner type to string");
|
inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||||
}
|
}
|
||||||
return "Vec<" + getTypeDeclaration(inner) + ">";
|
return "Vec<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
if (inner == null) {
|
if (inner == null) {
|
||||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
||||||
|
@ -266,7 +266,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
" (--enable-post-process-file for CLI).");
|
" (--enable-post-process-file for CLI).");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Boolean.TRUE.equals(ModelUtils.isGenerateAliasAsModel())) {
|
if (!Boolean.TRUE.equals(modelUtils.isGenerateAliasAsModel())) {
|
||||||
LOGGER.warn("generateAliasAsModel is set to false, which means array/map will be generated as model instead and the resulting code may have issues. Please enable `generateAliasAsModel` to address the issue.");
|
LOGGER.warn("generateAliasAsModel is set to false, which means array/map will be generated as model instead and the resulting code may have issues. Please enable `generateAliasAsModel` to address the issue.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||||
Map<String, Schema> definitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> definitions = modelUtils.getSchemas();
|
||||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||||
|
|
||||||
String pathFormatString = op.path;
|
String pathFormatString = op.path;
|
||||||
@ -762,7 +762,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// Determine the types that this operation produces. `getProducesInfo`
|
// Determine the types that this operation produces. `getProducesInfo`
|
||||||
// simply lists all the types, and then we add the correct imports to
|
// simply lists all the types, and then we add the correct imports to
|
||||||
// the generated library.
|
// the generated library.
|
||||||
List<String> produces = new ArrayList<String>(getProducesInfo(openAPI, operation));
|
List<String> produces = new ArrayList<String>(getProducesInfo(operation));
|
||||||
boolean producesXml = false;
|
boolean producesXml = false;
|
||||||
boolean producesPlainText = false;
|
boolean producesPlainText = false;
|
||||||
if (produces != null && !produces.isEmpty()) {
|
if (produces != null && !produces.isEmpty()) {
|
||||||
@ -925,7 +925,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
Schema response = (Schema) rsp.schema;
|
Schema response = (Schema) rsp.schema;
|
||||||
// Check whether we're returning an object with a defined XML namespace.
|
// Check whether we're returning an object with a defined XML namespace.
|
||||||
if (response != null && (!StringUtils.isEmpty(response.get$ref()))) {
|
if (response != null && (!StringUtils.isEmpty(response.get$ref()))) {
|
||||||
Schema model = definitions.get(ModelUtils.getSimpleRef(response.get$ref()));
|
Schema model = definitions.get(modelUtils.getSimpleRef(response.get$ref()));
|
||||||
if ((model != null)) {
|
if ((model != null)) {
|
||||||
XML xml = model.getXml();
|
XML xml = model.getXml();
|
||||||
if ((xml != null) && (xml.getNamespace() != null)) {
|
if ((xml != null) && (xml.getNamespace() != null)) {
|
||||||
@ -1114,7 +1114,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// restore things to sensible values.
|
// restore things to sensible values.
|
||||||
@Override
|
@Override
|
||||||
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
|
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
|
||||||
Schema original_schema = ModelUtils.getSchemaFromRequestBody(body);
|
Schema original_schema = modelUtils.getSchemaFromRequestBody(body);
|
||||||
CodegenParameter codegenParameter = super.fromRequestBody(body, imports, bodyParameterName);
|
CodegenParameter codegenParameter = super.fromRequestBody(body, imports, bodyParameterName);
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(original_schema.get$ref())) {
|
if (StringUtils.isNotBlank(original_schema.get$ref())) {
|
||||||
@ -1124,7 +1124,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
codegenParameter.isPrimitiveType = false;
|
codegenParameter.isPrimitiveType = false;
|
||||||
codegenParameter.isArray = false;
|
codegenParameter.isArray = false;
|
||||||
codegenParameter.isString = false;
|
codegenParameter.isString = false;
|
||||||
codegenParameter.isByteArray = ModelUtils.isByteArraySchema(original_schema);
|
codegenParameter.isByteArray = modelUtils.isByteArraySchema(original_schema);
|
||||||
|
|
||||||
|
|
||||||
// This is a model, so should only have an example if explicitly
|
// This is a model, so should only have an example if explicitly
|
||||||
@ -1142,12 +1142,12 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
String innerType = getTypeDeclaration(inner);
|
String innerType = getTypeDeclaration(inner);
|
||||||
return typeMapping.get("array") + "<" + innerType + ">";
|
return typeMapping.get("array") + "<" + innerType + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
String innerType = getTypeDeclaration(inner);
|
String innerType = getTypeDeclaration(inner);
|
||||||
StringBuilder typeDeclaration = new StringBuilder(typeMapping.get("map")).append("<").append(typeMapping.get("string")).append(", ");
|
StringBuilder typeDeclaration = new StringBuilder(typeMapping.get("map")).append("<").append(typeMapping.get("string")).append(", ");
|
||||||
@ -1177,11 +1177,11 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return instantiationTypes.get("array") + "<" + getSchemaType(inner) + ">";
|
return instantiationTypes.get("array") + "<" + getSchemaType(inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return instantiationTypes.get("map") + "<" + typeMapping.get("string") + ", " + getSchemaType(inner) + ">";
|
return instantiationTypes.get("map") + "<" + typeMapping.get("string") + ", " + getSchemaType(inner) + ">";
|
||||||
} else {
|
} else {
|
||||||
@ -1191,14 +1191,14 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel mdl = super.fromModel(name, model);
|
CodegenModel mdl = super.fromModel(name, model);
|
||||||
mdl.vendorExtensions.put("x-upper-case-name", name.toUpperCase(Locale.ROOT));
|
mdl.vendorExtensions.put("x-upper-case-name", name.toUpperCase(Locale.ROOT));
|
||||||
if (!StringUtils.isEmpty(model.get$ref())) {
|
if (!StringUtils.isEmpty(model.get$ref())) {
|
||||||
Schema schema = allDefinitions.get(ModelUtils.getSimpleRef(model.get$ref()));
|
Schema schema = allDefinitions.get(modelUtils.getSimpleRef(model.get$ref()));
|
||||||
mdl.dataType = typeMapping.get(schema.getType());
|
mdl.dataType = typeMapping.get(schema.getType());
|
||||||
}
|
}
|
||||||
if (ModelUtils.isArraySchema(model)) {
|
if (modelUtils.isArraySchema(model)) {
|
||||||
ArraySchema am = (ArraySchema) model;
|
ArraySchema am = (ArraySchema) model;
|
||||||
String xmlName = null;
|
String xmlName = null;
|
||||||
|
|
||||||
@ -1213,7 +1213,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
am.getItems() != null &&
|
am.getItems() != null &&
|
||||||
!StringUtils.isEmpty(am.getItems().get$ref())) {
|
!StringUtils.isEmpty(am.getItems().get$ref())) {
|
||||||
Schema inner_schema = allDefinitions.get(
|
Schema inner_schema = allDefinitions.get(
|
||||||
ModelUtils.getSimpleRef(am.getItems().get$ref()));
|
modelUtils.getSimpleRef(am.getItems().get$ref()));
|
||||||
|
|
||||||
if (inner_schema.getXml() != null &&
|
if (inner_schema.getXml() != null &&
|
||||||
inner_schema.getXml().getName() != null) {
|
inner_schema.getXml().getName() != null) {
|
||||||
@ -1376,29 +1376,29 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
String defaultValue = null;
|
String defaultValue = null;
|
||||||
if ((ModelUtils.isNullable(p)) && (p.getDefault() != null) && (p.getDefault().toString().equalsIgnoreCase("null")))
|
if ((modelUtils.isNullable(p)) && (p.getDefault() != null) && (p.getDefault().toString().equalsIgnoreCase("null")))
|
||||||
return "swagger::Nullable::Null";
|
return "swagger::Nullable::Null";
|
||||||
else if (ModelUtils.isBooleanSchema(p)) {
|
else if (modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
if (p.getDefault().toString().equalsIgnoreCase("false"))
|
||||||
defaultValue = "false";
|
defaultValue = "false";
|
||||||
else
|
else
|
||||||
defaultValue = "true";
|
defaultValue = "true";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
defaultValue = p.getDefault().toString();
|
defaultValue = p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
defaultValue = p.getDefault().toString();
|
defaultValue = p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
defaultValue = "\"" + (String) p.getDefault() + "\".to_string()";
|
defaultValue = "\"" + (String) p.getDefault() + "\".to_string()";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((defaultValue != null) && (ModelUtils.isNullable(p)))
|
if ((defaultValue != null) && (modelUtils.isNullable(p)))
|
||||||
defaultValue = "swagger::Nullable::Present(" + defaultValue + ")";
|
defaultValue = "swagger::Nullable::Present(" + defaultValue + ")";
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
@ -271,27 +271,27 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
return "None";
|
return "None";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "Map[String, " + inner + "].empty ";
|
return "Map[String, " + inner + "].empty ";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
if (ModelUtils.isSet(ap)) {
|
if (modelUtils.isSet(ap)) {
|
||||||
return "Set[" + inner + "].empty ";
|
return "Set[" + inner + "].empty ";
|
||||||
}
|
}
|
||||||
return "Seq[" + inner + "].empty ";
|
return "Seq[" + inner + "].empty ";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -260,11 +260,11 @@ public class ScalaFinchServerCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
|
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
|
@ -382,11 +382,11 @@ public class ScalaGatlingCodegen extends AbstractScalaCodegen implements Codegen
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
@ -333,48 +333,48 @@ public class ScalaPlayFrameworkServerCodegen extends AbstractScalaCodegen implem
|
|||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isDateSchema(p)) {
|
if (modelUtils.isDateSchema(p)) {
|
||||||
return "LocalDate.now";
|
return "LocalDate.now";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isDateTimeSchema(p)) {
|
if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return "OffsetDateTime.now";
|
return "OffsetDateTime.now";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isDoubleSchema(p)) {
|
if (modelUtils.isDoubleSchema(p)) {
|
||||||
return "0.0";
|
return "0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isFloatSchema(p)) {
|
if (modelUtils.isFloatSchema(p)) {
|
||||||
return "0.0F";
|
return "0.0F";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isIntegerSchema(p)) {
|
if (modelUtils.isIntegerSchema(p)) {
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isLongSchema(p)) {
|
if (modelUtils.isLongSchema(p)) {
|
||||||
return "0L";
|
return "0L";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
Schema ap = getAdditionalProperties(p);
|
Schema ap = getAdditionalProperties(p);
|
||||||
String inner = getSchemaType(ap);
|
String inner = getSchemaType(ap);
|
||||||
return "Map.empty[String, " + inner + "]";
|
return "Map.empty[String, " + inner + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
Schema items = ((ArraySchema) p).getItems();
|
Schema items = ((ArraySchema) p).getItems();
|
||||||
String inner = getSchemaType(items);
|
String inner = getSchemaType(items);
|
||||||
if (ModelUtils.isSet(p)) {
|
if (modelUtils.isSet(p)) {
|
||||||
return "Set.empty[" + inner + "]";
|
return "Set.empty[" + inner + "]";
|
||||||
}
|
}
|
||||||
return "List.empty[" + inner + "]";
|
return "List.empty[" + inner + "]";
|
||||||
|
@ -275,27 +275,27 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
|
|||||||
return "None";
|
return "None";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
return "Map[String, " + inner + "].empty ";
|
return "Map[String, " + inner + "].empty ";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
if (ModelUtils.isSet(ap)) {
|
if (modelUtils.isSet(ap)) {
|
||||||
return "Set[" + inner + "].empty ";
|
return "Set[" + inner + "].empty ";
|
||||||
}
|
}
|
||||||
return "Seq[" + inner + "].empty ";
|
return "Seq[" + inner + "].empty ";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -172,29 +172,29 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// comment out the following as the default value is no handled differently
|
// comment out the following as the default value is no handled differently
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
String inner = getSchemaType(getAdditionalProperties(p));
|
String inner = getSchemaType(getAdditionalProperties(p));
|
||||||
|
|
||||||
return "Map.empty[String, " + inner + "] ";
|
return "Map.empty[String, " + inner + "] ";
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
String collectionType = ModelUtils.isSet(ap) ? typeMapping.get("set") : typeMapping.get("array");
|
String collectionType = modelUtils.isSet(ap) ? typeMapping.get("set") : typeMapping.get("array");
|
||||||
|
|
||||||
// We assume that users would map these collections to a monoid with an identity function
|
// We assume that users would map these collections to a monoid with an identity function
|
||||||
// There's no reason to assume mutable structure here (which may make consumption more difficult)
|
// There's no reason to assume mutable structure here (which may make consumption more difficult)
|
||||||
return collectionType + ".empty[" + inner + "] ";
|
return collectionType + ".empty[" + inner + "] ";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -130,11 +130,11 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
|
@ -112,11 +112,11 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig
|
|||||||
Info info = openAPI.getInfo();
|
Info info = openAPI.getInfo();
|
||||||
info.setDescription(toHtml(info.getDescription()));
|
info.setDescription(toHtml(info.getDescription()));
|
||||||
info.setTitle(toHtml(info.getTitle()));
|
info.setTitle(toHtml(info.getTitle()));
|
||||||
Map<String, Schema> models = ModelUtils.getSchemas(openAPI);
|
Map<String, Schema> models = modelUtils.getSchemas();
|
||||||
for (Schema model : models.values()) {
|
for (Schema model : models.values()) {
|
||||||
model.setDescription(toHtml(model.getDescription()));
|
model.setDescription(toHtml(model.getDescription()));
|
||||||
model.setTitle(toHtml(model.getTitle()));
|
model.setTitle(toHtml(model.getTitle()));
|
||||||
|
@ -505,11 +505,11 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@ -601,18 +601,18 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
|
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType());
|
return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType());
|
||||||
} else {
|
} else {
|
||||||
return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType());
|
return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||||
}
|
}
|
||||||
@ -622,9 +622,9 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
return getSchemaType(getAdditionalProperties(p));
|
return getSchemaType(getAdditionalProperties(p));
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return "[" + inner + "]";
|
return "[" + inner + "]";
|
||||||
@ -737,7 +737,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (codegenModel.description != null) {
|
if (codegenModel.description != null) {
|
||||||
codegenModel.imports.add("ApiModel");
|
codegenModel.imports.add("ApiModel");
|
||||||
|
@ -516,11 +516,11 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
Schema inner = ap.getItems();
|
Schema inner = ap.getItems();
|
||||||
return ModelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">" : "[" + getTypeDeclaration(inner) + "]";
|
return modelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">" : "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
Schema inner = getAdditionalProperties(p);
|
Schema inner = getAdditionalProperties(p);
|
||||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||||
}
|
}
|
||||||
@ -612,7 +612,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
|
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType());
|
return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType());
|
||||||
} else {
|
} else {
|
||||||
return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType());
|
return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType());
|
||||||
@ -620,15 +620,15 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isIntegerSchema(p) || ModelUtils.isNumberSchema(p) || ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isIntegerSchema(p) || modelUtils.isNumberSchema(p) || modelUtils.isBooleanSchema(p)) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
// Datetime time stamps in Swift are expressed as Seconds with Microsecond precision.
|
// Datetime time stamps in Swift are expressed as Seconds with Microsecond precision.
|
||||||
// In Java, we need to be creative to get the Timestamp in Microseconds as a long.
|
// In Java, we need to be creative to get the Timestamp in Microseconds as a long.
|
||||||
Instant instant = ((OffsetDateTime) p.getDefault()).toInstant();
|
Instant instant = ((OffsetDateTime) p.getDefault()).toInstant();
|
||||||
long epochMicro = TimeUnit.SECONDS.toMicros(instant.getEpochSecond()) + ((long) instant.get(ChronoField.MICRO_OF_SECOND));
|
long epochMicro = TimeUnit.SECONDS.toMicros(instant.getEpochSecond()) + ((long) instant.get(ChronoField.MICRO_OF_SECOND));
|
||||||
return "Date(timeIntervalSince1970: " + String.valueOf(epochMicro) + ".0 / 1_000_000)";
|
return "Date(timeIntervalSince1970: " + String.valueOf(epochMicro) + ".0 / 1_000_000)";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||||
}
|
}
|
||||||
// TODO: Handle more cases from `ModelUtils`, such as Date
|
// TODO: Handle more cases from `ModelUtils`, such as Date
|
||||||
@ -638,12 +638,12 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toInstantiationType(Schema p) {
|
public String toInstantiationType(Schema p) {
|
||||||
if (ModelUtils.isMapSchema(p)) {
|
if (modelUtils.isMapSchema(p)) {
|
||||||
return getSchemaType(getAdditionalProperties(p));
|
return getSchemaType(getAdditionalProperties(p));
|
||||||
} else if (ModelUtils.isArraySchema(p)) {
|
} else if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema ap = (ArraySchema) p;
|
ArraySchema ap = (ArraySchema) p;
|
||||||
String inner = getSchemaType(ap.getItems());
|
String inner = getSchemaType(ap.getItems());
|
||||||
return ModelUtils.isSet(p) ? "Set<" + inner + ">" : "[" + inner + "]";
|
return modelUtils.isSet(p) ? "Set<" + inner + ">" : "[" + inner + "]";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -753,7 +753,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
Map<String, Schema> allDefinitions = modelUtils.getSchemas();
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
if (codegenModel.description != null) {
|
if (codegenModel.description != null) {
|
||||||
codegenModel.imports.add("ApiModel");
|
codegenModel.imports.add("ApiModel");
|
||||||
|
@ -362,7 +362,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isFileSchema(p)) {
|
if (modelUtils.isFileSchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
} else {
|
} else {
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -424,24 +424,24 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
protected String getParameterDataType(Parameter parameter, Schema p) {
|
protected String getParameterDataType(Parameter parameter, Schema p) {
|
||||||
// handle enums of various data types
|
// handle enums of various data types
|
||||||
Schema inner;
|
Schema inner;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
ArraySchema mp1 = (ArraySchema) p;
|
ArraySchema mp1 = (ArraySchema) p;
|
||||||
inner = mp1.getItems();
|
inner = mp1.getItems();
|
||||||
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
inner = (Schema) p.getAdditionalProperties();
|
inner = (Schema) p.getAdditionalProperties();
|
||||||
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
// Handle string enums
|
// Handle string enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
// Handle integer enums
|
// Handle integer enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
// Handle double enums
|
// Handle double enums
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(p.getEnum()));
|
||||||
@ -488,23 +488,23 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (modelUtils.isBooleanSchema(p)) {
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateSchema(p)) {
|
} else if (modelUtils.isDateSchema(p)) {
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (modelUtils.isDateTimeSchema(p)) {
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (modelUtils.isNumberSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
} else if (modelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return "'" + (String) p.getDefault() + "'";
|
return "'" + (String) p.getDefault() + "'";
|
||||||
}
|
}
|
||||||
@ -837,15 +837,15 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
Schema inner;
|
Schema inner;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (modelUtils.isArraySchema(p)) {
|
||||||
inner = ((ArraySchema) p).getItems();
|
inner = ((ArraySchema) p).getItems();
|
||||||
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + ">";
|
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(modelUtils.unaliasSchema(inner)) + ">";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (modelUtils.isMapSchema(p)) {
|
||||||
inner = (Schema) p.getAdditionalProperties();
|
inner = (Schema) p.getAdditionalProperties();
|
||||||
return "{ [key: string]: " + this.getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + "; }";
|
return "{ [key: string]: " + this.getTypeDeclaration(modelUtils.unaliasSchema(inner)) + "; }";
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (modelUtils.isFileSchema(p)) {
|
||||||
return "HttpFile";
|
return "HttpFile";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "any";
|
return "any";
|
||||||
} else {
|
} else {
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -166,9 +166,9 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isFileSchema(p)) {
|
if (modelUtils.isFileSchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -94,7 +94,7 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg
|
|||||||
@Override
|
@Override
|
||||||
public String getSchemaType(Schema p) {
|
public String getSchemaType(Schema p) {
|
||||||
String openAPIType = super.getSchemaType(p);
|
String openAPIType = super.getSchemaType(p);
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (modelUtils.isStringSchema(p)) {
|
||||||
if (p.getEnum() != null) {
|
if (p.getEnum() != null) {
|
||||||
return openAPIType;
|
return openAPIType;
|
||||||
}
|
}
|
||||||
|
@ -87,14 +87,14 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isFileSchema(p)) {
|
if (modelUtils.isFileSchema(p)) {
|
||||||
// There are two file types:
|
// There are two file types:
|
||||||
// 1) RequestFile: the parameter for the request lib when uploading a file
|
// 1) RequestFile: the parameter for the request lib when uploading a file
|
||||||
// (https://github.com/request/request#multipartform-data-multipart-form-uploads)
|
// (https://github.com/request/request#multipartform-data-multipart-form-uploads)
|
||||||
// 2) Buffer: for downloading files.
|
// 2) Buffer: for downloading files.
|
||||||
// Use RequestFile as a default. The return type is fixed to Buffer in handleMethodResponse.
|
// Use RequestFile as a default. The return type is fixed to Buffer in handleMethodResponse.
|
||||||
return "RequestFile";
|
return "RequestFile";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "Buffer";
|
return "Buffer";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -107,9 +107,9 @@ public class TypeScriptReduxQueryClientCodegen extends AbstractTypeScriptClientC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isFileSchema(p)) {
|
if (modelUtils.isFileSchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -108,9 +108,9 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isFileSchema(p)) {
|
if (modelUtils.isFileSchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (modelUtils.isBinarySchema(p)) {
|
||||||
return "Blob";
|
return "Blob";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
|
@ -252,27 +252,27 @@ public class ModelUtils {
|
|||||||
if (allOperations != null) {
|
if (allOperations != null) {
|
||||||
for (Operation operation : allOperations) {
|
for (Operation operation : allOperations) {
|
||||||
//Params:
|
//Params:
|
||||||
visitParameters(openAPI, operation.getParameters(), visitor, visitedSchemas);
|
visitParameters(operation.getParameters(), visitor, visitedSchemas);
|
||||||
|
|
||||||
//RequestBody:
|
//RequestBody:
|
||||||
RequestBody requestBody = getReferencedRequestBody(openAPI, operation.getRequestBody());
|
RequestBody requestBody = getReferencedRequestBody(operation.getRequestBody());
|
||||||
if (requestBody != null) {
|
if (requestBody != null) {
|
||||||
visitContent(openAPI, requestBody.getContent(), visitor, visitedSchemas);
|
visitContent(requestBody.getContent(), visitor, visitedSchemas);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Responses:
|
//Responses:
|
||||||
if (operation.getResponses() != null) {
|
if (operation.getResponses() != null) {
|
||||||
for (ApiResponse r : operation.getResponses().values()) {
|
for (ApiResponse r : operation.getResponses().values()) {
|
||||||
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
|
ApiResponse apiResponse = getReferencedApiResponse(r);
|
||||||
if (apiResponse != null) {
|
if (apiResponse != null) {
|
||||||
visitContent(openAPI, apiResponse.getContent(), visitor, visitedSchemas);
|
visitContent(apiResponse.getContent(), visitor, visitedSchemas);
|
||||||
if (apiResponse.getHeaders() != null) {
|
if (apiResponse.getHeaders() != null) {
|
||||||
for (Entry<String, Header> e : apiResponse.getHeaders().entrySet()) {
|
for (Entry<String, Header> e : apiResponse.getHeaders().entrySet()) {
|
||||||
Header header = getReferencedHeader(e.getValue());
|
Header header = getReferencedHeader(e.getValue());
|
||||||
if (header.getSchema() != null) {
|
if (header.getSchema() != null) {
|
||||||
visitSchema(header.getSchema(), e.getKey(), visitedSchemas, visitor);
|
visitSchema(header.getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||||
}
|
}
|
||||||
visitContent(openAPI, header.getContent(), visitor, visitedSchemas);
|
visitContent(header.getContent(), visitor, visitedSchemas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ public class ModelUtils {
|
|||||||
//Callbacks:
|
//Callbacks:
|
||||||
if (operation.getCallbacks() != null) {
|
if (operation.getCallbacks() != null) {
|
||||||
for (Callback c : operation.getCallbacks().values()) {
|
for (Callback c : operation.getCallbacks().values()) {
|
||||||
Callback callback = getReferencedCallback(openAPI, c);
|
Callback callback = getReferencedCallback(c);
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
for (PathItem p : callback.values()) {
|
for (PathItem p : callback.values()) {
|
||||||
visitPathItem(p, openAPI, visitor, visitedSchemas);
|
visitPathItem(p, openAPI, visitor, visitedSchemas);
|
||||||
@ -293,19 +293,19 @@ public class ModelUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Params:
|
//Params:
|
||||||
visitParameters(openAPI, pathItem.getParameters(), visitor, visitedSchemas);
|
visitParameters(pathItem.getParameters(), visitor, visitedSchemas);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visitParameters(OpenAPI openAPI, List<Parameter> parameters, OpenAPISchemaVisitor visitor,
|
private void visitParameters(List<Parameter> parameters, OpenAPISchemaVisitor visitor,
|
||||||
List<String> visitedSchemas) {
|
List<String> visitedSchemas) {
|
||||||
if (parameters != null) {
|
if (parameters != null) {
|
||||||
for (Parameter p : parameters) {
|
for (Parameter p : parameters) {
|
||||||
Parameter parameter = getReferencedParameter(openAPI, p);
|
Parameter parameter = getReferencedParameter(p);
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
if (parameter.getSchema() != null) {
|
if (parameter.getSchema() != null) {
|
||||||
visitSchema(parameter.getSchema(), null, visitedSchemas, visitor);
|
visitSchema(parameter.getSchema(), null, visitedSchemas, visitor);
|
||||||
}
|
}
|
||||||
visitContent(openAPI, parameter.getContent(), visitor, visitedSchemas);
|
visitContent(parameter.getContent(), visitor, visitedSchemas);
|
||||||
} else {
|
} else {
|
||||||
once(LOGGER).warn("Unreferenced parameter(s) found.");
|
once(LOGGER).warn("Unreferenced parameter(s) found.");
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ public class ModelUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visitContent(OpenAPI openAPI, Content content, OpenAPISchemaVisitor visitor, List<String> visitedSchemas) {
|
private void visitContent(Content content, OpenAPISchemaVisitor visitor, List<String> visitedSchemas) {
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
for (Entry<String, MediaType> e : content.entrySet()) {
|
for (Entry<String, MediaType> e : content.entrySet()) {
|
||||||
if (e.getValue().getSchema() != null) {
|
if (e.getValue().getSchema() != null) {
|
||||||
@ -834,14 +834,13 @@ public class ModelUtils {
|
|||||||
/**
|
/**
|
||||||
* If a Schema contains a reference to another Schema with '$ref', returns the referenced Schema if it is found or the actual Schema in the other cases.
|
* If a Schema contains a reference to another Schema with '$ref', returns the referenced Schema if it is found or the actual Schema in the other cases.
|
||||||
*
|
*
|
||||||
* @param openAPI specification being checked
|
|
||||||
* @param schema potentially containing a '$ref'
|
* @param schema potentially containing a '$ref'
|
||||||
* @return schema without '$ref'
|
* @return schema without '$ref'
|
||||||
*/
|
*/
|
||||||
public Schema getReferencedSchema(OpenAPI openAPI, Schema schema) {
|
public Schema getReferencedSchema(Schema schema) {
|
||||||
if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) {
|
if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) {
|
||||||
String name = getSimpleRef(schema.get$ref());
|
String name = getSimpleRef(schema.get$ref());
|
||||||
Schema referencedSchema = getSchema(openAPI, name);
|
Schema referencedSchema = getSchema(name);
|
||||||
if (referencedSchema != null) {
|
if (referencedSchema != null) {
|
||||||
return referencedSchema;
|
return referencedSchema;
|
||||||
}
|
}
|
||||||
@ -849,7 +848,7 @@ public class ModelUtils {
|
|||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Schema getSchema(OpenAPI openAPI, String name) {
|
public Schema getSchema(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -894,14 +893,13 @@ public class ModelUtils {
|
|||||||
/**
|
/**
|
||||||
* If a RequestBody contains a reference to an other RequestBody with '$ref', returns the referenced RequestBody if it is found or the actual RequestBody in the other cases.
|
* If a RequestBody contains a reference to an other RequestBody with '$ref', returns the referenced RequestBody if it is found or the actual RequestBody in the other cases.
|
||||||
*
|
*
|
||||||
* @param openAPI specification being checked
|
|
||||||
* @param requestBody potentially containing a '$ref'
|
* @param requestBody potentially containing a '$ref'
|
||||||
* @return requestBody without '$ref'
|
* @return requestBody without '$ref'
|
||||||
*/
|
*/
|
||||||
public RequestBody getReferencedRequestBody(OpenAPI openAPI, RequestBody requestBody) {
|
public RequestBody getReferencedRequestBody(RequestBody requestBody) {
|
||||||
if (requestBody != null && StringUtils.isNotEmpty(requestBody.get$ref())) {
|
if (requestBody != null && StringUtils.isNotEmpty(requestBody.get$ref())) {
|
||||||
String name = getSimpleRef(requestBody.get$ref());
|
String name = getSimpleRef(requestBody.get$ref());
|
||||||
RequestBody referencedRequestBody = getRequestBody(openAPI, name);
|
RequestBody referencedRequestBody = getRequestBody(name);
|
||||||
if (referencedRequestBody != null) {
|
if (referencedRequestBody != null) {
|
||||||
return referencedRequestBody;
|
return referencedRequestBody;
|
||||||
}
|
}
|
||||||
@ -909,7 +907,7 @@ public class ModelUtils {
|
|||||||
return requestBody;
|
return requestBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestBody getRequestBody(OpenAPI openAPI, String name) {
|
public RequestBody getRequestBody(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -923,14 +921,13 @@ public class ModelUtils {
|
|||||||
/**
|
/**
|
||||||
* If a ApiResponse contains a reference to an other ApiResponse with '$ref', returns the referenced ApiResponse if it is found or the actual ApiResponse in the other cases.
|
* If a ApiResponse contains a reference to an other ApiResponse with '$ref', returns the referenced ApiResponse if it is found or the actual ApiResponse in the other cases.
|
||||||
*
|
*
|
||||||
* @param openAPI specification being checked
|
|
||||||
* @param apiResponse potentially containing a '$ref'
|
* @param apiResponse potentially containing a '$ref'
|
||||||
* @return apiResponse without '$ref'
|
* @return apiResponse without '$ref'
|
||||||
*/
|
*/
|
||||||
public ApiResponse getReferencedApiResponse(OpenAPI openAPI, ApiResponse apiResponse) {
|
public ApiResponse getReferencedApiResponse(ApiResponse apiResponse) {
|
||||||
if (apiResponse != null && StringUtils.isNotEmpty(apiResponse.get$ref())) {
|
if (apiResponse != null && StringUtils.isNotEmpty(apiResponse.get$ref())) {
|
||||||
String name = getSimpleRef(apiResponse.get$ref());
|
String name = getSimpleRef(apiResponse.get$ref());
|
||||||
ApiResponse referencedApiResponse = getApiResponse(openAPI, name);
|
ApiResponse referencedApiResponse = getApiResponse(name);
|
||||||
if (referencedApiResponse != null) {
|
if (referencedApiResponse != null) {
|
||||||
return referencedApiResponse;
|
return referencedApiResponse;
|
||||||
}
|
}
|
||||||
@ -938,7 +935,7 @@ public class ModelUtils {
|
|||||||
return apiResponse;
|
return apiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiResponse getApiResponse(OpenAPI openAPI, String name) {
|
public ApiResponse getApiResponse(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -952,14 +949,13 @@ public class ModelUtils {
|
|||||||
/**
|
/**
|
||||||
* If a Parameter contains a reference to an other Parameter with '$ref', returns the referenced Parameter if it is found or the actual Parameter in the other cases.
|
* If a Parameter contains a reference to an other Parameter with '$ref', returns the referenced Parameter if it is found or the actual Parameter in the other cases.
|
||||||
*
|
*
|
||||||
* @param openAPI specification being checked
|
|
||||||
* @param parameter potentially containing a '$ref'
|
* @param parameter potentially containing a '$ref'
|
||||||
* @return parameter without '$ref'
|
* @return parameter without '$ref'
|
||||||
*/
|
*/
|
||||||
public Parameter getReferencedParameter(OpenAPI openAPI, Parameter parameter) {
|
public Parameter getReferencedParameter(Parameter parameter) {
|
||||||
if (parameter != null && StringUtils.isNotEmpty(parameter.get$ref())) {
|
if (parameter != null && StringUtils.isNotEmpty(parameter.get$ref())) {
|
||||||
String name = getSimpleRef(parameter.get$ref());
|
String name = getSimpleRef(parameter.get$ref());
|
||||||
Parameter referencedParameter = getParameter(openAPI, name);
|
Parameter referencedParameter = getParameter(name);
|
||||||
if (referencedParameter != null) {
|
if (referencedParameter != null) {
|
||||||
return referencedParameter;
|
return referencedParameter;
|
||||||
}
|
}
|
||||||
@ -967,7 +963,7 @@ public class ModelUtils {
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter getParameter(OpenAPI openAPI, String name) {
|
public Parameter getParameter(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -981,14 +977,13 @@ public class ModelUtils {
|
|||||||
/**
|
/**
|
||||||
* If a Callback contains a reference to an other Callback with '$ref', returns the referenced Callback if it is found or the actual Callback in the other cases.
|
* If a Callback contains a reference to an other Callback with '$ref', returns the referenced Callback if it is found or the actual Callback in the other cases.
|
||||||
*
|
*
|
||||||
* @param openAPI specification being checked
|
|
||||||
* @param callback potentially containing a '$ref'
|
* @param callback potentially containing a '$ref'
|
||||||
* @return callback without '$ref'
|
* @return callback without '$ref'
|
||||||
*/
|
*/
|
||||||
public Callback getReferencedCallback(OpenAPI openAPI, Callback callback) {
|
public Callback getReferencedCallback(Callback callback) {
|
||||||
if (callback != null && StringUtils.isNotEmpty(callback.get$ref())) {
|
if (callback != null && StringUtils.isNotEmpty(callback.get$ref())) {
|
||||||
String name = getSimpleRef(callback.get$ref());
|
String name = getSimpleRef(callback.get$ref());
|
||||||
Callback referencedCallback = getCallback(openAPI, name);
|
Callback referencedCallback = getCallback(name);
|
||||||
if (referencedCallback != null) {
|
if (referencedCallback != null) {
|
||||||
return referencedCallback;
|
return referencedCallback;
|
||||||
}
|
}
|
||||||
@ -996,7 +991,7 @@ public class ModelUtils {
|
|||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Callback getCallback(OpenAPI openAPI, String name) {
|
public Callback getCallback(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1567,13 +1562,12 @@ public class ModelUtils {
|
|||||||
* For OAS 2.0 documents, return the value of the 'swagger' attribute.
|
* For OAS 2.0 documents, return the value of the 'swagger' attribute.
|
||||||
* For OAS 3.x documents, return the value of the 'openapi' attribute.
|
* For OAS 3.x documents, return the value of the 'openapi' attribute.
|
||||||
*
|
*
|
||||||
* @param openAPI the object that encapsulates the OAS document.
|
|
||||||
* @param location the URL of the OAS document.
|
* @param location the URL of the OAS document.
|
||||||
* @param auths the list of authorization values to access the remote URL.
|
* @param auths the list of authorization values to access the remote URL.
|
||||||
*
|
*
|
||||||
* @return the version of the OpenAPI document.
|
* @return the version of the OpenAPI document.
|
||||||
*/
|
*/
|
||||||
public SemVer getOpenApiVersion(OpenAPI openAPI, String location, List<AuthorizationValue> auths) {
|
public SemVer getOpenApiVersion(String location, List<AuthorizationValue> auths) {
|
||||||
String version;
|
String version;
|
||||||
try {
|
try {
|
||||||
JsonNode document = readWithInfo(location, auths);
|
JsonNode document = readWithInfo(location, auths);
|
||||||
@ -1616,7 +1610,7 @@ public class ModelUtils {
|
|||||||
* @param schema the OAS schema.
|
* @param schema the OAS schema.
|
||||||
* @return true if the schema value can be an arbitrary type.
|
* @return true if the schema value can be an arbitrary type.
|
||||||
*/
|
*/
|
||||||
public boolean isAnyTypeSchema(OpenAPI openAPI, Schema schema) {
|
public boolean isAnyTypeSchema(Schema schema) {
|
||||||
if (schema == null) {
|
if (schema == null) {
|
||||||
once(LOGGER).error("Schema cannot be null in isAnyTypeSchema check");
|
once(LOGGER).error("Schema cannot be null in isAnyTypeSchema check");
|
||||||
return false;
|
return false;
|
||||||
|
@ -43,14 +43,16 @@ public class OpenApiEvaluator implements Validator<OpenAPI> {
|
|||||||
OpenApiSchemaValidations schemaValidations = new OpenApiSchemaValidations(ruleConfiguration);
|
OpenApiSchemaValidations schemaValidations = new OpenApiSchemaValidations(ruleConfiguration);
|
||||||
OpenApiOperationValidations operationValidations = new OpenApiOperationValidations(ruleConfiguration);
|
OpenApiOperationValidations operationValidations = new OpenApiOperationValidations(ruleConfiguration);
|
||||||
|
|
||||||
|
ModelUtils modelUtils = new ModelUtils(specification);
|
||||||
|
|
||||||
if (ruleConfiguration.isEnableUnusedSchemasRecommendation()) {
|
if (ruleConfiguration.isEnableUnusedSchemasRecommendation()) {
|
||||||
ValidationRule unusedSchema = ValidationRule.create(Severity.WARNING, "Unused schema", "A schema was determined to be unused.", s -> ValidationRule.Pass.empty());
|
ValidationRule unusedSchema = ValidationRule.create(Severity.WARNING, "Unused schema", "A schema was determined to be unused.", s -> ValidationRule.Pass.empty());
|
||||||
ModelUtils.getUnusedSchemas(specification).forEach(schemaName -> validationResult.addResult(Validated.invalid(unusedSchema, "Unused model: " + schemaName)));
|
modelUtils.getUnusedSchemas().forEach(schemaName -> validationResult.addResult(Validated.invalid(unusedSchema, "Unused model: " + schemaName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get list of all schemas under /components/schemas, including nested schemas defined inline and composed schema.
|
// Get list of all schemas under /components/schemas, including nested schemas defined inline and composed schema.
|
||||||
// The validators must be able to validate every schema defined in the OAS document.
|
// The validators must be able to validate every schema defined in the OAS document.
|
||||||
List<Schema> schemas = ModelUtils.getAllSchemas(specification);
|
List<Schema> schemas = modelUtils.getAllSchemas(specification);
|
||||||
schemas.forEach(schema -> {
|
schemas.forEach(schema -> {
|
||||||
SchemaWrapper wrapper = new SchemaWrapper(specification, schema);
|
SchemaWrapper wrapper = new SchemaWrapper(specification, schema);
|
||||||
validationResult.consume(schemaValidations.validate(wrapper));
|
validationResult.consume(schemaValidations.validate(wrapper));
|
||||||
@ -95,7 +97,7 @@ public class OpenApiEvaluator implements Validator<OpenAPI> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parameters.forEach(parameter -> {
|
parameters.forEach(parameter -> {
|
||||||
parameter = ModelUtils.getReferencedParameter(specification, parameter);
|
parameter = modelUtils.getReferencedParameter(parameter);
|
||||||
ParameterWrapper wrapper = new ParameterWrapper(specification, parameter);
|
ParameterWrapper wrapper = new ParameterWrapper(specification, parameter);
|
||||||
validationResult.consume(parameterValidations.validate(wrapper));
|
validationResult.consume(parameterValidations.validate(wrapper));
|
||||||
});
|
});
|
||||||
|
@ -92,7 +92,7 @@ class OpenApiSchemaValidations extends GenericValidator<SchemaWrapper> {
|
|||||||
* Note: the validator invokes checkNullType() for every top-level schema in the OAS document. The method
|
* Note: the validator invokes checkNullType() for every top-level schema in the OAS document. The method
|
||||||
* is not called for nested schemas that are defined inline.
|
* is not called for nested schemas that are defined inline.
|
||||||
*
|
*
|
||||||
* @param schema An input schema, regardless of the type of schema.
|
* @param schemaWrapper An input schema, regardless of the type of schema.
|
||||||
* @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail}
|
* @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail}
|
||||||
*/
|
*/
|
||||||
private static ValidationRule.Result checkNullType(SchemaWrapper schemaWrapper) {
|
private static ValidationRule.Result checkNullType(SchemaWrapper schemaWrapper) {
|
||||||
@ -102,7 +102,8 @@ class OpenApiSchemaValidations extends GenericValidator<SchemaWrapper> {
|
|||||||
SemVer version = new SemVer(schemaWrapper.getOpenAPI().getOpenapi());
|
SemVer version = new SemVer(schemaWrapper.getOpenAPI().getOpenapi());
|
||||||
if (version.atLeast("3.0") && version.compareTo(new SemVer("3.1")) < 0) {
|
if (version.atLeast("3.0") && version.compareTo(new SemVer("3.1")) < 0) {
|
||||||
// OAS spec is 3.0.x
|
// OAS spec is 3.0.x
|
||||||
if (ModelUtils.isNullType(schema)) {
|
ModelUtils modelUtils = new ModelUtils(null);
|
||||||
|
if (modelUtils.isNullType(schema)) {
|
||||||
result = new ValidationRule.Fail();
|
result = new ValidationRule.Fail();
|
||||||
String name = schema.getName();
|
String name = schema.getName();
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
@ -123,7 +124,7 @@ class OpenApiSchemaValidations extends GenericValidator<SchemaWrapper> {
|
|||||||
* <p>
|
* <p>
|
||||||
* The 'nullable' attribute is supported in OpenAPI Specification 3.0.x, but it is deprecated in OpenAPI 3.1 and above.
|
* The 'nullable' attribute is supported in OpenAPI Specification 3.0.x, but it is deprecated in OpenAPI 3.1 and above.
|
||||||
*
|
*
|
||||||
* @param schema An input schema, regardless of the type of schema
|
* @param schemaWrapper An input schema, regardless of the type of schema
|
||||||
* @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail}
|
* @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail}
|
||||||
*/
|
*/
|
||||||
private static ValidationRule.Result checkNullableAttribute(SchemaWrapper schemaWrapper) {
|
private static ValidationRule.Result checkNullableAttribute(SchemaWrapper schemaWrapper) {
|
||||||
@ -132,7 +133,8 @@ class OpenApiSchemaValidations extends GenericValidator<SchemaWrapper> {
|
|||||||
if (schemaWrapper.getOpenAPI() != null) {
|
if (schemaWrapper.getOpenAPI() != null) {
|
||||||
SemVer version = new SemVer(schemaWrapper.getOpenAPI().getOpenapi());
|
SemVer version = new SemVer(schemaWrapper.getOpenAPI().getOpenapi());
|
||||||
if (version.atLeast("3.1")) {
|
if (version.atLeast("3.1")) {
|
||||||
if (ModelUtils.isNullable(schema)) {
|
ModelUtils modelUtils = new ModelUtils(null);
|
||||||
|
if (modelUtils.isNullable(schema)) {
|
||||||
result = new ValidationRule.Fail();
|
result = new ValidationRule.Fail();
|
||||||
String name = schema.getName();
|
String name = schema.getName();
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
@ -157,7 +159,7 @@ class OpenApiSchemaValidations extends GenericValidator<SchemaWrapper> {
|
|||||||
* <p>
|
* <p>
|
||||||
* The type must be one of the following values: null, boolean, object, array, number, string, integer.
|
* The type must be one of the following values: null, boolean, object, array, number, string, integer.
|
||||||
*
|
*
|
||||||
* @param schema An input schema, regardless of the type of schema
|
* @param schemaWrapper An input schema, regardless of the type of schema
|
||||||
* @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail}
|
* @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail}
|
||||||
*/
|
*/
|
||||||
private static ValidationRule.Result checkInvalidType(SchemaWrapper schemaWrapper) {
|
private static ValidationRule.Result checkInvalidType(SchemaWrapper schemaWrapper) {
|
||||||
|
@ -76,8 +76,8 @@ public class DefaultCodegenTest {
|
|||||||
|
|
||||||
final DefaultCodegen codegen = new DefaultCodegen();
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
|
||||||
Assert.assertEquals(codegen.hasBodyParameter(openAPI, pingOperation), false);
|
Assert.assertEquals(codegen.hasBodyParameter(pingOperation), false);
|
||||||
Assert.assertEquals(codegen.hasBodyParameter(openAPI, createOperation), true);
|
Assert.assertEquals(codegen.hasBodyParameter(createOperation), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = RuntimeException.class)
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
@ -110,13 +110,13 @@ public class DefaultCodegenTest {
|
|||||||
.responses(
|
.responses(
|
||||||
new ApiResponses().addApiResponse("201", new ApiResponse()
|
new ApiResponses().addApiResponse("201", new ApiResponse()
|
||||||
.description("Created response")));
|
.description("Created response")));
|
||||||
Set<String> createConsumesInfo = DefaultCodegen.getConsumesInfo(openAPI, createOperation);
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
Set<String> createConsumesInfo = codegen.getConsumesInfo(createOperation);
|
||||||
Assert.assertEquals(createConsumesInfo.size(), 2);
|
Assert.assertEquals(createConsumesInfo.size(), 2);
|
||||||
Assert.assertTrue(createConsumesInfo.contains("application/json"), "contains 'application/json'");
|
Assert.assertTrue(createConsumesInfo.contains("application/json"), "contains 'application/json'");
|
||||||
Assert.assertTrue(createConsumesInfo.contains("application/xml"), "contains 'application/xml'");
|
Assert.assertTrue(createConsumesInfo.contains("application/xml"), "contains 'application/xml'");
|
||||||
Set<String> createProducesInfo = DefaultCodegen.getProducesInfo(openAPI, createOperation);
|
Set<String> createProducesInfo = codegen.getProducesInfo(createOperation);
|
||||||
Assert.assertEquals(createProducesInfo.size(), 0);
|
Assert.assertEquals(createProducesInfo.size(), 0);
|
||||||
final DefaultCodegen codegen = new DefaultCodegen();
|
|
||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
CodegenOperation coCreate = codegen.fromOperation("somepath", "post", createOperation, null);
|
CodegenOperation coCreate = codegen.fromOperation("somepath", "post", createOperation, null);
|
||||||
Assert.assertTrue(coCreate.hasConsumes);
|
Assert.assertTrue(coCreate.hasConsumes);
|
||||||
@ -126,10 +126,10 @@ public class DefaultCodegenTest {
|
|||||||
Operation updateOperationWithRef = new Operation()
|
Operation updateOperationWithRef = new Operation()
|
||||||
.requestBody(new RequestBody().$ref("#/components/requestBodies/MyRequestBody"))
|
.requestBody(new RequestBody().$ref("#/components/requestBodies/MyRequestBody"))
|
||||||
.responses(new ApiResponses().addApiResponse("201", new ApiResponse().$ref("#/components/responses/MyResponse")));
|
.responses(new ApiResponses().addApiResponse("201", new ApiResponse().$ref("#/components/responses/MyResponse")));
|
||||||
Set<String> updateConsumesInfo = DefaultCodegen.getConsumesInfo(openAPI, updateOperationWithRef);
|
Set<String> updateConsumesInfo = codegen.getConsumesInfo(updateOperationWithRef);
|
||||||
Assert.assertEquals(updateConsumesInfo.size(), 1);
|
Assert.assertEquals(updateConsumesInfo.size(), 1);
|
||||||
Assert.assertTrue(updateConsumesInfo.contains("application/json"), "contains 'application/json'");
|
Assert.assertTrue(updateConsumesInfo.contains("application/json"), "contains 'application/json'");
|
||||||
Set<String> updateProducesInfo = DefaultCodegen.getProducesInfo(openAPI, updateOperationWithRef);
|
Set<String> updateProducesInfo = codegen.getProducesInfo(updateOperationWithRef);
|
||||||
Assert.assertEquals(updateProducesInfo.size(), 1);
|
Assert.assertEquals(updateProducesInfo.size(), 1);
|
||||||
Assert.assertTrue(updateProducesInfo.contains("application/xml"), "contains 'application/xml'");
|
Assert.assertTrue(updateProducesInfo.contains("application/xml"), "contains 'application/xml'");
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class DefaultCodegenTest {
|
|||||||
final DefaultCodegen codegen = new DefaultCodegen();
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
Schema requestBodySchema = ModelUtils.getSchemaFromRequestBody(openAPI.getPaths().get("/fake").getGet().getRequestBody());
|
Schema requestBodySchema = codegen.getModelUtils().getSchemaFromRequestBody(openAPI.getPaths().get("/fake").getGet().getRequestBody());
|
||||||
CodegenParameter codegenParameter = codegen.fromFormProperty("enum_form_string", (Schema) requestBodySchema.getProperties().get("enum_form_string"), new HashSet<String>());
|
CodegenParameter codegenParameter = codegen.fromFormProperty("enum_form_string", (Schema) requestBodySchema.getProperties().get("enum_form_string"), new HashSet<String>());
|
||||||
|
|
||||||
Assert.assertEquals(codegenParameter.defaultValue, "-efg");
|
Assert.assertEquals(codegenParameter.defaultValue, "-efg");
|
||||||
@ -229,13 +229,14 @@ public class DefaultCodegenTest {
|
|||||||
// Test with OAS 2.0 document.
|
// Test with OAS 2.0 document.
|
||||||
String location = "src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml";
|
String location = "src/test/resources/2_0/python-client-experimental/petstore-with-fake-endpoints-models-for-testing.yaml";
|
||||||
OpenAPI openAPI = TestUtils.parseFlattenSpec(location);
|
OpenAPI openAPI = TestUtils.parseFlattenSpec(location);
|
||||||
SemVer version = ModelUtils.getOpenApiVersion(openAPI, location, null);
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
SemVer version = modelUtils.getOpenApiVersion(location, null);
|
||||||
Assert.assertEquals(version, new SemVer("2.0.0"));
|
Assert.assertEquals(version, new SemVer("2.0.0"));
|
||||||
|
|
||||||
// Test with OAS 3.0 document.
|
// Test with OAS 3.0 document.
|
||||||
location = "src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml";
|
location = "src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml";
|
||||||
openAPI = TestUtils.parseFlattenSpec(location);
|
openAPI = TestUtils.parseFlattenSpec(location);
|
||||||
version = ModelUtils.getOpenApiVersion(openAPI, location, null);
|
version = modelUtils.getOpenApiVersion(location, null);
|
||||||
Assert.assertEquals(version, new SemVer("3.0.0"));
|
Assert.assertEquals(version, new SemVer("3.0.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,11 +246,12 @@ public class DefaultCodegenTest {
|
|||||||
DefaultCodegen codegen = new DefaultCodegen();
|
DefaultCodegen codegen = new DefaultCodegen();
|
||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
codegen.setDisallowAdditionalPropertiesIfNotPresent(true);
|
codegen.setDisallowAdditionalPropertiesIfNotPresent(true);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
Schema schema = openAPI.getComponents().getSchemas().get("AdditionalPropertiesClass");
|
Schema schema = openAPI.getComponents().getSchemas().get("AdditionalPropertiesClass");
|
||||||
Assert.assertEquals(schema.getAdditionalProperties(), null);
|
Assert.assertEquals(schema.getAdditionalProperties(), null);
|
||||||
|
|
||||||
Schema addProps = ModelUtils.getAdditionalProperties(openAPI, schema);
|
Schema addProps = modelUtils.getAdditionalProperties(schema);
|
||||||
// The petstore-with-fake-endpoints-models-for-testing.yaml does not set the
|
// The petstore-with-fake-endpoints-models-for-testing.yaml does not set the
|
||||||
// 'additionalProperties' keyword for this model, hence assert the value to be null.
|
// 'additionalProperties' keyword for this model, hence assert the value to be null.
|
||||||
Assert.assertNull(addProps);
|
Assert.assertNull(addProps);
|
||||||
@ -275,7 +277,7 @@ public class DefaultCodegenTest {
|
|||||||
// We cannot differentiate between 'additionalProperties' not present and
|
// We cannot differentiate between 'additionalProperties' not present and
|
||||||
// additionalProperties: true.
|
// additionalProperties: true.
|
||||||
Assert.assertNull(child.getAdditionalProperties());
|
Assert.assertNull(child.getAdditionalProperties());
|
||||||
addProps = ModelUtils.getAdditionalProperties(openAPI, child);
|
addProps = modelUtils.getAdditionalProperties(child);
|
||||||
Assert.assertNull(addProps);
|
Assert.assertNull(addProps);
|
||||||
|
|
||||||
child = m.get("map_without_additional_properties");
|
child = m.get("map_without_additional_properties");
|
||||||
@ -286,7 +288,7 @@ public class DefaultCodegenTest {
|
|||||||
// We cannot differentiate between 'additionalProperties' not present and
|
// We cannot differentiate between 'additionalProperties' not present and
|
||||||
// additionalProperties: false.
|
// additionalProperties: false.
|
||||||
Assert.assertNull(child.getAdditionalProperties());
|
Assert.assertNull(child.getAdditionalProperties());
|
||||||
addProps = ModelUtils.getAdditionalProperties(openAPI, child);
|
addProps = modelUtils.getAdditionalProperties(child);
|
||||||
Assert.assertNull(addProps);
|
Assert.assertNull(addProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,13 +298,14 @@ public class DefaultCodegenTest {
|
|||||||
DefaultCodegen codegen = new DefaultCodegen();
|
DefaultCodegen codegen = new DefaultCodegen();
|
||||||
codegen.setDisallowAdditionalPropertiesIfNotPresent(false);
|
codegen.setDisallowAdditionalPropertiesIfNotPresent(false);
|
||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
Schema schema = openAPI.getComponents().getSchemas().get("AdditionalPropertiesClass");
|
Schema schema = openAPI.getComponents().getSchemas().get("AdditionalPropertiesClass");
|
||||||
Assert.assertNull(schema.getAdditionalProperties());
|
Assert.assertNull(schema.getAdditionalProperties());
|
||||||
|
|
||||||
// When the 'additionalProperties' keyword is not present, the schema may be
|
// When the 'additionalProperties' keyword is not present, the schema may be
|
||||||
// extended with any undeclared properties.
|
// extended with any undeclared properties.
|
||||||
Schema addProps = ModelUtils.getAdditionalProperties(openAPI, schema);
|
Schema addProps = modelUtils.getAdditionalProperties(schema);
|
||||||
Assert.assertNotNull(addProps);
|
Assert.assertNotNull(addProps);
|
||||||
Assert.assertTrue(addProps instanceof ObjectSchema);
|
Assert.assertTrue(addProps instanceof ObjectSchema);
|
||||||
CodegenModel cm = codegen.fromModel("AdditionalPropertiesClass", schema);
|
CodegenModel cm = codegen.fromModel("AdditionalPropertiesClass", schema);
|
||||||
@ -320,7 +323,7 @@ public class DefaultCodegenTest {
|
|||||||
// which means by default undeclared properties are allowed.
|
// which means by default undeclared properties are allowed.
|
||||||
Assert.assertNotNull(child);
|
Assert.assertNotNull(child);
|
||||||
Assert.assertNull(child.getAdditionalProperties());
|
Assert.assertNull(child.getAdditionalProperties());
|
||||||
addProps = ModelUtils.getAdditionalProperties(openAPI, child);
|
addProps = modelUtils.getAdditionalProperties(child);
|
||||||
Assert.assertNotNull(addProps);
|
Assert.assertNotNull(addProps);
|
||||||
Assert.assertTrue(addProps instanceof ObjectSchema);
|
Assert.assertTrue(addProps instanceof ObjectSchema);
|
||||||
|
|
||||||
@ -329,7 +332,7 @@ public class DefaultCodegenTest {
|
|||||||
// which means by default undeclared properties are allowed.
|
// which means by default undeclared properties are allowed.
|
||||||
Assert.assertNotNull(child);
|
Assert.assertNotNull(child);
|
||||||
Assert.assertNull(child.getAdditionalProperties());
|
Assert.assertNull(child.getAdditionalProperties());
|
||||||
addProps = ModelUtils.getAdditionalProperties(openAPI, child);
|
addProps = modelUtils.getAdditionalProperties(child);
|
||||||
Assert.assertNotNull(addProps);
|
Assert.assertNotNull(addProps);
|
||||||
Assert.assertTrue(addProps instanceof ObjectSchema);
|
Assert.assertTrue(addProps instanceof ObjectSchema);
|
||||||
|
|
||||||
@ -341,7 +344,7 @@ public class DefaultCodegenTest {
|
|||||||
// additionalProperties: true.
|
// additionalProperties: true.
|
||||||
Assert.assertNotNull(child.getAdditionalProperties());
|
Assert.assertNotNull(child.getAdditionalProperties());
|
||||||
Assert.assertEquals(child.getAdditionalProperties(), Boolean.TRUE);
|
Assert.assertEquals(child.getAdditionalProperties(), Boolean.TRUE);
|
||||||
addProps = ModelUtils.getAdditionalProperties(openAPI, child);
|
addProps = modelUtils.getAdditionalProperties(child);
|
||||||
Assert.assertNotNull(addProps);
|
Assert.assertNotNull(addProps);
|
||||||
Assert.assertTrue(addProps instanceof ObjectSchema);
|
Assert.assertTrue(addProps instanceof ObjectSchema);
|
||||||
|
|
||||||
@ -353,7 +356,7 @@ public class DefaultCodegenTest {
|
|||||||
// additionalProperties: false.
|
// additionalProperties: false.
|
||||||
Assert.assertNotNull(child.getAdditionalProperties());
|
Assert.assertNotNull(child.getAdditionalProperties());
|
||||||
Assert.assertEquals(child.getAdditionalProperties(), Boolean.FALSE);
|
Assert.assertEquals(child.getAdditionalProperties(), Boolean.FALSE);
|
||||||
addProps = ModelUtils.getAdditionalProperties(openAPI, child);
|
addProps = modelUtils.getAdditionalProperties(child);
|
||||||
Assert.assertNull(addProps);
|
Assert.assertNull(addProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +374,7 @@ public class DefaultCodegenTest {
|
|||||||
// extended with any undeclared properties.
|
// extended with any undeclared properties.
|
||||||
// However, in legacy 'additionalProperties' mode, this is interpreted as
|
// However, in legacy 'additionalProperties' mode, this is interpreted as
|
||||||
// 'no additional properties are allowed'.
|
// 'no additional properties are allowed'.
|
||||||
Schema addProps = ModelUtils.getAdditionalProperties(openAPI, schema);
|
Schema addProps = codegen.getModelUtils().getAdditionalProperties(schema);
|
||||||
Assert.assertNull(addProps);
|
Assert.assertNull(addProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,7 +433,7 @@ public class DefaultCodegenTest {
|
|||||||
final DefaultCodegen codegen = new DefaultCodegen();
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
|
||||||
Operation operation = openAPI.getPaths().get("/state").getPost();
|
Operation operation = openAPI.getPaths().get("/state").getPost();
|
||||||
Schema schema = ModelUtils.getSchemaFromRequestBody(operation.getRequestBody());
|
Schema schema = codegen.getModelUtils().getSchemaFromRequestBody(operation.getRequestBody());
|
||||||
String type = codegen.getSchemaType(schema);
|
String type = codegen.getSchemaType(schema);
|
||||||
|
|
||||||
Assert.assertNotNull(type);
|
Assert.assertNotNull(type);
|
||||||
@ -1347,7 +1350,7 @@ public class DefaultCodegenTest {
|
|||||||
// for us to check a model's children we need to run generator.generateModels
|
// for us to check a model's children we need to run generator.generateModels
|
||||||
// because children are assigned in config.updateAllModels which is invoked in generator.generateModels
|
// because children are assigned in config.updateAllModels which is invoked in generator.generateModels
|
||||||
List<File> files = new ArrayList<>();
|
List<File> files = new ArrayList<>();
|
||||||
List<String> filteredSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI);
|
List<String> filteredSchemas = generator.getModelUtils().getSchemasUsedOnlyInFormParam();
|
||||||
List<Object> allModels = new ArrayList<>();
|
List<Object> allModels = new ArrayList<>();
|
||||||
generator.generateModels(files, allModels, filteredSchemas);
|
generator.generateModels(files, allModels, filteredSchemas);
|
||||||
|
|
||||||
@ -2401,7 +2404,7 @@ public class DefaultCodegenTest {
|
|||||||
CodegenProperty mapWithAddPropsSchema;
|
CodegenProperty mapWithAddPropsSchema;
|
||||||
|
|
||||||
// make sure isGenerateAliasAsModel is false
|
// make sure isGenerateAliasAsModel is false
|
||||||
boolean isGenerateAliasAsModel = ModelUtils.isGenerateAliasAsModel();
|
boolean isGenerateAliasAsModel = codegen.getModelUtils().isGenerateAliasAsModel();
|
||||||
if (isGenerateAliasAsModel) {
|
if (isGenerateAliasAsModel) {
|
||||||
GlobalSettings.setProperty("generateAliasAsModel", "false");
|
GlobalSettings.setProperty("generateAliasAsModel", "false");
|
||||||
}
|
}
|
||||||
@ -2454,7 +2457,7 @@ public class DefaultCodegenTest {
|
|||||||
CodegenParameter mapWithAddPropsSchema;
|
CodegenParameter mapWithAddPropsSchema;
|
||||||
|
|
||||||
// make sure isGenerateAliasAsModel is false
|
// make sure isGenerateAliasAsModel is false
|
||||||
boolean isGenerateAliasAsModel = ModelUtils.isGenerateAliasAsModel();
|
boolean isGenerateAliasAsModel = codegen.getModelUtils().isGenerateAliasAsModel();
|
||||||
if (isGenerateAliasAsModel) {
|
if (isGenerateAliasAsModel) {
|
||||||
GlobalSettings.setProperty("generateAliasAsModel", "false");
|
GlobalSettings.setProperty("generateAliasAsModel", "false");
|
||||||
}
|
}
|
||||||
@ -2507,7 +2510,7 @@ public class DefaultCodegenTest {
|
|||||||
CodegenResponse mapWithAddPropsSchema;
|
CodegenResponse mapWithAddPropsSchema;
|
||||||
|
|
||||||
// make sure isGenerateAliasAsModel is false
|
// make sure isGenerateAliasAsModel is false
|
||||||
boolean isGenerateAliasAsModel = ModelUtils.isGenerateAliasAsModel();
|
boolean isGenerateAliasAsModel = codegen.getModelUtils().isGenerateAliasAsModel();
|
||||||
if (isGenerateAliasAsModel) {
|
if (isGenerateAliasAsModel) {
|
||||||
GlobalSettings.setProperty("generateAliasAsModel", "false");
|
GlobalSettings.setProperty("generateAliasAsModel", "false");
|
||||||
}
|
}
|
||||||
|
@ -394,6 +394,8 @@ public class DefaultGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRefModelValidationProperties() {
|
public void testRefModelValidationProperties() {
|
||||||
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/refAliasedPrimitiveWithValidation.yml");
|
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/refAliasedPrimitiveWithValidation.yml");
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
ClientOptInput opts = new ClientOptInput();
|
ClientOptInput opts = new ClientOptInput();
|
||||||
opts.openAPI(openAPI);
|
opts.openAPI(openAPI);
|
||||||
DefaultCodegen config = new DefaultCodegen();
|
DefaultCodegen config = new DefaultCodegen();
|
||||||
@ -412,7 +414,7 @@ public class DefaultGeneratorTest {
|
|||||||
Assert.assertEquals(stringRegex.getPattern(), expectedPattern);
|
Assert.assertEquals(stringRegex.getPattern(), expectedPattern);
|
||||||
|
|
||||||
// Validate when we alias/unalias
|
// Validate when we alias/unalias
|
||||||
Schema unaliasedStringRegex = ModelUtils.unaliasSchema(openAPI, stringRegex);
|
Schema unaliasedStringRegex = modelUtils.unaliasSchema(stringRegex);
|
||||||
Assert.assertEquals(unaliasedStringRegex.getPattern(), expectedPattern);
|
Assert.assertEquals(unaliasedStringRegex.getPattern(), expectedPattern);
|
||||||
|
|
||||||
// Validate when converting to property
|
// Validate when converting to property
|
||||||
|
@ -351,6 +351,7 @@ public class InlineModelResolverTest {
|
|||||||
public void resolveInlineRequestBody() {
|
public void resolveInlineRequestBody() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
RequestBody requestBodyReference = openAPI
|
RequestBody requestBodyReference = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -359,15 +360,15 @@ public class InlineModelResolverTest {
|
|||||||
.getRequestBody();
|
.getRequestBody();
|
||||||
assertNotNull(requestBodyReference.get$ref());
|
assertNotNull(requestBodyReference.get$ref());
|
||||||
|
|
||||||
RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, requestBodyReference);
|
RequestBody requestBody = modelUtils.getReferencedRequestBody(requestBodyReference);
|
||||||
MediaType mediaType = requestBody.getContent().get("application/json");
|
MediaType mediaType = requestBody.getContent().get("application/json");
|
||||||
assertTrue(ModelUtils.getReferencedSchema(openAPI, mediaType.getSchema()) instanceof ObjectSchema);
|
assertTrue(modelUtils.getReferencedSchema(mediaType.getSchema()) instanceof ObjectSchema);
|
||||||
|
|
||||||
ObjectSchema schema = (ObjectSchema) ModelUtils.getReferencedSchema(openAPI, mediaType.getSchema());
|
ObjectSchema schema = (ObjectSchema) modelUtils.getReferencedSchema(mediaType.getSchema());
|
||||||
assertTrue(schema.getProperties().get("name") instanceof StringSchema);
|
assertTrue(schema.getProperties().get("name") instanceof StringSchema);
|
||||||
assertNotNull(schema.getProperties().get("address").get$ref());
|
assertNotNull(schema.getProperties().get("address").get$ref());
|
||||||
|
|
||||||
Schema address = ModelUtils.getReferencedSchema(openAPI, schema.getProperties().get("address"));
|
Schema address = modelUtils.getReferencedSchema(schema.getProperties().get("address"));
|
||||||
assertTrue(address.getProperties().get("street") instanceof StringSchema);
|
assertTrue(address.getProperties().get("street") instanceof StringSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,11 +376,12 @@ public class InlineModelResolverTest {
|
|||||||
public void resolveInlineRequestBodyWithRequired() {
|
public void resolveInlineRequestBodyWithRequired() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
RequestBody requestBodyReference = openAPI.getPaths().get("/resolve_inline_request_body_with_required").getPost().getRequestBody();
|
RequestBody requestBodyReference = openAPI.getPaths().get("/resolve_inline_request_body_with_required").getPost().getRequestBody();
|
||||||
assertTrue(requestBodyReference.getRequired());
|
assertTrue(requestBodyReference.getRequired());
|
||||||
|
|
||||||
RequestBody referencedRequestBody = ModelUtils.getReferencedRequestBody(openAPI, requestBodyReference);
|
RequestBody referencedRequestBody = modelUtils.getReferencedRequestBody(requestBodyReference);
|
||||||
assertTrue(referencedRequestBody.getRequired());
|
assertTrue(referencedRequestBody.getRequired());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,6 +416,7 @@ public class InlineModelResolverTest {
|
|||||||
public void resolveInlineArrayRequestBody() {
|
public void resolveInlineArrayRequestBody() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -429,7 +432,7 @@ public class InlineModelResolverTest {
|
|||||||
assertNotNull(requestBody.getItems().get$ref());
|
assertNotNull(requestBody.getItems().get$ref());
|
||||||
assertEquals("#/components/schemas/InlineObject", requestBody.getItems().get$ref());
|
assertEquals("#/components/schemas/InlineObject", requestBody.getItems().get$ref());
|
||||||
|
|
||||||
Schema items = ModelUtils.getReferencedSchema(openAPI, ((ArraySchema) mediaType.getSchema()).getItems());
|
Schema items = modelUtils.getReferencedSchema(((ArraySchema) mediaType.getSchema()).getItems());
|
||||||
assertTrue(items.getProperties().get("street") instanceof StringSchema);
|
assertTrue(items.getProperties().get("street") instanceof StringSchema);
|
||||||
assertTrue(items.getProperties().get("city") instanceof StringSchema);
|
assertTrue(items.getProperties().get("city") instanceof StringSchema);
|
||||||
}
|
}
|
||||||
@ -456,6 +459,7 @@ public class InlineModelResolverTest {
|
|||||||
public void resolveInlineArrayResponse() {
|
public void resolveInlineArrayResponse() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -471,7 +475,7 @@ public class InlineModelResolverTest {
|
|||||||
ArraySchema responseSchema = (ArraySchema) mediaType.getSchema();
|
ArraySchema responseSchema = (ArraySchema) mediaType.getSchema();
|
||||||
assertEquals("#/components/schemas/inline_response_200", responseSchema.getItems().get$ref());
|
assertEquals("#/components/schemas/inline_response_200", responseSchema.getItems().get$ref());
|
||||||
|
|
||||||
Schema items = ModelUtils.getReferencedSchema(openAPI, responseSchema.getItems());
|
Schema items = modelUtils.getReferencedSchema(responseSchema.getItems());
|
||||||
assertTrue(items.getProperties().get("array_response_property") instanceof StringSchema);
|
assertTrue(items.getProperties().get("array_response_property") instanceof StringSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,6 +501,7 @@ public class InlineModelResolverTest {
|
|||||||
public void resolveInlineObjectResponseWithAdditionalProperties() {
|
public void resolveInlineObjectResponseWithAdditionalProperties() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -511,7 +516,7 @@ public class InlineModelResolverTest {
|
|||||||
Object additionalPropertiesObject = mediaType.getSchema().getAdditionalProperties();
|
Object additionalPropertiesObject = mediaType.getSchema().getAdditionalProperties();
|
||||||
assertTrue(additionalPropertiesObject instanceof Schema);
|
assertTrue(additionalPropertiesObject instanceof Schema);
|
||||||
|
|
||||||
Schema additionalProperties = ModelUtils.getReferencedSchema(openAPI, (Schema)additionalPropertiesObject);
|
Schema additionalProperties = modelUtils.getReferencedSchema((Schema)additionalPropertiesObject);
|
||||||
assertNotNull(additionalProperties);
|
assertNotNull(additionalProperties);
|
||||||
assertTrue(additionalProperties.getProperties().get("resolve_inline_object_response_with_additional_properties") instanceof StringSchema);
|
assertTrue(additionalProperties.getProperties().get("resolve_inline_object_response_with_additional_properties") instanceof StringSchema);
|
||||||
}
|
}
|
||||||
@ -547,6 +552,7 @@ public class InlineModelResolverTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -562,14 +568,14 @@ public class InlineModelResolverTest {
|
|||||||
assertNotNull(additionalProperties.get$ref());
|
assertNotNull(additionalProperties.get$ref());
|
||||||
assertTrue(additionalProperties.get$ref().startsWith("#/components/schemas/inline_response_"));
|
assertTrue(additionalProperties.get$ref().startsWith("#/components/schemas/inline_response_"));
|
||||||
|
|
||||||
Schema referencedSchema = ModelUtils.getReferencedSchema(openAPI, additionalProperties);
|
Schema referencedSchema = modelUtils.getReferencedSchema(additionalProperties);
|
||||||
Schema referencedSchemaProperty = (Schema) referencedSchema.getProperties().get("resolve_inline_map_schema_in_response_property");
|
Schema referencedSchemaProperty = (Schema) referencedSchema.getProperties().get("resolve_inline_map_schema_in_response_property");
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"#/components/schemas/_resolve_inline_map_schema_in_response_resolve_inline_map_schema_in_response_property",
|
"#/components/schemas/_resolve_inline_map_schema_in_response_resolve_inline_map_schema_in_response_property",
|
||||||
referencedSchemaProperty.get$ref()
|
referencedSchemaProperty.get$ref()
|
||||||
);
|
);
|
||||||
assertNotNull(ModelUtils.getReferencedSchema(openAPI, referencedSchemaProperty));
|
assertNotNull(modelUtils.getReferencedSchema(referencedSchemaProperty));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -631,6 +637,7 @@ public class InlineModelResolverTest {
|
|||||||
public void arbitraryRequestBodyArrayProperty() {
|
public void arbitraryRequestBodyArrayProperty() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -645,7 +652,7 @@ public class InlineModelResolverTest {
|
|||||||
ArraySchema requestBodySchema = (ArraySchema) mediaType.getSchema();
|
ArraySchema requestBodySchema = (ArraySchema) mediaType.getSchema();
|
||||||
assertNotNull(requestBodySchema.getItems().get$ref());
|
assertNotNull(requestBodySchema.getItems().get$ref());
|
||||||
|
|
||||||
Schema referencedSchema = ModelUtils.getReferencedSchema(openAPI, requestBodySchema.getItems());
|
Schema referencedSchema = modelUtils.getReferencedSchema(requestBodySchema.getItems());
|
||||||
assertTrue(referencedSchema.getProperties().get("arbitrary_request_body_array_property") instanceof ObjectSchema);
|
assertTrue(referencedSchema.getProperties().get("arbitrary_request_body_array_property") instanceof ObjectSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,6 +697,7 @@ public class InlineModelResolverTest {
|
|||||||
public void arbitraryObjectResponseArrayInline() {
|
public void arbitraryObjectResponseArrayInline() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -704,7 +712,7 @@ public class InlineModelResolverTest {
|
|||||||
ArraySchema schema = (ArraySchema) mediaType.getSchema();
|
ArraySchema schema = (ArraySchema) mediaType.getSchema();
|
||||||
assertNotNull(schema.getItems().get$ref());
|
assertNotNull(schema.getItems().get$ref());
|
||||||
|
|
||||||
Schema referencedSchema = ModelUtils.getReferencedSchema(openAPI, schema.getItems());
|
Schema referencedSchema = modelUtils.getReferencedSchema(schema.getItems());
|
||||||
assertTrue(referencedSchema.getProperties().get("arbitrary_object_response_array_inline") instanceof ObjectSchema);
|
assertTrue(referencedSchema.getProperties().get("arbitrary_object_response_array_inline") instanceof ObjectSchema);
|
||||||
|
|
||||||
ObjectSchema arbitaryObject = (ObjectSchema) referencedSchema.getProperties().get("arbitrary_object_response_array_inline");
|
ObjectSchema arbitaryObject = (ObjectSchema) referencedSchema.getProperties().get("arbitrary_object_response_array_inline");
|
||||||
@ -763,10 +771,11 @@ public class InlineModelResolverTest {
|
|||||||
|
|
||||||
|
|
||||||
private void checkComposedChildren(OpenAPI openAPI, List<Schema> children, String key) {
|
private void checkComposedChildren(OpenAPI openAPI, List<Schema> children, String key) {
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
assertNotNull(children);
|
assertNotNull(children);
|
||||||
Schema inlined = children.get(0);
|
Schema inlined = children.get(0);
|
||||||
assertEquals("#/components/schemas/ComposedObjectModelInline_" + key, inlined.get$ref());
|
assertEquals("#/components/schemas/ComposedObjectModelInline_" + key, inlined.get$ref());
|
||||||
Schema child = ModelUtils.getReferencedSchema(openAPI, inlined);
|
Schema child = modelUtils.getReferencedSchema(inlined);
|
||||||
assertNotNull(child.getProperties());
|
assertNotNull(child.getProperties());
|
||||||
assertNotNull(child.getProperties().get("composed_object_model_inline_" + key));
|
assertNotNull(child.getProperties().get("composed_object_model_inline_" + key));
|
||||||
}
|
}
|
||||||
@ -790,6 +799,7 @@ public class InlineModelResolverTest {
|
|||||||
public void inheritanceWithInlineDiscriminator() {
|
public void inheritanceWithInlineDiscriminator() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/regression_6905.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/regression_6905.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
assertTrue(openAPI.getComponents().getSchemas().get("PartyType") instanceof StringSchema);
|
assertTrue(openAPI.getComponents().getSchemas().get("PartyType") instanceof StringSchema);
|
||||||
assertTrue(openAPI.getComponents().getSchemas().get("CustomerType") instanceof StringSchema);
|
assertTrue(openAPI.getComponents().getSchemas().get("CustomerType") instanceof StringSchema);
|
||||||
@ -812,8 +822,8 @@ public class InlineModelResolverTest {
|
|||||||
// Party
|
// Party
|
||||||
ComposedSchema party = (ComposedSchema) openAPI.getComponents().getSchemas().get("Party");
|
ComposedSchema party = (ComposedSchema) openAPI.getComponents().getSchemas().get("Party");
|
||||||
List<Schema> partySchemas = party.getAllOf();
|
List<Schema> partySchemas = party.getAllOf();
|
||||||
Schema entity = ModelUtils.getReferencedSchema(openAPI, partySchemas.get(0));
|
Schema entity = modelUtils.getReferencedSchema(partySchemas.get(0));
|
||||||
Schema partyAllOf = ModelUtils.getReferencedSchema(openAPI, partySchemas.get(1));
|
Schema partyAllOf = modelUtils.getReferencedSchema(partySchemas.get(1));
|
||||||
|
|
||||||
assertEquals(partySchemas.get(0).get$ref(), "#/components/schemas/Entity");
|
assertEquals(partySchemas.get(0).get$ref(), "#/components/schemas/Entity");
|
||||||
assertEquals(partySchemas.get(1).get$ref(), "#/components/schemas/Party_allOf");
|
assertEquals(partySchemas.get(1).get$ref(), "#/components/schemas/Party_allOf");
|
||||||
@ -827,7 +837,7 @@ public class InlineModelResolverTest {
|
|||||||
|
|
||||||
// Contact
|
// Contact
|
||||||
ComposedSchema contact = (ComposedSchema) openAPI.getComponents().getSchemas().get("Contact");
|
ComposedSchema contact = (ComposedSchema) openAPI.getComponents().getSchemas().get("Contact");
|
||||||
Schema contactAllOf = ModelUtils.getReferencedSchema(openAPI, contact.getAllOf().get(1));
|
Schema contactAllOf = modelUtils.getReferencedSchema(contact.getAllOf().get(1));
|
||||||
|
|
||||||
assertEquals(contact.getExtensions().get("x-discriminator-value"), "contact");
|
assertEquals(contact.getExtensions().get("x-discriminator-value"), "contact");
|
||||||
assertEquals(contact.getAllOf().get(0).get$ref(), "#/components/schemas/Party");
|
assertEquals(contact.getAllOf().get(0).get$ref(), "#/components/schemas/Party");
|
||||||
@ -838,7 +848,7 @@ public class InlineModelResolverTest {
|
|||||||
// Customer
|
// Customer
|
||||||
ComposedSchema customer = (ComposedSchema) openAPI.getComponents().getSchemas().get("Customer");
|
ComposedSchema customer = (ComposedSchema) openAPI.getComponents().getSchemas().get("Customer");
|
||||||
List<Schema> customerSchemas = customer.getAllOf();
|
List<Schema> customerSchemas = customer.getAllOf();
|
||||||
Schema customerAllOf = ModelUtils.getReferencedSchema(openAPI, customerSchemas.get(1));
|
Schema customerAllOf = modelUtils.getReferencedSchema(customerSchemas.get(1));
|
||||||
|
|
||||||
assertEquals(customerSchemas.get(0).get$ref(), "#/components/schemas/Party");
|
assertEquals(customerSchemas.get(0).get$ref(), "#/components/schemas/Party");
|
||||||
assertNull(customer.getDiscriminator());
|
assertNull(customer.getDiscriminator());
|
||||||
@ -858,7 +868,7 @@ public class InlineModelResolverTest {
|
|||||||
// Person
|
// Person
|
||||||
ComposedSchema person = (ComposedSchema) openAPI.getComponents().getSchemas().get("Person");
|
ComposedSchema person = (ComposedSchema) openAPI.getComponents().getSchemas().get("Person");
|
||||||
List<Schema> personSchemas = person.getAllOf();
|
List<Schema> personSchemas = person.getAllOf();
|
||||||
Schema personAllOf = ModelUtils.getReferencedSchema(openAPI, personSchemas.get(1));
|
Schema personAllOf = modelUtils.getReferencedSchema(personSchemas.get(1));
|
||||||
|
|
||||||
// Discriminators are not defined at this level in the schema doc
|
// Discriminators are not defined at this level in the schema doc
|
||||||
assertEquals(personSchemas.get(0).get$ref(), "#/components/schemas/Customer");
|
assertEquals(personSchemas.get(0).get$ref(), "#/components/schemas/Customer");
|
||||||
@ -875,7 +885,7 @@ public class InlineModelResolverTest {
|
|||||||
// Organization
|
// Organization
|
||||||
ComposedSchema organization = (ComposedSchema) openAPI.getComponents().getSchemas().get("Organization");
|
ComposedSchema organization = (ComposedSchema) openAPI.getComponents().getSchemas().get("Organization");
|
||||||
List<Schema> organizationSchemas = organization.getAllOf();
|
List<Schema> organizationSchemas = organization.getAllOf();
|
||||||
Schema organizationAllOf = ModelUtils.getReferencedSchema(openAPI, organizationSchemas.get(1));
|
Schema organizationAllOf = modelUtils.getReferencedSchema(organizationSchemas.get(1));
|
||||||
|
|
||||||
// Discriminators are not defined at this level in the schema doc
|
// Discriminators are not defined at this level in the schema doc
|
||||||
assertEquals(organizationSchemas.get(0).get$ref(), "#/components/schemas/Customer");
|
assertEquals(organizationSchemas.get(0).get$ref(), "#/components/schemas/Customer");
|
||||||
@ -911,6 +921,7 @@ public class InlineModelResolverTest {
|
|||||||
public void emptyExampleOnStringTypeModels() {
|
public void emptyExampleOnStringTypeModels() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
MediaType mediaType = openAPI
|
MediaType mediaType = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -926,17 +937,18 @@ public class InlineModelResolverTest {
|
|||||||
ArraySchema schema = (ArraySchema) mediaType.getSchema();
|
ArraySchema schema = (ArraySchema) mediaType.getSchema();
|
||||||
assertEquals("#/components/schemas/EmptyExampleOnStringTypeModels", schema.getItems().get$ref());
|
assertEquals("#/components/schemas/EmptyExampleOnStringTypeModels", schema.getItems().get$ref());
|
||||||
|
|
||||||
assertTrue(ModelUtils.getReferencedSchema(openAPI, schema.getItems()) instanceof StringSchema);
|
assertTrue(modelUtils.getReferencedSchema(schema.getItems()) instanceof StringSchema);
|
||||||
assertNull(ModelUtils.getReferencedSchema(openAPI, schema.getItems()).getExample());
|
assertNull(modelUtils.getReferencedSchema(schema.getItems()).getExample());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullable() {
|
public void nullable() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
Schema nullablePropertyReference = (Schema) openAPI.getComponents().getSchemas().get("InlinePropertyIsNullable").getProperties().get("nullable_property");
|
Schema nullablePropertyReference = (Schema) openAPI.getComponents().getSchemas().get("InlinePropertyIsNullable").getProperties().get("nullable_property");
|
||||||
Schema nullablePropertySchema = ModelUtils.getReferencedSchema(openAPI, nullablePropertyReference);
|
Schema nullablePropertySchema = modelUtils.getReferencedSchema(nullablePropertyReference);
|
||||||
assertTrue(nullablePropertySchema.getNullable());
|
assertTrue(nullablePropertySchema.getNullable());
|
||||||
|
|
||||||
|
|
||||||
@ -950,7 +962,7 @@ public class InlineModelResolverTest {
|
|||||||
.getSchema()
|
.getSchema()
|
||||||
.getProperties()
|
.getProperties()
|
||||||
.get("nullable_request_body_property");
|
.get("nullable_request_body_property");
|
||||||
Schema nullableRequestBodySchema = ModelUtils.getReferencedSchema(openAPI, nullableRequestBodyReference);
|
Schema nullableRequestBodySchema = modelUtils.getReferencedSchema(nullableRequestBodyReference);
|
||||||
assertTrue(nullableRequestBodySchema.getNullable());
|
assertTrue(nullableRequestBodySchema.getNullable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,6 +970,7 @@ public class InlineModelResolverTest {
|
|||||||
public void callbacks() {
|
public void callbacks() {
|
||||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||||
new InlineModelResolver().flatten(openAPI);
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
|
|
||||||
RequestBody callbackRequestBodyReference = openAPI
|
RequestBody callbackRequestBodyReference = openAPI
|
||||||
.getPaths()
|
.getPaths()
|
||||||
@ -973,7 +986,7 @@ public class InlineModelResolverTest {
|
|||||||
RequestBody resolvedCallbackRequestBody = openAPI
|
RequestBody resolvedCallbackRequestBody = openAPI
|
||||||
.getComponents()
|
.getComponents()
|
||||||
.getRequestBodies()
|
.getRequestBodies()
|
||||||
.get(ModelUtils.getSimpleRef(callbackRequestBodyReference.get$ref()));
|
.get(modelUtils.getSimpleRef(callbackRequestBodyReference.get$ref()));
|
||||||
|
|
||||||
Schema callbackRequestSchemaReference = resolvedCallbackRequestBody
|
Schema callbackRequestSchemaReference = resolvedCallbackRequestBody
|
||||||
.getContent()
|
.getContent()
|
||||||
@ -984,7 +997,7 @@ public class InlineModelResolverTest {
|
|||||||
Schema resolvedCallbackSchema = openAPI
|
Schema resolvedCallbackSchema = openAPI
|
||||||
.getComponents()
|
.getComponents()
|
||||||
.getSchemas()
|
.getSchemas()
|
||||||
.get(ModelUtils.getSimpleRef(callbackRequestSchemaReference.get$ref()));
|
.get(modelUtils.getSimpleRef(callbackRequestSchemaReference.get$ref()));
|
||||||
|
|
||||||
Map properties = resolvedCallbackSchema.getProperties();
|
Map properties = resolvedCallbackSchema.getProperties();
|
||||||
assertTrue(properties.get("notificationId") instanceof StringSchema);
|
assertTrue(properties.get("notificationId") instanceof StringSchema);
|
||||||
|
@ -59,17 +59,19 @@ public class TestUtils {
|
|||||||
*/
|
*/
|
||||||
public static OpenAPI parseSpec(String specFilePath) {
|
public static OpenAPI parseSpec(String specFilePath) {
|
||||||
OpenAPI openAPI = new OpenAPIParser().readLocation(specFilePath, null, new ParseOptions()).getOpenAPI();
|
OpenAPI openAPI = new OpenAPIParser().readLocation(specFilePath, null, new ParseOptions()).getOpenAPI();
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
// Invoke helper function to get the original swagger version.
|
// Invoke helper function to get the original swagger version.
|
||||||
// See https://github.com/swagger-api/swagger-parser/pull/1374
|
// See https://github.com/swagger-api/swagger-parser/pull/1374
|
||||||
// Also see https://github.com/swagger-api/swagger-parser/issues/1369.
|
// Also see https://github.com/swagger-api/swagger-parser/issues/1369.
|
||||||
ModelUtils.getOpenApiVersion(openAPI, specFilePath, null);
|
modelUtils.getOpenApiVersion(specFilePath, null);
|
||||||
return openAPI;
|
return openAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OpenAPI parseContent(String jsonOrYaml) {
|
public static OpenAPI parseContent(String jsonOrYaml) {
|
||||||
OpenAPI openAPI = new OpenAPIParser().readContents(jsonOrYaml, null, null).getOpenAPI();
|
OpenAPI openAPI = new OpenAPIParser().readContents(jsonOrYaml, null, null).getOpenAPI();
|
||||||
|
ModelUtils modelUtils = new ModelUtils(openAPI);
|
||||||
// Invoke helper function to get the original swagger version.
|
// Invoke helper function to get the original swagger version.
|
||||||
ModelUtils.getOpenApiVersion(openAPI, jsonOrYaml, null);
|
modelUtils.getOpenApiVersion(jsonOrYaml, null);
|
||||||
return openAPI;
|
return openAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,23 +72,23 @@ public class AbstractGoCodegenTest {
|
|||||||
|
|
||||||
// Create an array schema with item type set to the array alias
|
// Create an array schema with item type set to the array alias
|
||||||
Schema<?> schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
Schema<?> schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
|
ModelUtils modelUtils = new ModelUtils(codegen.getOpenAPI());
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
String defaultValue = codegen.getTypeDeclaration(schema);
|
String defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "[][]int32");
|
Assert.assertEquals(defaultValue, "[][]int32");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "[]NestedArray");
|
Assert.assertEquals(defaultValue, "[]NestedArray");
|
||||||
|
|
||||||
// Create a map schema with additionalProperties type set to array alias
|
// Create a map schema with additionalProperties type set to array alias
|
||||||
schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray"));
|
schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "map[string][]int32");
|
Assert.assertEquals(defaultValue, "map[string][]int32");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "map[string]NestedArray");
|
Assert.assertEquals(defaultValue, "map[string]NestedArray");
|
||||||
}
|
}
|
||||||
|
@ -418,26 +418,27 @@ public class AbstractJavaCodegenTest {
|
|||||||
// Create an alias to an array schema
|
// Create an alias to an array schema
|
||||||
Schema<?> nestedArraySchema = new ArraySchema().items(new IntegerSchema().format("int32"));
|
Schema<?> nestedArraySchema = new ArraySchema().items(new IntegerSchema().format("int32"));
|
||||||
codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("NestedArray", nestedArraySchema)));
|
codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("NestedArray", nestedArraySchema)));
|
||||||
|
ModelUtils modelUtils = new ModelUtils(codegen.getOpenAPI());
|
||||||
|
|
||||||
// Create an array schema with item type set to the array alias
|
// Create an array schema with item type set to the array alias
|
||||||
schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
defaultValue = codegen.toDefaultValue(schema);
|
defaultValue = codegen.toDefaultValue(schema);
|
||||||
Assert.assertEquals(defaultValue, "new ArrayList<List<Integer>>()");
|
Assert.assertEquals(defaultValue, "new ArrayList<List<Integer>>()");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.toDefaultValue(schema);
|
defaultValue = codegen.toDefaultValue(schema);
|
||||||
Assert.assertEquals(defaultValue, "new ArrayList<NestedArray>()");
|
Assert.assertEquals(defaultValue, "new ArrayList<NestedArray>()");
|
||||||
|
|
||||||
// Create a map schema with additionalProperties type set to array alias
|
// Create a map schema with additionalProperties type set to array alias
|
||||||
schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray"));
|
schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
defaultValue = codegen.toDefaultValue(schema);
|
defaultValue = codegen.toDefaultValue(schema);
|
||||||
Assert.assertEquals(defaultValue, "new HashMap<String, List<Integer>>()");
|
Assert.assertEquals(defaultValue, "new HashMap<String, List<Integer>>()");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.toDefaultValue(schema);
|
defaultValue = codegen.toDefaultValue(schema);
|
||||||
Assert.assertEquals(defaultValue, "new HashMap<String, NestedArray>()");
|
Assert.assertEquals(defaultValue, "new HashMap<String, NestedArray>()");
|
||||||
|
|
||||||
@ -483,15 +484,16 @@ public class AbstractJavaCodegenTest {
|
|||||||
// Create an alias to an array schema
|
// Create an alias to an array schema
|
||||||
Schema<?> nestedArraySchema = new ArraySchema().items(new IntegerSchema().format("int32"));
|
Schema<?> nestedArraySchema = new ArraySchema().items(new IntegerSchema().format("int32"));
|
||||||
codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("NestedArray", nestedArraySchema)));
|
codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("NestedArray", nestedArraySchema)));
|
||||||
|
ModelUtils modelUtils = new ModelUtils(codegen.getOpenAPI());
|
||||||
|
|
||||||
// Create an array schema with item type set to the array alias
|
// Create an array schema with item type set to the array alias
|
||||||
schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "List<List<Integer>>");
|
Assert.assertEquals(defaultValue, "List<List<Integer>>");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "List<NestedArray>");
|
Assert.assertEquals(defaultValue, "List<NestedArray>");
|
||||||
|
|
||||||
@ -499,22 +501,22 @@ public class AbstractJavaCodegenTest {
|
|||||||
schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
schema.setUniqueItems(true);
|
schema.setUniqueItems(true);
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "Set<List<Integer>>");
|
Assert.assertEquals(defaultValue, "Set<List<Integer>>");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "Set<NestedArray>");
|
Assert.assertEquals(defaultValue, "Set<NestedArray>");
|
||||||
|
|
||||||
// Create a map schema with additionalProperties type set to array alias
|
// Create a map schema with additionalProperties type set to array alias
|
||||||
schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray"));
|
schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "Map<String, List<Integer>>");
|
Assert.assertEquals(defaultValue, "Map<String, List<Integer>>");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "Map<String, NestedArray>");
|
Assert.assertEquals(defaultValue, "Map<String, NestedArray>");
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ public class PythonClientTest {
|
|||||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml");
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml");
|
||||||
final DefaultCodegen codegen = new PythonClientCodegen();
|
final DefaultCodegen codegen = new PythonClientCodegen();
|
||||||
|
|
||||||
Schema modelSchema = ModelUtils.getSchema(openAPI, "DateTimeTest");
|
Schema modelSchema = codegen.getModelUtils().getSchema("DateTimeTest");
|
||||||
String defaultValue = codegen.toDefaultValue(modelSchema);
|
String defaultValue = codegen.toDefaultValue(modelSchema);
|
||||||
Assert.assertEquals(defaultValue, "dateutil_parser('2010-01-01T10:10:10.000111+01:00')");
|
Assert.assertEquals(defaultValue, "dateutil_parser('2010-01-01T10:10:10.000111+01:00')");
|
||||||
}
|
}
|
||||||
@ -421,7 +421,7 @@ public class PythonClientTest {
|
|||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
String modelName = "FreeFormWithValidation";
|
String modelName = "FreeFormWithValidation";
|
||||||
Schema modelSchema = ModelUtils.getSchema(openAPI, modelName);
|
Schema modelSchema = codegen.getModelUtils().getSchema(modelName);
|
||||||
final CodegenModel model = codegen.fromModel(modelName, modelSchema);
|
final CodegenModel model = codegen.fromModel(modelName, modelSchema);
|
||||||
Assert.assertEquals((int) model.getMinProperties(), 1);
|
Assert.assertEquals((int) model.getMinProperties(), 1);
|
||||||
}
|
}
|
||||||
|
@ -25,19 +25,21 @@ public class TypeScriptClientCodegenTest {
|
|||||||
new Schema().$ref("#/components/schemas/Child")
|
new Schema().$ref("#/components/schemas/Child")
|
||||||
);
|
);
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
ModelUtils modelUtils = new ModelUtils(api);
|
||||||
|
|
||||||
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Array<string>>");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Array<string>>");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Child>");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Child>");
|
||||||
|
|
||||||
// Same for Map
|
// Same for Map
|
||||||
parentSchema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/Child"));
|
parentSchema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/Child"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Array<string>; }");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Array<string>; }");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
Schema<?> childSchema = new ArraySchema().items(new StringSchema());
|
Schema<?> childSchema = new ArraySchema().items(new StringSchema());
|
||||||
|
|
||||||
OpenAPI api = TestUtils.createOpenAPI();
|
OpenAPI api = TestUtils.createOpenAPI();
|
||||||
|
ModelUtils modelUtils = new ModelUtils(api);
|
||||||
api.getComponents().addSchemas("Child", childSchema);
|
api.getComponents().addSchemas("Child", childSchema);
|
||||||
|
|
||||||
TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();
|
TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
@ -86,19 +87,19 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
new Schema().$ref("#/components/schemas/Child")
|
new Schema().$ref("#/components/schemas/Child")
|
||||||
);
|
);
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Array<string>>");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Array<string>>");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Child>");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Child>");
|
||||||
|
|
||||||
// Same for Map
|
// Same for Map
|
||||||
parentSchema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/Child"));
|
parentSchema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/Child"));
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(false);
|
modelUtils.setGenerateAliasAsModel(false);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Array<string>; }");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Array<string>; }");
|
||||||
|
|
||||||
ModelUtils.setGenerateAliasAsModel(true);
|
modelUtils.setGenerateAliasAsModel(true);
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }");
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ import java.util.Locale;
|
|||||||
/*
|
/*
|
||||||
import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME;
|
import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME;
|
||||||
import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue;
|
import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue;
|
||||||
import static io.swagger.codegen.utils.ModelUtils.updateCodegenPropertyEnum;
|
import static io.swagger.codegen.utils.modelUtils.updateCodegenPropertyEnum;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@SuppressWarnings("static-method")
|
@SuppressWarnings("static-method")
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user