Skip to content

Commit

Permalink
Code clean-up: remove DefaultCodegen#getSimpleRef(String) (#19)
Browse files Browse the repository at this point in the history
Use ModelUtils#getSimpleRef(String) instead
  • Loading branch information
jmini authored and wing328 committed May 13, 2018
1 parent 737e639 commit 41b0ff3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> 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);
}
Expand Down Expand Up @@ -1593,7 +1593,7 @@ protected void addProperties(Map<String, Schema> properties, List<String> 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;
}
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -4001,7 +3999,7 @@ protected Schema detectParent(ComposedSchema composedSchema, Map<String, Schema>
if (StringUtils.isBlank(ref)) {
return null;
}
ref = getSimpleRef(ref);
ref = ModelUtils.getSimpleRef(ref);
return allSchemas.get(ref);
}
return null;
Expand All @@ -4014,16 +4012,11 @@ protected String getParentName(ComposedSchema composedSchema, Map<String, Schema
if (StringUtils.isBlank(ref)) {
return null;
}
return getSimpleRef(ref);
return ModelUtils.getSimpleRef(ref);
}
return null;
}

// TODO decommission this function and replace it with ModelUtils.getSimpleRef() directly
protected String getSimpleRef(String ref) {
return ModelUtils.getSimpleRef(ref);
}

protected String getCollectionFormat(Parameter parameter) {
if (Parameter.StyleEnum.FORM.equals(parameter.getStyle())) {
// Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-values
Expand Down Expand Up @@ -4066,7 +4059,7 @@ public List<CodegenParameter> 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<String, Schema> properties = schema.getProperties();
Expand Down Expand Up @@ -4221,7 +4214,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\"\"";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(\"\")";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -826,7 +826,7 @@ public CodegenModel fromModel(String name, Schema model, Map<String, Schema> 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)) {
Expand Down Expand Up @@ -1051,7 +1051,7 @@ private boolean paramHasXmlNamespace(CodegenParameter param, Map<String, Schema>

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();
Expand Down

0 comments on commit 41b0ff3

Please # to comment.