-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add support for interface only with vertx #24655
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
Changes from all commits
ab0fb82
53a8a8c
24a9d47
ad5ff3e
3263099
5a8b8e3
286b4a2
451ee5b
e2d707a
3f1b266
759954e
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 | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,14 @@ | |||||||||||||||||||||||||||||||||||||||
| JsonObject {{paramName}} = body != null ? body.getJsonObject() : null; | ||||||||||||||||||||||||||||||||||||||||
| {{/isFile}} | ||||||||||||||||||||||||||||||||||||||||
| {{#isFile}} | ||||||||||||||||||||||||||||||||||||||||
| {{{dataType}}} {{paramName}} = routingContext.fileUploads().iterator().next(); | ||||||||||||||||||||||||||||||||||||||||
| {{{dataType}}} {{paramName}} = null; | ||||||||||||||||||||||||||||||||||||||||
| if (routingContext.fileUploads().isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||
|
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: For non-required file form params the new template produces a logically-dead empty FileUpload _file = null;
if (routingContext.fileUploads().isEmpty()) {
} else {
_file = routingContext.fileUploads().iterator().next();
}The Prompt for AI agentsThe |
||||||||||||||||||||||||||||||||||||||||
| {{#required}} | ||||||||||||||||||||||||||||||||||||||||
| routingContext.fail(400); | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| {{/required}} | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| {{paramName}} = routingContext.fileUploads().iterator().next(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+15
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. P1: Required multipart fields are validated only against any upload, so generated handlers accept a request missing one required named file and bind the first uploaded file to every file parameter. Select Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| {{/isFile}} | ||||||||||||||||||||||||||||||||||||||||
| {{/isFormParam}} | ||||||||||||||||||||||||||||||||||||||||
| 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 { | ||
|
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. P3: This test is named "RedactCredentials" but it only asserts that a body param is logged as "(body omitted)" ( Prompt for AI agents |
||
| 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.
P2: The new password-redaction path only fires when a parameter is directly flagged as
isPassword, but for form-encoded submissions those parameters are never individually flagged. InJavaVertXWebServerCodegen.postProcessOperationsWithModels, any operation with non-file form params has its form params collapsed into a single dummyformBodyJsonObjectparameter, so a form field such as apasswordnever reaches the{{#isPassword}}branch — it is instead dumped verbatim by the fall-throughlogger.debug("Parameter formBody is {}", formBody). As a result, the stated security goal of hiding password values in handler logs does not hold for form-encoded credentials, which are logged in full (at debug level) as part of the form payload. Consider omitting form-body contents from debug logging (or redacting known sensitive keys) rather than only suppressing individually-typed password params.Prompt for AI agents