Skip to content

Commit

Permalink
[issue: quarkiverse#536] feat: Added annotation @path(/) when 'subres…
Browse files Browse the repository at this point in the history
…ourceOperation' is empty
  • Loading branch information
Jefferson Cleyson Gomes Almeida committed Dec 11, 2023
1 parent a591421 commit 5cf15d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public interface {classname} {
@{op.httpMethod}
{#if op.subresourceOperation}
@Path("{op.path}")
{#else}
@Path("/")
{/if}
{#if op.hasConsumes}
@Consumes(\{{#for consume in op.consumes}"{consume.mediaType}"{#if consume_hasNext}, {/if}{/for}\})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openapitools.codegen.config.GlobalSettings;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.TokenRange;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.ImportDeclaration;
import com.github.javaparser.ast.Node;
Expand Down Expand Up @@ -130,6 +131,33 @@ void verifyEnumGeneration() throws URISyntaxException, FileNotFoundException {
.containsExactlyInAnyOrder("DISCONNECTED", "READY", "DELETING");
}

@Test
void verifyAtSignPathAnnotationGeneration() throws URISyntaxException, FileNotFoundException {
final List<File> generatedFiles = createGeneratorWrapper("petstore-openapi.json").generate("org.petstore");
final Optional<File> apiFile = generatedFiles.stream()
.filter(f -> f.getName().endsWith("PetApi.java")).findFirst();
assertThat(apiFile).isPresent();

final CompilationUnit cu = StaticJavaParser.parse(apiFile.orElseThrow());
final List<MethodDeclaration> methodDeclarations = cu.findAll(MethodDeclaration.class);

final List<String> methodNamesForChecking = List.of("addPet", "updatePet");

assertThat(methodDeclarations)
.hasSize(8)
.filteredOn(m -> methodNamesForChecking.contains(m.getNameAsString()))
.map(m -> m.getAnnotationByName("Path"))
.filteredOn(Optional::isPresent)
.map(Optional::get)
.map(Node::getTokenRange)
.filteredOn(Optional::isPresent)
.map(Optional::get)
.map(TokenRange::toString)
.hasSize(methodNamesForChecking.size())
.allMatch(value -> value.equals("@Path(\"/\")"));

}

@Test
void verifyDeprecatedFields() throws URISyntaxException, FileNotFoundException {
final Map<String, Object> codegenConfig = ClassCodegenConfigParser
Expand Down

0 comments on commit 5cf15d4

Please sign in to comment.