hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client

Home Page:https://heyapi.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

t.filter is not a function

enkelmedia opened this issue · comments

Description

@hey-api/openapi-ts": "^0.42.1, tested on 0.37.3 as well, same error.

Getting this error when running npm run api:generate (see script below).

The log does not really tell a lot:

t.filter is not a function
TypeError: t.filter is not a function
at Wr (D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:123742)
at D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:125675
at Array.map ()
at Gr (D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:125271)
at Jr (D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:124879)
at D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:125292
at Array.map ()
at Object.Gr [as object] (D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:125271)
at r (D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:140353)
at D:\Development\MyPackage\node_modules@hey-api\openapi-ts\dist\node\index.cjs:1:140612

Switching from the openapi-ts.config.ts to suing CLI parameters worked:

"generate:apinew" : "openapi-ts --input http://localhost:14655/swagger/swagger.json --output src/backend-api --debug true --enums typescript --lint true --schemas false",

OpenAPI specification (optional)

No response

Configuration

openapi-ts.config.ts:

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'http://localhost:14655/swagger/swagger.json',
  output: 'src/backend-api'
});

package.json

{
  "scripts" : {
     "generate:api" : "openapi-ts",
   }
}

System information (optional)

Windows 11
Node: 20.9.0

UPDATE:

Turns out passing schemas : false make it work, i did not realize that this was outputted by default. Error message still does not really tell me what is wrong so I'll keep the issue open if you want to look closer.

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'http://localhost:14655/swagger/swagger.json',
  output: 'src/backend-api',  
  enums : 'typescript',
  schemas : false,
  lint : true
});

@enkelmedia can you provide the OpenAPI spec? Or run with debug: true in the config

@jordanshatford when adding debug:true I just get the same error as in the log file.

image

I really can't share the schema publicly (sorry). I could send it privately if there is way.

I updated the initial post with some finding, the error goes away when I use schemas : false

@enkelmedia thanks. That narrows it down some. I'll take a look at what I can find. If I am still having issues I will provide a way for you to send the spec privately

@enkelmedia I think I will require the spec to further debug. Could you email it to me "jordanshatford@live.com"

@enkelmedia also lint option has been changed. You should specify "eslint" or "biome" based on the linter you are using.

Hmm... this is strange.

I tried to replicate the issue now and it worked with schemas: true.

I know I've made a couple of changes since I had the problem:

  • I did add eslint to the project after I had the issue last time.
  • Made som refactoring to the types returned by my endpoints. I used to have a strange .NET Exception type included. This is a quite complex type so maybe that was the issue.

I think that this issue is rare and quite a mistake on my site to include that type. I could try to replicate it if you would like to - otherwise I'm fine with closing this.

Regarding lint, if I don't want to perform linting - should I leave it out or set it to false?

@enkelmedia you can do either. Be default linting is not run. If you want to be explicit you can set to false.

@mrlubos ypu can close this ticket if you feel it's not longer necessary

Hey @enkelmedia, would you be able to spend a few minutes checking if you can narrow it down by undoing the changes you mentioned? It might be a bug on our side so I'd like to give it a try at least to confirm

@mrlubos & @jordanshatford

Of course, thats the least I can do!

Just rolled back, tested and got the same error. Then I removed the .NET Exception class from my DTO and after this, it works again. It was a mistake on my side, I don't think it's common for .NET devs to include the full Exception class in the DTOs.

Anyway, there might be some other issue and of course would be good to throw a better/more informative exception.

I emailed the json-specs to @jordanshatford if you want to do some further debugging.

Cheers!

Thanks! I haven't seen the spec so can't say if this is something we should fix, but it sounds like potentially we should at least throw a better error

@enkelmedia Thanks for emailing me the spec. I was away over the weekend but have just looked at it and made a fix. it will be included in the next release! Let use know if you have any other issues with the project.