Repository: cjbooms/fabrikt (kotlin)

Issue:
oneOf schema for additionalProperties throws exceptions
If you have an `additionalProperties` schema described as per below, there is a stack trace thrown during model generation.

```
additionalProperties:
  oneOf:
     - $ref: '#/component/schema/1'
     - $ref: '#/component/schema/2'
```


```
Exception in thread "main" java.lang.IllegalStateException: Unknown OAS type: object and format: null
        at ie.zalando.fabric.model.OasType$Companion.toOasType(OasType.kt:45)
        at ie.zalando.fabric.model.PolyglotTypeInfo$Companion.from(PolyglotTypeInfo.kt:60)
        at ie.zalando.fabric.model.PolyglotTypeInfo$Companion.from(PolyglotTypeInfo.kt:77)
        at ie.zalando.fabric.model.PolyglotTypeInfo$Companion.from(PolyglotTypeInfo.kt:77)
        at ie.zalando.fabric.model.PropertyInfo$MapField.<init>(PropertyInfo.kt:206)
        at ie.zalando.fabric.model.PropertyInfo$Companion.getInLinedProperties(PropertyInfo.kt:89)
        at ie.zalando.fabric.model.PropertyInfo$Companion.topLevelProperties(PropertyInfo.kt:68)
        at ie.zalando.fabric.model.PropertyInfo$Companion.topLevelProperties(PropertyInfo.kt:59)
        at ie.zalando.fabric.model.ModelInfo.<init>(ModelInfo.kt:57)
        at ie.zalando.fabric.model.ModelInfo.<init>(ModelInfo.kt:32)
        at ie.zalando.fabric.model.ModelInfo$Companion.modelInfosFromApi$fabric_generation_station(ModelInfo.kt:109)
        at ie.zalando.fabric.model.ApiSeed.<init>(ApiSeed.kt:39)
        at ie.zalando.fabric.model.ApiSeed$Companion.create(ApiSeed.kt:24)
        at ie.zalando.fabric.cli.CodeGen.generate(CodeGen.kt:41)
        at ie.zalando.fabric.cli.CodeGen.main(CodeGen.kt:22)
```

Pull request description:
Closes #22

Patch:
diff --git a/src/main/kotlin/com/cjbooms/fabrikt/model/OasType.kt b/src/main/kotlin/com/cjbooms/fabrikt/model/OasType.kt
index a93a8bb7..31ee591e 100644
--- a/src/main/kotlin/com/cjbooms/fabrikt/model/OasType.kt
+++ b/src/main/kotlin/com/cjbooms/fabrikt/model/OasType.kt
@@ -1,10 +1,10 @@
 package com.cjbooms.fabrikt.model
 
 import com.cjbooms.fabrikt.util.KaizenParserExtensions.isEnumDefinition
-import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleMapDefinition
-import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleOneOfAnyDefinition
 import com.cjbooms.fabrikt.util.KaizenParserExtensions.isMapTypeAdditionalProperties
 import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSchemaLess
+import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleMapDefinition
+import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleOneOfAnyDefinition
 import com.cjbooms.fabrikt.util.KaizenParserExtensions.isTypedAdditionalProperties
 import com.cjbooms.fabrikt.util.KaizenParserExtensions.isUnknownAdditionalProperties
 import com.cjbooms.fabrikt.util.KaizenParserExtensions.isUntypedAdditionalProperties
@@ -72,10 +72,10 @@ sealed class OasType(
                 isEnumDefinition() -> Specialization.ENUM
                 isMapTypeAdditionalProperties(oasKey) -> Specialization.TYPED_MAP_ADDITIONAL_PROPERTIES
                 isSimpleMapDefinition() -> Specialization.MAP
-                isSimpleOneOfAnyDefinition() -> Specialization.ONE_OF_ANY
                 isTypedAdditionalProperties(oasKey) -> Specialization.TYPED_OBJECT_ADDITIONAL_PROPERTIES
                 isUntypedAdditionalProperties(oasKey) -> Specialization.UNTYPED_OBJECT_ADDITIONAL_PROPERTIES
                 isUnknownAdditionalProperties(oasKey) -> Specialization.UNKNOWN_ADDITIONAL_PROPERTIES
+                isSimpleOneOfAnyDefinition() -> Specialization.ONE_OF_ANY
                 isSchemaLess() -> Specialization.UNTYPED_OBJECT
                 else -> Specialization.NONE
             }


Test patch:
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
index f242f52b..beaba7d3 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
@@ -50,6 +50,9 @@ class ModelGeneratorTest {
         MutableSettings.updateSettings(setOf(CodeGenerationType.HTTP_MODELS), emptySet(), emptySet(), emptySet())
     }
 
+    // @Test
+    // fun `debug single test`() = `correct models are generated for different OpenApi Specifications`("insert test case")
+
     @ParameterizedTest
     @MethodSource("testCases")
     fun `correct models are generated for different OpenApi Specifications`(testCaseName: String) {
diff --git a/src/test/resources/examples/anyOfOneOfAllOf/api.yaml b/src/test/resources/examples/anyOfOneOfAllOf/api.yaml
index 047b8206..bb7594ea 100644
--- a/src/test/resources/examples/anyOfOneOfAllOf/api.yaml
+++ b/src/test/resources/examples/anyOfOneOfAllOf/api.yaml
@@ -71,4 +71,14 @@ components:
           $ref: '#/components/schemas/AnyValue'
             
     AnyValue:
-      description: Tests support for https://swagger.io/docs/specification/data-models/data-types/#any
\ No newline at end of file
+      description: Tests support for https://swagger.io/docs/specification/data-models/data-types/#any
+      
+    OneOfAdditionalProps:
+      type: object
+      properties:
+        second_nested_any_of_prop:
+          type: string
+      additionalProperties:
+        oneOf:
+          - $ref: '#/components/schemas/FirstOneB'
+          - $ref: '#/components/schemas/SecondOneB'
\ No newline at end of file
diff --git a/src/test/resources/examples/anyOfOneOfAllOf/models/Models.kt b/src/test/resources/examples/anyOfOneOfAllOf/models/Models.kt
index 6ecb0d9d..248d9703 100644
--- a/src/test/resources/examples/anyOfOneOfAllOf/models/Models.kt
+++ b/src/test/resources/examples/anyOfOneOfAllOf/models/Models.kt
@@ -1,9 +1,14 @@
 package examples.anyOfOneOfAllOf.models
 
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonIgnore
 import com.fasterxml.jackson.annotation.JsonProperty
 import java.math.BigDecimal
 import kotlin.Any
 import kotlin.String
+import kotlin.collections.Map
+import kotlin.collections.MutableMap
 
 data class ComplexParent(
     @param:JsonProperty("oneOf")
@@ -59,6 +64,23 @@ data class MoreNesting(
     val moreNestedPropOne: String? = null
 )
 
+data class OneOfAdditionalProps(
+    @param:JsonProperty("second_nested_any_of_prop")
+    @get:JsonProperty("second_nested_any_of_prop")
+    val secondNestedAnyOfProp: String? = null
+) {
+    @get:JsonIgnore
+    val properties: MutableMap<String, Any> = mutableMapOf()
+
+    @JsonAnyGetter
+    fun get(): Map<String, Any> = properties
+
+    @JsonAnySetter
+    fun set(name: String, value: Any) {
+        properties[name] = value
+    }
+}
+
 data class SecondAnyA(
     @param:JsonProperty("second_nested_any_of_prop")
     @get:JsonProperty("second_nested_any_of_prop")