better warning, default value (#1492)

This commit is contained in:
William Cheng 2018-11-19 20:55:29 +08:00 committed by GitHub
parent b9949e1a8e
commit 363b095721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -297,8 +297,12 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
} }
if (projectDescription == null) { if (projectDescription == null) {
// when projectDescription is not specified, use info.description // when projectDescription is not specified, use info.description
if (StringUtils.isEmpty(info.getDescription())) {
projectDescription = "JS API client generated by OpenAPI Generator";
} else {
projectDescription = sanitizeName(info.getDescription()); projectDescription = sanitizeName(info.getDescription());
} }
}
// when licenceName is not specified, use info.license // when licenceName is not specified, use info.license
if (additionalProperties.get(CodegenConstants.LICENSE_NAME) == null && info.getLicense() != null) { if (additionalProperties.get(CodegenConstants.LICENSE_NAME) == null && info.getLicense() != null) {
@ -506,11 +510,16 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
private String getNameUsingModelPropertyNaming(String name) { private String getNameUsingModelPropertyNaming(String name) {
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) { switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
case original: return name; case original:
case camelCase: return org.openapitools.codegen.utils.StringUtils.camelize(name, true); return name;
case PascalCase: return org.openapitools.codegen.utils.StringUtils.camelize(name); case camelCase:
case snake_case: return org.openapitools.codegen.utils.StringUtils.underscore(name); return org.openapitools.codegen.utils.StringUtils.camelize(name, true);
default: throw new IllegalArgumentException("Invalid model property naming '" + case PascalCase:
return org.openapitools.codegen.utils.StringUtils.camelize(name);
case snake_case:
return org.openapitools.codegen.utils.StringUtils.underscore(name);
default:
throw new IllegalArgumentException("Invalid model property naming '" +
name + "'. Must be 'original', 'camelCase', " + name + "'. Must be 'original', 'camelCase', " +
"'PascalCase' or 'snake_case'"); "'PascalCase' or 'snake_case'");
} }
@ -871,7 +880,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
codegenModel.getVendorExtensions().put("x-itemType", getSchemaType(ModelUtils.getAdditionalProperties(model))); codegenModel.getVendorExtensions().put("x-itemType", getSchemaType(ModelUtils.getAdditionalProperties(model)));
} else { } else {
String type = model.getType(); String type = model.getType();
if (isPrimitiveType(type)){ if (isPrimitiveType(type)) {
codegenModel.vendorExtensions.put("x-isPrimitive", true); codegenModel.vendorExtensions.put("x-isPrimitive", true);
} }
} }

View File

@ -179,7 +179,7 @@ public class URLPathUtils {
LOGGER.warn("'scheme' not defined in the spec (2.0). Default to [http] for server URL [{}]", url); LOGGER.warn("'scheme' not defined in the spec (2.0). Default to [http] for server URL [{}]", url);
} else if (url.startsWith("/")) { } else if (url.startsWith("/")) {
url = LOCAL_HOST + url; url = LOCAL_HOST + url;
LOGGER.warn("'host' not defined in the spec (2.0). Default to [{}] for server URL [{}]", LOCAL_HOST, url); LOGGER.warn("'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [{}] for server URL [{}]", LOCAL_HOST, url);
} else if (!url.matches("[a-zA-Z][0-9a-zA-Z.+\\-]+://.+")) { } else if (!url.matches("[a-zA-Z][0-9a-zA-Z.+\\-]+://.+")) {
// Add http scheme for urls without a scheme. // Add http scheme for urls without a scheme.
// 2.0 spec is restricted to the following schemes: "http", "https", "ws", "wss" // 2.0 spec is restricted to the following schemes: "http", "https", "ws", "wss"