Skip to content

Commit

Permalink
Add support for any type
Browse files Browse the repository at this point in the history
  • Loading branch information
markussammallahti committed Nov 12, 2023
1 parent 34754a5 commit b3d9b58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sttp.tapir.codegen

import sttp.tapir.codegen.openapi.models.OpenapiModels.OpenapiDocument
import sttp.tapir.codegen.openapi.models.OpenapiSchemaType.{
OpenapiSchemaAny,
OpenapiSchemaBoolean,
OpenapiSchemaDouble,
OpenapiSchemaEnum,
Expand Down Expand Up @@ -66,6 +67,8 @@ object BasicGenerator {
("String", nb)
case OpenapiSchemaBoolean(nb) =>
("Boolean", nb)
case OpenapiSchemaAny(nb) =>
("io.circe.Json", nb)
case OpenapiSchemaRef(t) =>
(t.split('/').last, false)
case x => throw new NotImplementedError(s"Not all simple types supported! Found $x")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sttp.tapir.codegen
import sttp.tapir.codegen.openapi.models.OpenapiComponent
import sttp.tapir.codegen.openapi.models.OpenapiModels.OpenapiDocument
import sttp.tapir.codegen.openapi.models.OpenapiSchemaType.{
OpenapiSchemaAny,
OpenapiSchemaArray,
OpenapiSchemaConstantString,
OpenapiSchemaEnum,
Expand Down Expand Up @@ -108,6 +109,23 @@ class ClassDefinitionGeneratorSpec extends CompileCheckTestBase {
new ClassDefinitionGenerator().classDefs(doc).get shouldCompile ()
}

it should "generate class with any type" in {
val doc = OpenapiDocument(
"",
null,
null,
Some(
OpenapiComponent(
Map(
"Test" -> OpenapiSchemaObject(Map("anyType" -> OpenapiSchemaAny(false)), Seq("anyType"), false)
)
)
)
)

new ClassDefinitionGenerator().classDefs(doc).get shouldCompile ()
}

it should "generate class with inner class" in {
val doc = OpenapiDocument(
"",
Expand Down

0 comments on commit b3d9b58

Please sign in to comment.