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

Polymorph interfaces #13

Open
derolf opened this issue Sep 9, 2021 · 4 comments
Open

Polymorph interfaces #13

derolf opened this issue Sep 9, 2021 · 4 comments

Comments

@derolf
Copy link
Contributor

derolf commented Sep 9, 2021

Consider

interface Foo {
  foo: number;
}
interface Bar extends Foo {
  bar: number;
}

Currently, Bar generates a "flat" representation. However, we should embed Foo using allOf into Bar.

Happy to work on a PR if you agree!

@Eywek
Copy link
Owner

Eywek commented Sep 9, 2021

Hello,

Yes, you can try to open a PR if you want

@derolf
Copy link
Contributor Author

derolf commented Sep 9, 2021

Working on it already, do you know how to use ts-morph to only get the own props of a node?

BTW. I think that ONLY interface should generate explicit schema objects, all other types should always be inlined.

Otherwise, you get a bunch of weird intermediate explicit schema types in the schema, like this:

        Patched__title-string--__:
            type: object
            properties:
                title:
                    type: string

which stems from Patched<{title: string}> with

export type Patched<T> = {
  [P in keyof T]?: T[P] extends Array<infer U> ? Array<Patched<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<Patched<U>> : Patched<T[P]>;
};

These make it hard to maintain a stable OpenAPI spec and the codegens and users downstream cry. (BTW I have handwritten codegens for openAPI -> TypeScript and openAPI -> Dart)

@Eywek
Copy link
Owner

Eywek commented Sep 10, 2021

do you know how to use ts-morph to only get the own props of a node?

Nope sorry, I think you'll need to dig into ts-morph to find the method

I think that ONLY interface should generate explicit schema objects, all other types should always be inlined

IMO interfaces & types (i.e. type Foo = { bar: string } or interface Foo { bar: string }) (not only interfaces since not everyone use interfaces) should generate explicit schema objects and mapped types should be always inlined

@Eywek
Copy link
Owner

Eywek commented Mar 28, 2022

Otherwise, you get a bunch of weird intermediate explicit schema types in the schema, like this:

should be better with bba5a24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants