From 41b0ff351bbe84323e67b3e2688644ec84a679be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bresson?= Date: Sun, 13 May 2018 09:25:45 +0200 Subject: [PATCH] Code clean-up: remove DefaultCodegen#getSimpleRef(String) (#19) Use ModelUtils#getSimpleRef(String) instead --- .../openapitools/codegen/DefaultCodegen.java | 21 +++++++------------ .../languages/CppPistacheServerCodegen.java | 2 +- .../languages/CppQt5ClientCodegen.java | 2 +- .../languages/CppRestClientCodegen.java | 2 +- .../languages/CppRestbedServerCodegen.java | 2 +- .../languages/CppTizenClientCodegen.java | 2 +- .../codegen/languages/RustServerCodegen.java | 6 +++--- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 806df83f4c8f..f642c0bb2ee6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1472,7 +1472,7 @@ public CodegenModel fromModel(String name, Schema schema, Map al continue; } Schema refSchema = null; - String ref = getSimpleRef(interfaceSchema.get$ref()); + String ref = ModelUtils.getSimpleRef(interfaceSchema.get$ref()); if (allDefinitions != null) { refSchema = allDefinitions.get(ref); } @@ -1593,7 +1593,7 @@ protected void addProperties(Map properties, List requir } if (StringUtils.isNotBlank(schema.get$ref())) { - Schema interfaceSchema = allSchemas.get(getSimpleRef(schema.get$ref())); + Schema interfaceSchema = allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())); addProperties(properties, required, interfaceSchema, allSchemas); return; } @@ -2225,9 +2225,7 @@ public CodegenOperation fromOperation(String path, } } else { // process body parameter - if (StringUtils.isNotBlank(requestBody.get$ref())) { - requestBody = openAPI.getComponents().getRequestBodies().get(getSimpleRef(requestBody.get$ref())); - } + requestBody = ModelUtils.getReferencedRequestBody(openAPI, requestBody); String bodyParameterName = ""; if (op.vendorExtensions != null && op.vendorExtensions.containsKey("x-codegen-request-body-name")) { @@ -4001,7 +3999,7 @@ protected Schema detectParent(ComposedSchema composedSchema, Map if (StringUtils.isBlank(ref)) { return null; } - ref = getSimpleRef(ref); + ref = ModelUtils.getSimpleRef(ref); return allSchemas.get(ref); } return null; @@ -4014,16 +4012,11 @@ protected String getParentName(ComposedSchema composedSchema, Map fromRequestBodyToFormParameters(RequestBody body, LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body); Schema schema = ModelUtils.getSchemaFromRequestBody(body); if (StringUtils.isNotBlank(schema.get$ref())) { - schema = schemas.get(getSimpleRef(schema.get$ref())); + schema = schemas.get(ModelUtils.getSimpleRef(schema.get$ref())); } if (schema.getProperties() != null && !schema.getProperties().isEmpty()) { Map properties = schema.getProperties(); @@ -4221,7 +4214,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Map sc LOGGER.debug("Request body = " + body); Schema schema = ModelUtils.getSchemaFromRequestBody(body); if (StringUtils.isNotBlank(schema.get$ref())) { - name = getSimpleRef(schema.get$ref()); + name = ModelUtils.getSimpleRef(schema.get$ref()); schema = schemas.get(name); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java index 83f721d9c24e..9384b748933a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java @@ -331,7 +331,7 @@ public String toDefaultValue(Schema p) { } return "std::vector<" + inner + ">()"; } else if (!StringUtils.isEmpty(p.get$ref())) { // model - return "new " + toModelName(getSimpleRef(p.get$ref())) + "()"; + return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()"; } else if (ModelUtils.isStringSchema(p)) { return "\"\""; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java index 3e7f02671ab9..4927f0344426 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java @@ -344,7 +344,7 @@ public String toDefaultValue(Schema p) { } else if (ModelUtils.isStringSchema(p)) { return "new QString(\"\")"; } else if (!StringUtils.isEmpty(p.get$ref())) { - return "new " + toModelName(getSimpleRef(p.get$ref())) + "()"; + return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()"; } return "NULL"; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestClientCodegen.java index d5cce8cb2ee4..cd5da4cd03cf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestClientCodegen.java @@ -337,7 +337,7 @@ public String toDefaultValue(Schema p) { } return "std::vector<" + inner + ">()"; } else if (!StringUtils.isEmpty(p.get$ref())) { - return "new " + toModelName(getSimpleRef(p.get$ref())) + "()"; + return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()"; } else if (ModelUtils.isStringSchema(p)) { return "utility::conversions::to_string_t(\"\")"; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java index c5144c3dc1f4..135cc82ac4b9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java @@ -324,7 +324,7 @@ public String toDefaultValue(Schema p) { } return "std::vector<" + inner + ">()"; } else if (!StringUtils.isEmpty(p.get$ref())) { - return "new " + toModelName(getSimpleRef(p.get$ref())) + "()"; + return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()"; } return "nullptr"; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java index e419d4270351..2f2afe39139b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java @@ -225,7 +225,7 @@ public String toDefaultValue(Schema p) { } else if (ModelUtils.isArraySchema(p)) { return "new std::list()"; } else if (!StringUtils.isEmpty(p.get$ref())) { - return "new " + toModelName(getSimpleRef(p.get$ref())) + "()"; + return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()"; } else if (ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)) { return "null"; } else if (ModelUtils.isStringSchema(p)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index 19f7dbe5f4e6..e0187887fa76 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -688,7 +688,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation Schema response = (Schema) rsp.schema; // Check whether we're returning an object with a defined XML namespace. if (response != null && (!StringUtils.isEmpty(response.get$ref()))) { - Schema model = definitions.get(getSimpleRef(response.get$ref())); + Schema model = definitions.get(ModelUtils.getSimpleRef(response.get$ref())); if ((model != null)) { XML xml = model.getXml(); if ((xml != null) && (xml.getNamespace() != null)) { @@ -826,7 +826,7 @@ public CodegenModel fromModel(String name, Schema model, Map all CodegenModel mdl = super.fromModel(name, model, allDefinitions); mdl.vendorExtensions.put("upperCaseName", name.toUpperCase()); if (!StringUtils.isEmpty(model.get$ref())) { - Schema schema = allDefinitions.get(getSimpleRef(model.get$ref())); + Schema schema = allDefinitions.get(ModelUtils.getSimpleRef(model.get$ref())); mdl.dataType = typeMapping.get(schema.getType()); } if (ModelUtils.isArraySchema(model)) { @@ -1051,7 +1051,7 @@ private boolean paramHasXmlNamespace(CodegenParameter param, Map if ((refName != null) && (refName instanceof String)) { String name = (String) refName; - Schema model = definitions.get(getSimpleRef(name)); + Schema model = definitions.get(ModelUtils.getSimpleRef(name)); if (model != null) { XML xml = model.getXml();