Skip to content

Commit

Permalink
3234: use oneOf instead of inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
eanea committed Oct 11, 2023
1 parent 2b34395 commit 3a39268
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ private[schema] class TSchemaToASchema(toSchemaReference: ToSchemaReference, mar
case TSchemaType.SArray(nested @ TSchema(_, Some(name), _, _, _, _, _, _, _, _, _)) =>
ASchema(SchemaType.Array).copy(items = Some(toSchemaReference.map(nested, name)))
case TSchemaType.SArray(el) => ASchema(SchemaType.Array).copy(items = Some(apply(el)))
case TSchemaType.SOption(nested @ TSchema(_, Some(name), _, _, _, _, _, _, _, _, _)) if !markOptionsAsNullable =>
toSchemaReference.map(nested, name)
case TSchemaType.SOption(nested @ TSchema(_, Some(name), _, _, _, _, _, _, _, _, _)) => {
val ref = toSchemaReference.map(nested, name)
if (!markOptionsAsNullable) ref
else
ASchema.oneOf(List(ref), ref.discriminator).copy(nullable = Some(true))
}
case TSchemaType.SOption(el) => apply(el, isOptionElement = true)
case TSchemaType.SBinary() => ASchema(SchemaType.String).copy(format = SchemaFormat.Binary)
case TSchemaType.SDate() => ASchema(SchemaType.String).copy(format = SchemaFormat.Date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ components:
- requiredStringField
type: object
properties:
optionalObjField:
required:
- bar
type:
- object
- 'null'
properties:
bar:
type: integer
format: int32
optionalClassField:
oneOf:
- $ref: '#/components/schemas/Bar'
- type: 'null'
requiredStringField:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ 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") {
test("should mark optional class fields as nullable when configured to do so") {
case class Bar(bar: Int)
case class ClassWithOptionClassField(optionalObjField: Option[Bar], requiredStringField: String)

Expand Down

0 comments on commit 3a39268

Please sign in to comment.