Repository: cjbooms/fabrikt (kotlin)

Issue:
sealed class generation breaks when referenced from another schema
It looks like polymorphic class generation breaks as soon as that class is referenced from another schema. Here's an example that adds a `Wrapper` schema to the yml from the readme:

```diff
openapi: 3.0.0
components:
  schemas:
+    Wrapper:
+      type: object
+      properties:
+        polymorph:
+          $ref: '#/components/schemas/PolymorphicEnumDiscriminator'
    PolymorphicEnumDiscriminator:
      type: object
      discriminator:
        propertyName: some_enum
        mapping:
          obj_one: '#/components/schemas/ConcreteImplOne'
          obj_two: '#/components/schemas/ConcreteImplTwo'
      properties:
        some_enum:
          $ref: '#/components/schemas/EnumDiscriminator'
    ConcreteImplOne:
      allOf:
        - $ref: '#/components/schemas/PolymorphicEnumDiscriminator'
        - type: object
          properties:
            some_prop:
              type: string
    ConcreteImplTwo:
      allOf:
        - $ref: '#/components/schemas/PolymorphicEnumDiscriminator'
        - type: object
          properties:
            some_prop:
              type: string
    EnumDiscriminator:
      type: string
      enum:
        - obj_one
        - obj_two
```

In the generated code, `PolymorphicEnumDiscriminator` is generated as a regular `class` and the subtypes are missing:

```kotlin
data class Wrapper(
  @param:JsonProperty("polymorph")
  @get:JsonProperty("polymorph")
  @get:Valid
  val polymorph: PolymorphicEnumDiscriminator? = null
)

class PolymorphicEnumDiscriminator() {
  @param:JsonProperty("some_enum")
  @get:JsonProperty("some_enum")
  @get:NotNull
  val someEnum: EnumDiscriminator
}

enum class EnumDiscriminator(
  @JsonValue
  val value: String
) {
  OBJ_ONE("obj_one"),

  OBJ_TWO("obj_two");

  companion object {
    private val mapping: Map<String, EnumDiscriminator> =
        values().associateBy(EnumDiscriminator::value)

    fun fromValue(value: String): EnumDiscriminator? = mapping[value]
  }
}
```

Pull request:
A bug was introduced that was causing top-level schema definitions to be generated as part of the inlined generation logic. This resulted in complex polymorphic classes getting over-written with simpler inline-derived versions.

This PR removes the logic that generates referenced schemas during inline generation. It relies on the fact that these schemas will undergo regular/full generation.

Closes #103

Patch:
diff --git a/src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt b/src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt
index c1fdb22f..f7885cb3 100644
--- a/src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt
+++ b/src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt
@@ -199,15 +199,7 @@ class JacksonModelGenerator(
                     val inlinedModels = buildInLinedModels(props, enclosingSchema, apiDocUrl)
                     inlinedModels + currentModel
                 }
-                is PropertyInfo.ObjectRefField ->
-                    when {
-                        it.schema.isReferenceObjectDefinition() ->
-                            it.schema.topLevelProperties(HTTP_SETTINGS, enclosingSchema).let { props ->
-                                buildInLinedModels(props, enclosingSchema, apiDocUrl) +
-                                    standardDataClass(it.schema.safeName().toModelClassName(), props)
-                            }
-                        else -> emptySet()
-                    }
+                is PropertyInfo.ObjectRefField -> emptySet() // Not an inlined definition, so do nothing
                 is PropertyInfo.MapField ->
                     buildMapModel(it)?.let { mapModel -> setOf(mapModel) } ?: emptySet()
                 is PropertyInfo.AdditionalProperties ->


Test patch:
diff --git a/src/test/resources/examples/enumPolymorphicDiscriminator/api.yaml b/src/test/resources/examples/enumPolymorphicDiscriminator/api.yaml
index b0f17ace..13caccc1 100644
--- a/src/test/resources/examples/enumPolymorphicDiscriminator/api.yaml
+++ b/src/test/resources/examples/enumPolymorphicDiscriminator/api.yaml
@@ -5,6 +5,11 @@ info:
   version: ""
 components:
   schemas:
+    Wrapper:
+      type: object
+      properties:
+        polymorph:
+          $ref: '#/components/schemas/PolymorphicEnumDiscriminator'
     PolymorphicEnumDiscriminator:
       type: object
       discriminator:
diff --git a/src/test/resources/examples/enumPolymorphicDiscriminator/models/Models.kt b/src/test/resources/examples/enumPolymorphicDiscriminator/models/Models.kt
index 9de083e2..86d3e406 100644
--- a/src/test/resources/examples/enumPolymorphicDiscriminator/models/Models.kt
+++ b/src/test/resources/examples/enumPolymorphicDiscriminator/models/Models.kt
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
 import com.fasterxml.jackson.annotation.JsonSubTypes
 import com.fasterxml.jackson.annotation.JsonTypeInfo
 import com.fasterxml.jackson.annotation.JsonValue
+import javax.validation.Valid
 import javax.validation.constraints.NotNull
 import kotlin.String
 import kotlin.collections.Map
@@ -81,3 +82,10 @@ enum class EnumDiscriminator(
 sealed class PolymorphicEnumDiscriminator() {
     abstract val someEnum: EnumDiscriminator
 }
+
+data class Wrapper(
+    @param:JsonProperty("polymorph")
+    @get:JsonProperty("polymorph")
+    @get:Valid
+    val polymorph: PolymorphicEnumDiscriminator? = null
+)
diff --git a/src/test/resources/examples/githubApi/resources/reflection-config.json b/src/test/resources/examples/githubApi/resources/reflection-config.json
index b9724b71..7bb53b63 100644
--- a/src/test/resources/examples/githubApi/resources/reflection-config.json
+++ b/src/test/resources/examples/githubApi/resources/reflection-config.json
@@ -135,7 +135,7 @@
   "allDeclaredFields" : true,
   "allPublicFields" : true
 }, {
-  "name" : "examples.githubApi.models.Author",
+  "name" : "examples.githubApi.models.PullRequest",
   "allDeclaredConstructors" : true,
   "allPublicConstructors" : true,
   "allDeclaredMethods" : true,
@@ -143,7 +143,7 @@
   "allDeclaredFields" : true,
   "allPublicFields" : true
 }, {
-  "name" : "examples.githubApi.models.PullRequest",
+  "name" : "examples.githubApi.models.Author",
   "allDeclaredConstructors" : true,
   "allPublicConstructors" : true,
   "allDeclaredMethods" : true,