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
attention_line:
oneOf:
- type: 'null'
- type: stringtitle: Attention linedescription: The person or department for who the letter is intended.examples:
- Procurement departmentmaxLength: 300minLength: 1external_reference:
oneOf:
- type: 'null'
- $ref: '#/components/schemas/external_reference'external_updated_at:
type:
- string
- 'null'format: date-time
As you can see, for the DateTime known format it does not need to use oneOf.
This is my prefered format for nullable fields, e.g. it generates type: [ string, 'null' ] and then the format is outside that list.
AttentionLine and ExternalReference are both just some string newtype with extra requirements on the string length.
Independent of whether these get inlined or not, they generate use of oneOf instead of the nice type: [ string, 'null' ].
Would it be possible to always generate type: [ string, 'null' ] instead of oneOf, or at least when the type is inlined?
The text was updated successfully, but these errors were encountered:
Would it be possible to always generate type: [ string, 'null' ] instead of oneOf, or at least when the type is inlined?
If the type is known to be a primitive type, it gets the type as type: [ type, 'null' ] but as of now when ToSchema macro executes for Dummy it does not know what the actual type is when it sees field attention_line: Option<AttentionLine> or external_reference: Option<ExternalReference>. This is also why it treats it as a generic type and creates a oneOf composition type to describe a nullable type.
Perhaps there are ways to make it smarter but that requires more effort from the schema generation and it is not super simple. This would need some experimenting around possibilities and mean time let the thought age well.
This looks like a cool project! I have one question about the generated yaml with nullable fields:
This struct has three nullable fields:
It generates openapi yaml that looks like this:
As you can see, for the
DateTime
known format it does not need to useoneOf
.This is my prefered format for nullable fields, e.g. it generates
type: [ string, 'null' ]
and then theformat
is outside that list.AttentionLine
andExternalReference
are both just some string newtype with extra requirements on the string length.Independent of whether these get inlined or not, they generate use of
oneOf
instead of the nicetype: [ string, 'null' ]
.Would it be possible to always generate
type: [ string, 'null' ]
instead ofoneOf
, or at least when the type is inlined?The text was updated successfully, but these errors were encountered: