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
When a field is specified as being nullable using a oneOf, currently the java code (and I suppose some other languages too) that modelina generates contains an empty AnonymousSchema_ interface that is implemented by a single class.
The generated model would be more useable if that interface was dropped and usages replaced with the class.
Concretely, consider this example. The request here is that string2 and bar2 in this example would be treated the same as string1 and bar1, as they are both ways to express that a property is either null or has a value of a specific type.
asyncapi: 2.6.0
info:
title: union problem
version: "1"
defaultContentType: application/json
channels:
/lala:
publish:
message:
payload:
type: object
title: Foo
additionalProperties: false
properties:
# This generates a property of type String
string1:
type: [ "string", "null" ]
# This generates a property of type Object
string2:
oneOf:
- type: "null"
- type: string
# This generates a property of type Bar1
bar1:
type: ["object", "null"]
title: Bar1
additionalProperties: false
# This generates a property of type AnonymousSchema_*
bar2:
oneOf:
- type: "null"
- type: object
title: Bar2
additionalProperties: false
In this example there seems to be an easy workaround: just write your schema like string1 and bar1, not using oneOf. But that is not always an option, e.g. when the type is using a reference with $ref and the referenced type is not nullable in all contexts where it is used. (Or if you are a consumer of such an API, not in control of the schema).
How will this change help?
This would make generated classesmore useful: simpler, readable, avoiding casts in usage.
Screenshots
No response
How could it be implemented/designed?
I would guess in the same way as properties with types like type: [ "string", "null" ]; but I am not familiar with modelina internals.
Why do we need this improvement?
When a field is specified as being nullable using a oneOf, currently the java code (and I suppose some other languages too) that modelina generates contains an empty
AnonymousSchema_
interface that is implemented by a single class.The generated model would be more useable if that interface was dropped and usages replaced with the class.
Concretely, consider this example. The request here is that
string2
andbar2
in this example would be treated the same asstring1
andbar1
, as they are both ways to express that a property is either null or has a value of a specific type.In this example there seems to be an easy workaround: just write your schema like string1 and bar1, not using oneOf. But that is not always an option, e.g. when the type is using a reference with
$ref
and the referenced type is not nullable in all contexts where it is used. (Or if you are a consumer of such an API, not in control of the schema).How will this change help?
This would make generated classesmore useful: simpler, readable, avoiding casts in usage.
Screenshots
No response
How could it be implemented/designed?
I would guess in the same way as properties with types like
type: [ "string", "null" ]
; but I am not familiar with modelina internals.🚧 Breaking changes
No
👀 Have you checked for similar open issues?
🏢 Have you read the Contributing Guidelines?
Are you willing to work on this issue?
No, someone else can work on it.
The text was updated successfully, but these errors were encountered: