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

Upgrading from 1.0.0 to 1.1.0 causes "additionalProperties": false to be dropped. #1416

Closed
Jason3S opened this issue Sep 21, 2022 · 7 comments · Fixed by #1417
Closed

Upgrading from 1.0.0 to 1.1.0 causes "additionalProperties": false to be dropped. #1416

Jason3S opened this issue Sep 21, 2022 · 7 comments · Fixed by #1417
Labels

Comments

@Jason3S
Copy link
Contributor

Jason3S commented Sep 21, 2022

This is a preliminary report.

I'll investigate further to provide a simple repo case.

Using git bisect, the issue started with #1367

@Jason3S
Copy link
Contributor Author

Jason3S commented Sep 21, 2022

@daanboer,

I'll take a looks at the cause, but maybe you have an idea why additionalProperties gets dropped from some types.

@domoritz
Copy link
Member

Good catch. Thanks for looking into it. I can make a new release when we have a fix.

@domoritz domoritz added the bug label Sep 21, 2022
@daanboer
Copy link
Contributor

@Jason3S I am currently a bit short on time, but I can take a look if you provide a minimal example.

@Jason3S
Copy link
Contributor Author

Jason3S commented Sep 21, 2022

@daanboer,

I found the cause and have a quick fix. But, there might be some improvement.

Cause: Hidden types become NeverType and NeverType.additionalProperties is undefined by definition.

When combined with other types, additionalProperties bleeds into the final type:

if (
(other.additionalProperties || other.additionalProperties === undefined) &&
definition.additionalProperties == false
) {
delete definition.additionalProperties;
}

Possible fix:

        if (
            (other.additionalProperties || other.additionalProperties === undefined) &&
            definition.additionalProperties == false &&
            !(baseType instanceof NeverType)
        ) {
            delete definition.additionalProperties;
        }

But a better fix might be to make a HiddenType that extends NeverType and a HiddenTypeFormatter:

export class HiddenTypeFormatter implements SubTypeFormatter {
    public supportsType(type: HiddenType): boolean {
        return type instanceof HiddenType;
    }
    public getDefinition(type: HiddenType): Definition {
        return { not: {}, additionalProperties: false };
    }
    public getChildren(type: HiddenType): BaseType[] {
        return [];
    }
}

@daanboer
Copy link
Contributor

@Jason3S Nice find, personally I think it makes sense to introduce a HiddenType. However, I don't know whether it will need special casing in other regions of the code. Also, you can omit the not: {} in the return of getDefinition as additionalProperties is false anyway (and it just clutters the generated schema).

Jason3S added a commit to Jason3S/ts-json-schema-generator that referenced this issue Sep 21, 2022
fix: vega#1416

- Add HiddenType
- Add HiddenTypeFormatter
- Add test
Jason3S added a commit to Jason3S/ts-json-schema-generator that referenced this issue Sep 21, 2022
fix: vega#1416

- Add HiddenType
- Add HiddenTypeFormatter
- Add test
@Jason3S
Copy link
Contributor Author

Jason3S commented Sep 22, 2022

@domoritz,

Thank you for releasing 1.1.1.

@domoritz
Copy link
Member

Thanks for the fix

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

Successfully merging a pull request may close this issue.

3 participants