Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,6 @@ public interface CodegenConfig {
void setIgnoreImportMapping(boolean ignoreImportMapping);

boolean defaultIgnoreImportMappingOption();

boolean isUsingFlattenSpec();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4110,4 +4110,8 @@ protected boolean isModelObject(ModelImpl model) {
}
return false;
}

public boolean isUsingFlattenSpec() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* ParseOptions parseOptions = new ParseOptions();
* parseOptions.setFlatten(true);
* Swagger swagger = new SwaggerParser().read(rootNode, new ArrayList<>(), parseOptions);*/

@Deprecated
public class InlineModelResolver {
private Swagger swagger;
private boolean skipMatches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ public ClientOptInput toClientOptInput() {
final List<AuthorizationValue> authorizationValues = AuthParser.parse(auth);
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setFlatten(true);
if (config.isUsingFlattenSpec()) {
parseOptions.setFlatten(true);
}
Swagger swagger = new SwaggerParser().read(inputSpec, authorizationValues, parseOptions);

input.opts(new ClientOpts())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfi

public static final String OUTPUT_NAME = "outputFile";

public static final String MINMIZE_QUOTES = "minimizeQuotes";

public static final String SWAGGER_FILENAME_DEFAULT_YAML = "swagger.yaml";

protected String outputFile = SWAGGER_FILENAME_DEFAULT_YAML;
Expand All @@ -46,6 +48,10 @@ public SwaggerYamlGenerator() {
"output filename")
.defaultValue(SWAGGER_FILENAME_DEFAULT_YAML));

cliOptions.add(new CliOption(MINMIZE_QUOTES,
"minimize quotes")
.defaultValue(Boolean.TRUE.toString()));

supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
}

Expand Down Expand Up @@ -80,10 +86,21 @@ public void setOutputFile(String outputFile) {
@Override
public void processSwagger(Swagger swagger) {
try {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
boolean minimizeQuotes = !additionalProperties.containsKey(MINMIZE_QUOTES) ||
(additionalProperties.containsKey(MINMIZE_QUOTES) &&
additionalProperties.get(MINMIZE_QUOTES) instanceof Boolean ?
(Boolean)additionalProperties.get(MINMIZE_QUOTES) :
Boolean.valueOf((String)additionalProperties.get(MINMIZE_QUOTES)
)
);
YAMLFactory yamlFactory = new YAMLFactory()
.configure(YAMLGenerator.Feature.SPLIT_LINES, false)
.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true));
.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true);

yamlFactory.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, minimizeQuotes);

final ObjectMapper mapper = new ObjectMapper(yamlFactory);

configureMapper(mapper);
String swaggerString = mapper.writeValueAsString(swagger);
String outputFile = outputFolder + File.separator + this.outputFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SwaggerYamlOptionsProvider implements OptionsProvider {
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
public static final String OUTPUT_NAME = "swagger.yaml";
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
public static final String MINIMIZE_QUOTES = "true";

@Override
public String getLanguage() {
Expand All @@ -25,6 +26,7 @@ public Map<String, String> createOptions() {
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(SwaggerYamlGenerator.OUTPUT_NAME, OUTPUT_NAME)
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
.put(SwaggerYamlGenerator.MINMIZE_QUOTES, MINIMIZE_QUOTES)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class GeneratorInput {
private SecuritySchemeDefinition auth;
private AuthorizationValue authorizationValue;

private Boolean usingFlattenSpec = true;

public AuthorizationValue getAuthorizationValue() {
return authorizationValue;
}
Expand Down Expand Up @@ -57,4 +59,17 @@ public SecuritySchemeDefinition getSecurityDefinition() {
public void setSecurityDefinition(SecuritySchemeDefinition auth) {
this.auth = auth;
}

public Boolean isUsingFlattenSpec() {
return usingFlattenSpec;
}

public Boolean getUsingFlattenSpec() {
return usingFlattenSpec;
}

public void setUsingFlattenSpec(Boolean usingFlattenSpec) {
this.usingFlattenSpec = usingFlattenSpec;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.models.Swagger;
import io.swagger.models.auth.AuthorizationValue;
import io.swagger.parser.SwaggerParser;
import io.swagger.parser.util.ParseOptions;
import io.swagger.util.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -72,7 +73,19 @@ private static String generate(String language, GeneratorInput opts, Type type)
LOGGER.debug("ignoring empty spec");
node = null;
}
CodegenConfig codegenConfig = null;
try {
codegenConfig = CodegenConfigLoader.forName(language);
} catch (RuntimeException e) {
throw new BadRequestException("Unsupported target " + language + " supplied");
}

Swagger swagger;
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
if (codegenConfig.isUsingFlattenSpec() && !Boolean.FALSE.equals(opts.isUsingFlattenSpec())) {
parseOptions.setFlatten(true);
}
if (node == null) {
if (opts.getSwaggerUrl() != null) {
if (opts.getAuthorizationValue() != null) {
Expand All @@ -82,19 +95,19 @@ private static String generate(String language, GeneratorInput opts, Type type)

swagger =
new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues,
true);
parseOptions);
} else {
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
swagger = new SwaggerParser().read(opts.getSwaggerUrl(), null, parseOptions);
}
} else {
throw new BadRequestException("No swagger specification was supplied");
}
} else if (opts.getAuthorizationValue() != null) {
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
authorizationValues.add(opts.getAuthorizationValue());
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);
}
if (swagger == null) {
throw new BadRequestException("The swagger specification supplied was not valid");
Expand All @@ -116,12 +129,6 @@ private static String generate(String language, GeneratorInput opts, Type type)

clientOptInput.opts(clientOpts).swagger(swagger);

CodegenConfig codegenConfig = null;
try {
codegenConfig = CodegenConfigLoader.forName(language);
} catch (RuntimeException e) {
throw new BadRequestException("Unsupported target " + language + " supplied");
}

if (opts.getOptions() != null) {
codegenConfig.additionalProperties().putAll(opts.getOptions());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@
</repository>
</repositories>
<properties>
<swagger-parser-version>1.0.59</swagger-parser-version>
<swagger-parser-version>1.0.61-SNAPSHOT</swagger-parser-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<swagger-core-version>1.6.6</swagger-core-version>
Expand Down