Skip to content

Commit

Permalink
feat(parser): map JsonNode to Object (#2398)
Browse files Browse the repository at this point in the history
* Map JsonNode to Object

* Improve test

* Test nullability

* Remove nullability as Object is translated to unknown

---------

Co-authored-by: Anton Platonov <platosha@gmail.com>
  • Loading branch information
cromoteca and platosha authored May 20, 2024
1 parent d66305c commit 9be358f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.annotation.Nonnull;

import com.fasterxml.jackson.databind.JsonNode;
import com.vaadin.hilla.mappedtypes.Order;
import com.vaadin.hilla.mappedtypes.Pageable;
import com.vaadin.hilla.mappedtypes.Sort;
Expand All @@ -32,7 +33,7 @@ public final class TransferTypesPlugin
extends AbstractPlugin<PluginConfiguration> {
static private final Map<String, Class<?>> classMap = new HashMap<>();

{
static {
classMap.put("org.springframework.data.domain.Page", List.class);
classMap.put("org.springframework.data.domain.Pageable",
Pageable.class);
Expand All @@ -42,6 +43,7 @@ public final class TransferTypesPlugin
classMap.put("reactor.core.publisher.Flux", Flux.class);
classMap.put("com.vaadin.hilla.EndpointSubscription",
EndpointSubscription.class);
classMap.put(JsonNode.class.getName(), Object.class);
}

public TransferTypesPlugin() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vaadin.hilla.parser.plugins.transfertypes.jsonnode;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Endpoint {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.vaadin.hilla.parser.plugins.transfertypes.jsonnode;

import com.fasterxml.jackson.databind.JsonNode;

@Endpoint
public class JsonNodeEndpoint {
public JsonNode echo(JsonNode node) {
return node;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.vaadin.hilla.parser.plugins.transfertypes.jsonnode;

import com.vaadin.hilla.parser.core.Parser;
import com.vaadin.hilla.parser.plugins.backbone.BackbonePlugin;
import com.vaadin.hilla.parser.plugins.transfertypes.TransferTypesPlugin;
import com.vaadin.hilla.parser.plugins.transfertypes.test.helpers.TestHelper;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Set;

public class JsonNodeTest {
private final TestHelper helper = new TestHelper(getClass());

@Test
public void should_ReplaceJsonNodeClassWithObject()
throws IOException, URISyntaxException {
var openAPI = new Parser().classLoader(getClass().getClassLoader())
.classPath(Set.of(helper.getTargetDir().toString()))
.endpointAnnotation(Endpoint.class.getName())
.addPlugin(new BackbonePlugin())
.addPlugin(new TransferTypesPlugin()).execute();

helper.executeParserWithConfig(openAPI);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"openapi" : "3.0.1",
"info" : {
"title" : "Hilla Application",
"version" : "1.0.0"
},
"servers" : [
{
"url" : "http://localhost:8080/connect",
"description" : "Hilla Backend"
}
],
"tags" : [
{
"name" : "JsonNodeEndpoint",
"x-class-name" : "com.vaadin.hilla.parser.plugins.transfertypes.jsonnode.JsonNodeEndpoint"
}
],
"paths" : {
"/JsonNodeEndpoint/echo" : {
"post" : {
"tags" : [
"JsonNodeEndpoint"
],
"operationId" : "JsonNodeEndpoint_echo_POST",
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"type" : "object",
"properties" : {
"node" : {
"type" : "object"
}
}
}
}
}
},
"responses" : {
"200" : {
"description" : "",
"content" : {
"application/json" : {
"schema" : {
"type" : "object"
}
}
}
}
}
}
}
}
}

0 comments on commit 9be358f

Please sign in to comment.