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

feat: add TransferTypes plugin for Generator #3171

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ inputs:

runs:
using: composite
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
- 'packages/**/README.md'
- 'scripts/generator/templates/**/*.md'
pull_request_target:
types: [opened, synchronize, reopened]
types: [ opened, synchronize, reopened ]
paths-ignore:
- 'hilla-logo.svg'
- 'README.md'
Expand All @@ -34,6 +34,7 @@ jobs:
timeout-minutes: 5
env:
NX_SKIP_NX_CACHE: true
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1

steps:
- uses: actions-cool/check-user-permission@main
Expand Down
14,806 changes: 7,448 additions & 7,358 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
"license": "Apache-2.0",
"overrides": {
"esbuild": "$esbuild",
"prettier": "$prettier"
"prettier": "$prettier",
"react": "19.0.0",
"react-dom": "19.0.0",
"chai": "5"
},
"devDependencies": {
"@nx/js": "^20.3.1",
Expand All @@ -40,6 +43,8 @@
"@types/node": "^22.10.5",
"@vaadin/react-components": "24.7.0-alpha7",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/browser": "^3.0.4",
"@vitest/ui": "^3.0.4",
"@web/test-runner": "^0.19.0",
"chai-dom": "^1.12.0",
"compare-versions": "^6.1.1",
Expand Down Expand Up @@ -67,12 +72,12 @@
"nx": "^20.3.1",
"postcss": "^8.4.49",
"prettier": "^3.4.2",
"react-dom": "^18.3.1",
"simple-git-hooks": "^2.11.1",
"sync-request": "^6.1.0",
"tsx": "^4.19.2",
"type-fest": "^4.32.0",
"typescript": "5.7.3",
"vite": "^5.4.11"
"vite": "^5.4.11",
"vitest": "^3.0.4"
}
}
131 changes: 68 additions & 63 deletions packages/java/parser-jvm-plugin-transfertypes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,76 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.vaadin</groupId>
<artifactId>hilla-project</artifactId>
<version>24.7-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<parent>
<groupId>com.vaadin</groupId>
<artifactId>hilla-project</artifactId>
<version>24.7-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>

<artifactId>hilla-parser-jvm-plugin-transfertypes</artifactId>
<name>Hilla JVM Parser Transfer Types Plugin</name>
<packaging>jar</packaging>
<artifactId>hilla-parser-jvm-plugin-transfertypes</artifactId>
<name>Hilla JVM Parser Transfer Types Plugin</name>
<packaging>jar</packaging>

<properties>
<formatter.basedir>${project.parent.basedir}</formatter.basedir>
</properties>
<properties>
<formatter.basedir>${project.parent.basedir}</formatter.basedir>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-plugin-backbone</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-runtime-plugin-transfertypes</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-plugin-backbone</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-runtime-plugin-transfertypes</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-parser-jvm-test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.vaadin.hilla.mappedtypes.Order;
import com.vaadin.hilla.mappedtypes.Pageable;
import com.vaadin.hilla.mappedtypes.Sort;
Expand All @@ -25,10 +26,9 @@
import com.vaadin.hilla.parser.models.ClassRefSignatureModel;
import com.vaadin.hilla.parser.models.SignatureModel;
import com.vaadin.hilla.parser.plugins.backbone.BackbonePlugin;
import com.vaadin.hilla.parser.plugins.backbone.nodes.CompositeTypeSignatureNode;
import com.vaadin.hilla.parser.plugins.backbone.nodes.TypeSignatureNode;
import com.vaadin.hilla.parser.plugins.backbone.nodes.TypedNode;
import com.vaadin.hilla.runtime.transfertypes.EndpointSubscription;
import com.vaadin.hilla.runtime.transfertypes.File;
import com.vaadin.hilla.runtime.transfertypes.Flux;

