-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add support for interface only with vertx #24497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ab0fb82
53a8a8c
24a9d47
ad5ff3e
3263099
5a8b8e3
286b4a2
451ee5b
e2d707a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| generatorName: java-vertx-web | ||
| outputDir: samples/server/petstore/java-vertx-web-interface-only | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/JavaVertXWebServer | ||
| additionalProperties: | ||
| hideGenerationTimestamp: "true" | ||
| artifactId: java-vertx-web-server-interface-only | ||
| interfaceOnly: "true" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,9 @@ public class JavaVertXWebServerCodegen extends AbstractJavaCodegen { | |
| protected String resourceFolder = "src/main/resources"; | ||
| protected String apiVersion = "1.0.0-SNAPSHOT"; | ||
|
|
||
| public static final String INTERFACE_ONLY = "interfaceOnly"; | ||
| protected boolean interfaceOnly = false; | ||
|
|
||
| public JavaVertXWebServerCodegen() { | ||
| super(); | ||
|
|
||
|
|
@@ -52,11 +55,6 @@ public JavaVertXWebServerCodegen() { | |
| modelTemplateFiles.clear(); | ||
| modelTemplateFiles.put("model.mustache", ".java"); | ||
|
|
||
| apiTemplateFiles.clear(); | ||
| apiTemplateFiles.put("api.mustache", ".java"); | ||
| apiTemplateFiles.put("apiImpl.mustache", "Impl.java"); | ||
| apiTemplateFiles.put("apiHandler.mustache", "Handler.java"); | ||
|
|
||
| embeddedTemplateDir = templateDir = "JavaVertXWebServer"; | ||
|
|
||
| invokerPackage = "org.openapitools.vertxweb.server"; | ||
|
|
@@ -73,6 +71,8 @@ public JavaVertXWebServerCodegen() { | |
| updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage); | ||
| updateOption(CodegenConstants.INVOKER_PACKAGE, invokerPackage); | ||
| updateOption(DATE_LIBRARY, this.getDateLibrary()); | ||
|
|
||
| cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.")); | ||
|
|
||
| // Override type mapping | ||
| typeMapping.put("file", "FileUpload"); | ||
|
|
@@ -100,6 +100,18 @@ public String getHelp() { | |
| public void processOpts() { | ||
| super.processOpts(); | ||
|
|
||
| if (additionalProperties.containsKey(INTERFACE_ONLY)) { | ||
| interfaceOnly = Boolean.parseBoolean(additionalProperties.get(INTERFACE_ONLY).toString()); | ||
| } | ||
| additionalProperties.put(INTERFACE_ONLY, interfaceOnly); | ||
|
|
||
| apiTemplateFiles.clear(); | ||
| apiTemplateFiles.put("api.mustache", ".java"); | ||
| apiTemplateFiles.put("apiHandler.mustache", "Handler.java"); | ||
| if (!interfaceOnly) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved in prior commit |
||
| apiTemplateFiles.put("apiImpl.mustache", "Impl.java"); | ||
| } | ||
|
|
||
| apiTestTemplateFiles.clear(); | ||
|
|
||
| importMapping.remove("JsonCreator"); | ||
|
|
@@ -116,7 +128,9 @@ public void processOpts() { | |
| String sourcePackageFolder = sourceFolder + File.separator + invokerPackage.replace(".", File.separator); | ||
| supportingFiles.clear(); | ||
| supportingFiles.add(new SupportingFile("supportFiles/openapi.mustache", resourceFolder, "openapi.yaml")); | ||
| supportingFiles.add(new SupportingFile("supportFiles/HttpServerVerticle.mustache", sourcePackageFolder, "HttpServerVerticle.java")); | ||
| if (!interfaceOnly) { | ||
| supportingFiles.add(new SupportingFile("supportFiles/HttpServerVerticle.mustache", sourcePackageFolder, "HttpServerVerticle.java")); | ||
| } | ||
| supportingFiles.add(new SupportingFile("supportFiles/ApiResponse.mustache", sourcePackageFolder, "ApiResponse.java")); | ||
| supportingFiles.add(new SupportingFile("supportFiles/pom.mustache", "", "pom.xml")); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package org.openapitools.codegen.java.vertx; | ||
|
|
||
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import org.openapitools.codegen.ClientOptInput; | ||
| import org.openapitools.codegen.DefaultGenerator; | ||
| import org.openapitools.codegen.TestUtils; | ||
| import org.openapitools.codegen.languages.JavaVertXWebServerCodegen; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class JavaVertXWebServerCodegenTest { | ||
|
|
||
| private JavaVertXWebServerCodegen underTest; | ||
|
|
||
| @BeforeMethod | ||
| public void setup() { | ||
| this.underTest = new JavaVertXWebServerCodegen(); | ||
| } | ||
|
|
||
| @Test | ||
| public void itShouldSetTheDefaultTemplateKeys() { | ||
| underTest.processOpts(); | ||
|
|
||
| Assert.assertTrue(underTest.apiTemplateFiles().containsKey("api.mustache")); | ||
| Assert.assertTrue(underTest.apiTemplateFiles().containsKey("apiHandler.mustache")); | ||
| Assert.assertTrue(underTest.apiTemplateFiles().containsKey("apiImpl.mustache")); | ||
| } | ||
|
|
||
| @Test | ||
| public void itShouldNotSetApiImplMustacheKeyWhenInterfaceOnlyIsTrue() { | ||
| underTest.additionalProperties().put(JavaVertXWebServerCodegen.INTERFACE_ONLY, "true"); | ||
| underTest.processOpts(); | ||
|
|
||
| Assert.assertFalse(underTest.apiTemplateFiles().containsKey("apiImpl.mustache")); | ||
| } | ||
|
|
||
| @Test | ||
| public void itShouldRedactCredentialsInBodyParams() throws IOException { | ||
| Map<String, File> files = generatePetstoreServer(); | ||
| String apiHandlerPath = files.keySet().stream() | ||
| .filter(path -> path.endsWith("UserApiHandler.java")) | ||
| .findFirst() | ||
| .orElseThrow(() -> new AssertionError("UserApiHandler.java not found")); | ||
|
|
||
| File userApiHandler = files.get(apiHandlerPath); | ||
|
|
||
| TestUtils.assertFileContains(userApiHandler.toPath(), "logger.debug(\"Parameter user is (body omitted)\");"); | ||
| } | ||
|
|
||
| @Test | ||
| public void itShouldCheckFileUploadEmptiness() throws IOException { | ||
| Map<String, File> files = generatePetstoreServer(); | ||
| String apiHandlerPath = files.keySet().stream() | ||
| .filter(path -> path.endsWith("PetApiHandler.java")) | ||
| .findFirst() | ||
| .orElseThrow(() -> new AssertionError("PetApiHandler.java not found")); | ||
|
|
||
| File petApiHandler = files.get(apiHandlerPath); | ||
|
|
||
| TestUtils.assertFileContains(petApiHandler.toPath(), "if (routingContext.fileUploads().isEmpty()) {"); | ||
| TestUtils.assertFileContains(petApiHandler.toPath(), "} else {"); | ||
| TestUtils.assertFileContains(petApiHandler.toPath(), "_file = routingContext.fileUploads().iterator().next();"); | ||
| } | ||
|
|
||
| private Map<String, File> generatePetstoreServer() throws IOException { | ||
| File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); | ||
| output.deleteOnExit(); | ||
|
|
||
| OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); | ||
| DefaultGenerator defaultGenerator = new DefaultGenerator(); | ||
| ClientOptInput clientOptInput = new ClientOptInput(); | ||
| clientOptInput.openAPI(openAPI); | ||
|
|
||
| JavaVertXWebServerCodegen codegen = new JavaVertXWebServerCodegen(); | ||
| codegen.setOutputDir(output.getAbsolutePath()); | ||
|
|
||
| clientOptInput.config(codegen); | ||
| defaultGenerator.opts(clientOptInput); | ||
|
|
||
| return defaultGenerator.generate().stream() | ||
| .collect(Collectors.toMap(File::getPath, Function.identity())); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # OpenAPI Generator Ignore | ||
| # Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
|
||
| # Use this file to prevent files from being overwritten by the generator. | ||
| # The patterns follow closely to .gitignore or .dockerignore. | ||
|
|
||
| # As an example, the C# client generator defines ApiClient.cs. | ||
| # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
| #ApiClient.cs | ||
|
|
||
| # You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
| #foo/*/qux | ||
| # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
|
||
| # You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
| #foo/**/qux | ||
| # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
|
||
| # You can also negate patterns with an exclamation (!). | ||
| # For example, you can ignore all files in a docs folder with the file extension .md: | ||
| #docs/*.md | ||
| # Then explicitly reverse the ignore rule for a single file: | ||
| #!docs/README.md |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| README.md | ||
| pom.xml | ||
| src/main/java/org/openapitools/vertxweb/server/ApiResponse.java | ||
| src/main/java/org/openapitools/vertxweb/server/api/PetApi.java | ||
| src/main/java/org/openapitools/vertxweb/server/api/PetApiHandler.java | ||
| src/main/java/org/openapitools/vertxweb/server/api/StoreApi.java | ||
| src/main/java/org/openapitools/vertxweb/server/api/StoreApiHandler.java | ||
| src/main/java/org/openapitools/vertxweb/server/api/UserApi.java | ||
| src/main/java/org/openapitools/vertxweb/server/api/UserApiHandler.java | ||
| src/main/java/org/openapitools/vertxweb/server/model/Category.java | ||
| src/main/java/org/openapitools/vertxweb/server/model/ModelApiResponse.java | ||
| src/main/java/org/openapitools/vertxweb/server/model/Order.java | ||
| src/main/java/org/openapitools/vertxweb/server/model/Pet.java | ||
| src/main/java/org/openapitools/vertxweb/server/model/Tag.java | ||
| src/main/java/org/openapitools/vertxweb/server/model/User.java | ||
| src/main/resources/openapi.yaml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 7.25.0-SNAPSHOT |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Generator version: 7.25.0-SNAPSHOT | ||
|
|
||
| ## Getting Started | ||
|
|
||
| This document assumes you have maven available. | ||
|
|
||
| To build the project using maven, run: | ||
|
|
||
| ```bash | ||
| mvn package | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add the new folder to the github workflow: https://github.com/OpenAPITools/openapi-generator/blob/master/.github/workflows/samples-java-server-jdk8.yaml