Skip to content

Commit 574ed86

Browse files
authored
Merge pull request #1018 from swagger-api/swos-556
fixed map property issue
2 parents 8a978d8 + d5c8114 commit 574ed86

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegenConfig {
6060
public static final String ERROR_ON_UNKNOWN_ENUM = "errorOnUnknownEnum";
6161
public static final String CHECK_DUPLICATED_MODEL_NAME = "checkDuplicatedModelName";
6262

63+
public static final String WIREMOCK_OPTION = "wiremock";
64+
6365
protected String dateLibrary = "threetenbp";
6466
protected boolean java8Mode = false;
6567
protected boolean java11Mode = false;
@@ -190,6 +192,8 @@ public AbstractJavaCodegen() {
190192
cliOptions.add(java11Mode);
191193

192194
cliOptions.add(CliOption.newBoolean(CHECK_DUPLICATED_MODEL_NAME, "Check if there are duplicated model names (ignoring case)"));
195+
196+
cliOptions.add(CliOption.newBoolean(WIREMOCK_OPTION, "Use wiremock to generate endpoint calls to mock on generated tests."));
193197
}
194198

195199
@Override
@@ -356,6 +360,11 @@ public void processOpts() {
356360
additionalProperties.put(ERROR_ON_UNKNOWN_ENUM, errorOnUnknownEnum);
357361
}
358362

363+
if (additionalProperties.containsKey(WIREMOCK_OPTION)) {
364+
final boolean useWireMock = additionalProperties.get(WIREMOCK_OPTION) != null && Boolean.parseBoolean(additionalProperties.get(WIREMOCK_OPTION).toString());
365+
additionalProperties.put(WIREMOCK_OPTION, useWireMock);
366+
}
367+
359368
if (this instanceof NotNullAnnotationFeatures) {
360369
notNullOption = (NotNullAnnotationFeatures)this;
361370
if (additionalProperties.containsKey(NOT_NULL_JACKSON_ANNOTATION)) {

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen implements BeanValida
5353
public static final String RETROFIT_1 = "retrofit";
5454
public static final String RETROFIT_2 = "retrofit2";
5555

56-
public static final String WIREMOCK_OPTION = "wiremock";
57-
5856
protected String gradleWrapperPackage = "gradle.wrapper";
5957
protected boolean useRxJava = false;
6058
protected boolean useRxJava2 = false;
@@ -89,8 +87,6 @@ public JavaClientCodegen() {
8987
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
9088
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
9189

92-
cliOptions.add(CliOption.newBoolean(WIREMOCK_OPTION, "Use wiremock to generate endpoint calls to mock on generated tests."));
93-
9490
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.10.1. Enable gzip request encoding using '-DuseGzipFeature=true'.");
9591
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.10.1");
9692
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.26. JSON processing: Jackson 2.10.1");
@@ -177,11 +173,6 @@ public void processOpts() {
177173
this.setUseRuntimeException(convertPropertyToBooleanAndWriteBack(USE_RUNTIME_EXCEPTION));
178174
}
179175

180-
if (additionalProperties.containsKey(WIREMOCK_OPTION)) {
181-
final boolean useWireMock = additionalProperties.get(WIREMOCK_OPTION) != null && Boolean.parseBoolean(additionalProperties.get(WIREMOCK_OPTION).toString());
182-
additionalProperties.put(WIREMOCK_OPTION, useWireMock);
183-
}
184-
185176
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
186177
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
187178
final String apiFolder = (sourceFolder + File.separator + apiPackage).replace(".", File.separator);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@
2222
import io.swagger.v3.oas.models.Operation;
2323
import io.swagger.v3.oas.models.PathItem;
2424
import io.swagger.v3.oas.models.media.ArraySchema;
25+
import io.swagger.v3.oas.models.media.MapSchema;
2526
import io.swagger.v3.oas.models.media.Schema;
26-
import org.apache.commons.lang3.StringUtils;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
2929

3030
import java.io.File;
3131
import java.io.IOException;
3232
import java.io.Writer;
3333
import java.net.URL;
34-
import java.util.*;
34+
import java.util.ArrayList;
35+
import java.util.Arrays;
36+
import java.util.HashMap;
37+
import java.util.LinkedHashMap;
38+
import java.util.LinkedList;
39+
import java.util.List;
40+
import java.util.Map;
3541
import java.util.regex.Matcher;
3642
import java.util.stream.Collectors;
3743

@@ -475,7 +481,7 @@ public CodegenProperty fromProperty(String name, Schema propertySchema) {
475481
CodegenProperty codegenProperty = super.fromProperty(name, propertySchema);
476482
if (propertySchema != null && propertySchema.get$ref() != null) {
477483
Schema refSchema = OpenAPIUtil.getSchemaFromRefSchema(propertySchema, this.openAPI);
478-
if (refSchema != null && !isObjectSchema(refSchema) && !(refSchema instanceof ArraySchema) && refSchema.getEnum() == null) {
484+
if (refSchema != null && !isObjectSchema(refSchema) && !(refSchema instanceof ArraySchema) && !(refSchema instanceof MapSchema) && refSchema.getEnum() == null) {
479485
setSchemaProperties(name, codegenProperty, refSchema);
480486
processPropertySchemaTypes(name, codegenProperty, refSchema);
481487
}

src/main/resources/handlebars/JavaSpring/libraries/spring-cloud/apiClient.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import org.springframework.cloud.openfeign.FeignClient;
88
{{/isOpenFeign}}
99
import {{configPackage}}.ClientConfiguration;
1010

11-
{{=<% %>=}}
12-
@FeignClient(<%#isOpenFeign%>contextId="<%classname%>Client", <%/isOpenFeign%>name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%basePath%>}", configuration = ClientConfiguration.class)
13-
<%={{ }}=%>
11+
@FeignClient({{#isOpenFeign}}contextId="{{classname}}Client", {{/isOpenFeign}}name="${{braces "left"}}{{title}}.name:{{title}}{{braces "right"}}", url="${{braces "left"}}{{title}}.url:{{^wiremock}}{{basePath}}{{/wiremock}}{{#wiremock}}wiremock.base.path{{/wiremock}}{{braces "right"}}", configuration = ClientConfiguration.class)
1412
public interface {{classname}}Client extends {{classname}} {
1513
}

src/main/resources/handlebars/JavaSpring/libraries/spring-cloud/application-test.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ hystrix.command.default.execution.timeout.enabled: false
99
logging.level.{{apiPackage}}: DEBUG
1010

1111
feign.hystrix.enabled: true
12+
13+
{{#wiremock}}
14+
wiremock.base.path: http://localhost:33333
15+
{{/wiremock}}

src/main/resources/handlebars/JavaSpring/libraries/spring-cloud/pom.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,13 @@
138138
<artifactId>javax.servlet-api</artifactId>
139139
<scope>provided</scope>
140140
</dependency>
141+
{{#wiremock}}
142+
<dependency>
143+
<groupId>com.github.tomakehurst</groupId>
144+
<artifactId>wiremock</artifactId>
145+
<version>2.27.2</version>
146+
<scope>test</scope>
147+
</dependency>
148+
{{/wiremock}}
141149
</dependencies>
142150
</project>

src/test/java/io/swagger/codegen/v3/generators/options/JavaOptionsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public JavaOptionsProvider() {
7777
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
7878
.put(CodegenConstants.USE_OAS2, "true")
7979
.put(JavaClientCodegen.CHECK_DUPLICATED_MODEL_NAME, "false")
80+
.put(JavaClientCodegen.WIREMOCK_OPTION, "false")
8081
//.put("supportJava6", "true")
8182
.build();
8283
}

0 commit comments

Comments
 (0)