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

anyOf combining literals and objects generates incorrect code #2034

Open
danikenan opened this issue Feb 12, 2024 · 6 comments
Open

anyOf combining literals and objects generates incorrect code #2034

danikenan opened this issue Feb 12, 2024 · 6 comments
Assignees

Comments

@danikenan
Copy link

The following schema

"schedule": {
    "anyOf": [
      {
        "const": "manual"
      },
      {
        "$ref": "#/components/schemas/SimpleSchedule"
      },
      {
        "$ref": "#/components/schemas/CronSchedule"
      }
    ],
    "title": "Schedule"
},

produces the following:

schedule: (SimpleSchedule | CronSchedule);
@mrlubos
Copy link
Collaborator

mrlubos commented Feb 13, 2024

@danikenan what is the type you'd expect?

@mrlubos
Copy link
Collaborator

mrlubos commented Feb 20, 2024

@danikenan we just merged a fix for similar issue in our fork, mind having a look if it fixes your problem too?

@kevinand11
Copy link

@mrlubos Doesnt resolve it. The issue is that the tool resolves { "const": "manual" } to any instead of "manual"

@mrlubos
Copy link
Collaborator

mrlubos commented Feb 28, 2024

@mrlubos Doesnt resolve it. The issue is that the tool resolves `{

"const": "manual"

}toanyinstead of"manual"`

@kevinand11 I'll try to fix it this weekend

@mrlubos
Copy link
Collaborator

mrlubos commented Feb 29, 2024

@kevinand11 Please open a pull request with failing test case against our fork. The following spec

"AnyOfConst": {
    "anyOf": [
        {
            "const": "foo"
        },
        {
            "$ref": "#/components/schemas/ModelWithString"
        },
        {
            "$ref": "#/components/schemas/ModelWithArray"
        }
    ]
}

generates the following model

export type AnyOfConst = ("foo" | ModelWithString | ModelWithArray);

so I think this works as expected.

@mrlubos
Copy link
Collaborator

mrlubos commented Feb 29, 2024

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