Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

One of property creation missed #590

Merged
merged 11 commits into from
Jan 29, 2020
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@
<artifactId>testng</artifactId>
<version>${testng-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.swagger.codegen.v3.CodegenProperty;
import io.swagger.codegen.v3.CodegenResponse;
import io.swagger.codegen.v3.CodegenSecurity;
import io.swagger.codegen.v3.ISchemaHandler;
import io.swagger.codegen.v3.SupportingFile;
import io.swagger.codegen.v3.generators.examples.ExampleGenerator;
import io.swagger.codegen.v3.generators.handlebars.BaseItemsHelper;
Expand Down Expand Up @@ -160,7 +161,6 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
protected String httpUserAgent;
protected Boolean hideGenerationTimestamp = true;
protected TemplateEngine templateEngine = new HandlebarTemplateEngine(this);
protected SchemaHandler schemaHandler = new SchemaHandler(this);
// How to encode special characters like $
// They are translated to words like "Dollar" and prefixed with '
// Then translated back during JSON encoding and decoding
Expand Down Expand Up @@ -267,28 +267,6 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> processedMod
if (supportsInheritance) {
processCodegenModels(allModels);
}
for (String modelName : allModels.keySet()) {
final CodegenModel codegenModel = allModels.get(modelName);
if (!codegenModel.vendorExtensions.containsKey("x-is-composed-model")) {
continue;
}
List<String> modelNames = (List<String>) codegenModel.vendorExtensions.get("x-model-names");
if (modelNames == null || modelNames.isEmpty()) {
continue;
}
for (String name : modelNames) {
final CodegenModel model = allModels.get(name);
if (model == null) {
continue;
}
if (model.interfaceModels == null) {
model.interfaceModels = new ArrayList<>();
}
if (!model.interfaceModels.stream().anyMatch(value -> value.name.equalsIgnoreCase(modelName))) {
model.interfaceModels.add(codegenModel);
}
}
}
return processedModels;
}

Expand Down Expand Up @@ -1299,12 +1277,6 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
if (schema instanceof ArraySchema) {
codegenModel.getVendorExtensions().put(IS_ARRAY_MODEL_EXT_NAME, Boolean.TRUE);
codegenModel.getVendorExtensions().put(IS_CONTAINER_EXT_NAME, Boolean.TRUE);

final Schema items = ((ArraySchema) schema).getItems();
if (items != null && items instanceof ComposedSchema) {
schemaHandler.configureComposedModelFromSchemaItems(codegenModel, ((ComposedSchema) items));
}

codegenModel.arrayModelType = fromProperty(name, schema).complexType;
addParentContainer(codegenModel, name, schema);
}
Expand Down Expand Up @@ -1357,11 +1329,7 @@ else if (schema instanceof ComposedSchema) {
// parent model
final String parentName = getParentName(composed);
final Schema parent = StringUtils.isBlank(parentName) ? null : allDefinitions.get(parentName);

final List<Schema> allOf = composed.getAllOf();
final List<Schema> oneOf = composed.getOneOf();
final List<Schema> anyOf = composed.getAnyOf();

// interfaces (intermediate models)
if (allOf != null && !allOf.isEmpty()) {
for (int i = 0; i < allOf.size(); i++) {
Expand Down Expand Up @@ -1389,14 +1357,6 @@ else if (schema instanceof ComposedSchema) {
}
}
}
if (oneOf != null && !oneOf.isEmpty()) {
codegenModel.dataType = getSchemaType(composed);
this.schemaHandler.configureOneOfModel(codegenModel, oneOf);
}
if (anyOf != null && !anyOf.isEmpty()) {
codegenModel.dataType = getSchemaType(composed);
this.schemaHandler.configureAnyOfModel(codegenModel, anyOf);
}
if (parent != null) {
codegenModel.parentSchema = parentName;
codegenModel.parent = toModelName(parentName);
Expand Down Expand Up @@ -1704,9 +1664,6 @@ public CodegenProperty fromProperty(String name, Schema propertySchema) {
// handle inner property
CodegenProperty cp = fromProperty("inner", (Schema) propertySchema.getAdditionalProperties());
updatePropertyForMap(codegenProperty, cp);
} else if (propertySchema instanceof ComposedSchema) {
ComposedSchema composedProperty = (ComposedSchema) propertySchema;
this.schemaHandler.createCodegenModel(composedProperty, codegenProperty);
} else if (propertySchema instanceof MapSchema && hasTrueAdditionalProperties(propertySchema)) {

codegenProperty.getVendorExtensions().put(CodegenConstants.IS_CONTAINER_EXT_NAME, Boolean.TRUE);
Expand Down Expand Up @@ -3084,14 +3041,6 @@ private void addVars(CodegenModel codegenModel, List<CodegenProperty> vars, Map<
final CodegenProperty codegenProperty = fromProperty(key, propertySchema);
codegenProperty.required = mandatory.contains(key);

if (codegenProperty.vendorExtensions.containsKey("oneOf-model")) {
this.schemaHandler.configureOneOfModelFromProperty(codegenProperty, codegenModel);
}

if (codegenProperty.vendorExtensions.containsKey("anyOf-model")) {
this.schemaHandler.configureAnyOfModelFromProperty(codegenProperty, codegenModel);
}

if (propertySchema.get$ref() != null) {
if (this.openAPI == null) {
LOGGER.warn("open api utility object was not properly set.");
Expand Down Expand Up @@ -4284,4 +4233,8 @@ public void setIgnoreImportMapping(boolean ignoreImportMapping) {
public boolean defaultIgnoreImportMappingOption() {
return false;
}

public ISchemaHandler getSchemaHandler() {
return new SchemaHandler(this);
}
}
Loading