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

when use partial util type in exactOptionalProperty mode, undefinable property'sx-typia-required tag is incorrect. #831

Closed
rojiwon123 opened this issue Oct 3, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rojiwon123
Copy link
Contributor

rojiwon123 commented Oct 3, 2023

In v5.1.5,

when change undefinable property to optional property, x-typia-optional is not changed.

interface IOriginal {
    a?: string | null;
    b: undefined | string;
    c: string;
}

export interface IPartial extends Partial<IOriginal> {}
export interface IRequired extends Required<IPartial> {}

console.log(typia.json.application<[IOriginal, IPartial, IRequired]>().components.schemas);
{
    "IOriginal": {
        "type": "object",
        "properties": {
            "a": {
                "x-typia-required": true,
                "x-typia-optional": true,
                "type": "string",
                "nullable": true
            },
            "b": {
                // I guess, if `x-typia-required` is false, `b` is undefinable.
                "x-typia-required": false,
                "x-typia-optional": false,
                "type": "string"
            },
            "c": {
                "x-typia-required": true,
                "x-typia-optional": false,
                "type": "string"
            }
        },
        "nullable": false,
        "required": ["c"],
        "x-typia-jsDocTags": []
    },
    "IPartial": {
        "type": "object",
        "properties": {
            "a": {
                "x-typia-required": true,
                "x-typia-optional": true,
                "type": "string",
                "nullable": true
            },
            "b": {
                "x-typia-required": false,
                // I think, it is right that `x-typia-optional` is true.
                "x-typia-optional": false,
                "type": "string"
            },
            "c": {
                "x-typia-required": true,
                "x-typia-optional": true,
                "type": "string"
            }
        },
        "nullable": false,
        "x-typia-jsDocTags": []
    },
    "IRequired": {
        "type": "object",
        "properties": {
            "a": {
                "x-typia-required": true,
                "x-typia-optional": false,
                "type": "string",
                "nullable": true
            },
            "b": {
                "x-typia-required": false,
                "x-typia-optional": false,
                "type": "string"
            },
            "c": {
                "x-typia-required": true,
                "x-typia-optional": false,
                "type": "string"
            }
        },
        "nullable": false,
        "required": ["a", "c"],
        "x-typia-jsDocTags": []
    }
}

I guess x-typia-required mean definable property and x-typia-optional mean optional property.

@rojiwon123 rojiwon123 changed the title when use partial util type in exactOptionalProperty mode, undefindable property'sx-typia-required tag is incorrect. when use partial util type in exactOptionalProperty mode, undefinable property'sx-typia-required tag is incorrect. Oct 3, 2023
@samchon samchon self-assigned this Oct 4, 2023
@samchon samchon added the invalid This doesn't seem right label Oct 4, 2023
@samchon samchon closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@samchon
Copy link
Owner

samchon commented Oct 4, 2023

Next version v5.1.6 would be published soon.

@samchon samchon reopened this Oct 4, 2023
@samchon samchon added bug Something isn't working and removed invalid This doesn't seem right labels Oct 4, 2023
Repository owner deleted a comment from rojiwon123 Oct 4, 2023
@samchon
Copy link
Owner

samchon commented Oct 4, 2023

Additionally, as issues are being raised one by one, so patch versions are being released repeatedly.

Next time, please report it all at once \o/.

@rojiwon123
Copy link
Contributor Author

Additionally, as issues are being raised one by one, so patch versions are being released repeatedly.

Next time, please report it all at once \o/.

ok! i'm sorry and thank you :)

@rojiwon123
Copy link
Contributor Author

rojiwon123 commented Oct 4, 2023

Bug description

even if Partial or Required Util Type change property's optional feature, their typia tag x-typia-optional is not changed.

bug condition

  • tsconfig exactOptionalProperty mode
  • undefinable property
  • use Partial util type or Required util type (they change property's optional feature)

test case

export interface IQuery {
    required: string;
    nonRequired: string | undefined;
    optional?: string;
    none?: string | undefined;
}
export interface IPartialQuery extends Partial<IQuery> {}
export interface IRequiredQuery extends Required<IQuery> {}

const app = typia.json.application<[IQuery, IPartialQuery, IRequiredQuery]>();
const result1 = typia.assert<IJsonComponents.IObject>(
    app.components.schemas?.IQuery,
);
const result2 = typia.assert<IJsonComponents.IObject>(
    app.components.schemas?.IPartialQuery,
);
const result3 = typia.assert<IJsonComponents.IObject>(
    app.components.schemas?.IRequiredQuery,
);
console.log(
    "IQuery",
    Object.entries(result1.properties).map(([key, value]) => [
        key,
        value["x-typia-required"],
        value["x-typia-optional"],
    ]),
);
console.log(
    "IPartialQuery",
    Object.entries(result2.properties).map(([key, value]) => [
        key,
        value["x-typia-required"],
        value["x-typia-optional"],
    ]),
);
console.log(
    "IRequiredQuery",
    Object.entries(result3.properties).map(([key, value]) => [
        key,
        value["x-typia-required"],
        value["x-typia-optional"],
    ]),
);

expected

IQuery [
  [ 'required', true, false ],
  [ 'nonRequired', false, false ],
  [ 'optional', true, true ],
  [ 'none', false, true ]
]
IPartialQuery [
  [ 'required', true, true ],
  [ 'nonRequired', false, true ],
  [ 'optional', true, true ],
  [ 'none', false, true ]
]
IRequiredQuery [
  [ 'required', true, false ],
  [ 'nonRequired', false, false ],
  [ 'optional', true, false ],
  [ 'none', false, false ]
]

actual

IQuery [
  [ 'required', true, false ],
  [ 'nonRequired', false, false ],
  [ 'optional', true, true ],
  [ 'none', false, true ]
]
IPartialQuery [
  [ 'required', true, true ],
  [ 'nonRequired', false, `false` ],
  [ 'optional', true, true ],
  [ 'none', false, true ]
]
IRequiredQuery [
  [ 'required', true, false ],
  [ 'nonRequired', false, false ],
  [ 'optional', true, false ],
  [ 'none', false, `true` ]
]

`` is error result!

@rojiwon123
Copy link
Contributor Author

Additionally, as issues are being raised one by one, so patch versions are being released repeatedly.

Next time, please report it all at once \o/.

I apologize for providing short explanations that led to you performing repetitive tasks.
above comment is detail description of my bug report

@samchon samchon added the help wanted Extra attention is needed label Oct 4, 2023
@samchon samchon added enhancement New feature or request and removed bug Something isn't working labels Oct 5, 2023
@samchon samchon closed this as completed in cc0ca9a Oct 5, 2023
samchon added a commit that referenced this issue Oct 5, 2023
Fix #831 - exact optional type analyzing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants