Allow more attributes for "Reference Object" #4235
Replies: 4 comments 12 replies
-
To make a schema reference nullable in OpenAPI 3.1, use this prop:
anyOf:
- type: 'null'
- $ref: '#/components/schemas/MyObject' |
Beta Was this translation helpful? Give feedback.
-
Let me put the request in different words:
to:
So, while I define a complex object in Schema, I can define its default, examples, readOnly, writeOnly, or if it is nullable in its usage. Same as I’m happy to do with the summary and description. |
Beta Was this translation helpful? Give feedback.
-
@Amit-XMPie in OAS 3.1 the Schema Object In OAS 3.0, For modeling inheritance, JSON Schema is a constraint system, which requires a different mindset from a data definition system- you have to start with the least constrained schema as your re-usable base, and layer on more constraints. You cannot lift a constraint once added. Beyond that, OpenAPI and JSON Schema are separate projects, and requests for changes to JSON Schema should be directed to that project. I don't see anything for the OpenAPI project to do here. |
Beta Was this translation helpful? Give feedback.
-
I will assume that the issue is with the Microsoft Visual Studio OAS consumer (code generator), and not with the OAS definition, as when I add back the "nullable", even though it is marked as OAS 3.1.1, it is working as expected. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm adopting OAS 3.1.1 now (creation), and I'm pleased that for "Reference Object" you added overriding the "summary" and "description", but this is not enough, as other attributes should also be overridden, like readOnly, writeOnly, etc.
actually, the fact you removed the attribute "nullable" (in favor of the type "null"), is not good, as I like to override this in the "Reference Object" as well.
let me explain why:
while I'd like to define a complex type only once when I use it as a reference for example as a parameter to a method (path), I'd like to say that in this case, it can be "null", or "readOnly", or "writeOnly", but it is not in general "null", "readOnly" or "writeOnly", exactly as now I can have a different "description".
BTW: The same goes for the default value, example(s), which can be different depending on the usage and not related to the type itself (especially the default, where depending on its usage it can be different, like in enum types).
another remark:
I used to simulate it by "inheriting", i.e. creating a new schema, with "allOf" as the "Reference Object", and adding all properties that I like to override without specifying the actual schema (as it is inherited by "allOf"), but now that "nullable" is a type. I can't do this trick anymore, as I can't override the type (there is no sense overriding type when "inheriting").
furthermore, this trick does not work anymore for enum types (yet another "complex" schema that should not be defined several times, as it causes other issues).
please please consider this request, as it is absolutely useful, and it makes version 3.0.x + my trick better that 3.1.x
Beta Was this translation helpful? Give feedback.
All reactions