Skip to content

Commit

Permalink
Disable inline generation of full schema objects from array generation (
Browse files Browse the repository at this point in the history
#107)

* Sort client models in alphabetical order before comparing

* Removing inline generation of reference schema objects from the arrays sections.
  • Loading branch information
cjbooms authored Mar 3, 2022
1 parent b6cc274 commit dabaa46
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ class JacksonModelGenerator(
it.name.toModelClassName(enclosingModelName), props
)
}
items.isReferenceObjectDefinition() ->
items.topLevelProperties(HTTP_SETTINGS, enclosingSchema).let { props ->
buildInLinedModels(props, enclosingSchema, apiDocUrl) +
standardDataClass(items.safeName().toModelClassName(), props)
}
items.isEnumDefinition() ->
setOf(
buildEnumClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class OkHttpClientGeneratorTest {

@BeforeEach
fun init() {
MutableSettings.updateSettings(setOf(CodeGenerationType.CLIENT), setOf(ModelCodeGenOptionType.X_EXTENSIBLE_ENUMS), emptySet())
MutableSettings.updateSettings(
setOf(CodeGenerationType.CLIENT),
setOf(ModelCodeGenOptionType.X_EXTENSIBLE_ENUMS),
emptySet()
)
}

@ParameterizedTest
Expand Down Expand Up @@ -144,11 +148,13 @@ class OkHttpClientGeneratorTest {
private fun Models.toSingleFile(): String {
val destPackage = if (models.isNotEmpty()) models.first().destinationPackage else ""
val singleFileBuilder = FileSpec.builder(destPackage, "dummyFilename")
models.forEach {
val builder = singleFileBuilder
.addType(it.spec)
builder.build()
}
models
.sortedBy { it.spec.name }
.forEach {
val builder = singleFileBuilder
.addType(it.spec)
builder.build()
}
return Linter.lintString(singleFileBuilder.build().toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.ContributorStatus",
"name" : "examples.githubApi.models.OrganisationQueryResult",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.Contributor",
"name" : "examples.githubApi.models.RepositoryQueryResult",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.OrganisationQueryResult",
"name" : "examples.githubApi.models.PullRequestQueryResult",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.OrganisationStatus",
"name" : "examples.githubApi.models.Contributor",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.Webhook",
"name" : "examples.githubApi.models.ContributorStatus",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
Expand All @@ -87,39 +87,39 @@
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.RepositoryQueryResult",
"name" : "examples.githubApi.models.OrganisationStatus",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.RepositoryStatus",
"name" : "examples.githubApi.models.Repository",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.RepositoryVisibility",
"name" : "examples.githubApi.models.RepositoryStatus",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.Repository",
"name" : "examples.githubApi.models.RepositoryVisibility",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.PullRequestQueryResult",
"name" : "examples.githubApi.models.PullRequest",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
Expand All @@ -135,7 +135,7 @@
"allDeclaredFields" : true,
"allPublicFields" : true
}, {
"name" : "examples.githubApi.models.PullRequest",
"name" : "examples.githubApi.models.Webhook",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
Expand Down
46 changes: 23 additions & 23 deletions src/test/resources/examples/okHttpClient/models/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ import kotlin.String
import kotlin.collections.List
import kotlin.collections.Map

data class QueryResult(
@param:JsonProperty("items")
@get:JsonProperty("items")
@get:NotNull
@get:Size(min = 0)
@get:Valid
val items: List<Content>
)

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
Expand Down Expand Up @@ -52,37 +43,37 @@ sealed class Content(
abstract val modelType: ContentModelType
}

enum class ContentThirdAttr(
enum class ContentModelType(
@JsonValue
val value: String
) {
ENUM_TYPE_1("enum_type_1"),
FIRST_MODEL("first_model"),

ENUM_TYPE_2("enum_type_2");
SECOND_MODEL("second_model"),

THIRD_MODEL("third_model");

companion object {
private val mapping: Map<String, ContentThirdAttr> =
values().associateBy(ContentThirdAttr::value)
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)

fun fromValue(value: String): ContentThirdAttr? = mapping[value]
fun fromValue(value: String): ContentModelType? = mapping[value]
}
}

enum class ContentModelType(
enum class ContentThirdAttr(
@JsonValue
val value: String
) {
FIRST_MODEL("first_model"),

SECOND_MODEL("second_model"),
ENUM_TYPE_1("enum_type_1"),

THIRD_MODEL("third_model");
ENUM_TYPE_2("enum_type_2");

companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)
private val mapping: Map<String, ContentThirdAttr> =
values().associateBy(ContentThirdAttr::value)

fun fromValue(value: String): ContentModelType? = mapping[value]
fun fromValue(value: String): ContentThirdAttr? = mapping[value]
}
}

Expand Down Expand Up @@ -111,6 +102,15 @@ data class FirstModel(
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
}

data class QueryResult(
@param:JsonProperty("items")
@get:JsonProperty("items")
@get:NotNull
@get:Size(min = 0)
@get:Valid
val items: List<Content>
)

data class SecondModel(
@param:JsonProperty("id")
@get:JsonProperty("id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,6 @@ import kotlin.String
import kotlin.collections.List
import kotlin.collections.Map

enum class ContentType(
@JsonValue
val value: String
) {
APPLICATION_JSON("application/json"),

APPLICATION_VND_CUSTOM_MEDIA_JSON("application/vnd.custom.media+json");

companion object {
private val mapping: Map<String, ContentType> = values().associateBy(ContentType::value)

fun fromValue(value: String): ContentType? = mapping[value]
}
}

data class QueryResult(
@param:JsonProperty("items")
@get:JsonProperty("items")
@get:NotNull
@get:Size(min = 0)
@get:Valid
val items: List<Content>
)

data class OtherQueryResult(
@param:JsonProperty("items")
@get:JsonProperty("items")
@get:NotNull
@get:Size(min = 0)
@get:Valid
val items: List<AlternateResponseModel>
)

data class AlternateResponseModel(
@param:JsonProperty("extra_first_attr")
@get:JsonProperty("extra_first_attr")
Expand Down Expand Up @@ -85,6 +52,24 @@ sealed class Content(
abstract val modelType: ContentModelType
}

enum class ContentModelType(
@JsonValue
val value: String
) {
FIRST_MODEL("first_model"),

SECOND_MODEL("second_model"),

THIRD_MODEL("third_model");

companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)

fun fromValue(value: String): ContentModelType? = mapping[value]
}
}

enum class ContentThirdAttr(
@JsonValue
val value: String
Expand All @@ -101,21 +86,18 @@ enum class ContentThirdAttr(
}
}

enum class ContentModelType(
enum class ContentType(
@JsonValue
val value: String
) {
FIRST_MODEL("first_model"),

SECOND_MODEL("second_model"),
APPLICATION_JSON("application/json"),

THIRD_MODEL("third_model");
APPLICATION_VND_CUSTOM_MEDIA_JSON("application/vnd.custom.media+json");

companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)
private val mapping: Map<String, ContentType> = values().associateBy(ContentType::value)

fun fromValue(value: String): ContentModelType? = mapping[value]
fun fromValue(value: String): ContentType? = mapping[value]
}
}

Expand Down Expand Up @@ -144,6 +126,24 @@ data class FirstModel(
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
}

data class OtherQueryResult(
@param:JsonProperty("items")
@get:JsonProperty("items")
@get:NotNull
@get:Size(min = 0)
@get:Valid
val items: List<AlternateResponseModel>
)

data class QueryResult(
@param:JsonProperty("items")
@get:JsonProperty("items")
@get:NotNull
@get:Size(min = 0)
@get:Valid
val items: List<Content>
)

data class SecondModel(
@param:JsonProperty("id")
@get:JsonProperty("id")
Expand Down

0 comments on commit dabaa46

Please sign in to comment.