grantila / typeconv

Convert between JSON Schema, TypeScript, GraphQL, Open API and SureType
MIT License
421 stars 8 forks source link

[ts-to-oapi] Imported types are transformed #21

Closed enzoferey closed 1 year ago

enzoferey commented 2 years ago

Whenever you are transforming a TypeScript file to an OpenApi specification file, if you declare a type that reuses some other type that you import from a different file, the imported types are not included in the OpenApi specification file.

As an example this file:

import type { MyTypeB } from "./some-file";

export type A = MyTypeB;

generates:

$ref: '#/components/schemas/MyTypeB'

however no MyTypeB component is generated inside the file.

menocomp commented 1 year ago

I had a look at the readme file and it says:

typeconv doesn't support external references (to other files). If you have that, you need to use a reference parser and merge it into one inline-referenced file before using typeconv.

I have the same issue and not sure yet if I should squash types into one file, or run typeconv once per each file and collect the schemas via a program. Both options look difficult to do.

grantila commented 1 year ago

Right, I'll have to close this as simple not supported.

Merging typescript files into one is not just concatenating them, it requires language-level logic to do it right, so it makes more sense for other packages out there to do that job. Have a look at https://www.npmjs.com/package/dts-bundle-generator or https://www.npmjs.com/package/dts-generator they do precisely this.

enzoferey commented 1 year ago

Thanks for the references and explanations @menocomp @grantila ! This was a long time ago so I can't remember if the README was stating that at the time or not. If so, I'm sorry 👍🏻