Skip to content

Commit

Permalink
fix: Do not skip endpoint registration if there are no custom types (#…
Browse files Browse the repository at this point in the history
…2467) (CP: main) (#2469)

fix: Do not skip endpoint registration if there are no custom types (#2467)

Fixes #2461

Co-authored-by: Artur <artur@vaadin.com>
Co-authored-by: Anton Platonov <platosha@gmail.com>
  • Loading branch information
3 people authored May 24, 2024
1 parent 86bef3a commit 8d50d18
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,30 @@ public static String generateOpenAPI(Path buildDirectory,
public static Set<String> findOpenApiClasses(String openApiAsText)
throws IOException {
JsonNode openApi = new ObjectMapper().readTree(openApiAsText);
if (!openApi.has("components")) {
return Collections.emptySet();
}

Set<String> types = new HashSet<>();

// Endpoints
ArrayNode tags = (ArrayNode) openApi.get("tags");
if (openApi.has("tags")) {
ArrayNode tags = (ArrayNode) openApi.get("tags");

if (tags != null) {
tags.forEach(nameAndClass -> {
types.add(nameAndClass.get("x-class-name").asText());
});
if (tags != null) {
tags.forEach(nameAndClass -> {
types.add(nameAndClass.get("x-class-name").asText());
});
}
}

// Parameters and return types
ObjectNode schemas = (ObjectNode) openApi.get("components")
.get("schemas");
if (schemas != null) {
schemas.fieldNames().forEachRemaining(type -> {
types.add(type);
});
if (openApi.has("components")) {
ObjectNode schemas = (ObjectNode) openApi.get("components")
.get("schemas");
if (schemas != null) {
schemas.fieldNames().forEachRemaining(type -> {
types.add(type);
});
}
}

return types;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public class OpenAPIUtilTest {
@Test
public void emptySchemaReturnsNoComponents() throws IOException {
Assert.assertEquals(Collections.emptySet(),
parse("openapi-noendpoints.json"));
}

@Test
public void noComponentsReturnEndpointTypes() throws IOException {
Assert.assertEquals(Set.of(
"com.example.application.endpoints.helloreact.HelloReactEndpoint"),
parse("openapi-nocustomtypes.json"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"openapi": "3.0.1",
"info": {
"title": "Hilla Application",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:8080/connect",
"description": "Hilla Backend"
}
]
}

0 comments on commit 8d50d18

Please sign in to comment.