Skip to content

Commit 9670684

Browse files
authored
Merge branch 'master' into master
2 parents 8c9f516 + 9396a9f commit 9670684

File tree

75 files changed

+100
-16
lines changed

Some content is hidden

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

75 files changed

+100
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ dependency example:
7878
## Overview
7979
This is the Swagger Codegen project, which allows generation of API client libraries (SDK generation), server stubs and documentation automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification). Currently, the following languages/frameworks are supported:
8080

81-
- **API clients**: **ActionScript**, **Ada**, **Apex**, **Bash**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (Angular1.x, Angular2.x, Fetch, jQuery, Node)
81+
- **API clients**: **ActionScript**, **Ada**, **Apex**, **Bash**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (Angular1.x, Angular2.x, Fetch, jQuery, Node)
8282
- **Server stubs**: **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go**, **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin**, **PHP** (Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), Scalatra)
8383
- **API documentation generators**: **HTML**, **Confluence Wiki**
8484
- **Configuration files**: [**Apache2**](https://httpd.apache.org/)

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ protected String getScheme() {
107107
}
108108

109109
private String getHost() {
110+
StringBuilder hostBuilder = new StringBuilder();
111+
hostBuilder.append(getHostWithoutBasePath());
112+
if (!StringUtils.isEmpty(swagger.getBasePath()) && !swagger.getBasePath().equals("/")) {
113+
hostBuilder.append(swagger.getBasePath());
114+
}
115+
return hostBuilder.toString();
116+
}
117+
118+
private String getHostWithoutBasePath() {
110119
StringBuilder hostBuilder = new StringBuilder();
111120
hostBuilder.append(getScheme());
112121
hostBuilder.append("://");
@@ -116,9 +125,6 @@ private String getHost() {
116125
hostBuilder.append("localhost");
117126
LOGGER.warn("'host' not defined in the spec. Default to 'localhost'.");
118127
}
119-
if (!StringUtils.isEmpty(swagger.getBasePath()) && !swagger.getBasePath().equals("/")) {
120-
hostBuilder.append(swagger.getBasePath());
121-
}
122128
return hostBuilder.toString();
123129
}
124130

@@ -475,6 +481,7 @@ public int compare(CodegenOperation one, CodegenOperation another) {
475481
});
476482
Map<String, Object> operation = processOperations(config, tag, ops, allModels);
477483

484+
operation.put("hostWithoutBasePath", getHostWithoutBasePath());
478485
operation.put("basePath", basePath);
479486
operation.put("basePathWithoutHost", basePathWithoutHost);
480487
operation.put("contextPath", contextPath);
@@ -715,7 +722,7 @@ protected Map<String, Object> buildSupportFileBundle(List<Object> allOperations,
715722
if (swagger.getHost() != null) {
716723
bundle.put("host", swagger.getHost());
717724
}
718-
725+
bundle.put("hostWithoutBasePath", getHostWithoutBasePath());
719726
bundle.put("swagger", this.swagger);
720727
bundle.put("basePath", basePath);
721728
bundle.put("basePathWithoutHost", basePathWithoutHost);

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private void postProcessEnumRefs(final Map<String, Object> models) {
408408
// This is different in C# than most other generators, because enums in C# are compiled to integral types,
409409
// while enums in many other languages are true objects.
410410
CodegenModel refModel = enumRefs.get(var.datatype);
411-
var.allowableValues = refModel.allowableValues;
411+
var.allowableValues = new HashMap<>(refModel.allowableValues);
412412
var.isEnum = true;
413413

414414
updateCodegenPropertyEnum(var);

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Swift4Codegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
6060
protected static final String LIBRARY_PROMISE_KIT = "PromiseKit";
6161
protected static final String LIBRARY_RX_SWIFT = "RxSwift";
6262
protected static final String[] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT, LIBRARY_RX_SWIFT};
63+
protected static final String MODEL_CLASSES = "modelClasses";
6364
protected String projectName = "SwaggerClient";
6465
protected boolean unwrapRequired;
6566
protected boolean objcCompatible = false;
@@ -302,6 +303,10 @@ public void processOpts() {
302303
additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS);
303304
}
304305

306+
if (additionalProperties.containsKey(MODEL_CLASSES)) {
307+
additionalProperties.put("useModelClasses", true);
308+
}
309+
305310
setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));
306311

307312
supportingFiles.add(new SupportingFile("Podspec.mustache",

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Swift5Codegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Swift5Codegen extends DefaultCodegen implements CodegenConfig {
4747
private static final String LIBRARY_PROMISE_KIT = "PromiseKit";
4848
private static final String LIBRARY_RX_SWIFT = "RxSwift";
4949
private static final String[] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT, LIBRARY_RX_SWIFT};
50+
protected static final String MODEL_CLASSES = "modelClasses";
5051
protected String projectName = "SwaggerClient";
5152
private boolean unwrapRequired;
5253
private boolean objcCompatible = false;
@@ -289,6 +290,10 @@ public void processOpts() {
289290
additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS);
290291
}
291292

293+
if (additionalProperties.containsKey(MODEL_CLASSES)) {
294+
additionalProperties.put("useModelClasses", true);
295+
}
296+
292297
setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));
293298

294299
supportingFiles.add(new SupportingFile("Podspec.mustache",

modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,18 @@ dependencies {
127127
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
128128
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
129129
{{#joda}}
130-
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version",
130+
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
131131
{{/joda}}
132132
{{#java8}}
133133
compile "org.glassfish.jersey.inject:jersey-hk2:$jersey_version"
134-
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version",
134+
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
135135
{{/java8}}
136136
{{#supportJava6}}
137137
compile "commons-io:commons-io:$commons_io_version"
138138
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
139139
{{/supportJava6}}
140140
{{#threetenbp}}
141-
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
141+
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version"
142142
{{/threetenbp}}
143143
{{^java8}}
144144
compile "com.brsanthu:migbase64:2.2"

modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
5454
{{>generatedAnnotation}}
5555
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
5656
{{#operations}}
57+
@RequestMapping(value = "{{{contextPath}}}")
5758
public interface {{classname}} {
5859
{{#jdk8}}
5960

modules/swagger-codegen/src/main/resources/JavaSpring/libraries/spring-cloud/apiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package {{package}};
99
import {{configPackage}}.ClientConfiguration;
1010

1111
{{=<% %>=}}
12-
@FeignClient(name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%basePath%>}", configuration = ClientConfiguration.class)
12+
@FeignClient(name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%hostWithoutBasePath%>}", configuration = ClientConfiguration.class)
1313
<%={{ }}=%>
1414
public interface {{classname}}Client extends {{classname}} {
1515
}

modules/swagger-codegen/src/main/resources/go/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
148148
{{#hasFormParams}}
149149
{{#formParams}}
150150
{{#isFile}}
151-
{{^required}}
152151
var localVarFile {{dataType}}
152+
{{^required}}
153153
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
154154
localVarFileOk := false
155155
localVarFile, localVarFileOk = localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value().({{dataType}})

modules/swagger-codegen/src/main/resources/php/api.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ use {{invokerPackage}}\ObjectSerializer;
472472
$headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword());
473473
}
474474
{{/isBasic}}
475+
{{#isBearer}}
476+
// this endpoint requires Bearer token
477+
if ($this->config->getAccessToken() !== null) {
478+
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
479+
}
480+
{{/isBearer}}
475481
{{#isOAuth}}
476482
// this endpoint requires OAuth (access token)
477483
if ($this->config->getAccessToken() !== null) {

0 commit comments

Comments
 (0)