forked from loafle/openapi-generator-original
Fixes CodegenMediaType schema baseName (#11030)
This commit is contained in:
parent
b915ad99a8
commit
836e40f1d2
@ -6558,6 +6558,10 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
codegenParameter.pattern = toRegularExpression(schema.getPattern());
|
codegenParameter.pattern = toRegularExpression(schema.getPattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String toMediaTypeSchemaName(String contentType) {
|
||||||
|
return toModelName(contentType + "Schema");
|
||||||
|
}
|
||||||
|
|
||||||
protected LinkedHashMap<String, CodegenMediaType> getContent(Content content, Set<String> imports) {
|
protected LinkedHashMap<String, CodegenMediaType> getContent(Content content, Set<String> imports) {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -6605,9 +6609,9 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
ceMap.put(propName, ce);
|
ceMap.put(propName, ce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CodegenProperty schemaProp = fromProperty("schema", mt.getSchema());
|
|
||||||
CodegenMediaType codegenMt = new CodegenMediaType(schemaProp, ceMap);
|
|
||||||
String contentType = contentEntry.getKey();
|
String contentType = contentEntry.getKey();
|
||||||
|
CodegenProperty schemaProp = fromProperty(toMediaTypeSchemaName(contentType), mt.getSchema());
|
||||||
|
CodegenMediaType codegenMt = new CodegenMediaType(schemaProp, ceMap);
|
||||||
cmtContent.put(contentType, codegenMt);
|
cmtContent.put(contentType, codegenMt);
|
||||||
}
|
}
|
||||||
return cmtContent;
|
return cmtContent;
|
||||||
|
@ -3922,11 +3922,13 @@ public class DefaultCodegenTest {
|
|||||||
CodegenMediaType mt = content.get("application/json");
|
CodegenMediaType mt = content.get("application/json");
|
||||||
assertNull(mt.getEncoding());
|
assertNull(mt.getEncoding());
|
||||||
CodegenProperty cp = mt.getSchema();
|
CodegenProperty cp = mt.getSchema();
|
||||||
|
assertEquals(cp.baseName, "ApplicationJsonSchema");
|
||||||
assertNotNull(cp);
|
assertNotNull(cp);
|
||||||
|
|
||||||
mt = content.get("text/plain");
|
mt = content.get("text/plain");
|
||||||
assertNull(mt.getEncoding());
|
assertNull(mt.getEncoding());
|
||||||
cp = mt.getSchema();
|
cp = mt.getSchema();
|
||||||
|
assertEquals(cp.baseName, "TextPlainSchema");
|
||||||
assertNotNull(cp);
|
assertNotNull(cp);
|
||||||
// Note: the inline model resolver has a bug for this use case; it extracts an inline request body into a component
|
// Note: the inline model resolver has a bug for this use case; it extracts an inline request body into a component
|
||||||
// but the schema it references is not string type
|
// but the schema it references is not string type
|
||||||
@ -3940,11 +3942,13 @@ public class DefaultCodegenTest {
|
|||||||
mt = content.get("application/json");
|
mt = content.get("application/json");
|
||||||
assertNull(mt.getEncoding());
|
assertNull(mt.getEncoding());
|
||||||
cp = mt.getSchema();
|
cp = mt.getSchema();
|
||||||
|
assertEquals(cp.baseName, "ApplicationJsonSchema");
|
||||||
assertEquals(cp.complexType, "coordinates");
|
assertEquals(cp.complexType, "coordinates");
|
||||||
|
|
||||||
mt = content.get("text/plain");
|
mt = content.get("text/plain");
|
||||||
assertNull(mt.getEncoding());
|
assertNull(mt.getEncoding());
|
||||||
cp = mt.getSchema();
|
cp = mt.getSchema();
|
||||||
|
assertEquals(cp.baseName, "TextPlainSchema");
|
||||||
assertTrue(cp.isString);
|
assertTrue(cp.isString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user