forked from loafle/openapi-generator-original
Fix for multible tags in @Operation annotation (#11475)
* Check size of x-tags list * Remove unused variable assigment * Fix issue number in test method name * Fix typo * Add tag to @ApoOperation only if any tag is given * Rename data provider method * Remove unused import
This commit is contained in:
@@ -132,9 +132,9 @@ public interface {{classname}} {
|
||||
{{#summary}}
|
||||
summary = "{{{.}}}",
|
||||
{{/summary}}
|
||||
{{#vendorExtensions.x-tags}}
|
||||
{{#vendorExtensions.x-tags.size}}
|
||||
tags = { {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} },
|
||||
{{/vendorExtensions.x-tags}}
|
||||
{{/vendorExtensions.x-tags.size}}
|
||||
responses = {
|
||||
{{#responses}}
|
||||
@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = {
|
||||
@@ -153,7 +153,9 @@ public interface {{classname}} {
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
@ApiOperation(
|
||||
{{#vendorExtensions.x-tags.size}}
|
||||
tags = { {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} },
|
||||
{{/vendorExtensions.x-tags.size}}
|
||||
value = "{{{summary}}}",
|
||||
nickname = "{{{operationId}}}",
|
||||
notes = "{{{notes}}}"{{#returnBaseType}},
|
||||
|
||||
@@ -24,10 +24,13 @@ import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||
import java.util.function.Consumer;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.languages.SpringCodegen;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Ignore;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -807,4 +810,55 @@ public class SpringCodegenTest {
|
||||
Assert.assertEquals(codegen.importMapping().get("ParameterObject"), "org.springdoc.api.annotations.ParameterObject");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "issue11464TestCases")
|
||||
public void shouldGenerateOneTagAttributeForMultipleTags_Regression11464(String documentProvider, Consumer<String> assertFunction) throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
|
||||
OpenAPI openAPI = new OpenAPIParser()
|
||||
.readLocation("src/test/resources/bugs/issue_11464.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
|
||||
SpringCodegen codegen = new SpringCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, documentProvider);
|
||||
ClientOptInput input = new ClientOptInput();
|
||||
input.openAPI(openAPI);
|
||||
input.config(codegen);
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "false");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
|
||||
|
||||
generator.opts(input).generate();
|
||||
|
||||
assertFunction.accept(outputPath);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] issue11464TestCases() {
|
||||
return new Object[][] {
|
||||
{ DocumentationProviderFeatures.DocumentationProvider.SPRINGDOC.name(), (Consumer<String>) outputPath -> {
|
||||
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/NoneApi.java"),
|
||||
"@Operation( operationId = \"getNone\", summary = \"No Tag\", responses = {");
|
||||
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/SingleApi.java"),
|
||||
"@Operation( operationId = \"getSingleTag\", summary = \"Single Tag\", tags = { \"tag1\" }, responses = {");
|
||||
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/MultipleApi.java"),
|
||||
"@Operation( operationId = \"getMultipleTags\", summary = \"Multiple Tags\", tags = { \"tag1\", \"tag2\" }, responses = {");
|
||||
}},
|
||||
{ DocumentationProviderFeatures.DocumentationProvider.SPRINGFOX.name(), (Consumer<String>) outputPath -> {
|
||||
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/NoneApi.java"),
|
||||
"@ApiOperation( value = \"No Tag\", nickname = \"getNone\", notes = \"\", response = ");
|
||||
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/SingleApi.java"),
|
||||
"@ApiOperation( tags = { \"tag1\" }, value = \"Single Tag\", nickname = \"getSingleTag\", notes = \"\", response = ");
|
||||
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/MultipleApi.java"),
|
||||
"@ApiOperation( tags = { \"tag1\", \"tag2\" }, value = \"Multiple Tags\", nickname = \"getMultipleTags\", notes = \"\", response = ");
|
||||
}},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
openapi: '3.0.3'
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Example Api
|
||||
paths:
|
||||
/none:
|
||||
get:
|
||||
summary: No Tag
|
||||
operationId: get_none
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
/single:
|
||||
get:
|
||||
summary: Single Tag
|
||||
operationId: get_single_tag
|
||||
tags:
|
||||
- tag1
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
/multiple:
|
||||
get:
|
||||
summary: Multiple Tags
|
||||
operationId: get_multiple_tags
|
||||
tags:
|
||||
- tag1
|
||||
- tag2
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
Reference in New Issue
Block a user