autorest
autorest copied to clipboard
Support anyOf/oneOf
- Useful for ADL
- Some Swagger scenarios unlocked
@sarangan12 @xirzec Our swagger has not support anyOf/oneOf yet. Also, we need to think about how to support it in typescript SDK , for anyOf, we may use something like type C = A ! B, I wonder how to support oneOf in Typescript?
@sarangan12 @xirzec Our swagger has not support anyOf/oneOf yet. Also, we need to think about how to support it in typescript SDK , for anyOf, we may use something like type C = A ! B, I wonder how to support oneOf in Typescript?
oneOf
is tricky for TypeScript if the interfaces are compatible, e.g. {a: string}
and {b: number}
would be hard to do "oneOf" without having the expanded types be something like {a: string, b?: undefined}
and {a?: undefined, b: number}
-- I think in most cases we could just do the type union and not worry about the intersection case, especially if there is a discriminant property that is distinct in each.
Okay. I agree that we can make things simpler and no need to worry about the intersection case. cc @ramya-rao-a
Is there any update on support for this feature? Is there anything we as a community can contribute to help make this happen?
We have a number of APIs which we are modernising to .NET 6.0 & OpenAPI 3.x and migrating from Azure Functions to Azure Container Apps and we'd like to modernise the client SDK generation approach too - specifically .NET 6.0 SDK clients, but lack of anyOf
/ oneOf
support is a blocker for us.
I'm using npm tsoa to generate a swagger.json that contain anyOf if a property is string or number or boolean. There is a fallback to object that cause the TS client throws an exception while parsing the response. So I have to avoid any anyOf generation or the client doesn't work.
TS Client error:
modelProperties cannot be null or undefined in the mapper
swagger 3.0:
"value": { "anyOf": [ { "type": "string" }, { "type": "number", "format": "double" }, { "type": "boolean" } ], "nullable": true }
Are there plans for this to be picked up anytime soon? We're trying to generate a python SDK from this, and it uses anyOf
and unfortunately we have no way around it. The spec being used is OAI3 and throws this for many paths:
error | schema_violation | Schema violation: must be equal to one of the allowed values (paths > /api/v1/billing/skus > get > parameters > 1 > schema > anyOf > 1 > type)
allowedValues: array, boolean, integer, number, object, string
- http://localhost:8000/openapi.json:1:13608
Or is there a workaround in the meantime that I should be making use of? Cheers