public final class TransferTypesPlugin
Expand All @@ -48,6 +48,8 @@ public final class TransferTypesPlugin
classMap.put(JsonNode.class.getName(), Object.class);
classMap.put(ObjectNode.class.getName(), Object.class);
classMap.put(ArrayNode.class.getName(), List.class);
classMap.put("org.springframework.web.multipart.MultipartFile",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the added spring-web dependency, is there a reason not to use the MultipartFile.class.getName() instead of the string literal version of the class name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Good question. Actually, I just followed the approach for other Spring classes in this file. Should we reconsider this approach?

File.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.file;

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,9 @@
package com.vaadin.hilla.parser.plugins.transfertypes.file;

import org.springframework.web.multipart.MultipartFile;

@Endpoint
public class MultipartFileEndpoint {
public void uploadFile(MultipartFile file) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.vaadin.hilla.parser.plugins.transfertypes.file;

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

import org.junit.jupiter.api.Test;

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;

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

@Test
public void should_ReplaceMultipartFileClassWithLocalFileClass()
throws IOException, URISyntaxException {
var openAPI = new Parser()
.classPath(Set.of(helper.getTargetDir().toString()))
.endpointAnnotations(List.of(Endpoint.class))
.addPlugin(new BackbonePlugin())
.addPlugin(new TransferTypesPlugin())
.execute(List.of(MultipartFileEndpoint.class));

helper.executeParserWithConfig(openAPI);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"openapi" : "3.0.1",
"info" : {
"title" : "Hilla Application",
"version" : "1.0.0"
},
"servers" : [
{
"url" : "http://localhost:8080/connect",
"description" : "Hilla Backend"
}
],
"tags" : [
{
"name" : "MultipartFileEndpoint",
"x-class-name" : "com.vaadin.hilla.parser.plugins.transfertypes.file.MultipartFileEndpoint"
}
],
"paths" : {
"/MultipartFileEndpoint/uploadFile" : {
"post" : {
"tags" : [
"MultipartFileEndpoint"
],
"operationId" : "MultipartFileEndpoint_uploadFile_POST",
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"type" : "object",
"properties" : {
"file" : {
"nullable" : true,
"anyOf" : [
{
"$ref" : "#/components/schemas/com.vaadin.hilla.runtime.transfertypes.File"
}
]
}
}
}
}
}
},
"responses" : {
"200" : {
"description" : ""
}
}
}
}
},
"components" : {
"schemas" : {
"com.vaadin.hilla.runtime.transfertypes.File" : {
"type" : "object"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.vaadin.hilla.runtime.transfertypes;

public record File() {
}
2 changes: 1 addition & 1 deletion packages/ts/frontend/src/Connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
FluxConnection,
type FluxSubscriptionStateChangeEvent,
} from './FluxConnection.js';
import type { VaadinGlobal } from './types.js';
import type { VaadinGlobal } from './types.t.js';

const $wnd = globalThis as VaadinGlobal;

Expand Down
2 changes: 1 addition & 1 deletion packages/ts/frontend/src/CookieManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function calculatePath({ pathname }: URL): string {
return pathname.length > 1 && pathname.endsWith('/') ? pathname.slice(0, -1) : pathname;
}

const CookieManager: Cookies.CookiesStatic = Cookies.withAttributes({
const CookieManager: typeof Cookies = Cookies.withAttributes({
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
path: calculatePath(new URL(globalThis.document?.baseURI ?? '/')),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/frontend/test/Connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
UnauthorizedResponseError,
type FluxConnection,
} from '../src/index.js';
import type { Vaadin, VaadinGlobal } from '../src/types.js';
import type { Vaadin, VaadinGlobal } from '../src/types.t.js';
import { subscribeStub } from './mocks/atmosphere.js';
import { fluxConnectionSubscriptionStubs } from './mocks/FluxConnection.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "es2022"
"target": "es2021"
},
"include": ["src", "test"],
"exclude": ["test/**/*.snap.ts"]
Expand Down
Loading
Loading