Skip to content

Commit

Permalink
refactor: unify getTypeDeclaration for rust
Browse files Browse the repository at this point in the history
  • Loading branch information
DDtKey committed Feb 21, 2024
1 parent 91e0dce commit 401bedb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public String getTypeDeclaration(Schema p) {
String datatype;
try {
datatype = toModelName(ModelUtils.getSimpleRef(p.get$ref()));
datatype = "models::" + datatype;
datatype = "models::" + toModelName(datatype);
} catch (Exception e) {
LOGGER.warn("Error obtaining the datatype from schema (model):{}. Datatype default to Object", p);
datatype = "Object";
Expand All @@ -261,7 +261,20 @@ public String getTypeDeclaration(Schema p) {
return typeMapping.get("file");
}

return super.getTypeDeclaration(p);
String oasType = getSchemaType(p);
if (typeMapping.containsKey(oasType)) {
return typeMapping.get(oasType);
}

if (typeMapping.containsValue(oasType)) {
return oasType;
}

if (languageSpecificPrimitives.contains(oasType)) {
return oasType;
}

return "models::" + toModelName(oasType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,24 +439,9 @@ public String modelDocFileFolder() {

@Override
public String getTypeDeclaration(Schema p) {
// use unaliased schema for client-side
Schema unaliasSchema = unaliasSchema(p);
String typeDeclaration = super.getTypeDeclaration(unaliasSchema);

// Check if we need to UpperCamelize the type after super invocation
String schemaType = getSchemaType(unaliasSchema);
if (typeDeclaration.equals(schemaType)) {
if (typeMapping.containsValue(schemaType)) {
return schemaType;
}

if (languageSpecificPrimitives.contains(schemaType)) {
return schemaType;
}

typeDeclaration = "models::" + toModelName(schemaType);
}

return typeDeclaration;
return super.getTypeDeclaration(unaliasSchema);
}

@Override
Expand Down

0 comments on commit 401bedb

Please sign in to comment.