-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
nestia/SDK issues: Invalid Types, and Incomplete API Generation #677
Comments
Upgrade to the latest version, then such error report would be printed. As Nestia SDK is targetting the client developers, it enforces API controller methods to define explicit types. -----------------------------------------------------------
Nestia SDK Generator
-----------------------------------------------------------
Analyzing reflections
- controllers: #2
- paths: #4
- routes: #4
Analyzing source codes
-----------------------------------------------------------
Nestia Error Report
-----------------------------------------------------------
libs\user\src\user.controller.ts - error on UserController.update()
- implicit (unnamed) parameter type from "updateUserDto".
libs\user\src\user.controller.ts - error on UserController.delete()
- implicit (unnamed) parameter type from "deleteUserDto". |
Hi @samchon, I've encountered same issues with the latest version of nestia, after fixing all the type-related error. Here are the issues:
To:
|
Your controller methods still do not have the explicit return type, and it is even same with your service providers. |
Got it, thanks. I was trying to make the issue reproduction as simple as possible. Since the I fixed the return type to simply be "string", in both controller and service. The issues are still valid. |
You're importing prisma auto generated TMP type that can't be exported to the SDK library. It's actually not explicit. The name In that case, you've to choose one option of below:
/*
* File: nestia.config.ts
* File Created: 2023-09-21 04:29:25
* Author: Val Liu <[email protected]>
*
* -----
* Last Modified: 2023-11-06 07:33:31
* Modified By: Val Liu
* -----
*/
import { INestiaConfig } from "@nestia/sdk";
export const NESTIA_CONFIG: INestiaConfig = {
/**
* Building `swagger.json` is also possible.
*
* If not specified, you can't build the `swagger.json`.
*/
swagger: {
/**
* Output path of the `swagger.json`.
*
* If you've configured only directory, the file name would be the `swagger.json`.
* Otherwise you've configured the full path with file name and extension, the
* `swagger.json` file would be renamed to it.
*/
output: "packages/swagger.json",
servers: [
{
url: "http://localhost:3000",
description: "Local Server",
},
],
},
/**
* List of files or directories containing the NestJS controller classes.
*/
input: ["libs/**/*.controller.ts", "src/**/*.controller.ts"],
/**
* Output directory that SDK would be placed in.
*
* If not configured, you can't build the SDK library.
*/
output: "src/api",
/**
* Target directory that SDK distribution files would be placed in.
*
* If you configure this property and runs `npx nestia sdk` command,
* distribution environments for the SDK library would be generated.
*
* After the SDK library generation, move to the `distribute` directory,
* and runs `npm publish` command, then you can share SDK library with
* other client (frontend) developers.
*/
distribute: "packages/api",
/**
* Allow simulation mode.
*
* If you configure this property to be `true`, the SDK library would be contain
* simulation mode. In the simulation mode, the SDK library would not communicate
* with the real backend server, but just returns random mock-up data
* with requestion data validation.
*
* For reference, random mock-up data would be generated by `typia.random<T>()`
* function.
*
* @default false
*/
// simulate: true,
/**
* Whether to clone DTO structures or not.
*
* If being configured, all of DTOs used in the backend server would be cloned
* into the `structures` directory, and the SDK library would be refer to the
* cloned DTOs instead of the original.
*
* @default false
*/
clone: true,
};
export default NESTIA_CONFIG; |
Also, I'll enhance the error message reporting following your advise. |
Hi @samchon, It's great to see that we have the However, there are still some issues with clone, and the updated repository can be found here (same place) 1. The
|
Then no way. Define the explicit type instead of using the Prisma generated TMP type. |
I used Prisma TMP type, for the purpose of "Single Source of Truth" (from the Prisma model). |
As primsa has too long and deep structured name, no way right now. How about suggest a spec that renaming DTO clone rule about this case? |
Any updates? I would really like to be able to use the types of Prisma instead of the clone option |
Summary
packages/api
.Detail
I have created a GitHub repository to replicate these issues. You can find it here
To make it work, you can simply run
npm i
and thennpx nestia sdk
.Issue 1: Invalid Types Named "___type"
There are multiple "__type" imports from locations where they are not valid.
Issue 2: Incomplete API Generation
This issue is closely related to the first one. For example, the "Read" API is not functioning properly due to
Primitive<__type & __type>
. Additionally, TypeScript warns about "ES2015 module syntax" being preferred over namespaces.Issue 3: The distribution package
functional
folder is missing.The
functional
folder exists insidesrc/api
but is missing from thepackages/api
directory, which is set up for distribution.Issue 4: "Shared" Type Location for NPM Distribution
There are relative path imports in the "distribution" directory, which may cause complications when publishing to npm. To resolve this, it's advisable to copy them into the distribution folder.
The text was updated successfully, but these errors were encountered: