generated from jeka-dev/wrapper-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce JkOpenApi for dealing with project without using KBean mech…
…anism.
- Loading branch information
Showing
7 changed files
with
114 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,71 @@ | ||
package dev.jeka.plugins.openapi; | ||
|
||
import dev.jeka.core.api.project.JkProject; | ||
|
||
public class JkOpenApi { | ||
|
||
private final String version; | ||
|
||
private JkOpenApi(String version) { | ||
this.version = version; | ||
} | ||
|
||
public static JkOpenApi ofVersion(String version) { | ||
return new JkOpenApi(version); | ||
} | ||
|
||
public static JkOpenApi ofDefaultVersion() { | ||
return ofVersion(JkOpenApiGeneratorCli.DEFAULT_CLI_VERSION); | ||
} | ||
|
||
/** | ||
* Appends a source generator to the specified project, generating code using the specified generatorName and | ||
* the specified location for specification. <p> | ||
* This returns a {@link JkOpenApiSourceGenerator} that can be customized. | ||
* | ||
* | ||
* @param generatorName The code generator to use. See <a href="https://openapi-generator.tech/docs/generators">list here</a>. | ||
* @param specLocation The url or local path of the specification location. | ||
*/ | ||
public JkOpenApiSourceGenerator addSourceGenerator(JkProject project, String generatorName, String specLocation) { | ||
JkOpenApiSourceGenerator generator = JkOpenApiSourceGenerator.of(generatorName, specLocation) | ||
.setCliVersion(version); | ||
project.compilation.addSourceGenerator(generator); | ||
return generator; | ||
} | ||
|
||
/** | ||
* @see #addSourceGenerator(JkProject, String, String) | ||
* @param packageName the package name where source code should be generated | ||
*/ | ||
public JkOpenApiSourceGenerator addSourceGenerator(JkProject project, String generatorName, String specLocation, String packageName) { | ||
JkOpenApiSourceGenerator generator = JkOpenApiSourceGenerator.of(generatorName, specLocation) | ||
.setCliVersion(version).customize(builder -> builder | ||
.addApiAndModelPackage(packageName) | ||
.add(JkOpenapiCmdBuilder.MODEL_NAME_PREFIX, "Rest") | ||
); | ||
project.compilation.addSourceGenerator(generator); | ||
return generator; | ||
} | ||
|
||
/** | ||
* Appends a Springboot server code generation to the specified project. | ||
* The generated model code will bbe prefixed with 'Rest'. | ||
* @see #addSourceGenerator(JkProject, String, String) | ||
*/ | ||
public JkOpenApiSourceGenerator addSpringbootServerGenerator(JkProject project, String specLocation, String packageName) { | ||
return addSourceGenerator(project, "spring", specLocation, packageName).customize(builder -> | ||
builder.addAdditionalProperties("useSpringBoot3", "true") | ||
); | ||
} | ||
|
||
/** | ||
* Appends a Java client code generation to the specified project. | ||
* The generated model code will bbe prefixed with 'Rest'. | ||
* @see #addSourceGenerator(JkProject, String, String) | ||
*/ | ||
public JkOpenApiSourceGenerator addJavaGenerator(JkProject project, String specLocation, String packageName) { | ||
return addSourceGenerator(project, "client", specLocation, packageName); | ||
} | ||
|
||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.