You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Append Format property value to root schema when serializing as v2 if contained in anyOf, allOf, oneOf of child schemas #992
var schema = new OpenApiSchema();
if (context.Settings.IEEE754Compatible)
{
schema.OneOf = new List<OpenApiSchema>
{
new OpenApiSchema { Type = "number", Format = "decimal" },
new OpenApiSchema { Type = "string" },
};
}
The expected serialization for v2 should look like below:
changed the title [-]Remove `Format` property in the root schema when serializing primitive types as v3 if already contained in `anyOf`, `allOf``, `oneOf`[/-][+]Remove `Format` property in the root schema when serializing primitive types as v3 if already contained in `anyOf`, `allOf`, `oneOf`[/+]on Aug 31, 2022
Thanks for creating the issue here.
Before we proceed with a fix, I'd like to make sure we're on the same page on what to implement first.
I do think the backward compatible aspects with V2 should be the sole responsibility of this library and it should not push decisions on dependents for that aspect.
In different terms, I don't think that the OpenAPI.net.OData lib should have to set the format on the root schema "just in case we end up serializing to v2". But rather set things as they are expected to be in v3, and have this library handle the compatibility aspects.
When this library needs to serialize as v2, it should see a schema is a composition (one/any of) and take the first type and format it can find to use from them.
Does that make sense?
When reproducing the above issue using the following schema:
Age :
oneOf :
- type: number
format: decimal
- type: string
I've noticed that during V2 serialization, any OneOf/AnyOf schema objects are written out as an allOf with only the first schema in the list as an attempt to downgrade gracefully and the rest are completely ignored.
So the above schema would result to:
Ideally it wouldn't but since v2 doesn't support all/any of we need to make choices here. And the more important information is the fact that the client will get a int64 in the vast majority of cases, not a string, not an enum.
aaaah I didn't know we had that option. The issue I can see with that approach is that the allOf will have conflicting entries, and we'll end up generating an allOf schema that can never be satisfied (e.g. "must be a string" and "must be an integer")
changed the title [-]Remove `Format` property in the root schema when serializing primitive types as v3 if already contained in `anyOf`, `allOf`, `oneOf`[/-][+]Append `Format` property to root schema when serializing as v2 if contained in `anyOf`, `allOf`, `oneOf` of child schemas[/+]on Sep 7, 2022
changed the title [-]Append `Format` property to root schema when serializing as v2 if contained in `anyOf`, `allOf`, `oneOf` of child schemas[/-][+]Append `Format` property value to root schema when serializing as v2 if contained in `anyOf`, `allOf`, `oneOf` of child schemas[/+]on Sep 7, 2022
Activity
[-]Remove `Format` property in the root schema when serializing primitive types as v3 if already contained in `anyOf`, `allOf``, `oneOf`[/-][+]Remove `Format` property in the root schema when serializing primitive types as v3 if already contained in `anyOf`, `allOf`, `oneOf`[/+]baywet commentedon Aug 31, 2022
Thanks for creating the issue here.
Before we proceed with a fix, I'd like to make sure we're on the same page on what to implement first.
I do think the backward compatible aspects with V2 should be the sole responsibility of this library and it should not push decisions on dependents for that aspect.
In different terms, I don't think that the OpenAPI.net.OData lib should have to set the format on the root schema "just in case we end up serializing to v2". But rather set things as they are expected to be in v3, and have this library handle the compatibility aspects.
When this library needs to serialize as v2, it should see a schema is a composition (one/any of) and take the first type and format it can find to use from them.
Does that make sense?
MaggieKimani1 commentedon Sep 1, 2022
When reproducing the above issue using the following schema:
I've noticed that during V2 serialization, any
OneOf/AnyOfschema objects are written out as anallOfwith only the first schema in the list as an attempt to downgrade gracefully and the rest are completely ignored.So the above schema would result to:
with the
type : stringschema stripped out. Is this the intended behaviour Darrel (@darrelmiller), Vincent Biret (@baywet) and if so, why is that so?baywet commentedon Sep 1, 2022
I believe the first example in Irvine's initial post doesn't match the following ones and should instead have been
And sometimes we can even have something like
In both cases I do think that taking the first entry and ignoring the remaining when serializing to v2 should get us to the right place.
MaggieKimani1 commentedon Sep 1, 2022
Okay. I think I'm just curious why the rest of the schema components get ignored by design and what that achieves.
baywet commentedon Sep 1, 2022
Ideally it wouldn't but since v2 doesn't support all/any of we need to make choices here. And the more important information is the fact that the client will get a int64 in the vast majority of cases, not a string, not an enum.
irvinesunday commentedon Sep 1, 2022
v2 supports
allOf.Should
oneOfandanyOfbe collapsed intoallOfwhen serializing as v2 as is currently the case?baywet commentedon Sep 1, 2022
aaaah I didn't know we had that option. The issue I can see with that approach is that the allOf will have conflicting entries, and we'll end up generating an allOf schema that can never be satisfied (e.g. "must be a string" and "must be an integer")
[-]Remove `Format` property in the root schema when serializing primitive types as v3 if already contained in `anyOf`, `allOf`, `oneOf`[/-][+]Append `Format` property to root schema when serializing as v2 if contained in `anyOf`, `allOf`, `oneOf` of child schemas[/+][-]Append `Format` property to root schema when serializing as v2 if contained in `anyOf`, `allOf`, `oneOf` of child schemas[/-][+]Append `Format` property value to root schema when serializing as v2 if contained in `anyOf`, `allOf`, `oneOf` of child schemas[/+]