Description
openapi-typescript version
12.1.3
Node.js version
23.6.0
OS + version
macOS 15.2
Description
I ran into an issue while working when using the open api lib
@ApiProperty({ type: [String] })
@computed()
public get permissions(): string[] {
return this.permissionRelation.map((p) => p.name)
}
I am getting this error
"message": "Class constructor User cannot be invoked without 'new'",
"name": "TypeError",
"status": 500,
"frames": [
{
"file": "Users/junkaihwong/Projects/kkip-app/node_modules/.pnpm/openapi-metadata@0.1.1_reflect-metadata@0.2.2/node_modules/openapi-metadata/dist/loaders/type.js",
"filePath": "/Users/junkaihwong/Projects/kkip-app/node_modules/.pnpm/openapi-metadata@0.1.1_reflect-metadata@0.2.2/node_modules/openapi-metadata/dist/loaders/type.js",
"line": 104,
"callee": "loadType",
"calleeShort": "loadType",
I've pinpointed the error to the .map function but when i tried swapping .map with any other array iterator but it still gives me the same error. My code runs fine tho. Wondering if it has anything to do with anything the screenshot and is there a quick fix / workaround? Appreciate any help 🙏
Reproduction
Reproduce by doing the following:
- Initialising adonis (pnpm create adonisjs@latest hello-world -- --kit=api --auth-guard=access_tokens --db=postgres)
- Installing dependency (node ace add @foadonis/openapi )
- Setting up routes and adding controllers and updating the model to use .map() in the User Model
@ApiProperty()
@computed()
public get name(): string[] {
return ['hwllo'].map((q) => q)
}
You will be greeted by this error:
"message": "Class constructor User cannot be invoked without 'new'",
"name": "TypeError",
"status": 500,
At point 3, the code looks like this: https://github.com/jollyjunkaih/adonis-openapi-bug
Expected result
It's not supposed to fail
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint
)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)