-
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] map common abstract fields in trait (oneOf enum) to have (un)al…
…iasing translation of types (#3089)
- Loading branch information
Showing
6 changed files
with
255 additions
and
21 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
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,8 @@ | ||
package test.component | ||
|
||
import zio.prelude.Newtype | ||
import zio.schema.Schema | ||
|
||
object Weight extends Newtype[Float] { | ||
implicit val schema: Schema[Weight.Type] = Schema.primitive[Float].transform(wrap, unwrap) | ||
} |
30 changes: 30 additions & 0 deletions
30
zio-http-gen/src/test/resources/ComponentAnimalWithAbstractAliasedMembers.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,30 @@ | ||
package test.component | ||
|
||
import zio.schema._ | ||
import zio.schema.annotation._ | ||
|
||
@noDiscriminator | ||
sealed trait Animal { | ||
def age: Age.Type | ||
def weight: Weight.Type | ||
} | ||
object Animal { | ||
|
||
implicit val codec: Schema[Animal] = DeriveSchema.gen[Animal] | ||
case class Alligator( | ||
age: Age.Type, | ||
weight: Weight.Type, | ||
num_teeth: Int, | ||
) extends Animal | ||
object Alligator { | ||
implicit val codec: Schema[Alligator] = DeriveSchema.gen[Alligator] | ||
} | ||
case class Zebra( | ||
age: Age.Type, | ||
weight: Weight.Type, | ||
num_stripes: Int, | ||
) extends Animal | ||
object Zebra { | ||
implicit val codec: Schema[Zebra] = DeriveSchema.gen[Zebra] | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
zio-http-gen/src/test/resources/ComponentAnimalWithAbstractUnAliasedMembers.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,30 @@ | ||
package test.component | ||
|
||
import zio.schema._ | ||
import zio.schema.annotation._ | ||
|
||
@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, | ||
) extends Animal | ||
object Zebra { | ||
implicit val codec: Schema[Zebra] = DeriveSchema.gen[Zebra] | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
zio-http-gen/src/test/resources/inline_schema_sumtype_with_reusable_aliased_fields.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,81 @@ | ||
info: | ||
title: Animals Service | ||
version: 0.0.1 | ||
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 | ||
"500": | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/HttpError' | ||
description: Internal Server Error | ||
openapi: 3.0.3 | ||
components: | ||
schemas: | ||
Age: | ||
type: integer | ||
format: int32 | ||
Weight: | ||
type: number | ||
format: float | ||
Animal: | ||
oneOf: | ||
- $ref: '#/components/schemas/Alligator' | ||
- $ref: '#/components/schemas/Zebra' | ||
AnimalSharedFields: | ||
type: object | ||
required: | ||
- age | ||
- weight | ||
properties: | ||
age: | ||
$ref: '#/components/schemas/Age' | ||
weight: | ||
$ref: '#/components/schemas/Weight' | ||
Alligator: | ||
allOf: | ||
- $ref: '#/components/schemas/AnimalSharedFields' | ||
- type: object | ||
required: | ||
- num_teeth | ||
properties: | ||
num_teeth: | ||
type: integer | ||
format: int32 | ||
Zebra: | ||
allOf: | ||
- $ref: '#/components/schemas/AnimalSharedFields' | ||
- type: object | ||
required: | ||
- num_stripes | ||
properties: | ||
num_stripes: | ||
type: integer | ||
format: int32 | ||
HttpError: | ||
type: object | ||
properties: | ||
messages: | ||
type: string |
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