From 75a722ce5d71d5e670f4f56f11315c21e3f30fa7 Mon Sep 17 00:00:00 2001 From: Lars Uffmann Date: Sun, 9 Jan 2022 09:36:48 +0100 Subject: [PATCH] replace AUTO with preferredAnnotationLibrary --- .../languages/AbstractJavaCodegen.java | 14 +++--- .../DocumentationProviderFeatures.java | 2 - .../DocumentationProviderFeaturesTest.java | 44 +++++++++---------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index cc40727e8c96..1e5bd25ffa4e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -272,7 +272,7 @@ public AbstractJavaCodegen() { CliOption annotationLibraryCliOption = new CliOption(ANNOTATION_LIBRARY, "Select the complementary documentation annotation library.") - .defaultValue(AnnotationLibrary.AUTO.toCliOptValue()); + .defaultValue(defaultDocumentationProvider().getPreferredAnnotationLibrary().toCliOptValue()); supportedAnnotationLibraries().forEach(al -> annotationLibraryCliOption.addEnum(al.toCliOptValue(), al.getDescription())); cliOptions.add(annotationLibraryCliOption); @@ -289,29 +289,25 @@ public void processOpts() { if (! supportedDocumentationProvider().contains(documentationProvider)) { String msg = String.format(Locale.ROOT, - "The Documentation Provider %s is not supported by this generator", + "The [%s] Documentation Provider is not supported by this generator", documentationProvider.toCliOptValue()); throw new IllegalArgumentException(msg); } annotationLibrary = AnnotationLibrary.ofCliOption( (String) additionalProperties.getOrDefault(ANNOTATION_LIBRARY, - AnnotationLibrary.AUTO.toCliOptValue()) + documentationProvider.getPreferredAnnotationLibrary().toCliOptValue()) ); - if (annotationLibrary == AnnotationLibrary.AUTO) { - annotationLibrary = documentationProvider.getPreferredAnnotationLibrary(); - } - if (! supportedAnnotationLibraries().contains(annotationLibrary)) { - String msg = String.format(Locale.ROOT, "The Annotation Library %s is not supported by this generator", + String msg = String.format(Locale.ROOT, "The Annotation Library [%s] is not supported by this generator", annotationLibrary.toCliOptValue()); throw new IllegalArgumentException(msg); } if (! documentationProvider.supportedAnnotationLibraries().contains(annotationLibrary)) { String msg = String.format(Locale.ROOT, - "The documentation provider %s does not support %s as complementary annotation library", + "The [%s] documentation provider does not support [%s] as complementary annotation library", documentationProvider.toCliOptValue(), annotationLibrary.toCliOptValue()); throw new IllegalArgumentException(msg); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/features/DocumentationProviderFeatures.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/features/DocumentationProviderFeatures.java index 3a4cd3941d16..6e488ec4d7c3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/features/DocumentationProviderFeatures.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/features/DocumentationProviderFeatures.java @@ -130,8 +130,6 @@ public String toCliOptValue() { } enum AnnotationLibrary { - AUTO("autoAnnotationLibrary", "Use the preferred annotation library of the selected documentation provider."), - NONE("withoutAnnotationLibrary", "Do not annotate Model and Api with complementary annotations."), SWAGGER1("swagger1AnnotationLibrary", "Annotate Model and Api using the Swagger Annotations 1.x library."), diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/features/DocumentationProviderFeaturesTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/features/DocumentationProviderFeaturesTest.java index 138254d453d3..42e29ccbe516 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/features/DocumentationProviderFeaturesTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/features/DocumentationProviderFeaturesTest.java @@ -1,50 +1,50 @@ package org.openapitools.codegen.languages.features; -import java.io.PrintWriter; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.AnnotationLibrary; import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DocumentationProvider; -import org.testng.annotations.AfterTest; import org.testng.annotations.Test; public class DocumentationProviderFeaturesTest { - PrintWriter writer = new PrintWriter(System.out); - - @AfterTest - void flush() { - writer.flush(); - } - @Test(priority = 0) void generateDocumentationProviderTable() { - writer.println("### DocumentationProvider\n"); - writer.println("|Cli Option|Description|Property Name|Preferred Annotation Library|Supported Annotation Libraries|"); - writer.println("|----------|-----------|-------------|----------------------------|------------------------------|"); List providers = Arrays.asList(DocumentationProvider.values()); - providers.forEach(dp -> writer.printf("|**%s**|%s|`%s`|%s|%s|\n", + StringBuilder sb = new StringBuilder(); + sb.append("### DocumentationProvider\n"); + sb.append("|Cli Option|Description|Property Name|Preferred Annotation Library|Supported Annotation Libraries|\n"); + sb.append("|----------|-----------|-------------|----------------------------|------------------------------|\n"); + providers.forEach(dp -> sb.append(String.format(Locale.ROOT, "|**%s**|%s|`%s`|%s|%s|\n", dp.toCliOptValue(), dp.getDescription(), dp.getPropertyName(), dp.getPreferredAnnotationLibrary().toCliOptValue(), - dp.supportedAnnotationLibraries().stream().map(AnnotationLibrary::toCliOptValue).collect(Collectors.joining(", ")) - )); - writer.println(); + dp.supportedAnnotationLibraries().stream() + .map(AnnotationLibrary::toCliOptValue) + .collect(Collectors.joining(", ")) + ))); + sb.append("\n"); + + System.out.println(sb); } @Test(priority = 1) void generateAnnotationLibraryTable() { - writer.println("### AnnotationLibrary\n"); - writer.println("|Cli Option|Description|Property Name|"); - writer.println("|----------|-----------|-----------|"); List libraries = Arrays.asList(AnnotationLibrary.values()); - libraries.forEach(dp -> writer.printf("|**%s**|%s|`%s`|\n", + StringBuilder sb = new StringBuilder(); + sb.append("### AnnotationLibrary\n"); + sb.append("|Cli Option|Description|Property Name|\n"); + sb.append("|----------|-----------|-----------|\n"); + libraries.forEach(dp -> sb.append(String.format(Locale.ROOT, "|**%s**|%s|`%s`|\n", dp.toCliOptValue(), dp.getDescription(), dp.getPropertyName() - )); - writer.println(); + ))); + sb.append("\n"); + + System.out.println(sb); } } \ No newline at end of file