Skip to content

support nested any-of to use with openapi v3.1 type null#1683

Open
smarlhens wants to merge 1 commit intoferdikoomen:mainfrom
smarlhens:feat/support-nested-any-of
Open

support nested any-of to use with openapi v3.1 type null#1683
smarlhens wants to merge 1 commit intoferdikoomen:mainfrom
smarlhens:feat/support-nested-any-of

Conversation

@smarlhens
Copy link
Copy Markdown

Hi there 👋🏻

Thanks @ferdikoomen for your amazing job on this library 🙏🏻

I've tried my best to implement support for nested anyOf in order to use the type null rework on open api specification v3.1.

It seems related to #1643.

I remain at your disposal for any feedback on the implementation.

I wish you a great day ☀️

Best regards ☮️

@PaulVrugt
Copy link
Copy Markdown

I have a nested anyOf within an oneOf. Like:

"SomeDto": {
        "type": "object",
        "properties": {
          "value": {
            "oneOf": [
              {
                "type": "integer",
                "format": "int32"
              },
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "number"
                    }
                  ]
                }
              }
            ],
            "nullable": true
          }
        },
        "additionalProperties": false
      },

The generated api code seems to ignore the AnyOf, and generates the type as:

export type SomeDto = {
  value?: (number | string) | null;
};

instead of:

export type SomeDto = {
  value?: (number | string | Array<number | string>) | null;
};

does this PR also fix this issue?

@smarlhens
Copy link
Copy Markdown
Author

hey @PaulVrugt,

with this PR changes, it will generate:

export type SomeDto = {
    value?: (number | string | Array<(string | number)>) | null;
};

you can check on your machine if you want:

git clone [email protected]:smarlhens/openapi-typescript-codegen.git
git checkout feat/support-nested-any-of
npm install

then add at the end of components.schemas inside test/spec/v3.json:

"SomeDto": {
    "type": "object",
    "properties": {
        "value": {
            "oneOf": [
                {
                    "type": "integer",
                    "format": "int32"
                },
                {
                    "type": "string"
                },
                {
                    "type": "array",
                    "items": {
                        "anyOf": [
                            {
                                "type": "string"
                            },
                            {
                                "type": "number"
                            }
                        ]
                    }
                }
            ],
            "nullable": true
        }
    }
}

and then run

npm run test:update
git diff

you will see that inside test/__snapshots__/index.spec.ts.snap, in line to be added, the export type of SomeDto will be equal to the first snippet I wrote.

@PaulVrugt
Copy link
Copy Markdown

Hi @smarlhens ,

so the short answer is yes right? :)

@PaulVrugt
Copy link
Copy Markdown

@ferdikoomen can we get this merged? We are running into this in our code

@smarlhens
Copy link
Copy Markdown
Author

Hi @smarlhens ,

so the short answer is yes right? :)

Yes 👍🏻

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

Successfully merging this pull request may close these issues.

2 participants