swagger-codegen-ts icon indicating copy to clipboard operation
swagger-codegen-ts copied to clipboard

anyOf support

Open Geksanit opened this issue 6 months ago • 2 comments

I suggest adding support anyOf to codegen. the difference between anyOf and oneOf is discussed here: https://stackoverflow.com/a/56039838

Geksanit avatar Dec 28 '23 07:12 Geksanit

That SO answer might be incorrect about mixed element types in arrays.

It appears that the difference between oneOf/anyOf only affects the validation:

  • anyOf allows inputs that conform to multiple anyOf members;
  • oneOf requires that the input object matches exactly one union member. After a match is found, we should check that the input does not match any other options.

The generated type would be a union type in both cases.

In fact, we do not do this "exactly one" check, so our implementation of oneOf actually behaves like anyOf.

kokovtsev avatar Jan 09 '24 15:01 kokovtsev

@Geksanit please review some work-in-progress in #181, if you're ok with the approach I will apply the same to OpenAPI 2.0 and AsyncAPI

kokovtsev avatar Jan 10 '24 10:01 kokovtsev