-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gen] fix codegen to reference subtypes nested with their encapsulati…
…ng object when referenced directly (#2869) * [gen] add failing test * [gen] implement code to make basic test pass * [gen] make the test more generic, so it would capture more edge cases - which again makes it fail * [gen] implement the needed code to make the broader test to pass * [gen] add some documentation * restore @@ flaky * [gen] simplified code for better maintainability * [gen] scaladocs now have FQCN in referenced types * [gen] fix wrong doc
- Loading branch information
Showing
5 changed files
with
285 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
zio-http-gen/src/test/resources/ComponentAnimalWithFieldsReferencingSubs.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package test.component | ||
|
||
import zio.schema._ | ||
import zio.schema.annotation._ | ||
import zio.Chunk | ||
|
||
@noDiscriminator | ||
sealed trait Animal { | ||
def age: Int | ||
def weight: Float | ||
} | ||
object Animal { | ||
|
||
implicit val codec: Schema[Animal] = DeriveSchema.gen[Animal] | ||
case class Alligator( | ||
age: Int, | ||
weight: Float, | ||
num_teeth: Int, | ||
) extends Animal | ||
object Alligator { | ||
|
||
implicit val codec: Schema[Alligator] = DeriveSchema.gen[Alligator] | ||
|
||
} | ||
case class Zebra( | ||
age: Int, | ||
weight: Float, | ||
num_stripes: Int, | ||
dazzle: Chunk[Zebra], | ||
) extends Animal | ||
object Zebra { | ||
|
||
implicit val codec: Schema[Zebra] = DeriveSchema.gen[Zebra] | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package test.component | ||
|
||
import zio.schema._ | ||
|
||
case class Lion( | ||
eats: Animal.Zebra, | ||
enemy: Option[Animal.Alligator], | ||
) | ||
object Lion { | ||
|
||
implicit val codec: Schema[Lion] = DeriveSchema.gen[Lion] | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
zio-http-gen/src/test/resources/inline_schema_sumtype_with_subtype_referenced_directly.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
info: | ||
title: Animals Service | ||
version: 0.0.1 | ||
servers: | ||
- url: http://127.0.0.1:5000/ | ||
tags: | ||
- name: Animals_API | ||
paths: | ||
/api/v1/zoo/{animal}: | ||
get: | ||
operationId: get_animal | ||
parameters: | ||
- in: path | ||
name: animal | ||
schema: | ||
type: string | ||
required: true | ||
tags: | ||
- Animals_API | ||
description: Get animals by species name | ||
responses: | ||
"200": | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Animal' | ||
description: OK | ||
openapi: 3.0.3 | ||
components: | ||
schemas: | ||
Animal: | ||
oneOf: | ||
- $ref: '#/components/schemas/Alligator' | ||
- $ref: '#/components/schemas/Zebra' | ||
AnimalSharedFields: | ||
type: object | ||
required: | ||
- age | ||
- weight | ||
properties: | ||
age: | ||
type: integer | ||
format: int32 | ||
minimum: 0 | ||
weight: | ||
type: number | ||
format: float | ||
minimum: 0 | ||
Alligator: | ||
allOf: | ||
- $ref: '#/components/schemas/AnimalSharedFields' | ||
- type: object | ||
required: | ||
- num_teeth | ||
properties: | ||
num_teeth: | ||
type: integer | ||
format: int32 | ||
minimum: 0 | ||
Zebra: | ||
allOf: | ||
- $ref: '#/components/schemas/AnimalSharedFields' | ||
- type: object | ||
required: | ||
- num_stripes | ||
- dazzle | ||
properties: | ||
num_stripes: | ||
type: integer | ||
format: int32 | ||
minimum: 0 | ||
dazzle: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Zebra' | ||
Lion: | ||
type: object | ||
required: | ||
- eats | ||
properties: | ||
eats: | ||
$ref: '#/components/schemas/Zebra' | ||
enemy: | ||
$ref: '#/components/schemas/Alligator' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters