Skip to content
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

[issue: #536] - Added annotation @Path("/") when operation is empty #585

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading