diff --git a/bin/configs/python.yaml b/bin/configs/python.yaml index 12a23163bd6..4412061bc5e 100644 --- a/bin/configs/python.yaml +++ b/bin/configs/python.yaml @@ -1,6 +1,6 @@ generatorName: python outputDir: samples/openapi3/client/petstore/python -inputSpec: modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +inputSpec: modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore_customized.yaml templateDir: modules/openapi-json-schema-generator/src/main/resources/python additionalProperties: packageName: petstore_api diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java index fe916dc699c..5f1a60ca93f 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java @@ -22,6 +22,7 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.headers.Header; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.security.SecurityScheme; @@ -88,6 +89,10 @@ public interface CodegenConfig { String headerDocFileFolder(); + String parameterFileFolder(); + + String parameterDocFileFolder(); + String modelPackage(); String packageName(); @@ -180,6 +185,10 @@ public interface CodegenConfig { Map headerDocTemplateFiles(); + Map parameterTemplateFiles(); + + Map parameterDocTemplateFiles(); + Map pathEndpointTemplateFiles(); Set pathEndpointTestTemplateFiles(); @@ -244,9 +253,11 @@ public interface CodegenConfig { String toHeaderFilename(String componentName); - String toPathFileName(String path); + String toPathFilename(String path); + + String toParameterFilename(String baseName); - String toParameterFileName(String baseName); + String toParameterDocFilename(String componentName); String toModelImport(String refClass); @@ -403,4 +414,6 @@ public interface CodegenConfig { CodegenResponse fromResponse(ApiResponse response, String sourceJsonPath); CodegenHeader fromHeader(Header parameter, String sourceJsonPath); + + CodegenParameter fromParameter(Parameter parameter, String sourceJsonPath); } diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java index 82a470231e1..91db7748cde 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java @@ -33,6 +33,10 @@ public class CodegenConstants { public static final String HEADERS = "headers"; public static final String HEADER_DOCS = "headerDocs"; + + public static final String PARAMETERS = "parameters"; + + public static final String PARAMETER_DOCS = "parameterDocs"; public static final String SUPPORTING_FILES = "supportingFiles"; public static final String MODEL_TESTS = "modelTests"; public static final String MODEL_DOCS = "modelDocs"; diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java index 77bdfc483e0..1d2bcd1c97a 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java @@ -39,7 +39,6 @@ public class CodegenOperation { public List queryParams = new ArrayList(); public List headerParams = new ArrayList(); public List implicitHeadersParams = new ArrayList(); - public List formParams = new ArrayList(); public List cookieParams = new ArrayList(); public List requiredParams = new ArrayList(); public List optionalParams = new ArrayList(); @@ -121,22 +120,13 @@ public boolean getHasPathParams() { return nonEmpty(pathParams); } - /** - * Check if there's at least one form parameter - * - * @return true if any form parameter exists, false otherwise - */ - public boolean getHasFormParams() { - return nonEmpty(formParams); - } - /** * Check if there's at least one body parameter or at least one form parameter * * @return true if body or form parameter exists, false otherwise */ public boolean getHasBodyOrFormParams() { - return getHasBodyParam() || getHasFormParams(); + return getHasBodyParam(); } /** @@ -341,7 +331,6 @@ public String toString() { sb.append(", pathParams=").append(pathParams); sb.append(", queryParams=").append(queryParams); sb.append(", headerParams=").append(headerParams); - sb.append(", formParams=").append(formParams); sb.append(", cookieParams=").append(cookieParams); sb.append(", requiredParams=").append(requiredParams); sb.append(", optionalParams=").append(optionalParams); @@ -407,7 +396,6 @@ public boolean equals(Object o) { Objects.equals(pathParams, that.pathParams) && Objects.equals(queryParams, that.queryParams) && Objects.equals(headerParams, that.headerParams) && - Objects.equals(formParams, that.formParams) && Objects.equals(cookieParams, that.cookieParams) && Objects.equals(requiredParams, that.requiredParams) && Objects.equals(optionalParams, that.optionalParams) && @@ -440,7 +428,7 @@ public int hashCode() { isRestful, isDeprecated, isCallbackRequest, uniqueItems, path, operationId, httpMethod, summary, unescapedNotes, notes, baseName, defaultResponse, consumes, produces, prioritizedContentTypes, servers, requestBody, allParams, bodyParams, - pathParams, queryParams, headerParams, formParams, cookieParams, requiredParams, optionalParams, + pathParams, queryParams, headerParams, cookieParams, requiredParams, optionalParams, authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs, vendorExtensions, nickname, operationIdOriginal, operationIdLowerCase, operationIdCamelCase, operationIdSnakeCase, statusCodeResponses, wildcardCodeResponses, diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index bc50586f2c6..5df210f4646 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -199,6 +199,8 @@ apiTemplateFiles are for API outputs only (controllers/handlers). protected Map modelTestTemplateFiles = new HashMap<>(); protected Map apiDocTemplateFiles = new HashMap<>(); protected Map modelDocTemplateFiles = new HashMap<>(); + protected Map parameterTemplateFiles = new HashMap<>(); + protected Map parameterDocTemplateFiles = new HashMap<>(); protected Map reservedWordsMappings = new HashMap<>(); protected String templateDir; protected String embeddedTemplateDir; @@ -1230,6 +1232,12 @@ public Map modelTemplateFiles() { @Override public Map responseDocTemplateFiles() { return responseDocTemplateFiles; } + @Override + public Map parameterTemplateFiles() { return parameterTemplateFiles; } + + @Override + public Map parameterDocTemplateFiles() { return parameterDocTemplateFiles; } + @Override public Map pathEndpointTemplateFiles() { return pathEndpointTemplateFiles; } @@ -1307,6 +1315,12 @@ public String modelDocFileFolder() { @Override public String headerDocFileFolder() { return outputFolder; } + @Override + public String parameterFileFolder() { return outputFolder; } + + @Override + public String parameterDocFileFolder() { return outputFolder; } + @Override public Map additionalProperties() { return additionalProperties; @@ -1547,15 +1561,18 @@ public String toModuleFilename(String name) { return camelize(name); } - public String toPathFileName(String name) { + public String toPathFilename(String name) { return toModuleFilename(name); } @Override - public String toParameterFileName(String basename) { + public String toParameterFilename(String basename) { return toModuleFilename(basename); } + @Override + public String toParameterDocFilename(String componentName) { return toModuleFilename(componentName); } + /** * Return the capitalized file name of the model test * @@ -4295,59 +4312,40 @@ public CodegenOperation fromOperation(String path, List requiredParams = new ArrayList<>(); List optionalParams = new ArrayList<>(); - CodegenParameter bodyParam = null; - RequestBody requestBody = operation.getRequestBody(); - if (requestBody != null) { - String contentType = getContentType(requestBody); - if (contentType != null) { - contentType = contentType.toLowerCase(Locale.ROOT); - } - if (contentType != null && - (contentType.startsWith("application/x-www-form-urlencoded") || - contentType.startsWith("multipart"))) { - // process form parameters - formParams = fromRequestBodyToFormParameters(requestBody, sourceJsonPath + "/requestBody"); - op.isMultipart = contentType.startsWith("multipart"); - for (CodegenParameter cp : formParams) { - setParameterEncodingValues(cp, requestBody.getContent().get(contentType)); - postProcessParameter(cp); - } - if (formParams.size() == 1) { - bodyParam = formParams.get(0); - } - } else { - String bodyParameterName = getBodyParameterName(op); - bodyParam = fromRequestBody(requestBody, bodyParameterName, sourceJsonPath + "/requestBody"); - bodyParam.description = escapeText(requestBody.getDescription()); - postProcessParameter(bodyParam); + CodegenParameter requestBody = null; + RequestBody opRequestBody = operation.getRequestBody(); + if (opRequestBody != null) { - bodyParams.add(bodyParam); + String bodyParameterName = getBodyParameterName(op); + requestBody = fromRequestBody(opRequestBody, bodyParameterName, sourceJsonPath + "/requestBody"); + requestBody.description = escapeText(opRequestBody.getDescription()); + postProcessParameter(requestBody); - // add example - if (schemas != null && !isSkipOperationExample() && requestBody.getContent() != null) { - String firstContentType = (String) requestBody.getContent().keySet().toArray()[0]; - op.requestBodyExamples = new ExampleGenerator(schemas, this.openAPI).generate(null, new ArrayList<>(getConsumesInfo(this.openAPI, operation)), requestBody.getContent().get(firstContentType).getSchema()); - } + bodyParams.add(requestBody); + + // add example + if (schemas != null && !isSkipOperationExample() && opRequestBody.getContent() != null) { + String firstContentType = (String) opRequestBody.getContent().keySet().toArray()[0]; + op.requestBodyExamples = new ExampleGenerator(schemas, this.openAPI).generate( + null, new ArrayList<>(getConsumesInfo(this.openAPI, operation)), opRequestBody.getContent().get(firstContentType).getSchema()); } } if (parameters != null) { Integer i = 0; for (Parameter param : parameters) { - param = ModelUtils.getReferencedParameter(this.openAPI, param); - String usedSourceJsonPath = sourceJsonPath + "/parameters/" + i.toString(); CodegenParameter p = fromParameter(param, usedSourceJsonPath); allParams.add(p); i++; - if (param instanceof QueryParameter || "query".equalsIgnoreCase(param.getIn())) { + if (p.isQueryParam) { queryParams.add(p.copy()); - } else if (param instanceof PathParameter || "path".equalsIgnoreCase(param.getIn())) { + } else if (p.isPathParam) { pathParams.add(p.copy()); - } else if (param instanceof HeaderParameter || "header".equalsIgnoreCase(param.getIn())) { + } else if (p.isHeaderParam) { headerParams.add(p.copy()); - } else if (param instanceof CookieParameter || "cookie".equalsIgnoreCase(param.getIn())) { + } else if (p.isCookieParam) { cookieParams.add(p.copy()); } else { LOGGER.warn("Unknown parameter type for {}", p.baseName); @@ -4365,11 +4363,11 @@ public CodegenOperation fromOperation(String path, op.hasOptionalParams = true; } } - if (bodyParam != null) { - if (bodyParam.required) { - requiredParams.add(bodyParam.copy()); + if (requestBody != null) { + if (requestBody.required) { + requiredParams.add(requestBody.copy()); } else { - optionalParams.add(bodyParam.copy()); + optionalParams.add(requestBody.copy()); op.hasOptionalParams = true; } } @@ -4381,7 +4379,7 @@ public CodegenOperation fromOperation(String path, } } - op.requestBody = bodyParam; + op.requestBody = requestBody; op.httpMethod = httpMethod.toUpperCase(Locale.ROOT); // move "required" parameters in front of "optional" parameters @@ -4405,7 +4403,6 @@ else if (one.required) op.queryParams = queryParams; op.headerParams = headerParams; op.cookieParams = cookieParams; - op.formParams = formParams; op.requiredParams = requiredParams; op.optionalParams = optionalParams; op.externalDocs = operation.getExternalDocs(); @@ -4580,13 +4577,13 @@ public CodegenHeader fromHeader(Header header, String sourceJsonPath) { CodegenHeader codegenHeader = new CodegenHeader(); setHeaderInfo(usedHeader, codegenHeader, usedSourceJsonPath, "Header"); + if (usedHeader.getStyle() != null) { + codegenHeader.style = usedHeader.getStyle().toString(); + } if (headerRef != null) { String refModule = toRefModule(headerRef, "headers"); codegenHeader.setRefModule(refModule); } - if (usedHeader.getStyle() != null) { - codegenHeader.style = usedHeader.getStyle().toString(); - } if (sourceJsonPath != null) { String[] refPieces = sourceJsonPath.split("/"); if (sourceJsonPath.startsWith("#/components/headers/") && refPieces.length == 4) { @@ -4661,51 +4658,73 @@ private void setHeaderInfo(Header header, CodegenHeader codegenHeader, String so * @return Codegen Parameter object */ public CodegenParameter fromParameter(Parameter parameter, String sourceJsonPath) { + String parameterRef = parameter.get$ref(); + Parameter usedParameter = parameter; + String usedSourceJsonPath = sourceJsonPath; + if (parameterRef != null) { + usedParameter = ModelUtils.getReferencedParameter(this.openAPI, parameter); + usedSourceJsonPath = parameterRef; + } + CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER); Header prameterHeader = new Header(); - prameterHeader.setContent(parameter.getContent()); - prameterHeader.setDescription(parameter.getDescription()); - prameterHeader.setDeprecated(parameter.getDeprecated()); - prameterHeader.setSchema(parameter.getSchema()); - prameterHeader.set$ref(parameter.get$ref()); - prameterHeader.setExamples(parameter.getExamples()); - prameterHeader.setExample(parameter.getExample()); - prameterHeader.setExplode(parameter.getExplode()); - prameterHeader.setExtensions(parameter.getExtensions()); - prameterHeader.setRequired(parameter.getRequired()); - setHeaderInfo(prameterHeader, codegenParameter, sourceJsonPath, "Parameter"); - - if (parameter.getStyle() != null) { - codegenParameter.style = parameter.getStyle().toString(); + prameterHeader.setContent(usedParameter.getContent()); + prameterHeader.setDescription(usedParameter.getDescription()); + prameterHeader.setDeprecated(usedParameter.getDeprecated()); + prameterHeader.setSchema(usedParameter.getSchema()); + prameterHeader.set$ref(usedParameter.get$ref()); + prameterHeader.setExamples(usedParameter.getExamples()); + prameterHeader.setExample(usedParameter.getExample()); + prameterHeader.setExplode(usedParameter.getExplode()); + prameterHeader.setExtensions(usedParameter.getExtensions()); + prameterHeader.setRequired(usedParameter.getRequired()); + setHeaderInfo(prameterHeader, codegenParameter, usedSourceJsonPath, "Parameter"); + + if (usedParameter.getStyle() != null) { + codegenParameter.style = usedParameter.getStyle().toString(); + } + codegenParameter.baseName = usedParameter.getName(); + + if (parameterRef != null) { + String refModule = toRefModule(parameterRef, "parameters"); + codegenParameter.setRefModule(refModule); + } + if (sourceJsonPath != null) { + String[] refPieces = sourceJsonPath.split("/"); + if (sourceJsonPath.startsWith("#/components/parameters/") && refPieces.length == 4) { + String componentName = refPieces[3]; + codegenParameter.setModulePath(toModulePath(componentName, "parameters")); + String refModule = toRefModule(sourceJsonPath, "parameters"); + codegenParameter.setRefModule(refModule); + } } - codegenParameter.baseName = parameter.getName(); if (GlobalSettings.getProperty("debugParser") != null) { LOGGER.info("working on Parameter {}", parameter.getName()); LOGGER.info("JSON schema: {}", codegenParameter.jsonSchema); } - if (parameter instanceof QueryParameter || "query".equalsIgnoreCase(parameter.getIn())) { + if (parameter instanceof QueryParameter || "query".equalsIgnoreCase(usedParameter.getIn())) { codegenParameter.isQueryParam = true; - codegenParameter.isAllowEmptyValue = parameter.getAllowEmptyValue() != null && parameter.getAllowEmptyValue(); - } else if (parameter instanceof PathParameter || "path".equalsIgnoreCase(parameter.getIn())) { + codegenParameter.isAllowEmptyValue = parameter.getAllowEmptyValue() != null && usedParameter.getAllowEmptyValue(); + } else if (parameter instanceof PathParameter || "path".equalsIgnoreCase(usedParameter.getIn())) { codegenParameter.required = true; codegenParameter.isPathParam = true; - } else if (parameter instanceof HeaderParameter || "header".equalsIgnoreCase(parameter.getIn())) { + } else if (parameter instanceof HeaderParameter || "header".equalsIgnoreCase(usedParameter.getIn())) { codegenParameter.isHeaderParam = true; - } else if (parameter instanceof CookieParameter || "cookie".equalsIgnoreCase(parameter.getIn())) { + } else if (parameter instanceof CookieParameter || "cookie".equalsIgnoreCase(usedParameter.getIn())) { codegenParameter.isCookieParam = true; } else { - LOGGER.warn("Unknown parameter type: {}", parameter.getName()); + LOGGER.warn("Unknown parameter type: {}", usedParameter.getName()); } if (parameter.getStyle() != null) { - codegenParameter.isDeepObject = Parameter.StyleEnum.DEEPOBJECT == parameter.getStyle(); + codegenParameter.isDeepObject = Parameter.StyleEnum.DEEPOBJECT == usedParameter.getStyle(); } // set the parameter example value // should be overridden by lang codegen - setParameterExampleValue(codegenParameter, parameter); + setParameterExampleValue(codegenParameter, usedParameter); postProcessParameter(codegenParameter); LOGGER.debug("debugging codegenParameter return: {}", codegenParameter); @@ -5942,14 +5961,6 @@ public void writePropertyBack(String propertyKey, boolean value) { additionalProperties.put(propertyKey, value); } - protected String getContentType(RequestBody requestBody) { - if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { - LOGGER.debug("Cannot determine the content type. Returning null."); - return null; - } - return new ArrayList<>(requestBody.getContent().keySet()).get(0); - } - private void setOauth2Info(CodegenSecurity codegenSecurity, OAuthFlow flow) { codegenSecurity.authorizationUrl = flow.getAuthorizationUrl(); codegenSecurity.tokenUrl = flow.getTokenUrl(); @@ -6116,56 +6127,6 @@ public String getHelp() { return null; } - public List fromRequestBodyToFormParameters(RequestBody body, String sourceJsonPath) { - List parameters = new ArrayList<>(); - LOGGER.debug("debugging fromRequestBodyToFormParameters= {}", body); - String propertyName = getBodyParameterName(null); - CodegenParameter codegenParameter = fromFormProperty(propertyName, body, sourceJsonPath); - parameters.add(codegenParameter); - return parameters; - } - - public CodegenParameter fromFormProperty(String name, RequestBody body, String sourceJsonPath) { - Schema schema = ModelUtils.getSchemaFromRequestBody(body); - Schema propertySchema = ModelUtils.getReferencedSchema(this.openAPI, schema); - - CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER); - - LOGGER.debug("Debugging fromFormProperty {}: {}", name, propertySchema); - CodegenProperty codegenProperty = fromProperty(name, propertySchema, false, false, sourceJsonPath); - - codegenParameter.setSchema(codegenProperty); - codegenParameter.setContent(getContent(body.getContent(), codegenParameter.imports, "", sourceJsonPath)); - - codegenParameter.baseName = codegenProperty.baseName; - codegenParameter.paramName = toParamName(codegenParameter.baseName); - // non-array/map - updateCodegenPropertyEnum(codegenProperty); - - - codegenParameter.isFormParam = Boolean.TRUE; - codegenParameter.description = escapeText(codegenProperty.description); - codegenParameter.unescapedDescription = codegenProperty.getDescription(); - codegenParameter.jsonSchema = Json.pretty(propertySchema); - - if (codegenProperty.getVendorExtensions() != null && !codegenProperty.getVendorExtensions().isEmpty()) { - codegenParameter.vendorExtensions = codegenProperty.getVendorExtensions(); - } - if (propertySchema.getRequired() != null && !propertySchema.getRequired().isEmpty() && propertySchema.getRequired().contains(codegenProperty.baseName)) { - codegenParameter.required = Boolean.TRUE; - } - - if (!addSchemaImportsFromV3SpecLocations) { - // import - if (codegenProperty.refClass != null) { - codegenParameter.imports.add(codegenProperty.refClass); - } - } - setParameterExampleValue(codegenParameter); - - return codegenParameter; - } - protected void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set imports, String bodyParameterName, boolean forceSimpleRef, String sourceJsonPath) { CodegenModel codegenModel = null; if (StringUtils.isNotBlank(name)) { @@ -6468,6 +6429,8 @@ private String toRefModule(String ref, String expectedComponentType) { return toResponseModuleName(refPieces[3]); case "headers": return toHeaderFilename(refPieces[3]); + case "parameters": + return toParameterFilename(refPieces[3]); } return null; } diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index dd5fbf2246e..622304cfda8 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -449,8 +449,8 @@ private void generateFiles(List> processTemplateToFileInfos, boolea void generatePaths(List files, Map> operationsMap) { Paths paths = this.openAPI.getPaths(); - if (paths == null) { - LOGGER.warn("Skipping generation of paths because specification document has no paths."); + if (paths == null || paths.isEmpty()) { + LOGGER.warn("Skipping generation of paths because the specification document lacks them."); return; } List> pathsFiles = new ArrayList<>(); @@ -531,11 +531,15 @@ void generatePaths(List files, Map> operati for (String templateFile: config.pathEndpointParameterTemplateFiles()) { Integer i = 0; for (CodegenParameter cp: co.allParams) { + if (cp.refModule != null) { + // skip generation of parameter if it refs another location + continue; + } Map paramMap = new HashMap<>(); paramMap.put("parameter", cp); paramMap.put("imports", cp.imports); paramMap.put("packageName", packageName); - outputFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, config.toParameterFileName(i.toString()) + ".py")); + outputFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, config.toParameterFilename(i.toString()) + ".py")); pathsFiles.add(Arrays.asList(paramMap, templateFile, outputFilename)); i++; } @@ -567,7 +571,7 @@ void generatePaths(List files, Map> operati headerMap.put("header", header); headerMap.put("imports", header.imports); headerMap.put("packageName", packageName); - String headerFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, responseModuleName, config.toParameterFileName(headerName) + ".py")); + String headerFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, responseModuleName, config.toParameterFilename(headerName) + ".py")); pathsFiles.add(Arrays.asList(headerMap, headerTemplateFile, headerFilename)); } } @@ -608,7 +612,7 @@ void generatePaths(List files, Map> operati String path = pathsEntry.getKey(); String apiClassName = config.toModelName(path); pathToApiClassname.put(path, apiClassName); - pathModuleToApiClassname.put(config.toPathFileName(path), apiClassName); + pathModuleToApiClassname.put(config.toPathFilename(path), apiClassName); } if (!config.pathEndpointTemplateFiles().isEmpty()) { // paths.__init__.py @@ -691,7 +695,7 @@ void generatePaths(List files, Map> operati private TreeMap generateResponses(List files) { final Map specResponses = this.openAPI.getComponents().getResponses(); if (specResponses == null) { - LOGGER.warn("Skipping generation of responses because specification document has no responses."); + LOGGER.warn("Skipping generation of component responses because the specification document lacks them."); return null; } TreeMap responses = new TreeMap<>(); @@ -733,7 +737,7 @@ private TreeMap generateResponses(List files) { headerMap.put("header", header); headerMap.put("imports", header.imports); headerMap.put("packageName", config.packageName()); - String headerFilename = responseFileFolder + File.separatorChar + config.toParameterFileName(headerName) + ".py"; + String headerFilename = responseFileFolder + File.separatorChar + config.toParameterFilename(headerName) + ".py"; try { File written = processTemplateToFile(headerMap, headerTemplateName, headerFilename, generateResponses, CodegenConstants.RESPONSES, responseFileFolder); if (written != null) { @@ -760,6 +764,7 @@ private TreeMap generateResponses(List files) { Map templateData = new HashMap<>(); templateData.put("packageName", config.packageName()); + templateData.put("complexTypePrefix", "../../components/schema/"); templateData.put("response", response); try { File written = processTemplateToFile(templateData, templateName, filename, generateResponseDocumentation, CodegenConstants.REQUEST_BODY_DOCS); @@ -780,7 +785,7 @@ private TreeMap generateResponses(List files) { private TreeMap generateRequestBodies(List files) { final Map specRequestBodies = this.openAPI.getComponents().getRequestBodies(); if (specRequestBodies == null) { - LOGGER.warn("Skipping generation of requestBodies because specification document has no requestBodies."); + LOGGER.warn("Skipping generation of component requestBodies because the specification document lacks them."); return null; } TreeMap requestBodies = new TreeMap<>(); @@ -840,10 +845,74 @@ private TreeMap generateRequestBodies(List files return requestBodies; } + private TreeMap generateParameters(List files) { + final Map specParameters = this.openAPI.getComponents().getParameters(); + if (specParameters == null || specParameters.isEmpty()) { + LOGGER.warn("Skipping generation of component parameters because the specification document lacks them."); + return null; + } + TreeMap parameters = new TreeMap<>(); + for (Map.Entry entry: specParameters.entrySet()) { + String componentName = entry.getKey(); + Parameter specParameter = entry.getValue(); + String sourceJsonPath = "#/components/parameters/" + componentName; + CodegenParameter parameter = config.fromParameter(specParameter, sourceJsonPath); + parameters.put(componentName, parameter); + Boolean generateParameters = Boolean.TRUE; + for (Map.Entry entryInfo : config.parameterTemplateFiles().entrySet()) { + String templateName = entryInfo.getKey(); + String suffix = entryInfo.getValue(); + String fileFolder = config.parameterFileFolder(); + String filename = fileFolder + File.separatorChar + config.toParameterFilename(componentName) + suffix; + Map templateData = new HashMap<>(); + templateData.put("packageName", config.packageName()); + templateData.put("parameter", parameter); + templateData.put("imports", parameter.imports); + + try { + File written = processTemplateToFile(templateData, templateName, filename, generateParameters, CodegenConstants.PARAMETERS, fileFolder); + if (written != null) { + files.add(written); + if (config.isEnablePostProcessFile() && !dryRun) { + config.postProcessFile(written, "parameter"); + } + } + } catch (Exception e) { + throw new RuntimeException("Could not generate file '" + filename + "'", e); + } + } + Boolean generateParameterDocs = Boolean.TRUE; + for (Map.Entry entryInfo : config.parameterDocTemplateFiles().entrySet()) { + String templateName = entryInfo.getKey(); + String suffix = entryInfo.getValue(); + String fileFolder = config.parameterDocFileFolder(); + String filename = fileFolder + File.separatorChar + config.toParameterDocFilename(componentName) + suffix; + Map templateData = new HashMap<>(); + templateData.put("packageName", config.packageName()); + templateData.put("parameter", parameter); + templateData.put("complexTypePrefix", "../../components/schema/"); + templateData.put("imports", parameter.imports); + + try { + File written = processTemplateToFile(templateData, templateName, filename, generateParameterDocs, CodegenConstants.PARAMETER_DOCS, fileFolder); + if (written != null) { + files.add(written); + if (config.isEnablePostProcessFile() && !dryRun) { + config.postProcessFile(written, "parameter-doc"); + } + } + } catch (Exception e) { + throw new RuntimeException("Could not generate file '" + filename + "'", e); + } + } + } + return parameters; + } + private TreeMap generateHeaders(List files) { final Map specHeaders = this.openAPI.getComponents().getHeaders(); if (specHeaders == null || specHeaders.isEmpty()) { - LOGGER.warn("Skipping generation of specHeaders because specification document has no specHeaders."); + LOGGER.warn("Skipping generation of component headers because the specification document lacks them."); return null; } TreeMap headers = new TreeMap<>(); @@ -885,6 +954,7 @@ private TreeMap generateHeaders(List files) { Map templateData = new HashMap<>(); templateData.put("packageName", config.packageName()); templateData.put("headers", Collections.singletonMap("unsetHeaderName", header)); + templateData.put("complexTypePrefix", "../../components/schema/"); templateData.put("imports", header.imports); try { @@ -913,8 +983,8 @@ void generateModels(List files, List allModels, List unu } final Map schemas = ModelUtils.getSchemas(this.openAPI); - if (schemas == null) { - LOGGER.warn("Skipping generation of models because specification document has no schemas."); + if (schemas == null || schemas.isEmpty()) { + LOGGER.warn("Skipping generation of component schemas because the specification document lacks them."); return; } @@ -1272,7 +1342,13 @@ private void generateSupportingFiles(List files, Map bundl generateVersionMetadata(files); } - Map buildSupportFileBundle(List allOperations, List allModels, TreeMap requestBodies, TreeMap responses, TreeMap headers) { + Map buildSupportFileBundle( + List allOperations, + List allModels, + TreeMap requestBodies, + TreeMap responses, + TreeMap headers, + TreeMap parameters) { Map bundle = new HashMap<>(config.additionalProperties()); bundle.put("apiPackage", config.apiPackage()); @@ -1308,6 +1384,7 @@ Map buildSupportFileBundle(List allOperations, Li bundle.put("requestBodies", requestBodies); bundle.put("responses", responses); bundle.put("headers", headers); + bundle.put("parameters", parameters); bundle.put("models", allModels); bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar)); bundle.put("modelPackage", config.modelPackage()); @@ -1436,9 +1513,11 @@ public List generate() { TreeMap responses = generateResponses(files); // components.headers TreeMap headers = generateHeaders(files); + // components.parameters + TreeMap parameters = generateParameters(files); // supporting files - Map bundle = buildSupportFileBundle(allOperations, allModels, requestBodies, responses, headers); + Map bundle = buildSupportFileBundle(allOperations, allModels, requestBodies, responses, headers, parameters); generateSupportingFiles(files, bundle); if (dryRun) { diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index cddcad6d74c..5f558836eff 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -90,6 +90,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen { protected String requestBodyDocPath = "docs/components/request_bodies/"; protected String responseDocPath = "docs/components/responses/"; protected String headerDocPath = "docs/components/headers/"; + protected String parameterDocPath = "docs/components/parameters/"; protected boolean useNose = false; protected boolean useInlineModelResolver = false; @@ -333,6 +334,8 @@ public void processOpts() { responseDocTemplateFiles.put("response_doc.handlebars", ".md"); headerTemplateFiles.put("header.handlebars", ".py"); headerDocTemplateFiles.put("header_doc.handlebars", ".md"); + parameterTemplateFiles.put("parameter.handlebars", ".py"); + parameterDocTemplateFiles.put("parameter_doc.handlebars", ".md"); if (StringUtils.isEmpty(System.getenv("PYTHON_POST_PROCESS_FILE"))) { LOGGER.info("Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE=\"/usr/local/bin/yapf -i\"' (Linux/Mac)"); @@ -514,10 +517,17 @@ public String headerFileFolder() { return outputFolder + File.separatorChar + packagePath() + File.separatorChar + "components" + File.separatorChar + "headers"; } + @Override + public String parameterFileFolder() { + return outputFolder + File.separatorChar + packagePath() + File.separatorChar + "components" + File.separatorChar + "parameters"; + } + public String headerDocFileFolder() { return outputFolder + File.separator + headerDocPath; } + public String parameterDocFileFolder() { return outputFolder + File.separator + parameterDocPath; } + protected File processTemplateToFile(Map templateData, String templateName, String outputFilename, boolean shouldGenerate, String skippedByOption) throws IOException { String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar); File target = new File(adjustedOutputFilename); @@ -984,7 +994,7 @@ protected void addBodyModelSchema(CodegenParameter codegenParameter, String name } else { codegenParameter.baseName = bodyParameterName; } - codegenParameter.paramName = toParameterFileName(codegenParameter.baseName); + codegenParameter.paramName = toParameterFilename(codegenParameter.baseName); codegenParameter.description = codegenModel.description; } else { CodegenProperty codegenProperty = fromProperty("property", schema, false, false, sourceJsonPath); @@ -1008,7 +1018,7 @@ protected void addBodyModelSchema(CodegenParameter codegenParameter, String name codegenParameter.baseName = bodyParameterName; } - codegenParameter.paramName = toParameterFileName(codegenParameter.baseName); + codegenParameter.paramName = toParameterFilename(codegenParameter.baseName); codegenParameter.description = codegenModelDescription; } } @@ -2002,30 +2012,6 @@ public void setParameterExampleValue(CodegenParameter codegenParameter, RequestB codegenParameter.example = toExampleValue(schema, example); } - /** - * Create a CodegenParameter for a Form Property - * We have a custom version of this method so we can invoke - * setParameterExampleValue(codegenParameter, parameter) - * rather than setParameterExampleValue(codegenParameter) - * This ensures that all of our samples are generated in - * toExampleValueRecursive - * - * @param name the property name - * @param body the RequestBody definition - * @return the resultant CodegenParameter - */ - @Override - public CodegenParameter fromFormProperty(String name, RequestBody body, String sourceJsonPath) { - CodegenParameter cp = super.fromFormProperty(name, body, sourceJsonPath); - Parameter p = new Parameter(); - Schema schema = ModelUtils.getSchemaFromRequestBody(body); - Schema propertySchema = ModelUtils.getReferencedSchema(this.openAPI, schema); - p.setSchema(propertySchema); - p.setName(cp.paramName); - setParameterExampleValue(cp, p); - return cp; - } - /** * Return a map from model name to Schema for efficient lookup. * @@ -2470,23 +2456,6 @@ public String packageName() { return packageName; } - /** - * A custom version of this method is needed to ensure that the form object parameter is kept as-is - * as an object and is not exploded into separate parameters - * @param body the body that is being handled - * @return the list of length one containing a single type object CodegenParameter - */ - @Override - public List fromRequestBodyToFormParameters(RequestBody body, String sourceJsonPath) { - List parameters = new ArrayList<>(); - LOGGER.debug("debugging fromRequestBodyToFormParameters= {}", body); - CodegenParameter cp = fromFormProperty("body", body, sourceJsonPath); - cp.isFormParam = false; - cp.isBodyParam = true; - parameters.add(cp); - return parameters; - } - protected boolean needToImport(String refClass) { boolean containsPeriod = refClass.contains("."); if (containsPeriod) { @@ -2513,7 +2482,7 @@ public CodegenOperation fromOperation(String path, CodegenOperation co = super.fromOperation(path, httpMethod, operation, servers); co.httpMethod = httpMethod.toLowerCase(Locale.ROOT); // smuggle pathModuleName in nickname - co.nickname = toPathFileName(path); + co.nickname = toPathFilename(path); // smuggle path Api class name ins operationIdSnakeCase co.operationIdSnakeCase = toModelName(path); @@ -2611,7 +2580,7 @@ public Map postProcessSupportingFileData(Map obj } @Override - public String toParameterFileName(String name) { + public String toParameterFilename(String name) { try { Integer.parseInt(name); // for parameters in path, or an endpoint @@ -2622,9 +2591,12 @@ public String toParameterFileName(String name) { } } + @Override + public String toParameterDocFilename(String componentName) { return toParameterFilename(componentName); } + @Override public String toParamName(String basename) { - return toParameterFileName(basename); + return toParameterFilename(basename); } protected String toModulePath(String componentName, String priorJsonPathSegment) { @@ -2638,6 +2610,8 @@ protected String toModulePath(String componentName, String priorJsonPathSegment) return prefix + "responses." + toResponseModuleName(componentName); case "headers": return prefix + "headers." + toHeaderFilename(componentName); + case "parameters": + return prefix + "headers." + toParameterFilename(componentName); } return null; } diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/README_common.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/README_common.handlebars index ebe3104ee05..99eaa491be8 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/README_common.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/README_common.handlebars @@ -55,6 +55,14 @@ HTTP request | Method | Description - {{#with this}}[{{refModule}}](docs/components/headers/{{refModule}}.md){{/with}} {{/each}} {{/if}} +{{#if parameters}} + +## Component Parameters + +{{#each parameters}} +- {{#with this}}[{{refModule}}](docs/components/parameters/{{refModule}}.md){{/with}} +{{/each}} +{{/if}} ## Documentation For Authorization diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/endpoint.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/endpoint.handlebars index d40333e914f..4382ece0c71 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/endpoint.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/endpoint.handlebars @@ -27,6 +27,11 @@ from {{packageName}}.components.responses import {{refModule}} as response_for_{ {{/if}} {{/with}} {{/each}} +{{#each allParams}} +{{#if refModule}} +from {{packageName}}.components.parameters import {{refModule}} +{{/if}} +{{/each}} {{#unless isStub}} from .. import path @@ -42,7 +47,9 @@ from . import request_body {{/unless}} {{/with}} {{#each allParams}} +{{#unless refModule}} from . import {{paramName}} +{{/unless}} {{/each}} {{#or queryParams headerParams pathParams cookieParams}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/endpoint_doc.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/endpoint_doc.handlebars index d2080cf702a..2c7d61be5a1 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/endpoint_doc.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/endpoint_doc.handlebars @@ -87,14 +87,18 @@ skip_deserialization | bool | default is False | when True, headers and body wil Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- {{#each queryParams}} + {{#if refModule}} +{{baseName}} | [{{refModule}}.schema](../../../components/parameters/{{refModule}}.md) | | {{#unless required}}optional{{/unless}} + {{else}} {{baseName}} | [{{paramName}}.schema](#{{paramName}}.schema) | | {{#unless required}}optional{{/unless}} + {{/if}} {{/each}} - {{#each queryParams}} - {{#with schema}} + {{#each queryParams as | parameter |}} + {{#unless parameter.refModule}} -{{> api_doc_schema_type_hint schemaNamePrefix1=../paramName complexTypePrefix="../../../components/schema/" }} - {{/with}} +{{> parameter_doc complexTypePrefix="../../../components/schema/" }} + {{/unless}} {{/each}} {{/if}} {{#if headerParams}} @@ -105,13 +109,17 @@ Key | Input Type | Description | Notes Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- {{#each headerParams}} + {{#if refModule}} +{{baseName}} | [{{refModule}}.schema](../../../components/parameters/{{refModule}}.md) | | {{#unless required}}optional{{/unless}} + {{else}} {{baseName}} | [{{paramName}}.schema](#{{paramName}}.schema) | | {{#unless required}}optional{{/unless}} + {{/if}} {{/each}} - {{#each headerParams}} - {{#with schema}} + {{#each headerParams as | parameter |}} + {{#unless parameter.refModule}} -{{> api_doc_schema_type_hint schemaNamePrefix1=../paramName complexTypePrefix="../../../components/schema/" }} - {{/with}} +{{> parameter_doc complexTypePrefix="../../../components/schema/" }} + {{/unless}} {{/each}} {{/if}} {{#if pathParams}} @@ -122,13 +130,17 @@ Key | Input Type | Description | Notes Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- {{#each pathParams}} + {{#if refModule}} +{{baseName}} | [{{refModule}}.schema](../../../components/parameters/{{refModule}}.md) | | {{#unless required}}optional{{/unless}} + {{else}} {{baseName}} | [{{paramName}}.schema](#{{paramName}}.schema) | | {{#unless required}}optional{{/unless}} + {{/if}} {{/each}} - {{#each pathParams}} - {{#with schema}} + {{#each pathParams as | parameter |}} + {{#unless parameter.refModule}} -{{> api_doc_schema_type_hint schemaNamePrefix1=../paramName complexTypePrefix="../../../components/schema/" }} - {{/with}} +{{> parameter_doc complexTypePrefix="../../../components/schema/" }} + {{/unless}} {{/each}} {{/if}} {{#if cookieParams}} @@ -139,13 +151,17 @@ Key | Input Type | Description | Notes Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- {{#each cookieParams}} + {{#if refModule}} +{{baseName}} | [{{refModule}}.schema](../../../components/parameters/{{refModule}}.md) | | {{#unless required}}optional{{/unless}} + {{else}} {{baseName}} | [{{paramName}}.schema](#{{paramName}}.schema) | | {{#unless required}}optional{{/unless}} + {{/if}} {{/each}} - {{#each cookieParams}} - {{#with schema}} + {{#each cookieParams as | parameter |}} + {{#unless parameter.refModule}} -{{> api_doc_schema_type_hint schemaNamePrefix1=../paramName complexTypePrefix="../../../components/schema/" }} - {{/with}} +{{> parameter_doc complexTypePrefix="../../../components/schema/" }} + {{/unless}} {{/each}} {{/if}} {{else}} @@ -174,7 +190,7 @@ default | [response_for_default.ApiResponse](#response_for_default.ApiResponse) {{#each responses}} {{#unless refModule}} -{{> response_doc response=this }} +{{> response_doc response=this complexTypePrefix="../../../components/schema/" }} {{/unless}} {{/each}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/footer_links.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/footer_links.handlebars index 457ec6b90fc..c0ca059cce2 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/footer_links.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/footer_links.handlebars @@ -1 +1 @@ -{{#if endpointsLink}}[[Back to Endpoints]]({{readmePath}}README.md#Endpoints) {{/if}}{{#if schemasLink}}[[Back to Component Schemas]]({{readmePath}}README.md#Component-Schemas) {{/if}}{{#if responsesLink}}[[Back to Component Responses]]({{readmePath}}README.md#Component-Responses) {{/if}}{{#if requestBodiesLink}}[[Back to Component RequestBodies]]({{readmePath}}README.md#Component-RequestBodies) {{/if}}{{#if headersLink}}[[Back to Component Headers]]({{readmePath}}README.md#Component-Headers) {{/if}}[[Back to README]]({{readmePath}}README.md) \ No newline at end of file +{{#if endpointsLink}}[[Back to Endpoints]]({{readmePath}}README.md#Endpoints) {{/if}}{{#if schemasLink}}[[Back to Component Schemas]]({{readmePath}}README.md#Component-Schemas) {{/if}}{{#if responsesLink}}[[Back to Component Responses]]({{readmePath}}README.md#Component-Responses) {{/if}}{{#if requestBodiesLink}}[[Back to Component RequestBodies]]({{readmePath}}README.md#Component-RequestBodies) {{/if}}{{#if headersLink}}[[Back to Component Headers]]({{readmePath}}README.md#Component-Headers) {{/if}}{{#if parametersLink}}[[Back to Component Parameters]]({{readmePath}}README.md#Component-Parameters) {{/if}}[[Back to README]]({{readmePath}}README.md) \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/header_doc.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/header_doc.handlebars index f6c6d0031f8..95eeefc6ce1 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/header_doc.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/header_doc.handlebars @@ -5,14 +5,14 @@ {{#if schema}} {{#with schema}} -{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1=../paramName schemaNamePrefix2="." complexTypePrefix="../../components/schema/" }} +{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1=../paramName schemaNamePrefix2="." }} {{/with}} {{else}} {{#each getContent}} {{#with this}} {{#with schema}} -{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1=../paramName schemaNamePrefix2="." complexTypePrefix="../../../components/schema/" }} +{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1=../paramName schemaNamePrefix2="." }} {{/with}} {{/with}} {{/each}} @@ -27,14 +27,14 @@ # {{modulePath}} {{#if schema}} {{#with schema}} -{{> api_doc_schema_type_hint complexTypePrefix="../../../components/schema/" }} +{{> api_doc_schema_type_hint }} {{/with}} {{else}} {{#each getContent}} {{#with this}} {{#with schema}} -{{> api_doc_schema_type_hint complexTypePrefix="../../../components/schema/" }} +{{> api_doc_schema_type_hint }} {{/with}} {{/with}} {{/each}} @@ -46,14 +46,14 @@ {{#if schema}} {{#with schema}} -{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1="response_for_" schemaNamePrefix2=../../@key schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../../components/schema/" }} +{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1="response_for_" schemaNamePrefix2=../../@key schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." }} {{/with}} {{else}} {{#each getContent}} {{#with this}} {{#with schema}} -{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1="response_for_" schemaNamePrefix2=../../../@key schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../../components/schema/" }} +{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1="response_for_" schemaNamePrefix2=../../../@key schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." }} {{/with}} {{/with}} {{/each}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/parameter_doc.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/parameter_doc.handlebars new file mode 100644 index 00000000000..dc9c4f6fd76 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/parameter_doc.handlebars @@ -0,0 +1,21 @@ +{{#if parameter.modulePath}} + +## {{parameter.modulePath}} +{{/if}} +{{#if parameter.schema}} + {{#with parameter.schema}} +{{> api_doc_schema_type_hint schemaNamePrefix1=../paramName }} + {{/with}} +{{else}} + {{#each parameter.getContent}} + {{#with this}} + {{#with schema}} +{{> api_doc_schema_type_hint schemaNamePrefix1=../paramName }} + {{/with}} + {{/with}} + {{/each}} +{{/if}} +{{#if parameter.modulePath}} + +[[Back to top]](#top) {{> footer_links readmePath="../../../" parametersLink=true}} +{{/if}} \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/response_doc.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/response_doc.handlebars index c6748d03c61..1e82b61a780 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/response_doc.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/response_doc.handlebars @@ -15,7 +15,7 @@ headers | {{#unless headers}}Unset{{else}}[Headers](#Headers){{/unless}} | {{#un {{#each content}} {{#with this.schema}} -{{> api_doc_schema_type_hint complexTypePrefix="../../components/schema/" }} +{{> api_doc_schema_type_hint }} {{/with}} {{/each}} {{else}} @@ -24,7 +24,7 @@ headers | {{#unless headers}}Unset{{else}}[response_for_{{@key}}.Headers](#respo {{#each content}} {{#with this.schema}} -{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1="response_for_" schemaNamePrefix2=../../@key schemaNamePrefix3="." complexTypePrefix="../../../components/schema/" }} +{{> api_doc_schema_type_hint anchorContainsPeriod=true schemaNamePrefix1="response_for_" schemaNamePrefix2=../../@key schemaNamePrefix3="." }} {{/with}} {{/each}} {{/if}} diff --git a/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index c5884f07ed4..0a1e466f386 100644 --- a/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -242,9 +242,9 @@ public void testFormParameterHasDefaultValue() { codegen.setOpenAPI(openAPI); RequestBody reqBody = openAPI.getPaths().get("/fake").getGet().getRequestBody(); - CodegenParameter codegenParameter = codegen.fromFormProperty("enum_form_string", reqBody, null); + CodegenParameter codegenParameter = codegen.fromRequestBody(reqBody, "enum_form_string", null); - Assert.assertEquals(codegenParameter.getSchema().getVars().get(1).defaultValue, "-efg"); + Assert.assertEquals(codegenParameter.getContent().get("application/x-www-form-urlencoded").getSchema().getVars().size(), 0, "no vars because the schem is refed"); } @Test @@ -254,9 +254,13 @@ public void testDateTimeFormParameterHasDefaultValue() { codegen.setOpenAPI(openAPI); RequestBody reqBody = openAPI.getPaths().get("/thingy/{date}").getPost().getRequestBody(); - CodegenParameter codegenParameter = codegen.fromFormProperty("visitDate", reqBody, null); + CodegenParameter codegenParameter = codegen.fromRequestBody(reqBody, "visitDate", null); - Assert.assertEquals(codegenParameter.getSchema().getVars().get(0).defaultValue, "1971-12-19T03:39:57-08:00"); + Assert.assertEquals(codegenParameter.getContent().get("application/x-www-form-urlencoded").getSchema().getRef(), "#/components/schemas/updatePetWithForm_request"); + + Schema specModel = openAPI.getComponents().getSchemas().get("updatePetWithForm_request"); + CodegenModel model = codegen.fromModel("updatePetWithForm_request", specModel); + Assert.assertEquals(model.getVars().get(0).defaultValue, "1971-12-19T03:39:57-08:00"); } @Test @@ -268,7 +272,7 @@ public void testOriginalOpenApiDocumentVersion() { Assert.assertEquals(version, new SemVer("2.0.0")); // 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_customized.yaml"; openAPI = TestUtils.parseFlattenSpec(location); version = ModelUtils.getOpenApiVersion(openAPI, location, null); Assert.assertEquals(version, new SemVer("3.0.0")); @@ -444,7 +448,7 @@ public void testAdditionalPropertiesV2SpecDisallowAdditionalPropertiesIfNotPrese @Test public void testAdditionalPropertiesV3SpecDisallowAdditionalPropertiesIfNotPresentFalse() { - OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml"); + OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/python/petstore_customized.yaml"); DefaultCodegen codegen = new DefaultCodegen(); codegen.setDisallowAdditionalPropertiesIfNotPresent(false); codegen.supportsAdditionalPropertiesWithComposedSchema = true; @@ -2429,8 +2433,8 @@ public void testFormComposedSchema() { "post", path.getPost(), path.getServers()); - assertEquals(operation.formParams.size(), 1, - "The list of parameters only includes the ref type"); + assertEquals(operation.allParams.size(), 0); + assertNotNull(operation.requestBody); } @Test @@ -4059,26 +4063,15 @@ public void testRequestBodyContent() { path = "/requestBodyWithEncodingTypes"; co = codegen.fromOperation(path, "POST", openAPI.getPaths().get(path).getPost(), null); - List formParams = co.formParams; - - assertEquals(formParams.get(0).getSchema().getVars().get(0).baseName, "int-param"); - assertFalse(formParams.get(0).getSchema().getVars().get(0).isContainer); - - assertEquals(formParams.get(0).getSchema().getVars().get(1).baseName, "explode-true"); - assertTrue(formParams.get(0).getSchema().getVars().get(1).isContainer); - - assertEquals(formParams.get(0).getSchema().getVars().get(2).baseName, "explode-false"); - assertTrue(formParams.get(0).getSchema().getVars().get(2).isContainer); - - assertEquals(formParams.get(0).getSchema().getVars().get(3).baseName, "no-style-no-explode"); - assertTrue(formParams.get(0).getSchema().getVars().get(3).isContainer); - - assertEquals(formParams.get(0).getSchema().getVars().get(4).baseName, "style-specified"); - assertTrue(formParams.get(0).getSchema().getVars().get(4).isContainer); + CodegenProperty formSchema = co.requestBody.getContent().get("application/x-www-form-urlencoded").getSchema(); + List formParams = formSchema.getVars(); + LinkedHashMap encoding = co.requestBody.getContent().get("application/x-www-form-urlencoded").getEncoding(); - assertEquals(formParams.get(0).getSchema().getVars().get(5).baseName, "style-specified-no-explode"); - assertTrue(formParams.get(0).getSchema().getVars().get(5).isContainer); + assertEquals(formSchema.getRef(), "#/components/schemas/_requestBodyWithEncodingTypes_post_request"); + assertEquals(formParams.size(), 0, "no form params because the schema is referenced"); + assertEquals(encoding.get("int-param").getExplode(), true); + assertEquals(encoding.get("explode-false").getExplode(), false); } @Test @@ -4161,9 +4154,9 @@ public void testUnalias() { Assert.assertEquals(requestBodySchema2.get$ref(), "#/components/schemas/updatePetWithForm_request"); RequestBody reqBody = openAPI.getPaths().get("/thingy/{date}").getPost().getRequestBody(); - CodegenParameter codegenParameter = codegen.fromFormProperty("visitDate", reqBody, null); + CodegenParameter codegenParameter = codegen.fromRequestBody(reqBody, "visitDate", null); - Assert.assertEquals(codegenParameter.getSchema().getVars().get(0).defaultValue, "1971-12-19T03:39:57-08:00"); + Assert.assertEquals(codegenParameter.getContent().get("application/x-www-form-urlencoded").getSchema().getRef(), "#/components/schemas/updatePetWithForm_request"); } @Test diff --git a/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java b/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java index a79338b77d0..4dcc7d35e44 100644 --- a/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java +++ b/modules/openapi-json-schema-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java @@ -657,7 +657,8 @@ public void testHandlesTrailingSlashInServers() { Map> paths = generator.processPaths(config.openAPI.getPaths()); generator.generateApis(files, allOperations, allModels, paths); - Map bundle = generator.buildSupportFileBundle(allOperations, allModels, null, null, null); + Map bundle = generator.buildSupportFileBundle( + allOperations, allModels, null, null, null, null); LinkedList servers = (LinkedList) bundle.get("servers"); Assert.assertEquals(servers.get(0).url, ""); Assert.assertEquals(servers.get(1).url, "http://trailingshlash.io:80/v1"); @@ -684,7 +685,8 @@ public void testHandlesRelativeUrlsInServers() { Map> paths = generator.processPaths(config.openAPI.getPaths()); generator.generateApis(files, allOperations, allModels, paths); - Map bundle = generator.buildSupportFileBundle(allOperations, allModels, null, null, null); + Map bundle = generator.buildSupportFileBundle( + allOperations, allModels, null, null, null, null); LinkedList servers = (LinkedList) bundle.get("servers"); Assert.assertEquals(servers.get(0).url, "/relative/url"); } diff --git a/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore_customized.yaml similarity index 98% rename from modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml rename to modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore_customized.yaml index ab68f1f62b3..0ec125f4e7b 100644 --- a/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore_customized.yaml @@ -457,6 +457,10 @@ paths: $ref: '#/components/headers/NumberHeader' int32: $ref: '#/components/headers/Int32JsonContentTypeHeader' + ref-schema-header: + $ref: '#/components/headers/RefSchemaHeader' + ref-content-schema-header: + $ref: '#/components/headers/RefContentSchemaHeader' content: application/xml: schema: @@ -484,12 +488,7 @@ paths: description: '' operationId: getUserByName parameters: - - name: username - in: path - description: The name that needs to be fetched. Use user1 for testing. - required: true - schema: - type: string + - $ref: '#/components/parameters/PathUserName' responses: '200': description: successful operation @@ -511,12 +510,7 @@ paths: description: This can only be done by the logged in user. operationId: updateUser parameters: - - name: username - in: path - description: name that need to be deleted - required: true - schema: - type: string + - $ref: '#/components/parameters/PathUserName' responses: '400': description: Invalid user supplied @@ -536,12 +530,7 @@ paths: description: This can only be done by the logged in user. operationId: deleteUser parameters: - - name: username - in: path - description: The name that needs to be deleted - required: true - schema: - type: string + - $ref: '#/components/parameters/PathUserName' responses: '200': $ref: '#/components/responses/SuccessDescriptionOnly' @@ -1644,6 +1633,30 @@ servers: - 'v2' default: 'v2' components: + parameters: + PathUserName: + name: username + in: path + description: the use name to use + required: true + schema: + type: string + RefSchemaStringWithValidation: + name: RSstringWithValidation + in: path + description: a path string with validation + required: true + schema: + $ref: '#/components/schemas/StringWithValidation' + ComponentRefSchemaStringWithValidation: + name: CRSstringWithValidation + in: path + description: a path string with validation + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/StringWithValidation' responses: SuccessDescriptionOnly: description: Success @@ -1656,6 +1669,10 @@ components: $ref: '#/components/headers/NumberHeader' int32: $ref: '#/components/headers/Int32JsonContentTypeHeader' + ref-schema-header: + $ref: '#/components/headers/RefSchemaHeader' + ref-content-schema-header: + $ref: '#/components/headers/RefContentSchemaHeader' content: application/json: schema: @@ -1720,6 +1737,18 @@ components: schema: type: integer format: int32 + RefSchemaHeader: + description: header that has a ref in the schema + required: true + schema: + $ref: '#/components/schemas/StringWithValidation' + RefContentSchemaHeader: + description: int32 JSON content-type header + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/StringWithValidation' securitySchemes: petstore_auth: type: oauth2 diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/FILES b/samples/openapi3/client/petstore/python/.openapi-generator/FILES index 992e322d465..0bb25f9a5c8 100644 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -68,7 +68,12 @@ docs/apis/tags/user_api/logout_user.md docs/apis/tags/user_api/update_user.md docs/components/headers/int32_json_content_type_header_header.md docs/components/headers/number_header_header.md +docs/components/headers/ref_content_schema_header_header.md +docs/components/headers/ref_schema_header_header.md docs/components/headers/string_header_header.md +docs/components/parameters/parameter_component_ref_schema_string_with_validation.md +docs/components/parameters/parameter_path_user_name.md +docs/components/parameters/parameter_ref_schema_string_with_validation.md docs/components/request_bodies/client_request_body.md docs/components/request_bodies/pet_request_body.md docs/components/request_bodies/user_array_request_body.md @@ -266,7 +271,12 @@ petstore_api/apis/tags/user_api.py petstore_api/components/__init__.py petstore_api/components/headers/int32_json_content_type_header_header.py petstore_api/components/headers/number_header_header.py +petstore_api/components/headers/ref_content_schema_header_header.py +petstore_api/components/headers/ref_schema_header_header.py petstore_api/components/headers/string_header_header.py +petstore_api/components/parameters/parameter_component_ref_schema_string_with_validation.py +petstore_api/components/parameters/parameter_path_user_name.py +petstore_api/components/parameters/parameter_ref_schema_string_with_validation.py petstore_api/components/request_bodies/__init__.py petstore_api/components/request_bodies/client_request_body.py petstore_api/components/request_bodies/pet_request_body.py @@ -830,17 +840,14 @@ petstore_api/paths/user_logout/get/__init__.pyi petstore_api/paths/user_username/__init__.py petstore_api/paths/user_username/delete/__init__.py petstore_api/paths/user_username/delete/__init__.pyi -petstore_api/paths/user_username/delete/parameter_0.py petstore_api/paths/user_username/delete/response_for_404/__init__.py petstore_api/paths/user_username/get/__init__.py petstore_api/paths/user_username/get/__init__.pyi -petstore_api/paths/user_username/get/parameter_0.py petstore_api/paths/user_username/get/response_for_200/__init__.py petstore_api/paths/user_username/get/response_for_400/__init__.py petstore_api/paths/user_username/get/response_for_404/__init__.py petstore_api/paths/user_username/put/__init__.py petstore_api/paths/user_username/put/__init__.pyi -petstore_api/paths/user_username/put/parameter_0.py petstore_api/paths/user_username/put/request_body.py petstore_api/paths/user_username/put/response_for_400/__init__.py petstore_api/paths/user_username/put/response_for_404/__init__.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index f98a27b144f..1966ab2f960 100644 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -372,8 +372,16 @@ HTTP request | Method | Description - [int32_json_content_type_header_header](docs/components/headers/int32_json_content_type_header_header.md) - [number_header_header](docs/components/headers/number_header_header.md) +- [ref_content_schema_header_header](docs/components/headers/ref_content_schema_header_header.md) +- [ref_schema_header_header](docs/components/headers/ref_schema_header_header.md) - [string_header_header](docs/components/headers/string_header_header.md) +## Component Parameters + +- [parameter_component_ref_schema_string_with_validation](docs/components/parameters/parameter_component_ref_schema_string_with_validation.md) +- [parameter_path_user_name](docs/components/parameters/parameter_path_user_name.md) +- [parameter_ref_schema_string_with_validation](docs/components/parameters/parameter_ref_schema_string_with_validation.md) + ## Documentation For Authorization diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/fake_api/query_param_with_json_content_type.md b/samples/openapi3/client/petstore/python/docs/apis/tags/fake_api/query_param_with_json_content_type.md index 29dd9b7fe3d..3659713e10c 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/fake_api/query_param_with_json_content_type.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/fake_api/query_param_with_json_content_type.md @@ -52,6 +52,13 @@ Key | Input Type | Description | Notes someParam | [parameter_0.schema](#parameter_0.schema) | | +# parameter_0.schema + +## Model Type Info +Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- +dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, FileIO | | + ### Return Types, Responses Code | Class | Description diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/delete_user.md b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/delete_user.md index a7734456a76..7297e22e0bf 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/delete_user.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/delete_user.md @@ -50,14 +50,7 @@ skip_deserialization | bool | default is False | when True, headers and body wil Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- -username | [parameter_0.schema](#parameter_0.schema) | | - -# parameter_0.schema - -## Model Type Info -Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- -str, | str, | | +username | [parameter_path_user_name.schema](../../../components/parameters/parameter_path_user_name.md) | | ### Return Types, Responses diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/get_user_by_name.md b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/get_user_by_name.md index 9ec603ee493..b8248b67da7 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/get_user_by_name.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/get_user_by_name.md @@ -49,14 +49,7 @@ skip_deserialization | bool | default is False | when True, headers and body wil Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- -username | [parameter_0.schema](#parameter_0.schema) | | - -# parameter_0.schema - -## Model Type Info -Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- -str, | str, | | +username | [parameter_path_user_name.schema](../../../components/parameters/parameter_path_user_name.md) | | ### Return Types, Responses diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/login_user.md b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/login_user.md index e19687b16e7..49fee4e8f59 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/login_user.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/login_user.md @@ -100,9 +100,11 @@ str, | str, | | Key | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- +ref-schema-header | [ref_schema_header_header.schema](../../../components/headers/ref_schema_header_header.md#schema) | | optional X-Rate-Limit | [response_for_200.parameter_x_rate_limit.schema](#response_for_200.parameter_x_rate_limit.schema) | | optional int32 | [int32_json_content_type_header_header.schema](../../../components/headers/int32_json_content_type_header_header.md#schema) | | optional X-Expires-After | [response_for_200.parameter_x_expires_after.schema](#response_for_200.parameter_x_expires_after.schema) | | optional +ref-content-schema-header | [ref_content_schema_header_header.schema](../../../components/headers/ref_content_schema_header_header.md#schema) | | optional stringHeader | [string_header_header.schema](../../../components/headers/string_header_header.md#schema) | | optional numberHeader | [number_header_header.schema](../../../components/headers/number_header_header.md#schema) | | optional diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/update_user.md b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/update_user.md index b29c99c029a..3eccb64bc28 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/update_user.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/user_api/update_user.md @@ -75,14 +75,7 @@ Type | Description | Notes Key | Input Type | Description | Notes ------------- | ------------- | ------------- | ------------- -username | [parameter_0.schema](#parameter_0.schema) | | - -# parameter_0.schema - -## Model Type Info -Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- -str, | str, | | +username | [parameter_path_user_name.schema](../../../components/parameters/parameter_path_user_name.md) | | ### Return Types, Responses diff --git a/samples/openapi3/client/petstore/python/docs/components/headers/ref_content_schema_header_header.md b/samples/openapi3/client/petstore/python/docs/components/headers/ref_content_schema_header_header.md new file mode 100644 index 00000000000..858f885d9a5 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/components/headers/ref_content_schema_header_header.md @@ -0,0 +1,9 @@ +# petstore_api.components.headers.ref_content_schema_header_header + +# schema +Type | Description | Notes +------------- | ------------- | ------------- +[**StringWithValidation**](../../components/schema/string_with_validation.StringWithValidation.md) | | + + +[[Back to top]](#top) [[Back to Component Headers]](../../../README.md#Component-Headers) [[Back to README]](../../../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/components/headers/ref_schema_header_header.md b/samples/openapi3/client/petstore/python/docs/components/headers/ref_schema_header_header.md new file mode 100644 index 00000000000..da6f3f2bed3 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/components/headers/ref_schema_header_header.md @@ -0,0 +1,8 @@ +# petstore_api.components.headers.ref_schema_header_header +# schema +Type | Description | Notes +------------- | ------------- | ------------- +[**StringWithValidation**](../../components/schema/string_with_validation.StringWithValidation.md) | | + + +[[Back to top]](#top) [[Back to Component Headers]](../../../README.md#Component-Headers) [[Back to README]](../../../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_component_ref_schema_string_with_validation.md b/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_component_ref_schema_string_with_validation.md new file mode 100644 index 00000000000..2656b6a09ab --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_component_ref_schema_string_with_validation.md @@ -0,0 +1,9 @@ + +## petstore_api.components.headers.parameter_component_ref_schema_string_with_validation +# schema +Type | Description | Notes +------------- | ------------- | ------------- +[**StringWithValidation**](../../components/schema/string_with_validation.StringWithValidation.md) | | + + +[[Back to top]](#top) [[Back to Component Parameters]](../../../README.md#Component-Parameters) [[Back to README]](../../../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_path_user_name.md b/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_path_user_name.md new file mode 100644 index 00000000000..9f57010f125 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_path_user_name.md @@ -0,0 +1,10 @@ + +## petstore_api.components.headers.parameter_path_user_name +# schema + +## Model Type Info +Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- +str, | str, | | + +[[Back to top]](#top) [[Back to Component Parameters]](../../../README.md#Component-Parameters) [[Back to README]](../../../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_ref_schema_string_with_validation.md b/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_ref_schema_string_with_validation.md new file mode 100644 index 00000000000..298b4e75840 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/components/parameters/parameter_ref_schema_string_with_validation.md @@ -0,0 +1,9 @@ + +## petstore_api.components.headers.parameter_ref_schema_string_with_validation +# schema +Type | Description | Notes +------------- | ------------- | ------------- +[**StringWithValidation**](../../components/schema/string_with_validation.StringWithValidation.md) | | + + +[[Back to top]](#top) [[Back to Component Parameters]](../../../README.md#Component-Parameters) [[Back to README]](../../../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/components/responses/success_with_json_api_response_response.md b/samples/openapi3/client/petstore/python/docs/components/responses/success_with_json_api_response_response.md index 40d7b3d5712..92599e0145c 100644 --- a/samples/openapi3/client/petstore/python/docs/components/responses/success_with_json_api_response_response.md +++ b/samples/openapi3/client/petstore/python/docs/components/responses/success_with_json_api_response_response.md @@ -16,7 +16,9 @@ Type | Description | Notes Key | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- +ref-schema-header | [ref_schema_header_header.schema](../../components/headers/ref_schema_header_header.md#schema) | | optional int32 | [int32_json_content_type_header_header.schema](../../components/headers/int32_json_content_type_header_header.md#schema) | | optional +ref-content-schema-header | [ref_content_schema_header_header.schema](../../components/headers/ref_content_schema_header_header.md#schema) | | optional stringHeader | [string_header_header.schema](../../components/headers/string_header_header.md#schema) | | optional numberHeader | [number_header_header.schema](../../components/headers/number_header_header.md#schema) | | optional diff --git a/samples/openapi3/client/petstore/python/petstore_api/components/headers/ref_content_schema_header_header.py b/samples/openapi3/client/petstore/python/petstore_api/components/headers/ref_content_schema_header_header.py new file mode 100644 index 00000000000..2991b90c8e2 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/components/headers/ref_content_schema_header_header.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import typing_extensions +import urllib3 + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + +from petstore_api.components.schema import string_with_validation + + +schema = string_with_validation.StringWithValidation + + +parameter_oapg = api_client.HeaderParameterWithoutName( + style=api_client.ParameterStyle.SIMPLE, + content={ + "application/json": schema, + }, + required=True, +) diff --git a/samples/openapi3/client/petstore/python/petstore_api/components/headers/ref_schema_header_header.py b/samples/openapi3/client/petstore/python/petstore_api/components/headers/ref_schema_header_header.py new file mode 100644 index 00000000000..61221f7f1ae --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/components/headers/ref_schema_header_header.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import typing_extensions +import urllib3 + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + +from petstore_api.components.schema import string_with_validation + + +schema = string_with_validation.StringWithValidation + + +parameter_oapg = api_client.HeaderParameterWithoutName( + style=api_client.ParameterStyle.SIMPLE, + schema=schema, + required=True, +) diff --git a/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_component_ref_schema_string_with_validation.py b/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_component_ref_schema_string_with_validation.py new file mode 100644 index 00000000000..a7df29875cc --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_component_ref_schema_string_with_validation.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import typing_extensions +import urllib3 + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + +from petstore_api.components.schema import string_with_validation + + +schema = string_with_validation.StringWithValidation + + +parameter_oapg = api_client.PathParameter( + name="CRSstringWithValidation", + content={ + "application/json": schema, + }, + required=True, +) diff --git a/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_path_user_name.py b/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_path_user_name.py new file mode 100644 index 00000000000..50a40c422fd --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_path_user_name.py @@ -0,0 +1,36 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import typing_extensions +import urllib3 + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +schema = schemas.StrSchema + + +parameter_oapg = api_client.PathParameter( + name="username", + style=api_client.ParameterStyle.SIMPLE, + schema=schema, + required=True, +) diff --git a/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_ref_schema_string_with_validation.py b/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_ref_schema_string_with_validation.py new file mode 100644 index 00000000000..3b30a8f2324 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/components/parameters/parameter_ref_schema_string_with_validation.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +from dataclasses import dataclass +import typing_extensions +import urllib3 + +from petstore_api import api_client, exceptions +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + +from petstore_api.components.schema import string_with_validation + + +schema = string_with_validation.StringWithValidation + + +parameter_oapg = api_client.PathParameter( + name="RSstringWithValidation", + style=api_client.ParameterStyle.SIMPLE, + schema=schema, + required=True, +) diff --git a/samples/openapi3/client/petstore/python/petstore_api/components/responses/success_with_json_api_response_response/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/components/responses/success_with_json_api_response_response/__init__.py index ceb9a0c5011..77043c49369 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/components/responses/success_with_json_api_response_response/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/components/responses/success_with_json_api_response_response/__init__.py @@ -16,7 +16,9 @@ from petstore_api import schemas # noqa: F401 from petstore_api.components.schema import api_response +from petstore_api.components.headers import ref_schema_header_header as parameter_ref_schema_header from petstore_api.components.headers import int32_json_content_type_header_header as parameter_int32_json_content_type_header +from petstore_api.components.headers import ref_content_schema_header_header as parameter_ref_content_schema_header from petstore_api.components.headers import string_header_header as parameter_string_header from petstore_api.components.headers import number_header_header as parameter_number_header @@ -25,7 +27,9 @@ class Header: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { + 'ref-schema-header': typing.Union[parameter_ref_schema_header.schema, ], 'int32': typing.Union[parameter_int32_json_content_type_header.schema, decimal.Decimal, int, ], + 'ref-content-schema-header': typing.Union[parameter_ref_content_schema_header.schema, ], 'stringHeader': typing.Union[parameter_string_header.schema, str, ], 'numberHeader': typing.Union[parameter_number_header.schema, str, ], } @@ -43,7 +47,9 @@ class Params(RequiredParams, OptionalParams): parameters = [ + parameter_ref_schema_header.parameter_oapg, parameter_int32_json_content_type_header.parameter_oapg, + parameter_ref_content_schema_header.parameter_oapg, parameter_string_header.parameter_oapg, parameter_number_header.parameter_oapg, ] diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_login/get/response_for_200/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/paths/user_login/get/response_for_200/__init__.py index 43890c08306..d28563a9540 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_login/get/response_for_200/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_login/get/response_for_200/__init__.py @@ -14,9 +14,11 @@ import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 +from petstore_api.components.headers import ref_schema_header_header as parameter_ref_schema_header from . import parameter_x_rate_limit from petstore_api.components.headers import int32_json_content_type_header_header as parameter_int32_json_content_type_header from . import parameter_x_expires_after +from petstore_api.components.headers import ref_content_schema_header_header as parameter_ref_content_schema_header from petstore_api.components.headers import string_header_header as parameter_string_header from petstore_api.components.headers import number_header_header as parameter_number_header @@ -25,8 +27,10 @@ class Header: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { + 'ref-schema-header': typing.Union[parameter_ref_schema_header.schema, ], 'X-Rate-Limit': typing.Union[parameter_x_rate_limit.schema, decimal.Decimal, int, ], 'int32': typing.Union[parameter_int32_json_content_type_header.schema, decimal.Decimal, int, ], + 'ref-content-schema-header': typing.Union[parameter_ref_content_schema_header.schema, ], 'stringHeader': typing.Union[parameter_string_header.schema, str, ], 'numberHeader': typing.Union[parameter_number_header.schema, str, ], } @@ -45,9 +49,11 @@ class Params(RequiredParams, OptionalParams): parameters = [ + parameter_ref_schema_header.parameter_oapg, parameter_x_rate_limit.parameter_oapg, parameter_int32_json_content_type_header.parameter_oapg, parameter_x_expires_after.parameter_oapg, + parameter_ref_content_schema_header.parameter_oapg, parameter_string_header.parameter_oapg, parameter_number_header.parameter_oapg, ] diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.py index 328be90ec45..58472e1ac41 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.py @@ -24,10 +24,10 @@ from petstore_api import schemas # noqa: F401 from petstore_api.components.responses import success_description_only_response as response_for_200 +from petstore_api.components.parameters import parameter_path_user_name from .. import path from . import response_for_404 -from . import parameter_0 @@ -35,7 +35,7 @@ class RequestPathParameters: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { - 'username': typing.Union[parameter_0.schema, str, ], + 'username': typing.Union[parameter_path_user_name.schema, str, ], } ) OptionalParams = typing_extensions.TypedDict( @@ -51,7 +51,7 @@ class Params(RequiredParams, OptionalParams): parameters = [ - parameter_0.parameter_oapg, + parameter_path_user_name.parameter_oapg, ] __StatusCodeToResponse = typing_extensions.TypedDict( diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.pyi b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.pyi index 3c88c02d79c..c55c51bbd5d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.pyi +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/delete/__init__.pyi @@ -24,9 +24,9 @@ import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 from petstore_api.components.responses import success_description_only_response as response_for_200 +from petstore_api.components.parameters import parameter_path_user_name from . import response_for_404 -from . import parameter_0 @@ -34,7 +34,7 @@ class RequestPathParameters: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { - 'username': typing.Union[parameter_0.schema, str, ], + 'username': typing.Union[parameter_path_user_name.schema, str, ], } ) OptionalParams = typing_extensions.TypedDict( @@ -50,7 +50,7 @@ class RequestPathParameters: parameters = [ - parameter_0.parameter_oapg, + parameter_path_user_name.parameter_oapg, ] class BaseApi(api_client.Api): diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.py index f70a8fea25e..77aff5ec993 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.py @@ -24,12 +24,12 @@ import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 +from petstore_api.components.parameters import parameter_path_user_name from .. import path from . import response_for_200 from . import response_for_400 from . import response_for_404 -from . import parameter_0 @@ -37,7 +37,7 @@ class RequestPathParameters: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { - 'username': typing.Union[parameter_0.schema, str, ], + 'username': typing.Union[parameter_path_user_name.schema, str, ], } ) OptionalParams = typing_extensions.TypedDict( @@ -53,7 +53,7 @@ class Params(RequiredParams, OptionalParams): parameters = [ - parameter_0.parameter_oapg, + parameter_path_user_name.parameter_oapg, ] __StatusCodeToResponse = typing_extensions.TypedDict( diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.pyi b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.pyi index 800d174be9e..9c5e11d6c98 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.pyi +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/get/__init__.pyi @@ -24,11 +24,11 @@ import uuid # noqa: F401 import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 +from petstore_api.components.parameters import parameter_path_user_name from . import response_for_200 from . import response_for_400 from . import response_for_404 -from . import parameter_0 @@ -36,7 +36,7 @@ class RequestPathParameters: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { - 'username': typing.Union[parameter_0.schema, str, ], + 'username': typing.Union[parameter_path_user_name.schema, str, ], } ) OptionalParams = typing_extensions.TypedDict( @@ -52,7 +52,7 @@ class RequestPathParameters: parameters = [ - parameter_0.parameter_oapg, + parameter_path_user_name.parameter_oapg, ]_all_accept_content_types = ( 'application/xml', 'application/json', diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.py index 659700c3c7e..d4fd1b4c6e8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.py @@ -24,12 +24,12 @@ import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 +from petstore_api.components.parameters import parameter_path_user_name from .. import path from . import response_for_400 from . import response_for_404 from . import request_body -from . import parameter_0 @@ -37,7 +37,7 @@ class RequestPathParameters: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { - 'username': typing.Union[parameter_0.schema, str, ], + 'username': typing.Union[parameter_path_user_name.schema, str, ], } ) OptionalParams = typing_extensions.TypedDict( @@ -53,7 +53,7 @@ class Params(RequiredParams, OptionalParams): parameters = [ - parameter_0.parameter_oapg, + parameter_path_user_name.parameter_oapg, ] __StatusCodeToResponse = typing_extensions.TypedDict( diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.pyi b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.pyi index 5b9e01539ca..1772d1caed3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.pyi +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/user_username/put/__init__.pyi @@ -24,11 +24,11 @@ import uuid # noqa: F401 import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 +from petstore_api.components.parameters import parameter_path_user_name from . import response_for_400 from . import response_for_404 from . import request_body -from . import parameter_0 @@ -36,7 +36,7 @@ class RequestPathParameters: RequiredParams = typing_extensions.TypedDict( 'RequiredParams', { - 'username': typing.Union[parameter_0.schema, str, ], + 'username': typing.Union[parameter_path_user_name.schema, str, ], } ) OptionalParams = typing_extensions.TypedDict( @@ -52,7 +52,7 @@ class RequestPathParameters: parameters = [ - parameter_0.parameter_oapg, + parameter_path_user_name.parameter_oapg, ] class BaseApi(api_client.Api):