Skip to content

Commit ff00e47

Browse files
authored
Merge branch 'master' into issue-470-swift-4-multiple-enum-error
2 parents e079de8 + 1dfd7ab commit ff00e47

File tree

106 files changed

+2436
-1642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2436
-1642
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@
247247
</dependencies>
248248
<properties>
249249
<swagger-codegen-version>3.0.12-SNAPSHOT</swagger-codegen-version>
250-
<swagger-parser-version>2.0.14</swagger-parser-version>
251-
<swagger-core-version>2.0.9</swagger-core-version>
252-
<jackson-version>2.9.9</jackson-version>
250+
<swagger-parser-version>2.0.15-SNAPSHOT</swagger-parser-version>
251+
<swagger-core-version>2.0.10-SNAPSHOT</swagger-core-version>
252+
<jackson-version>2.9.10</jackson-version>
253253
<scala-version>2.11.1</scala-version>
254254
<felix-version>3.3.0</felix-version>
255255
<commons-io-version>2.4</commons-io-version>

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
21472147
while (true) {
21482148
boolean exists = false;
21492149
for (CodegenParameter cp : allParams) {
2150-
if (codegenParameter.paramName.equals(cp.paramName)) {
2150+
if (codegenParameter.paramName != null && codegenParameter.paramName.equals(cp.paramName)) {
21512151
exists = true;
21522152
break;
21532153
}

src/main/java/io/swagger/codegen/v3/generators/dotnet/AbstractCSharpCodegen.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.swagger.codegen.v3.generators.handlebars.lambda.TitlecaseLambda;
1616
import io.swagger.codegen.v3.generators.handlebars.lambda.UppercaseLambda;
1717
import io.swagger.codegen.v3.utils.ModelUtils;
18+
import io.swagger.codegen.v3.utils.URLPathUtil;
1819
import io.swagger.v3.oas.models.OpenAPI;
1920
import io.swagger.v3.oas.models.Operation;
2021
import io.swagger.v3.oas.models.PathItem;
@@ -33,6 +34,7 @@
3334
import org.slf4j.LoggerFactory;
3435

3536
import java.io.File;
37+
import java.net.URL;
3638
import java.util.ArrayList;
3739
import java.util.Arrays;
3840
import java.util.HashMap;
@@ -959,6 +961,18 @@ public void setPreserveNewLines(boolean preserveNewLines) {
959961
@Override
960962
public void preprocessOpenAPI(OpenAPI openAPI) {
961963
super.preprocessOpenAPI(openAPI);
964+
965+
final URL urlInfo = URLPathUtil.getServerURL(openAPI);
966+
if ( urlInfo != null && urlInfo.getPort() > 0) {
967+
additionalProperties.put("serverUrl", String.format("%s://%s:%s", urlInfo.getProtocol(), urlInfo.getHost(), urlInfo.getPort()));
968+
969+
if (StringUtils.isNotBlank(urlInfo.getPath())) {
970+
additionalProperties.put("basePathWithoutHost", urlInfo.getPath());
971+
}
972+
} else {
973+
additionalProperties.put("serverUrl", URLPathUtil.LOCAL_HOST);
974+
}
975+
962976
if (this.preserveNewLines) {
963977
Map<String, Schema> schemaMap = openAPI.getComponents() != null ? openAPI.getComponents().getSchemas() : null;
964978
if (schemaMap != null) {
@@ -1056,4 +1070,4 @@ public void postProcessParameter(CodegenParameter parameter) {
10561070
}
10571071
*/
10581072

1059-
}
1073+
}

src/main/java/io/swagger/codegen/v3/generators/dotnet/AspNetCoreServerCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.swagger.codegen.v3.CodegenType;
1111
import io.swagger.codegen.v3.SupportingFile;
1212
import io.swagger.codegen.v3.generators.handlebars.ExtensionHelper;
13+
import io.swagger.codegen.v3.utils.URLPathUtil;
1314
import io.swagger.v3.core.util.Json;
1415
import io.swagger.v3.oas.models.OpenAPI;
1516
import io.swagger.v3.oas.models.security.SecurityScheme;
@@ -18,6 +19,7 @@
1819
import org.slf4j.LoggerFactory;
1920

2021
import java.io.File;
22+
import java.net.URL;
2123
import java.util.Arrays;
2224
import java.util.List;
2325
import java.util.Map;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.swagger.codegen.v3.generators.handlebars.lambda;
2+
3+
import com.github.jknack.handlebars.Lambda;
4+
import com.github.jknack.handlebars.Template;
5+
6+
import java.io.IOException;
7+
8+
/**
9+
* @author Franz See <[email protected]> <https://see.net.ph>
10+
*/
11+
public class CapitaliseLambda extends LowercaseLambda implements Lambda {
12+
13+
@Override
14+
public Object apply(Object o, Template template) throws IOException {
15+
String text = (String) super.apply(o, template);
16+
if (text.length() == 1) {
17+
text = String.valueOf(Character.toUpperCase(text.charAt(0)));
18+
} else if (text.length() > 1) {
19+
text = Character.toUpperCase(text.charAt(0)) + text.substring(1);
20+
}
21+
return text;
22+
}
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.swagger.codegen.v3.generators.handlebars.lambda;
2+
3+
import com.github.jknack.handlebars.Lambda;
4+
import com.github.jknack.handlebars.Template;
5+
import io.swagger.codegen.v3.CodegenConfig;
6+
7+
import java.io.IOException;
8+
import java.util.regex.Matcher;
9+
10+
/**
11+
* @author Franz See <[email protected]> <https://see.net.ph>
12+
*/
13+
public class EscapeDoubleQuotesLambda implements Lambda {
14+
15+
private CodegenConfig generator = null;
16+
17+
public EscapeDoubleQuotesLambda() {
18+
19+
}
20+
21+
public EscapeDoubleQuotesLambda generator(final CodegenConfig generator) {
22+
this.generator = generator;
23+
return this;
24+
}
25+
26+
@Override
27+
public Object apply(Object o, Template template) throws IOException {
28+
String text = template.apply(o);
29+
if (text == null || text.length() == 0) {
30+
return text;
31+
}
32+
text = text.replaceAll("\"", Matcher.quoteReplacement("\\\""));
33+
if (generator != null && generator.reservedWords().contains(text)) {
34+
text = generator.escapeReservedWord(text);
35+
}
36+
37+
return text;
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.swagger.codegen.v3.generators.handlebars.lambda;
2+
3+
import com.github.jknack.handlebars.Lambda;
4+
import com.github.jknack.handlebars.Template;
5+
import io.swagger.codegen.v3.CodegenConfig;
6+
7+
import java.io.IOException;
8+
9+
/**
10+
* @author Franz See <[email protected]> <https://see.net.ph>
11+
*/
12+
public class RemoveLineBreakLambda implements Lambda {
13+
14+
private CodegenConfig generator = null;
15+
16+
public RemoveLineBreakLambda() {
17+
18+
}
19+
20+
public RemoveLineBreakLambda generator(final CodegenConfig generator) {
21+
this.generator = generator;
22+
return this;
23+
}
24+
25+
@Override
26+
public Object apply(Object o, Template template) throws IOException {
27+
String text = template.apply(o);
28+
if (text == null || text.length() == 0) {
29+
return text;
30+
}
31+
text = text.replaceAll("\\r|\\n", "");
32+
if (generator != null && generator.reservedWords().contains(text)) {
33+
text = generator.escapeReservedWord(text);
34+
}
35+
36+
return text;
37+
}
38+
}

src/main/java/io/swagger/codegen/v3/generators/java/JavaClientCodegen.java

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@ public JavaClientCodegen() {
8383
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
8484
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
8585

86-
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'.");
87-
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.9.9");
88-
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.9");
86+
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'.");
87+
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.9.10");
88+
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.10");
8989
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'.");
9090
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.");
9191
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)");
9292
supportedLibraries.put("resttemplate", "HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.9.9");
9393
supportedLibraries.put("resteasy", "HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.9.9");
94-
supportedLibraries.put("vertx", "HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.9.9");
95-
supportedLibraries.put("google-api-client", "HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.9.9");
9694

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

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

193-
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
194-
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
195-
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
196-
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
197-
}
198193
supportingFiles.add(new SupportingFile( "gradlew.mustache", "", "gradlew") );
199194
supportingFiles.add(new SupportingFile( "gradlew.bat.mustache", "", "gradlew.bat") );
200195
supportingFiles.add(new SupportingFile( "gradle-wrapper.properties.mustache",
@@ -215,7 +210,7 @@ public void processOpts() {
215210
apiDocTemplateFiles.remove("api_doc.mustache");
216211
}
217212

218-
if (!("feign".equals(getLibrary()) || "resttemplate".equals(getLibrary()) || usesAnyRetrofitLibrary() || "google-api-client".equals(getLibrary()))) {
213+
if (!("feign".equals(getLibrary()) || "resttemplate".equals(getLibrary()) || usesAnyRetrofitLibrary())) {
219214
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
220215
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
221216
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
@@ -250,18 +245,6 @@ public void processOpts() {
250245
} else if("resttemplate".equals(getLibrary())) {
251246
additionalProperties.put("jackson", "true");
252247
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
253-
} else if("vertx".equals(getLibrary())) {
254-
typeMapping.put("file", "AsyncFile");
255-
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile");
256-
setJava8Mode(true);
257-
additionalProperties.put("java8", "true");
258-
additionalProperties.put("jackson", "true");
259-
260-
apiTemplateFiles.put("apiImpl.mustache", "Impl.java");
261-
apiTemplateFiles.put("rxApiImpl.mustache", ".java");
262-
supportingFiles.remove(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
263-
} else if ("google-api-client".equals(getLibrary())) {
264-
additionalProperties.put("jackson", "true");
265248
} else {
266249
LOGGER.error("Unknown library option (-l/--library): " + getLibrary());
267250
}
@@ -397,16 +380,7 @@ && getBooleanValue(another, CodegenConstants.IS_PATH_PARAM_EXT_NAME)){
397380

398381
@Override
399382
public String apiFilename(String templateName, String tag) {
400-
if("vertx".equals(getLibrary())) {
401-
String suffix = apiTemplateFiles().get(templateName);
402-
String subFolder = "";
403-
if (templateName.startsWith("rx")) {
404-
subFolder = "/rxjava";
405-
}
406-
return apiFileFolder() + subFolder + '/' + toApiFilename(tag) + suffix;
407-
} else {
408-
return super.apiFilename(templateName, tag);
409-
}
383+
return super.apiFilename(templateName, tag);
410384
}
411385

412386
/**

0 commit comments

Comments
 (0)