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

Optional properties are assigned inverse? #7

Closed
florianmartens opened this issue Aug 30, 2021 · 7 comments
Closed

Optional properties are assigned inverse? #7

florianmartens opened this issue Aug 30, 2021 · 7 comments

Comments

@florianmartens
Copy link
Contributor

florianmartens commented Aug 30, 2021

This is such a great library that saves me a ton of time. I'm super grateful it exists! I have a small issue as illustrated below:

profile.entitiy.ts

export class ProfileEntity implements Profile {
    @ApiProperty()
    id: string;

    @ApiProperty()
    createdAt: Date;

    @ApiProperty()
    updatedAt: Date;

    @ApiProperty({ required: false })
    address: string;

    @ApiProperty({ required: false })
    city: string;

    @ApiProperty({ required: false })
    countryCode: string;

    @ApiProperty({ required: false })
    phone: string;

    @ApiProperty({ required: false })
    twitterLink: string;

    @ApiProperty({ required: false })
    linkedInLink: string;

    @ApiProperty()
    userId: string;
}

Generated type

export type ProfileEntity = {
    id?: string;
    createdAt?: Date;
    updatedAt?: Date;
    address: string;
    city: string;
    countryCode: string;
    phone: string;
    twitterLink: string;
    linkedInLink: string;
    userId?: string;
};

It seems to be as if the optional ? is appended inverse to the way it should be {required: false} should result in the type being optional and vice versa.

This happens to all my types (the above is just an example).

@vmarchaud
Copy link
Collaborator

Which library are you using the translate the decorators in openapi definition ? Could you share the definition to be able to reproduce the issue ?

@florianmartens
Copy link
Contributor Author

florianmartens commented Aug 30, 2021

Of course. I'm using NestJS which includes the package @nestjs/swagger.

I created a gist with my swagger.json file here.

@vmarchaud
Copy link
Collaborator

Indeed this should be reversed from the openapi definition. Do you know if you have time to investigate this ?

@florianmartens
Copy link
Contributor Author

florianmartens commented Sep 1, 2021

I think that it would probably take me some time to figure out what's going in this project. If it's just a super quick fix like a missing inversion, the library creator or maintainer might be kind enough to quickly fix it.

Alternatively, I might find some time in the future to poke around in the code but can't make that commitment as of now.

@vmarchaud
Copy link
Collaborator

I was asking because i know that he's in holiday right now so if that was blocking/urgent, that may have been faster to make a PR direclty but no worries

Eywek added a commit that referenced this issue Sep 5, 2021
@Eywek
Copy link
Owner

Eywek commented Sep 5, 2021

Hello,

It should be fixed in the 1.0.0-alpha.20 version, can you confirm?

@florianmartens
Copy link
Contributor Author

Hey @Eywek , I can confirm that the fix works. Thank you!

@Eywek Eywek closed this as completed Sep 6, 2021
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

3 participants