mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-05 07:01:01 +00:00
[python] Fix NPE in example generation (#5082)
This commit is contained in:
parent
ac528aaf07
commit
bcff006dc8
@ -829,36 +829,39 @@ 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();
|
|
||||||
Set<String> propkeys = null;
|
|
||||||
if (properties != null) propkeys = properties.keySet();
|
|
||||||
if (toExclude != null && reqs.contains(toExclude)) {
|
|
||||||
reqs.remove(toExclude);
|
|
||||||
}
|
|
||||||
for (String toRemove : included_schemas) {
|
|
||||||
if (reqs.contains(toRemove)) {
|
|
||||||
reqs.remove(toRemove);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(schema.getTitle()) && !"null".equals(schema.getTitle())) {
|
Map<String, Schema> properties = schema.getProperties();
|
||||||
included_schemas.add(schema.getTitle());
|
Set<String> propkeys = null;
|
||||||
}
|
if (properties != null) propkeys = properties.keySet();
|
||||||
if (null != schema.getRequired()) for (Object toAdd : schema.getRequired()) {
|
if (toExclude != null && reqs.contains(toExclude)) {
|
||||||
reqs.add((String)toAdd);
|
reqs.remove(toExclude);
|
||||||
}
|
}
|
||||||
if (null!=propkeys) for (String propname : propkeys) {
|
for (String toRemove : included_schemas) {
|
||||||
Schema schema2 = properties.get(propname);
|
if (reqs.contains(toRemove)) {
|
||||||
if (reqs.contains(propname)) {
|
reqs.remove(toRemove);
|
||||||
String refTitle = schema2.getTitle();
|
}
|
||||||
if (StringUtils.isBlank(refTitle) || "null".equals(refTitle)) {
|
}
|
||||||
schema2.setTitle(propname);
|
if (StringUtils.isNotBlank(schema.getTitle()) && !"null".equals(schema.getTitle())) {
|
||||||
|
included_schemas.add(schema.getTitle());
|
||||||
|
}
|
||||||
|
if (null != schema.getRequired()) for (Object toAdd : schema.getRequired()) {
|
||||||
|
reqs.add((String) toAdd);
|
||||||
|
}
|
||||||
|
if (null != propkeys) for (String propname : propkeys) {
|
||||||
|
Schema schema2 = properties.get(propname);
|
||||||
|
if (reqs.contains(propname)) {
|
||||||
|
String refTitle = schema2.getTitle();
|
||||||
|
if (StringUtils.isBlank(refTitle) || "null".equals(refTitle)) {
|
||||||
|
schema2.setTitle(propname);
|
||||||
|
}
|
||||||
|
example += "\n" + indentation_string + underscore(propname) + " = " +
|
||||||
|
toExampleValueRecursive(schema2, included_schemas, indentation + 1) + ", ";
|
||||||
}
|
}
|
||||||
example += "\n" + indentation_string + underscore(propname) + " = "+
|
|
||||||
toExampleValueRecursive(schema2, included_schemas, indentation+1)+", ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
example +=")";
|
example +=")";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user