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

0.44.0 intersection types regression #387

Open
laat opened this issue Nov 25, 2020 · 8 comments
Open

0.44.0 intersection types regression #387

laat opened this issue Nov 25, 2020 · 8 comments

Comments

@laat
Copy link
Contributor

laat commented Nov 25, 2020

types.ts given these types:

export interface Links {
    readonly self: HrefLink;
    readonly myLink: HrefLink & TemplatedLink;
}
export interface HrefLink {
  readonly href: string;
}
export interface TemplatedLink {
  readonly templated: true;
}

program.ts and a program that generates the schema:

import path from 'path';
import util from 'util'
import * as TJS from 'typescript-json-schema';

const program = TJS.getProgramFromFiles([path.join(__dirname, "types.ts")]);
const schema = TJS.generateSchema(program, "Links", {
  noExtraProps: true, // important
});

console.log(util.inspect(schema, { depth: Infinity }));

0.43.0 gives the expected intersection:

{
  type: 'object',
  properties: {
    self: { '$ref': '#/definitions/HrefLink' },
    myLink: {
      additionalProperties: false,
      type: 'object',
      properties: {
        href: { type: 'string' },
        templated: { type: 'boolean', enum: [ true ] }
      }
    }
  },
  additionalProperties: false,
  definitions: {
    HrefLink: {
      type: 'object',
      properties: { href: { type: 'string' } },
      additionalProperties: false
    }
  },
  '$schema': 'http://json-schema.org/draft-07/schema#'
}

0.44.0 HrefLink properties is missing in myLink:

{
  type: 'object',
  properties: {
    self: { '$ref': '#/definitions/HrefLink' },
    myLink: {
      additionalProperties: false,
      type: 'object',
      properties: { templated: { type: 'boolean', enum: [ true ] } }
    }
  },
  additionalProperties: false,
  definitions: {
    HrefLink: {
      type: 'object',
      properties: { href: { type: 'string' } },
      additionalProperties: false
    }
  },
  '$schema': 'http://json-schema.org/draft-07/schema#'
}
@domoritz
Copy link
Collaborator

Could that be coming from #383? cc @darkowic

@darkowic
Copy link
Contributor

Not sure... But we do have a similar test here https://github.com/YousefED/typescript-json-schema/blob/master/test/programs/type-intersection/main.ts and everything is passing on CI.

@laat
Copy link
Contributor Author

laat commented Nov 26, 2020

I bisected the commits, and it was introduced in b69cd3c

@darkowic
Copy link
Contributor

Can you improve the test scenarios and try to handle it? I did in this comment my best but if something was not covered then it is hard to be safe... Maybe I will have time at the weekend to look at it...

@laat
Copy link
Contributor Author

laat commented Nov 26, 2020

It's very understandable that it happens when it's not covered by tests, this just happens from time to time. Nobody blames you :)

I can create a PR with a test-case that should pass, but I'm afraid that I'm not familiar enough with the guts of this package to fix it.

@laat
Copy link
Contributor Author

laat commented Nov 26, 2020

@darkowic I have added a test that fails in #388.

I have verified that this test passed before b69cd3c.

I'm sorry that I cannot be of more help.

@domoritz
Copy link
Collaborator

Thank you for debugging, providing a test case, and helping to fix the issue both of you!

@dmitry-urenev
Copy link

Hey guys, do you know if there is any progress with this issue?

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

4 participants