mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
added configuration for swagger-yaml output file, #3597
This commit is contained in:
parent
7a49f96a03
commit
7bc9c4041b
@ -1,27 +1,28 @@
|
|||||||
package io.swagger.codegen.languages;
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
import java.io.File;
|
import io.swagger.codegen.*;
|
||||||
|
import io.swagger.models.Swagger;
|
||||||
|
import io.swagger.util.Yaml;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import io.swagger.codegen.CodegenConfig;
|
import java.io.File;
|
||||||
import io.swagger.codegen.CodegenType;
|
|
||||||
import io.swagger.codegen.DefaultCodegen;
|
|
||||||
import io.swagger.codegen.SupportingFile;
|
|
||||||
import io.swagger.models.Swagger;
|
|
||||||
import io.swagger.util.Yaml;
|
|
||||||
|
|
||||||
public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfig {
|
public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfig {
|
||||||
|
public static final String OUTPUT_NAME = "outputFile";
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerYamlGenerator.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerYamlGenerator.class);
|
||||||
|
|
||||||
|
protected String outputFile = "swagger.yaml";
|
||||||
|
|
||||||
public SwaggerYamlGenerator() {
|
public SwaggerYamlGenerator() {
|
||||||
super();
|
super();
|
||||||
embeddedTemplateDir = templateDir = "swagger";
|
embeddedTemplateDir = templateDir = "swagger";
|
||||||
outputFolder = "generated-code/swagger";
|
outputFolder = "generated-code/swagger";
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption(OUTPUT_NAME, "output filename"));
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +41,20 @@ public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfi
|
|||||||
return "Creates a static swagger.yaml file.";
|
return "Creates a static swagger.yaml file.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
if(additionalProperties.containsKey(OUTPUT_NAME)) {
|
||||||
|
this.outputFile = additionalProperties.get(OUTPUT_NAME).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processSwagger(Swagger swagger) {
|
public void processSwagger(Swagger swagger) {
|
||||||
try {
|
try {
|
||||||
String swaggerString = Yaml.mapper().writeValueAsString(swagger);
|
String swaggerString = Yaml.mapper().writeValueAsString(swagger);
|
||||||
String outputFile = outputFolder + File.separator + "swagger.yaml";
|
String outputFile = outputFolder + File.separator + this.outputFile;
|
||||||
FileUtils.writeStringToFile(new File(outputFile), swaggerString);
|
FileUtils.writeStringToFile(new File(outputFile), swaggerString);
|
||||||
LOGGER.debug("wrote file to " + outputFile);
|
LOGGER.debug("wrote file to " + outputFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -20,6 +20,7 @@ public class SwaggerYamlOptionsProvider implements OptionsProvider {
|
|||||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put("outputFile", "swagger.yaml")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user