Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ff52894
Schema mixnins and base classes removed, validate added, output class…
spacether Jun 14, 2023
d7d1a0e
Updates passed types in api_client and api_response
spacether Jul 4, 2023
d51efe4
Does not run validation twice for unstances of ouput clas for object …
spacether Jul 4, 2023
3705a1f
Adds tests that verify that array and object validations are not run …
spacether Jul 4, 2023
c1b8ef1
Fixes schema ouput class instantiation to use super new
spacether Jul 5, 2023
9a87cb0
Renames two new templates to validate
spacether Jul 5, 2023
f2fdf26
Renames two last new templates to _helper_prefix_ref_property_value_t…
spacether Jul 5, 2023
f973754
Removes two unused templates
spacether Jul 5, 2023
fee9a4e
Adds new method to array output class
spacether Jul 5, 2023
4d28a70
Adds new method to object output classes
spacether Jul 5, 2023
f88c767
Adds test_dict_validate_using_output_class
spacether Jul 5, 2023
4f42819
Adds test_list_validate_using_output_class
spacether Jul 5, 2023
c2bcfa7
Replaces immutabledict.immutabledict with schemas.immutabledict
spacether Jul 5, 2023
2d7b629
Removes unneeded init methods for dict output classes
spacether Jul 5, 2023
cd37113
Removes unneeded immutabledict imports
spacether Jul 5, 2023
4f30a19
Fixes operation code samples in docs
spacether Jul 5, 2023
e2d8f5d
Silences schema not found warnings
spacether Jul 5, 2023
8245732
Adds requestBodySchemas to codegenOperation
spacether Jul 5, 2023
39dbf9f
Updates RequestBodySchemas jsonPathPiece names
spacether Jul 5, 2023
0799c14
Adds request body schema imports
spacether Jul 6, 2023
7dfe54c
Shortens request body schema imports in operation.py
spacether Jul 6, 2023
8ddaf72
Reverts content schema imports to be direct
spacether Jul 6, 2023
ad39d7f
Fixes response ApiRespinse body definition
spacether Jul 6, 2023
7c08f2c
Removes content and content type init imports
spacether Jul 6, 2023
e7c14c1
Fixes testResponseWithNoSchemaInHeaders
spacether Jul 6, 2023
ca2201a
Fixes bug in detecting param required that broke two java tests
spacether Jul 6, 2023
44b8f23
Samples regenerated
spacether Jul 6, 2023
25a9d54
Fixes test of noncomplintdisc sample
spacether Jul 6, 2023
cfa8bb9
Fixes some tests
spacether Jul 6, 2023
4eb76e0
Fixes path test validate typo
spacether Jul 7, 2023
d73a190
Allows int or float into int schemas because values like 1.0 need to …
spacether Jul 7, 2023
f20e210
Adds Bool class and uses it during validation only
spacether Jul 7, 2023
c6fd270
Fixes the last of the unit test sample tests
spacether Jul 7, 2023
943f6e7
Samples updated
spacether Jul 7, 2023
554c6d9
Fixes two python tests
spacether Jul 7, 2023
219aeb5
Fixes last broken test in petstore
spacether Jul 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,10 @@ private void generateContent(List<File> files, LinkedHashMap<CodegenKey, Codegen
String templateFile = contentTypeEntry.getKey();
String outputFile = contentTypeEntry.getValue();
String outputFilepath = config.getFilepath(contentTypeJsonPath) + File.separatorChar + outputFile;
HashMap<String, Object> contentTypeTemplateData = new HashMap<>();
contentTypeTemplateData.put("schema", schema);
try {
File written = processTemplateToFile(new HashMap<>(), templateFile, outputFilepath, true, CodegenConstants.CONTENT);
File written = processTemplateToFile(contentTypeTemplateData, templateFile, outputFilepath, true, CodegenConstants.CONTENT);
if (written != null) {
files.add(written);
if (config.isEnablePostProcessFile() && !dryRun) {
Expand All @@ -602,8 +604,10 @@ private void generateContent(List<File> files, LinkedHashMap<CodegenKey, Codegen
String contentTemplateFile = contentEntry.getKey();
String outputFile = contentEntry.getValue();
String outputFilepath = config.getFilepath(contentJsonPath) + File.separatorChar + outputFile;
HashMap<String, Object> contentTemplateData = new HashMap<>();
contentTemplateData.put("content", content);
try {
File written = processTemplateToFile(new HashMap<>(), contentTemplateFile, outputFilepath, true, CodegenConstants.CONTENT);
File written = processTemplateToFile(contentTemplateData, contentTemplateFile, outputFilepath, true, CodegenConstants.CONTENT);
if (written != null) {
files.add(written);
if (config.isEnablePostProcessFile() && !dryRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AbstractPythonCodegen() {
"False", "async", "await",
// imports, imports_schema_types.handlebars, include these to prevent name collision
"datetime", "decimal", "functools", "io", "re",
"typing", "typing_extensions", "uuid", "frozendict", "schemas"
"typing", "typing_extensions", "uuid", "immutabledict", "schemas"
));

languageSpecificPrimitives.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public PythonClientCodegen() {
"return", "def", "for", "lambda", "try", "self", "nonlocal", "None", "True",
"False", "async", "await",
// types
"float", "int", "str", "bool", "dict", "frozendict", "list", "tuple"));
"float", "int", "str", "bool", "dict", "immutabledict", "list", "tuple"));

regexModifiers = new HashMap<>();
regexModifiers.put('i', "IGNORECASE");
Expand Down Expand Up @@ -310,13 +310,13 @@ public PythonClientCodegen() {
GlobalSettings.setProperty("x-disallow-additional-properties-if-not-present", "false");

// this tells users what openapi types turn in to
instantiationTypes.put("object", "frozendict.frozendict");
instantiationTypes.put("object", "immutabledict.immutabledict");
instantiationTypes.put("array", "tuple");
instantiationTypes.put("string", "str");
instantiationTypes.put("number", "decimal.Decimal");
instantiationTypes.put("integer", "decimal.Decimal");
instantiationTypes.put("boolean", "schemas.BoolClass");
instantiationTypes.put("null", "schemas.NoneClass");
instantiationTypes.put("number", "typing.Union[float, int]");
instantiationTypes.put("integer", "int");
instantiationTypes.put("boolean", "bool");
instantiationTypes.put("null", "None");

languageSpecificPrimitives.add("file_type");
languageSpecificPrimitives.add("none_type");
Expand Down Expand Up @@ -722,7 +722,11 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("api_client.hbs", packagePath(), "api_client.py"));
supportingFiles.add(new SupportingFile("api_response.hbs", packagePath(), "api_response.py"));
supportingFiles.add(new SupportingFile("rest.hbs", packagePath(), "rest.py"));
supportingFiles.add(new SupportingFile("schemas.hbs", packagePath(), "schemas.py"));
supportingFiles.add(new SupportingFile("schemas/__init__.hbs", packagePath() + File.separator + "schemas", "__init__.py"));
supportingFiles.add(new SupportingFile("schemas/validation.hbs", packagePath() + File.separator + "schemas", "validation.py"));
supportingFiles.add(new SupportingFile("schemas/schema.hbs", packagePath() + File.separator + "schemas", "schema.py"));
supportingFiles.add(new SupportingFile("schemas/schemas.hbs", packagePath() + File.separator + "schemas", "schemas.py"));
supportingFiles.add(new SupportingFile("schemas/format.hbs", packagePath() + File.separator + "schemas", "format.py"));
supportingFiles.add(new SupportingFile("security_schemes.hbs", packagePath(), "security_schemes.py"));
supportingFiles.add(new SupportingFile("server.hbs", packagePath(), "server.py"));

Expand Down Expand Up @@ -1299,10 +1303,16 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
}
if (null != schema.get$ref()) {
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
String ref = ModelUtils.getSimpleRef(schema.get$ref());
String refValue = schema.get$ref();
String ref = ModelUtils.getSimpleRef(refValue);
Schema refSchema = allDefinitions.get(ref);
if (null == refSchema) {
LOGGER.warn("Unable to find referenced schema " + schema.get$ref() + "\n");
if (refValue.startsWith("#/components/schemas/")) {
LOGGER.warn("Unable to find referenced schema " + refValue + "\n");
}
// TODO get examples working for refs like
// #/paths/~1fake~1parameterCollisions~1{1}~1{aB}~1{Ab}~1{self}~1{A-B}~1/post/parameters/5/schema
// #/components/responses/SuccessInlineContentAndHeader/headers/someHeader/schema
return fullPrefix + "None" + closeChars;
}
String refModelName = getRefClassWithRefModule(schema);
Expand Down Expand Up @@ -1858,15 +1868,6 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> dat
return data;
}

@Override
protected String getImport(String className, CodegenSchema schema) {
if (className == null) {
return "from " + packageName() + ".components.schema import " + schema.refInfo.refModule;
}
String[] classPieces = className.split("\\.");
return "from " + packageName() + ".components.schema import " + classPieces[0];
}

@Override
protected String getRefClassWithModule(String ref, String sourceJsonPath) {
String refModule = toRefModule(ref, sourceJsonPath, "schemas");
Expand Down Expand Up @@ -1961,14 +1962,79 @@ private String toSchemaRefClass(String ref, String sourceJsonPath) {
if (sourceJsonPath != null && ref.startsWith(sourceJsonPath + "/")) {
// internal in-schema reference, no import needed
// TODO handle this in the future
return null;
if (getFilepath(sourceJsonPath).equals(getFilepath(ref))) {
// TODO ensure that getFilepath returns the same file for somePath/get/QueryParameters
// TODO ensure that getFilepath returns the same file for schemas/SomeSchema...
return null;
}
}
// reference is external, import needed
// module info is stored in refModule
if (ref.startsWith("#/components/schemas/") && refPieces.length == 4) {
String schemaName = refPieces[3];
return toModelName(schemaName, ref);
}
if (ref.startsWith("#/components/parameters/")) {
if (refPieces.length == 5) {
// #/components/parameters/PathUserName/schema
String schemaName = refPieces[4];
return toModelName(schemaName, ref);
}
if (refPieces.length == 7) {
// #/components/parameters/PathUserName/content/mediaType/schema
String schemaName = refPieces[6];
return toModelName(schemaName, ref);
}
}
if (ref.startsWith("#/components/headers/")) {
if (refPieces.length == 5) {
// #/components/headers/Int32JsonContentTypeHeader/schema
String schemaName = refPieces[4];
return toModelName(schemaName, ref);
}
if (refPieces.length == 7) {
// #/components/headers/Int32JsonContentTypeHeader/content/application~1json/schema
String schemaName = refPieces[6];
return toModelName(schemaName, ref);
}
}
if (ref.startsWith("#/components/responses/")) {
if (refPieces.length == 7) {
// #/components/responses/SuccessInlineContentAndHeader/headers/someHeader/schema
String schemaName = refPieces[6];
return toModelName(schemaName, ref);
}
if (refPieces.length == 9) {
// #/components/responses/SuccessInlineContentAndHeader/headers/someHeader/content/application~1json/schema
String schemaName = refPieces[8];
return toModelName(schemaName, ref);
}
}
if (ref.startsWith("#/paths/")) {
if (refPieces.length == 7) {
// #/paths/~1pet~1{petId}/get/parameters/0/schema
String schemaName = refPieces[6];
return toModelName(schemaName, ref);
} else if (refPieces.length == 8) {
// #/paths/~1user~1login/get/responses/200/headers/X-Rate-Limit/schema
String schemaName = refPieces[7];
return toModelName(schemaName, ref);
} else if (refPieces.length == 9) {
// #/paths/~1pet~1{petId}/get/parameters/0/content/mediaType/schema
// #/paths/~1user~1login/get/responses/200/headers/X-Rate-Limit/schema
String schemaName = refPieces[8];
return toModelName(schemaName, ref);
} else if (refPieces.length == 10) {
// #/paths/~1user~1login/get/responses/200/headers/X-Rate-Limit/content/application~1json/schema
String schemaName = refPieces[9];
return toModelName(schemaName, ref);
} else if (refPieces.length == 11) {
// #/paths/~1user~1login/get/responses/200/headers/X-Rate-Limit/content/application~1json/schema
String schemaName = refPieces[10];
return toModelName(schemaName, ref);
}

}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ public CodegenHeader(String description, String unescapedDescription, String exa
this.refInfo = refInfo;
}

public CodegenHeader getSelfOrDeepestRef() {
CodegenHeader selfOrRefParam = this;
while (selfOrRefParam.refInfo != null) {
selfOrRefParam = selfOrRefParam.refInfo.ref;
}
return selfOrRefParam;
}

public String getSchemaJsonPath() {
CodegenHeader selfOrRefParam = this;
while (selfOrRefParam.refInfo != null) {
selfOrRefParam = selfOrRefParam.refInfo.ref;
}
// parameter is now de-referenced
CodegenSchema schema = null;
if (selfOrRefParam.schema != null) {
schema = selfOrRefParam.schema;
} else {
CodegenKey contentTypeKey = selfOrRefParam.content.keySet().iterator().next();
schema = selfOrRefParam.content.get(contentTypeKey).schema;
}
schema = schema.getSelfOrDeepestRef();
return schema.jsonPath;
}

@Override
public int hashCode() {
return Objects.hash(jsonPathPiece, explode, description, unescapedDescription, style, example, vendorExtensions, deprecated, required, schema, content, refInfo, imports, componentModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ public class CodegenOperation {
public final LinkedHashSet<String> produces;
public final List<CodegenServer> servers;
public final CodegenRequestBody requestBody;
public final List<CodegenSchema> requestBodySchemas;
public final List<CodegenParameter> allParams;
public final List<CodegenParameter> pathParams;
public final boolean hasRequiredPathParams;
public final CodegenSchema pathParameters;
public final List<CodegenParameter> queryParams;
public final boolean hasRequiredQueryParams;
public final CodegenSchema queryParameters;
public final List<CodegenParameter> headerParams;
public final boolean hasRequiredHeaderParams;
public final CodegenSchema headerParameters;
public final List<CodegenParameter> cookieParams;
public final boolean hasRequiredCookieParams;
public final CodegenSchema cookieParameters;
public final boolean hasRequiredParamOrBody;
public final boolean hasOptionalParamOrBody;
public final List<HashMap<String, CodegenSecurityRequirementValue>> security;
Expand All @@ -54,7 +55,7 @@ public class CodegenOperation {
public final CodegenKey operationId;
public final CodegenKey jsonPathPiece;

public CodegenOperation(Boolean deprecated, boolean hasErrorResponseObject, String summary, String unescapedDescription, String description, LinkedHashSet<String> produces, List<CodegenServer> servers, CodegenRequestBody requestBody, List<CodegenParameter> allParams, List<CodegenParameter> pathParams, List<CodegenParameter> queryParams, List<CodegenParameter> headerParams, List<CodegenParameter> cookieParams, boolean hasRequiredParamOrBody, boolean hasOptionalParamOrBody, List<HashMap<String, CodegenSecurityRequirementValue>> security, Map<String, CodegenTag> tags, TreeMap<String, CodegenResponse> responses, TreeMap<Integer, CodegenResponse> statusCodeResponses, TreeMap<Integer, CodegenResponse> wildcardCodeResponses, TreeMap<String, CodegenResponse> nonDefaultResponses, CodegenResponse defaultResponse, List<CodegenCallback> callbacks, ExternalDocumentation externalDocs, Map<String, Object> vendorExtensions, CodegenKey operationId, CodegenKey jsonPathPiece) {
public CodegenOperation(Boolean deprecated, boolean hasErrorResponseObject, String summary, String unescapedDescription, String description, LinkedHashSet<String> produces, List<CodegenServer> servers, CodegenRequestBody requestBody, List<CodegenSchema> requestBodySchemas, List<CodegenParameter> allParams, List<CodegenParameter> pathParams, CodegenSchema pathParameters, List<CodegenParameter> queryParams, CodegenSchema queryParameters, List<CodegenParameter> headerParams, CodegenSchema headerParameters, List<CodegenParameter> cookieParams, CodegenSchema cookieParameters, boolean hasRequiredParamOrBody, boolean hasOptionalParamOrBody, List<HashMap<String, CodegenSecurityRequirementValue>> security, Map<String, CodegenTag> tags, TreeMap<String, CodegenResponse> responses, TreeMap<Integer, CodegenResponse> statusCodeResponses, TreeMap<Integer, CodegenResponse> wildcardCodeResponses, TreeMap<String, CodegenResponse> nonDefaultResponses, CodegenResponse defaultResponse, List<CodegenCallback> callbacks, ExternalDocumentation externalDocs, Map<String, Object> vendorExtensions, CodegenKey operationId, CodegenKey jsonPathPiece) {
this.deprecated = deprecated;
this.hasErrorResponseObject = hasErrorResponseObject;
this.summary = summary;
Expand All @@ -63,59 +64,16 @@ public CodegenOperation(Boolean deprecated, boolean hasErrorResponseObject, Stri
this.produces = produces;
this.servers = servers;
this.requestBody = requestBody;
this.requestBodySchemas = requestBodySchemas;
this.allParams = allParams;
this.pathParams = pathParams;
if (pathParams == null) {
this.hasRequiredPathParams = false;
} else {
boolean val = false;
for (CodegenParameter p: pathParams) {
if (Boolean.TRUE.equals(p.required)) {
val = true;
break;
}
}
this.hasRequiredPathParams = val;
}
this.pathParameters = pathParameters;
this.queryParams = queryParams;
if (queryParams == null) {
this.hasRequiredQueryParams = false;
} else {
boolean val = false;
for (CodegenParameter p: queryParams) {
if (Boolean.TRUE.equals(p.required)) {
val = true;
break;
}
}
this.hasRequiredQueryParams = val;
}
this.queryParameters = queryParameters;
this.headerParams = headerParams;
if (headerParams == null) {
this.hasRequiredHeaderParams = false;
} else {
boolean val = false;
for (CodegenParameter p: headerParams) {
if (Boolean.TRUE.equals(p.required)) {
val = true;
break;
}
}
this.hasRequiredHeaderParams = val;
}
this.headerParameters = headerParameters;
this.cookieParams = cookieParams;
if (cookieParams == null) {
this.hasRequiredCookieParams = false;
} else {
boolean val = false;
for (CodegenParameter p: cookieParams) {
if (Boolean.TRUE.equals(p.required)) {
val = true;
break;
}
}
this.hasRequiredCookieParams = val;
}
this.cookieParameters = cookieParameters;
this.hasRequiredParamOrBody = hasRequiredParamOrBody;
this.hasOptionalParamOrBody = hasOptionalParamOrBody;
this.security = security;
Expand Down Expand Up @@ -221,6 +179,7 @@ public String toString() {
sb.append(", produces=").append(produces);
sb.append(", servers=").append(servers);
sb.append(", requestBody=").append(requestBody);
sb.append(", requestBodySchemas=").append(requestBodySchemas);
sb.append(", allParams=").append(allParams);
sb.append(", pathParams=").append(pathParams);
sb.append(", queryParams=").append(queryParams);
Expand Down Expand Up @@ -256,6 +215,7 @@ public boolean equals(Object o) {
Objects.equals(produces, that.produces) &&
Objects.equals(servers, that.servers) &&
Objects.equals(requestBody, that.requestBody) &&
Objects.equals(requestBodySchemas, that.requestBodySchemas) &&
Objects.equals(allParams, that.allParams) &&
Objects.equals(pathParams, that.pathParams) &&
Objects.equals(queryParams, that.queryParams) &&
Expand All @@ -280,7 +240,7 @@ public int hashCode() {

return Objects.hash(deprecated, operationId,
summary, unescapedDescription, description, defaultResponse,
produces, servers, requestBody, allParams,
produces, servers, requestBody, requestBodySchemas, allParams,
pathParams, queryParams, headerParams, cookieParams, hasRequiredParamOrBody, hasOptionalParamOrBody,
security, tags, responses, callbacks, externalDocs,
vendorExtensions, statusCodeResponses, wildcardCodeResponses,
Expand Down
Loading