Skip to content

Commit

Permalink
Merge pull request #1 from swagger-api/master
Browse files Browse the repository at this point in the history
Update fork
  • Loading branch information
crazyk2 authored Oct 15, 2019
2 parents a14bf10 + ec3bc36 commit f4fb131
Show file tree
Hide file tree
Showing 262 changed files with 462 additions and 9,178 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.12-SNAPSHOT</version>
<version>1.0.13-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -246,10 +246,10 @@
</dependency>
</dependencies>
<properties>
<swagger-codegen-version>3.0.12-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.15-SNAPSHOT</swagger-parser-version>
<swagger-core-version>2.0.9</swagger-core-version>
<jackson-version>2.9.9</jackson-version>
<swagger-codegen-version>3.0.12</swagger-codegen-version>
<swagger-parser-version>2.0.15</swagger-parser-version>
<swagger-core-version>2.0.10</swagger-core-version>
<jackson-version>2.9.10</jackson-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<commons-io-version>2.4</commons-io-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4133,16 +4133,23 @@ else if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle())) {
}
}

private boolean isObjectSchema (Schema schema) {
public boolean isObjectSchema (Schema schema) {
if (schema instanceof ObjectSchema ||schema instanceof ComposedSchema) {
return true;
}
if (SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType()) && !(schema instanceof MapSchema)) {
if (SchemaTypeUtil.OBJECT_TYPE.equalsIgnoreCase(schema.getType()) && !(schema instanceof MapSchema)) {
return true;
}
if (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty()) {
return true;
}
if (StringUtils.isNotBlank(schema.get$ref())) {
Schema refSchema = OpenAPIUtil.getSchemaFromRefSchema(schema, openAPI);
if (refSchema != null) {
return isObjectSchema(refSchema);
}
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ private void configureModel(CodegenModel codegenModel, String name) {

private boolean hasNonObjectSchema(List<Schema> schemas) {
for (Schema schema : schemas) {
boolean hasNonObjectSchema = (!(schema instanceof ObjectSchema)) || (schema.getProperties() != null && !schema.getProperties().isEmpty());
if (hasNonObjectSchema) {
if (!codegenConfig.isObjectSchema(schema)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.swagger.codegen.v3.generators.handlebars.lambda.TitlecaseLambda;
import io.swagger.codegen.v3.generators.handlebars.lambda.UppercaseLambda;
import io.swagger.codegen.v3.utils.ModelUtils;
import io.swagger.codegen.v3.utils.URLPathUtil;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
Expand All @@ -33,6 +34,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -959,6 +961,18 @@ public void setPreserveNewLines(boolean preserveNewLines) {
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);

final URL urlInfo = URLPathUtil.getServerURL(openAPI);
if ( urlInfo != null && urlInfo.getPort() > 0) {
additionalProperties.put("serverUrl", String.format("%s://%s:%s", urlInfo.getProtocol(), urlInfo.getHost(), urlInfo.getPort()));

if (StringUtils.isNotBlank(urlInfo.getPath())) {
additionalProperties.put("basePathWithoutHost", urlInfo.getPath());
}
} else {
additionalProperties.put("serverUrl", URLPathUtil.LOCAL_HOST);
}

if (this.preserveNewLines) {
Map<String, Schema> schemaMap = openAPI.getComponents() != null ? openAPI.getComponents().getSchemas() : null;
if (schemaMap != null) {
Expand Down Expand Up @@ -1056,4 +1070,4 @@ public void postProcessParameter(CodegenParameter parameter) {
}
*/

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.codegen.v3.CodegenType;
import io.swagger.codegen.v3.SupportingFile;
import io.swagger.codegen.v3.generators.handlebars.ExtensionHelper;
import io.swagger.codegen.v3.utils.URLPathUtil;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityScheme;
Expand All @@ -18,6 +19,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public void processOpts() {
} else {
importMapping.put("Schema", "io.swagger.v3.oas.annotations.media.Schema");
}

importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty");
importMapping.put("JsonSubTypes", "com.fasterxml.jackson.annotation.JsonSubTypes");
importMapping.put("JsonTypeInfo", "com.fasterxml.jackson.annotation.JsonTypeInfo");
Expand All @@ -398,7 +398,7 @@ public void processOpts() {
if(additionalProperties.containsKey(JAVA8_MODE)) {
setJava8Mode(Boolean.parseBoolean(additionalProperties.get(JAVA8_MODE).toString()));
if ( java8Mode ) {
additionalProperties.put("java8", "true");
additionalProperties.put("java8", true);
}
}

Expand Down Expand Up @@ -427,7 +427,7 @@ public void processOpts() {
importMapping.put("LocalDate", "org.joda.time.LocalDate");
importMapping.put("DateTime", "org.joda.time.DateTime");
} else if (dateLibrary.startsWith("java8")) {
additionalProperties.put("java8", "true");
additionalProperties.put("java8", true);
additionalProperties.put("jsr310", "true");
typeMapping.put("date", "LocalDate");
importMapping.put("LocalDate", "java.time.LocalDate");
Expand All @@ -439,7 +439,7 @@ public void processOpts() {
importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
}
} else if (dateLibrary.equals("legacy")) {
additionalProperties.put("legacyDates", "true");
additionalProperties.put("legacyDates", true);
}
}

Expand Down Expand Up @@ -947,7 +947,9 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
}
if (model.discriminator != null && model.discriminator.getPropertyName().equals(property.baseName)) {
property.vendorExtensions.put("x-is-discriminator-property", true);
model.imports.add("JsonTypeId");
if (additionalProperties.containsKey("jackson")) {
model.imports.add("JsonTypeId");
}
}
}

Expand Down Expand Up @@ -1345,7 +1347,7 @@ private String deriveInvokerPackageName(String input) {
public void setSupportJava6(boolean value) {
this.supportJava6 = value;
}

public String toRegularExpression(String pattern) {
return escapeText(pattern);
}
Expand Down Expand Up @@ -1401,7 +1403,7 @@ public void setLanguageArguments(List<CodegenArgument> languageArguments) {
.value(Boolean.FALSE.toString()));
}
}

super.setLanguageArguments(languageArguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
if (!this.additionalProperties.containsKey("serverPort")) {
final URL urlInfo = URLPathUtil.getServerURL(openAPI);
String port = "8080"; // Default value for a JEE Server
if ( urlInfo != null && urlInfo.getPort() != 0) {
port = String.valueOf(urlInfo.getPort());
if ( urlInfo != null && urlInfo.getPort() > 0) {
port = String.valueOf(urlInfo.getPort());
}
this.additionalProperties.put("serverPort", port);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,14 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));

supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.9.9. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.9.9");
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.9");
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.9.10. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.9.10");
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.10");
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.8.0. JSON processing: Gson 2.6.1 (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)");
supportedLibraries.put("resttemplate", "HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.9.9");
supportedLibraries.put("resteasy", "HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.9.9");
supportedLibraries.put("vertx", "HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.9.9");
supportedLibraries.put("google-api-client", "HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.9.9");

CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
libraryOption.setEnum(supportedLibraries);
Expand Down Expand Up @@ -187,14 +185,11 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
}

// google-api-client doesn't use the Swagger auth, because it uses Google Credential directly (HttpRequestInitializer)
if (!"google-api-client".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));

supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
}
supportingFiles.add(new SupportingFile( "gradlew.mustache", "", "gradlew") );
supportingFiles.add(new SupportingFile( "gradlew.bat.mustache", "", "gradlew.bat") );
supportingFiles.add(new SupportingFile( "gradle-wrapper.properties.mustache",
Expand All @@ -215,7 +210,7 @@ public void processOpts() {
apiDocTemplateFiles.remove("api_doc.mustache");
}

if (!("feign".equals(getLibrary()) || "resttemplate".equals(getLibrary()) || usesAnyRetrofitLibrary() || "google-api-client".equals(getLibrary()))) {
if (!("feign".equals(getLibrary()) || "resttemplate".equals(getLibrary()) || usesAnyRetrofitLibrary())) {
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
Expand Down Expand Up @@ -250,18 +245,6 @@ public void processOpts() {
} else if("resttemplate".equals(getLibrary())) {
additionalProperties.put("jackson", "true");
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
} else if("vertx".equals(getLibrary())) {
typeMapping.put("file", "AsyncFile");
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile");
setJava8Mode(true);
additionalProperties.put("java8", "true");
additionalProperties.put("jackson", "true");

apiTemplateFiles.put("apiImpl.mustache", "Impl.java");
apiTemplateFiles.put("rxApiImpl.mustache", ".java");
supportingFiles.remove(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
} else if ("google-api-client".equals(getLibrary())) {
additionalProperties.put("jackson", "true");
} else {
LOGGER.error("Unknown library option (-l/--library): " + getLibrary());
}
Expand Down Expand Up @@ -397,16 +380,7 @@ && getBooleanValue(another, CodegenConstants.IS_PATH_PARAM_EXT_NAME)){

@Override
public String apiFilename(String templateName, String tag) {
if("vertx".equals(getLibrary())) {
String suffix = apiTemplateFiles().get(templateName);
String subFolder = "";
if (templateName.startsWith("rx")) {
subFolder = "/rxjava";
}
return apiFileFolder() + subFolder + '/' + toApiFilename(tag) + suffix;
} else {
return super.apiFilename(templateName, tag);
}
return super.apiFilename(templateName, tag);
}

/**
Expand Down Expand Up @@ -547,7 +521,8 @@ protected List<Map<String, Object>> modelInheritanceSupportInGson(List<?> allMod
}
}
List<Map<String, Object>> parentsList = new ArrayList<>();
for (CodegenModel parentModel : byParent.keySet()) {
for (Map.Entry<CodegenModel, List<CodegenModel>> parentModelEntry : byParent.entrySet()) {
CodegenModel parentModel = parentModelEntry.getKey();
List<Map<String, Object>> childrenList = new ArrayList<>();
Map<String, Object> parent = new HashMap<>();
parent.put("classname", parentModel.classname);
Expand All @@ -566,6 +541,7 @@ protected List<Map<String, Object>> modelInheritanceSupportInGson(List<?> allMod
}
parentsList.add(parent);
}

return parentsList;
}

Expand Down
Loading

0 comments on commit f4fb131

Please sign in to comment.