Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 094dafe

Browse files
committed
Changes IJsonSchemaValidationProperties to JsonSchema because that is the interface that it represents
Updates CodegenParameter, removes JsonSchema info Further updates to fromParameter call sites
1 parent d50d4a3 commit 094dafe

File tree

8 files changed

+33
-1379
lines changed

8 files changed

+33
-1379
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* CodegenModel represents a schema object in a OpenAPI document.
2929
*/
3030
@JsonIgnoreProperties({"parentModel", "interfaceModels"})
31-
public class CodegenModel implements IJsonSchemaValidationProperties {
31+
public class CodegenModel implements JsonSchema {
3232
// The parent model name from the schemas. The parent is determined by inspecting the allOf, anyOf and
3333
// oneOf attributes in the OAS. First codegen inspects 'allOf', then 'anyOf', then 'oneOf'.
3434
// If there are multiple object references in the attribute ('allOf', 'anyOf', 'oneOf'), and one of the

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java

Lines changed: 7 additions & 759 deletions
Large diffs are not rendered by default.

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.util.*;
2121

22-
public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperties {
22+
public class CodegenProperty implements Cloneable, JsonSchema {
2323
/**
2424
* The value of the 'type' attribute in the OpenAPI schema.
2525
* The per-language codegen logic may change to a language-specific type.

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.util.*;
2121

22-
public class CodegenResponse implements IJsonSchemaValidationProperties {
22+
public class CodegenResponse implements JsonSchema {
2323
public final List<CodegenProperty> headers = new ArrayList<CodegenProperty>();
2424
private List<CodegenParameter> responseHeaders = new ArrayList<CodegenParameter>();
2525
public String code;

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 11 additions & 575 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
1515
import org.openapitools.codegen.utils.ModelUtils;
1616

17-
public interface IJsonSchemaValidationProperties {
17+
public interface JsonSchema {
1818
CodegenProperty getContains();
1919

2020
void setContains(CodegenProperty contains);
@@ -216,7 +216,7 @@ public interface IJsonSchemaValidationProperties {
216216
String getFormat();
217217

218218
/**
219-
* Syncs all the schema's type properties into the IJsonSchemaValidationProperties instance
219+
* Syncs all the schema's type properties into the JsonSchema instance
220220
* for now this only supports types without format information
221221
* TODO: in the future move the format handling in here too
222222
* @param p the schema which contains the type info

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.swagger.v3.oas.models.tags.Tag;
2929

3030
import org.apache.commons.io.FileUtils;
31+
import org.openapitools.codegen.JsonSchema;
3132
import org.openapitools.codegen.api.TemplatePathLocator;
3233
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
3334
import org.openapitools.codegen.model.ModelMap;
@@ -67,7 +68,6 @@
6768

6869
import static org.openapitools.codegen.utils.OnceLogger.once;
6970
import static org.openapitools.codegen.utils.StringUtils.camelize;
70-
import static org.openapitools.codegen.utils.StringUtils.escape;
7171
import static org.openapitools.codegen.utils.StringUtils.underscore;
7272

7373
public class PythonClientCodegen extends AbstractPythonCodegen {
@@ -741,7 +741,7 @@ are defined in that schema (x.properties). We do this because validation should
741741
they are not.
742742
*/
743743
@Override
744-
protected void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValidationProperties property, String sourceJsonPath){
744+
protected void addVarsRequiredVarsAdditionalProps(Schema schema, JsonSchema property, String sourceJsonPath){
745745
setAddProps(schema, property, sourceJsonPath);
746746
if (ModelUtils.isAnyType(schema) && supportsAdditionalPropertiesWithComposedSchema) {
747747
// if anyType schema has properties then add them
@@ -1128,19 +1128,6 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
11281128
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName, String sourceJsonPath) {
11291129
CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName, sourceJsonPath);
11301130
cp.baseName = "body";
1131-
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
1132-
if (schema.get$ref() == null) {
1133-
return cp;
1134-
}
1135-
Schema unaliasedSchema = unaliasSchema(schema);
1136-
CodegenProperty unaliasedProp = fromProperty(
1137-
"body", unaliasedSchema, false, false, sourceJsonPath);
1138-
Boolean dataTypeMismatch = !cp.dataType.equals(unaliasedProp.dataType);
1139-
Boolean baseTypeMismatch = !cp.baseType.equals(unaliasedProp.refClass) && unaliasedProp.refClass != null;
1140-
if (dataTypeMismatch || baseTypeMismatch) {
1141-
cp.dataType = unaliasedProp.dataType;
1142-
cp.baseType = unaliasedProp.refClass;
1143-
}
11441131
return cp;
11451132
}
11461133

@@ -1183,10 +1170,7 @@ protected void addBodyModelSchema(CodegenParameter codegenParameter, String name
11831170
codegenParameter.baseName = bodyParameterName;
11841171
}
11851172
codegenParameter.paramName = toParamName(codegenParameter.baseName);
1186-
codegenParameter.baseType = codegenModel.classname;
1187-
codegenParameter.dataType = getTypeDeclaration(codegenModel.classname);
11881173
codegenParameter.description = codegenModel.description;
1189-
codegenParameter.isNullable = codegenModel.isNullable;
11901174
} else {
11911175
CodegenProperty codegenProperty = fromProperty("property", schema, false, false, sourceJsonPath);
11921176

@@ -1210,13 +1194,8 @@ protected void addBodyModelSchema(CodegenParameter codegenParameter, String name
12101194
}
12111195

12121196
codegenParameter.paramName = toParamName(codegenParameter.baseName);
1213-
codegenParameter.baseType = codegenModelName;
1214-
codegenParameter.dataType = getTypeDeclaration(codegenModelName);
12151197
codegenParameter.description = codegenModelDescription;
12161198
}
1217-
1218-
// set nullable
1219-
setParameterNullable(codegenParameter, codegenProperty);
12201199
}
12211200

12221201
}
@@ -1374,15 +1353,6 @@ protected List<Map<String, Object>> buildEnumVars(List<Object> values, String da
13741353
return enumVars;
13751354
}
13761355

1377-
@Override
1378-
public void postProcessParameter(CodegenParameter p) {
1379-
postProcessPattern(p.pattern, p.vendorExtensions);
1380-
if (p.baseType != null && languageSpecificPrimitives.contains(p.baseType)) {
1381-
// set baseType to null so the api docs will not point to a model for languageSpecificPrimitives
1382-
p.baseType = null;
1383-
}
1384-
}
1385-
13861356
/**
13871357
* Sets the value of the 'model.parent' property in CodegenModel
13881358
* We have a custom version of this function so we can add the dataType on the ArrayModel
@@ -2251,7 +2221,7 @@ protected Map<String, Schema> getModelNameToSchemaCache() {
22512221
* @param property the property for the above schema
22522222
*/
22532223
@Override
2254-
protected void setAddProps(Schema schema, IJsonSchemaValidationProperties property, String sourceJsonPath){
2224+
protected void setAddProps(Schema schema, JsonSchema property, String sourceJsonPath){
22552225
Schema addPropsSchema = getSchemaFromBooleanOrSchema(schema.getAdditionalProperties());
22562226
if (addPropsSchema == null) {
22572227
return;

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import io.swagger.v3.parser.util.SchemaTypeUtil;
3636
import org.apache.commons.lang3.StringUtils;
3737
import org.openapitools.codegen.CodegenModel;
38-
import org.openapitools.codegen.IJsonSchemaValidationProperties;
38+
import org.openapitools.codegen.JsonSchema;
3939
import org.openapitools.codegen.config.GlobalSettings;
4040
import org.openapitools.codegen.model.ModelMap;
4141
import org.openapitools.codegen.model.ModelsMap;
@@ -1623,8 +1623,8 @@ public static boolean isAnyType(Schema schema) {
16231623
return (schema.get$ref() == null && schema.getType() == null);
16241624
}
16251625

1626-
public static void syncValidationProperties(Schema schema, IJsonSchemaValidationProperties target) {
1627-
// TODO move this method to IJsonSchemaValidationProperties
1626+
public static void syncValidationProperties(Schema schema, JsonSchema target) {
1627+
// TODO move this method to JsonSchema
16281628
if (schema != null && target != null) {
16291629
if (isNullType(schema) || schema.get$ref() != null || isBooleanSchema(schema)) {
16301630
return;
@@ -1668,25 +1668,25 @@ public static void syncValidationProperties(Schema schema, IJsonSchemaValidation
16681668
}
16691669
}
16701670

1671-
private static void setArrayValidations(Integer minItems, Integer maxItems, Boolean uniqueItems, IJsonSchemaValidationProperties target) {
1671+
private static void setArrayValidations(Integer minItems, Integer maxItems, Boolean uniqueItems, JsonSchema target) {
16721672
if (minItems != null) target.setMinItems(minItems);
16731673
if (maxItems != null) target.setMaxItems(maxItems);
16741674
if (uniqueItems != null) target.setUniqueItems(uniqueItems);
16751675
if (uniqueItems != null) target.setUniqueItemsBoolean(uniqueItems);
16761676
}
16771677

1678-
private static void setObjectValidations(Integer minProperties, Integer maxProperties, IJsonSchemaValidationProperties target) {
1678+
private static void setObjectValidations(Integer minProperties, Integer maxProperties, JsonSchema target) {
16791679
if (minProperties != null) target.setMinProperties(minProperties);
16801680
if (maxProperties != null) target.setMaxProperties(maxProperties);
16811681
}
16821682

1683-
private static void setStringValidations(Integer minLength, Integer maxLength, String pattern, IJsonSchemaValidationProperties target) {
1683+
private static void setStringValidations(Integer minLength, Integer maxLength, String pattern, JsonSchema target) {
16841684
if (minLength != null) target.setMinLength(minLength);
16851685
if (maxLength != null) target.setMaxLength(maxLength);
16861686
if (pattern != null) target.setPattern(pattern);
16871687
}
16881688

1689-
private static void setNumericValidations(Schema schema, BigDecimal multipleOf, BigDecimal minimum, BigDecimal maximum, Boolean exclusiveMinimum, Boolean exclusiveMaximum, IJsonSchemaValidationProperties target) {
1689+
private static void setNumericValidations(Schema schema, BigDecimal multipleOf, BigDecimal minimum, BigDecimal maximum, Boolean exclusiveMinimum, Boolean exclusiveMaximum, JsonSchema target) {
16901690
if (multipleOf != null) target.setMultipleOf(multipleOf);
16911691
if (minimum != null) {
16921692
if (isIntegerSchema(schema)) {

0 commit comments

Comments
 (0)