mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 17:19:15 +00:00
fix NPE with cpp qt5, add logic to avoid NPE with composed schema (#267)
This commit is contained in:
@@ -1148,6 +1148,18 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
**/
|
||||
@SuppressWarnings("static-method")
|
||||
public String getSchemaType(Schema schema) {
|
||||
// TODO better logic to handle compose schema
|
||||
if (schema instanceof ComposedSchema) { // composed schema
|
||||
ComposedSchema cs = (ComposedSchema) schema;
|
||||
for (Schema s : cs.getAllOf()) {
|
||||
if (s != null) {
|
||||
// using the first schema defined in allOf
|
||||
schema = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(schema.get$ref())) { // object
|
||||
// get the schema/model name from $ref
|
||||
String schemaName = ModelUtils.getSimpleRef(schema.get$ref());
|
||||
|
||||
@@ -345,6 +345,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
@@ -362,6 +363,11 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (type == null) {
|
||||
LOGGER.warn("Model name can't be null. Defaul to 'UnknownModel'.");
|
||||
type = "UnknownModel";
|
||||
}
|
||||
|
||||
if (typeMapping.keySet().contains(type) ||
|
||||
typeMapping.values().contains(type) ||
|
||||
importMapping.values().contains(type) ||
|
||||
|
||||
Reference in New Issue
Block a user