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 15 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
13,631 changes: 6,386 additions & 7,245 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 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 Down Expand Up @@ -67,7 +70,6 @@
"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",
Expand Down
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() {
}
5 changes: 1 addition & 4 deletions packages/ts/generator-cli/src/GeneratorIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { dirname, isAbsolute, join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import type File from '@vaadin/hilla-generator-core/File.js';
import Plugin, { type PluginConstructor } from '@vaadin/hilla-generator-core/Plugin.js';
import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';
import GeneratorIOException from './GeneratorIOException.js';
Expand Down Expand Up @@ -64,7 +63,7 @@ export default class GeneratorIO {
filesToDelete.delete(filename);
});

const deletedFiles = new Set(
return new Set(
await Promise.all(
[...filesToDelete].map(async (filename) => {
const resolved = this.resolveGeneratedFile(filename);
Expand All @@ -76,8 +75,6 @@ export default class GeneratorIO {
}),
),
);

return deletedFiles;
}

async createFileIndex(filenames: string[]): Promise<void> {
Expand Down
1 change: 0 additions & 1 deletion packages/ts/generator-cli/test/GeneratorIO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { statSync } from 'node:fs';
import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import File from '@vaadin/hilla-generator-core/File.js';
import LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
Expand Down
7 changes: 2 additions & 5 deletions packages/ts/generator-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@
"./Schema.js": {
"default": "./Schema.js"
},
"./SharedStorage.js": {
"types": "./SharedStorage.d.ts"
},
"./utils.js": {
"default": "./utils.js"
"./SharedStorage.t.js": {
"types": "./SharedStorage.t.d.ts"
}
},
"repository": {
Expand Down
21 changes: 0 additions & 21 deletions packages/ts/generator-core/src/File.ts

This file was deleted.

Loading
Loading