diff --git a/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/BasicGenerator.scala b/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/BasicGenerator.scala index 1b9515f887..5b387bcd1f 100644 --- a/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/BasicGenerator.scala +++ b/openapi-codegen/core/src/main/scala/sttp/tapir/codegen/BasicGenerator.scala @@ -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, @@ -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") diff --git a/openapi-codegen/core/src/test/scala/sttp/tapir/codegen/ClassDefinitionGeneratorSpec.scala b/openapi-codegen/core/src/test/scala/sttp/tapir/codegen/ClassDefinitionGeneratorSpec.scala index 9686096361..27c37eea95 100644 --- a/openapi-codegen/core/src/test/scala/sttp/tapir/codegen/ClassDefinitionGeneratorSpec.scala +++ b/openapi-codegen/core/src/test/scala/sttp/tapir/codegen/ClassDefinitionGeneratorSpec.scala @@ -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, @@ -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( "",