Skip to content

Commit

Permalink
fix flatten option
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed May 31, 2022
1 parent 1de79da commit 305249e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion modules/swagger-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
</reporting>
<properties>
<diffutils-version>1.3.0</diffutils-version>
<swagger-codegen-v2-version>2.4.27</swagger-codegen-v2-version>
<swagger-codegen-v2-version>2.4.28-SNAPSHOT</swagger-codegen-v2-version>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.models.Swagger;
import io.swagger.models.auth.UrlMatcher;
import io.swagger.parser.SwaggerParser;
import io.swagger.parser.util.ParseOptions;
import io.swagger.v3.core.util.Json;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -108,15 +109,26 @@ public static io.swagger.codegen.ClientOptInput getClientOptInputV2(GenerationRe
}
LOGGER.debug("getClientOptInputV2 - processed auth");

CodegenConfig codegenConfig=null;
try {
codegenConfig = CodegenConfigLoader.forName(lang);
} catch(RuntimeException e) {
throw new BadRequestException("Unsupported target " + lang + " supplied");
}
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
if (codegenConfig.isUsingFlattenSpec() && !Boolean.FALSE.equals(generationRequest.getOptions().isUsingFlattenSpecForV2())) {
parseOptions.setFlatten(true);
}
Swagger swagger;
if (StringUtils.isBlank(inputSpec)) {
if (inputSpecURL != null) {
if (!authorizationValues.isEmpty()) {
swagger =
new SwaggerParser().read(inputSpecURL, authorizationValues,
true);
parseOptions);
} else {
swagger = new SwaggerParser().read(inputSpecURL);
swagger = new SwaggerParser().read(inputSpecURL, null, parseOptions);
}
} else {
throw new BadRequestException("No swagger specification was supplied");
Expand All @@ -126,9 +138,9 @@ public static io.swagger.codegen.ClientOptInput getClientOptInputV2(GenerationRe
try {
JsonNode node = io.swagger.util.Json.mapper().readTree(inputSpec);
if (!authorizationValues.isEmpty()) {
swagger = new SwaggerParser().read(node, authorizationValues, true);
swagger = new SwaggerParser().read(node, authorizationValues, parseOptions);
} else {
swagger = new SwaggerParser().read(node, true);
swagger = new SwaggerParser().read(node, null,parseOptions);
}
} catch (Exception e) {
LOGGER.error("Exception parsing input spec", e);
Expand All @@ -144,12 +156,6 @@ public static io.swagger.codegen.ClientOptInput getClientOptInputV2(GenerationRe
io.swagger.codegen.ClientOptInput clientOptInput = new io.swagger.codegen.ClientOptInput();
ClientOpts clientOpts = new ClientOpts();

CodegenConfig codegenConfig=null;
try {
codegenConfig = CodegenConfigLoader.forName(lang);
} catch(RuntimeException e) {
throw new BadRequestException("Unsupported target " + lang + " supplied");
}
codegenConfig.setOutputDir(generationRequest.getOptions().getOutputDir());
codegenConfig.setInputSpec(inputSpec);
if (isNotEmpty(options.getApiPackage())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class Options {
private String outputDir = "";
private Boolean resolveFully;

private Boolean usingFlattenSpecForV2;

private Map<String, String> codegenArguments = new LinkedHashMap<>();

private boolean flattenInlineComposedSchemas = false;
Expand Down Expand Up @@ -504,4 +506,21 @@ public Options flattenInlineComposedSchemas(boolean flattenInlineComposedSchemas
this.flattenInlineComposedSchemas = flattenInlineComposedSchemas;
return this;
}

public Boolean isUsingFlattenSpecForV2() {
return usingFlattenSpecForV2;
}

public Boolean getUsingFlattenSpecForV2() {
return usingFlattenSpecForV2;
}

public void setUsingFlattenSpecForV2(Boolean usingFlattenSpecForV2) {
this.usingFlattenSpecForV2 = usingFlattenSpecForV2;
}

public Options usingFlattenSpecForV2(Boolean usingFlattenSpecForV2) {
this.usingFlattenSpecForV2 = usingFlattenSpecForV2;
return this;
}
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,10 @@
</repositories>
<properties>
<swagger-codegen-generators-version>1.0.35-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.1.13</swagger-core-version>
<swagger-core-version>2.2.1-SNAPSHOT</swagger-core-version>
<swagger-core-version-v1>1.6.6</swagger-core-version-v1>
<swagger-parser-version>2.0.30</swagger-parser-version>
<swagger-parser-version-v1>1.0.59</swagger-parser-version-v1>
<swagger-parser-version>2.1.0-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.61-SNAPSHOT</swagger-parser-version-v1>
<jackson-version>2.13.2</jackson-version>
<!--
jackson-databind 2.13.2 is still affected by CVE-2020-36518.
Expand Down

0 comments on commit 305249e

Please sign in to comment.