Skip to content

Commit

Permalink
[gen] verify issue #3077 is fixed (#3178)
Browse files Browse the repository at this point in the history
[gen] adding test that has previously would have failed - issue has been fixed in another commit

Co-authored-by: Nabil Abdel-Hafeez <[email protected]>
  • Loading branch information
hochgi and 987Nabil authored Sep 27, 2024
1 parent 15bcccc commit f74fd6d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zio-http-gen/src/test/resources/ComponentAliasKey.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package test.component

import zio.prelude.Newtype
import zio.schema.Schema
import java.util.UUID

object Key extends Newtype[UUID] {
implicit val schema: Schema[Key.Type] = Schema.primitive[UUID].transform(wrap, unwrap)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
info:
title: Dummy Service
version: 0.0.1
servers:
- url: http://127.0.0.1:5000/
tags:
- name: Dummy_API
paths:
/api/text_by_key:
get:
operationId: text_by_key
description: Get a dictionary mapping keys to text
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/ObjectWithDictionary'
description: OK
openapi: 3.0.3
components:
schemas:
Key:
type: string
format: uuid
ObjectWithDictionary:
type: object
required:
- dict
properties:
dict:
type: object
additionalProperties:
type: string
x-string-key-schema:
$ref: '#/components/schemas/Key'
23 changes: 23 additions & 0 deletions zio-http-gen/src/test/scala/zio/http/gen/scala/CodeGenSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,29 @@ object CodeGenSpec extends ZIOSpecDefault {
}
}
} @@ TestAspect.exceptScala3,
test("Schema with newtype only referenced as dictionary key") {
val openAPIString = stringFromResource("/inline_schema_alias_only_as_key_schema.yaml")

openApiFromYamlString(openAPIString) { oapi =>
codeGenFromOpenAPI(
oapi,
Config.default.copy(generateSafeTypeAliases = true),
) { testDir =>
allFilesShouldBe(
testDir.toFile,
List(
"api/Text_by_key.scala",
"component/Key.scala",
"component/ObjectWithDictionary.scala",
),
) && fileShouldBe(
testDir,
"component/Key.scala",
"/ComponentAliasKey.scala",
)
}
}
} @@ TestAspect.exceptScala3,
test("Generate all responses") {
val oapi =
OpenAPI(
Expand Down

0 comments on commit f74fd6d

Please sign in to comment.