forked from loafle/openapi-generator-original
fix NPE, add new files
This commit is contained in:
@@ -1459,13 +1459,9 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
protected void addProperties(Map<String, Schema> properties, List<String> required, Schema schema, Map<String, Schema> allSchemas) {
|
||||
if (schema == null) {
|
||||
throw new RuntimeException("schema cannot be null in addProperties");
|
||||
}
|
||||
|
||||
if (schema instanceof ComposedSchema) {
|
||||
ComposedSchema composedSchema = (ComposedSchema) schema;
|
||||
if(composedSchema.getAllOf() == null) {
|
||||
if (composedSchema.getAllOf() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1476,7 +1472,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(schema.get$ref())) {
|
||||
Schema interfaceSchema = allSchemas.get(schema.get$ref());
|
||||
Schema interfaceSchema = allSchemas.get(getSimpleRef(schema.get$ref()));
|
||||
addProperties(properties, required, interfaceSchema, allSchemas);
|
||||
return;
|
||||
}
|
||||
@@ -1646,11 +1642,11 @@ public class DefaultCodegen {
|
||||
} else { // type is number and without format
|
||||
property.isNumber = Boolean.TRUE;
|
||||
}
|
||||
|
||||
/* TODO fix Could not process model 'Enum_Test'.Please make sure that your schema is correct!
|
||||
if (p.getEnum() != null) {
|
||||
List<Double> _enum = p.getEnum();
|
||||
property._enum = new ArrayList<String>();
|
||||
for (Double i : _enum) {
|
||||
for (Double i : _enum) { <<<<< line throwing exception
|
||||
property._enum.add(i.toString());
|
||||
}
|
||||
property.isEnum = true;
|
||||
@@ -1659,7 +1655,7 @@ public class DefaultCodegen {
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
if (p instanceof DateSchema) {
|
||||
|
||||
@@ -1011,6 +1011,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
Set<String> allImports = new LinkedHashSet<String>();
|
||||
for (String key : definitions.keySet()) {
|
||||
Schema schema = definitions.get(key);
|
||||
if (schema == null)
|
||||
throw new RuntimeException("schema cannnot be null in processMoels");
|
||||
CodegenModel cm = config.fromModel(key, schema, allDefinitions);
|
||||
Map<String, Object> mo = new HashMap<String, Object>();
|
||||
mo.put("model", cm);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.openapitools.codegen.utils;
|
||||
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
public class URLPathUtil {
|
||||
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(URLPathUtil.class);
|
||||
|
||||
public static final String LOCAL_HOST = "http://localhost";
|
||||
|
||||
public static URL getServerURL(OpenAPI openAPI) {
|
||||
final List<Server> servers = openAPI.getServers();
|
||||
if (servers == null || servers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final Server server = servers.get(0);
|
||||
try {
|
||||
return new URL(server.getUrl());
|
||||
} catch (MalformedURLException e) {
|
||||
LOGGER.warn("Not valid URL: " + server.getUrl(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getScheme(OpenAPI openAPI, CodegenConfig config) {
|
||||
String scheme;
|
||||
URL url = getServerURL(openAPI);
|
||||
if (url != null) {
|
||||
scheme = url.getProtocol();
|
||||
} else {
|
||||
scheme = "https";
|
||||
}
|
||||
if (config != null) {
|
||||
scheme = config.escapeText(scheme);
|
||||
}
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public static String getHost(OpenAPI openAPI){
|
||||
if (openAPI.getServers() != null && openAPI.getServers().size() > 0) {
|
||||
return openAPI.getServers().get(0).getUrl();
|
||||
}
|
||||
return LOCAL_HOST;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user