guardrail-dev / guardrail-dev/guardrail
Traits with discriminator are not sealed
- Dominant language
- Scala
- Stars
- 541
- Forks
- 138
- PR merge metrics
- No merged PRs in 30d
Description
Hello !
When using the following schema :
```yaml
Strategy:
required:
- type
discriminator: type
properties:
type:
type: string
SomeStrategy:
allOf:
- $ref: '#/definitions/Strategy'
- required:
- type
- description
properties:
type:
type: string
enum:
- SomeStrategy
description:
type: string
AnotherStrategy:
allOf:
- $ref: '#/definitions/Strategy'
- required:
- type
- description
properties:
type:
type: string
enum:
- AnotherStrategy
description:
type: string
```
I get the generated code :
```scala
trait Strategy
object Strategy {
val discriminator: String = "type"
implicit val encoder: Encoder[Strategy] = Encoder.instance({
case e: SomeStrategy =>
e.asJsonObject.add(discriminator, "SomeStrategy".asJson).asJson
case e: AnotherStrategy =>
e.asJsonObject.add(discriminator, "AnotherStrategy".asJson).asJson
})
```
which is incorrect, the trait should be sealed or the pattern matching should include
`case _ => `
Contributor guide
Assessment
This issue has not been assessed yet.