[python] Fix NPE in example generation (#5082)

This commit is contained in:
Jim Schubert 2020-01-22 19:22:18 -05:00 committed by GitHub
parent ac528aaf07
commit bcff006dc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -829,9 +829,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
// List<String> reqs = schema.getRequired(); // List<String> reqs = schema.getRequired();
// if required and optionals // if required and optionals
List<String> reqs = new ArrayList<String>(); List<String> reqs = new ArrayList<>();
for (Object toAdd : schema.getProperties().keySet()) if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
reqs.add((String)toAdd); for (Object toAdd : schema.getProperties().keySet()) {
reqs.add((String) toAdd);
}
Map<String, Schema> properties = schema.getProperties(); Map<String, Schema> properties = schema.getProperties();
Set<String> propkeys = null; Set<String> propkeys = null;
@ -848,17 +850,18 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
included_schemas.add(schema.getTitle()); included_schemas.add(schema.getTitle());
} }
if (null != schema.getRequired()) for (Object toAdd : schema.getRequired()) { if (null != schema.getRequired()) for (Object toAdd : schema.getRequired()) {
reqs.add((String)toAdd); reqs.add((String) toAdd);
} }
if (null!=propkeys) for (String propname : propkeys) { if (null != propkeys) for (String propname : propkeys) {
Schema schema2 = properties.get(propname); Schema schema2 = properties.get(propname);
if (reqs.contains(propname)) { if (reqs.contains(propname)) {
String refTitle = schema2.getTitle(); String refTitle = schema2.getTitle();
if (StringUtils.isBlank(refTitle) || "null".equals(refTitle)) { if (StringUtils.isBlank(refTitle) || "null".equals(refTitle)) {
schema2.setTitle(propname); schema2.setTitle(propname);
} }
example += "\n" + indentation_string + underscore(propname) + " = "+ example += "\n" + indentation_string + underscore(propname) + " = " +
toExampleValueRecursive(schema2, included_schemas, indentation+1)+", "; toExampleValueRecursive(schema2, included_schemas, indentation + 1) + ", ";
}
} }
} }
example +=")"; example +=")";