Skip to content

Commit

Permalink
replace AUTO with preferredAnnotationLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
cachescrubber committed Jan 9, 2022
1 parent b7160a1 commit 75a722c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DocumentationProvider> 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<AnnotationLibrary> 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);
}
}

0 comments on commit 75a722c

Please sign in to comment.