Skip to content

Commit 038b9e4

Browse files
committed
refactor changes related to #8712 in order to solve maven build fail.
1 parent 1f93f09 commit 038b9e4

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ public CodegenOperation fromOperation(String path,
21912191
op.returnBaseType = cm.baseType;
21922192
}
21932193
}
2194-
op.examples = new ExampleGenerator(definitions).generate(methodResponse.getExamples(), operation.getProduces(), responseProperty);
2194+
op.examples = getExamples(definitions, methodResponse.getExamples(), operation.getProduces(), responseProperty);
21952195
op.defaultResponse = toDefaultValue(responseProperty);
21962196
op.returnType = cm.datatype;
21972197
op.hasReference = definitions != null && definitions.containsKey(op.returnBaseType);
@@ -2272,7 +2272,7 @@ public CodegenOperation fromOperation(String path,
22722272
bodyParam = p;
22732273
bodyParams.add(p.copy());
22742274
if(definitions != null) {
2275-
op.requestBodyExamples = new ExampleGenerator(definitions).generate(null, operation.getConsumes(), bodyParam.dataType);
2275+
op.requestBodyExamples = getExamples(definitions, null, consumes, bodyParam.dataType);
22762276
}
22772277
} else if (param instanceof FormParameter) {
22782278
formParams.add(p.copy());
@@ -3816,6 +3816,15 @@ public boolean convertPropertyToBoolean(String propertyKey) {
38163816
return booleanValue;
38173817
}
38183818

3819+
protected List<Map<String, String>> getExamples(Map<String, Model> definitions, Map<String, Object> examples, List<String> mediaTypes, Object object) {
3820+
if (object instanceof Property) {
3821+
Property responseProperty = (Property) object;
3822+
return new ExampleGenerator(definitions).generate(examples, mediaTypes, responseProperty);
3823+
}
3824+
// this must be a model name instead
3825+
return new ExampleGenerator(definitions).generate(examples, mediaTypes, object.toString());
3826+
}
3827+
38193828
public void writePropertyBack(String propertyKey, boolean value) {
38203829
additionalProperties.put(propertyKey, value);
38213830
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package io.swagger.codegen.languages;
22

33
import java.io.File;
4+
import java.util.List;
5+
import java.util.Map;
46

57
import io.swagger.codegen.CliOption;
68
import io.swagger.codegen.CodegenConstants;
9+
import io.swagger.models.Model;
10+
import io.swagger.models.properties.Property;
711
import org.apache.commons.io.FileUtils;
812
import org.apache.commons.lang3.StringUtils;
913
import org.slf4j.Logger;
@@ -35,8 +39,6 @@ public SwaggerGenerator() {
3539
"output filename")
3640
.defaultValue(SWAGGER_FILENAME_DEFAULT_JSON));
3741
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
38-
39-
System.setProperty(CodegenConstants.SUPPORTING_FILES, Boolean.TRUE.toString());
4042
}
4143

4244
@Override
@@ -84,7 +86,15 @@ public void setOutputFile(String outputFile) {
8486
public String escapeQuotationMark(String input) {
8587
// just return the original string
8688
return input;
87-
}
89+
}
90+
91+
@Override
92+
protected List<Map<String, String>> getExamples(Map<String, Model> definitions, Map<String, Object> examples, List<String> produces, Object object) {
93+
if (examples == null || examples.isEmpty()) {
94+
return null;
95+
}
96+
return super.getExamples(definitions, examples, produces, object);
97+
}
8898

8999
@Override
90100
public String escapeUnsafeCharacters(String input) {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
99
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
1010
import io.swagger.codegen.*;
11+
import io.swagger.codegen.examples.ExampleGenerator;
1112
import io.swagger.jackson.mixin.ResponseSchemaMixin;
13+
import io.swagger.models.Model;
1214
import io.swagger.models.Response;
1315
import io.swagger.models.Swagger;
16+
import io.swagger.models.properties.Property;
1417
import io.swagger.util.DeserializationModule;
1518
import io.swagger.util.Yaml;
1619
import org.apache.commons.io.FileUtils;
@@ -19,6 +22,8 @@
1922
import org.slf4j.LoggerFactory;
2023

2124
import java.io.File;
25+
import java.util.List;
26+
import java.util.Map;
2227

2328
public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfig {
2429

@@ -41,8 +46,6 @@ public SwaggerYamlGenerator() {
4146
.defaultValue(SWAGGER_FILENAME_DEFAULT_YAML));
4247

4348
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
44-
45-
System.setProperty(CodegenConstants.SUPPORTING_FILES, Boolean.TRUE.toString());
4649
}
4750

4851
@Override
@@ -99,7 +102,15 @@ public String escapeQuotationMark(String input) {
99102
public String escapeUnsafeCharacters(String input) {
100103
// just return the original string
101104
return input;
102-
}
105+
}
106+
107+
@Override
108+
protected List<Map<String, String>> getExamples(Map<String, Model> definitions, Map<String, Object> examples, List<String> produces, Object object) {
109+
if (examples == null || examples.isEmpty()) {
110+
return null;
111+
}
112+
return super.getExamples(definitions, examples, produces, object);
113+
}
103114

104115
private void configureMapper(ObjectMapper mapper) {
105116
Module deserializerModule = new DeserializationModule(true, true);

modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientCodegenTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public class RubyClientCodegenTest {
3232
@BeforeMethod
3333
public void setUp() throws Exception {
3434
folder.create();
35-
if (System.getProperty(CodegenConstants.SUPPORTING_FILES) != null) {
36-
System.clearProperty(CodegenConstants.SUPPORTING_FILES);
37-
}
3835
}
3936

4037
@AfterMethod

0 commit comments

Comments
 (0)