-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3234: use markOptionsAsNullable for Option reference types #3235
3234: use markOptionsAsNullable for Option reference types #3235
Conversation
Could you maybe add a test? tapir/docs/openapi-docs/src/test/scalajvm/sttp/tapir/docs/openapi/VerifyYamlTest.scala Line 656 in 68e643f
|
done :) |
@@ -666,6 +666,20 @@ class VerifyYamlTest extends AnyFunSuite with Matchers { | |||
actualYamlNoIndent shouldBe expectedYaml | |||
} | |||
|
|||
test("should mark optional class fields as nullable by inlining them when configured to do so") { | |||
case class Bar(bar: Int) | |||
case class ClassWithOptionClassField(optionalIntField: Option[Bar], requiredStringField: String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: optionalObjField
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah :) fixed it
209e1eb
to
2b34395
Compare
type: object | ||
properties: | ||
optionalObjField: | ||
required: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by inlining the schema we end up with an unused Bar
component. Maybe it would be better to generate a one of, e.g.:
ClassWithOptionClassField:
required:
- requiredStringField
type: object
properties:
optionalObjField:
oneOf:
- type: 'null'
- $ref: '#/components/schemas/Bar'
requiredStringField:
type: string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'll require changes in the sttp-apispec
for all encoders.
I could do it for the circe
integration only. will it be acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- PR for
sttp-apispec
circe is ready support nullable for anyOf & oneOf sttp-apispec#118 - updated current PR to generete
oneOf
instead of inlining
5a7a72e
to
3a39268
Compare
optionalClassField: | ||
oneOf: | ||
- $ref: '#/components/schemas/Bar' | ||
- type: 'null' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- type: 'null'
requires to merge & use softwaremill/sttp-apispec#118
val ref = toSchemaReference.map(nested, name) | ||
if (!markOptionsAsNullable) ref | ||
else | ||
ASchema.oneOf(List(ref), ref.discriminator).copy(nullable = Some(true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe doing here simply ASchema.oneOf(List(ref, ASchema(SchemaType.Null), None)
would work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this change, let's see if things work :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great! thank you :)
what else is needed to merge the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing, tests pass :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
fixes #3234
markOptionsAsNullable = true