Skip to content

Commit

Permalink
Fix inline generation bug #103 (#105)
Browse files Browse the repository at this point in the history
A bug was introduced somewhere that was causing top-level schema definitions to be generated as part of the inlined schema generation logic. This had resulted in complex polymorphic classes getting over-written with simpler inline-derived versions of those classes.
This PR simply removes the logic that generates referenced object definitions during inline generation. It relies on the fact that these schemas will undergo regular generation.
  • Loading branch information
cjbooms authored Mar 2, 2022
1 parent 4d695e4 commit b6cc274
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ info:
version: ""
components:
schemas:
Wrapper:
type: object
properties:
polymorph:
$ref: '#/components/schemas/PolymorphicEnumDiscriminator'
PolymorphicEnumDiscriminator:
type: object
discriminator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.Author",
"name" : "examples.githubApi.models.PullRequest",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.PullRequest",
"name" : "examples.githubApi.models.Author",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
Expand Down

0 comments on commit b6cc274

Please sign in to comment.