-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
cli/src/main/java/com/github/slamdev/openapispringgenerator/cli/Convert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.slamdev.openapispringgenerator.cli; | ||
|
||
import com.github.slamdev.openapispringgenerator.lib.generator.OpenAPIYamlCodegen; | ||
import io.swagger.codegen.v3.ClientOptInput; | ||
import io.swagger.codegen.v3.DefaultGenerator; | ||
import io.swagger.codegen.v3.config.CodegenConfigurator; | ||
import io.swagger.codegen.v3.generators.openapi.OpenAPIGenerator; | ||
import picocli.CommandLine; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
@CommandLine.Command(name = "convert", mixinStandardHelpOptions = true, description = "convert to OpenAPI v3") | ||
public class Convert implements Runnable { | ||
|
||
@CommandLine.Option(names = {"-f", "--input-file"}, required = true, description = "path to a spec file") | ||
private Path specFile; | ||
|
||
@CommandLine.Option(names = {"-o", "--output-file"}, required = true, description = "path to store the generated file") | ||
private Path outputFile; | ||
|
||
@Override | ||
public void run() { | ||
Path abs = outputFile.toAbsolutePath(); | ||
CodegenConfigurator configurator = new CodegenConfigurator(); | ||
configurator.setLang(OpenAPIYamlCodegen.class.getName()); | ||
configurator.setOutputDir(abs.getParent().toString()); | ||
configurator.addAdditionalProperty(OpenAPIGenerator.OUTPUT_NAME, abs.getFileName().toString()); | ||
configurator.addAdditionalProperty(OpenAPIGenerator.FLATTEN_SPEC, true); | ||
try { | ||
configurator.setInputSpec(new String(Files.readAllBytes(specFile))); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
ClientOptInput input = configurator.toClientOptInput(); | ||
DefaultGenerator generator = new DefaultGenerator(); | ||
generator.opts(input); | ||
generator.setGenerateSwaggerMetadata(false); | ||
generator.generate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...main/java/com/github/slamdev/openapispringgenerator/lib/generator/OpenAPIYamlCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.slamdev.openapispringgenerator.lib.generator; | ||
|
||
import io.swagger.codegen.v3.generators.openapi.OpenAPIYamlGenerator; | ||
|
||
public class OpenAPIYamlCodegen extends OpenAPIYamlGenerator { | ||
|
||
@Override | ||
public void processOpts() { | ||
super.processOpts(); | ||
supportingFiles.clear(); | ||
} | ||
} |