Skip to content

Commit

Permalink
Only set genTypes default if query params is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrikandersen committed Jan 13, 2025
1 parent ba65c85 commit 35bd3e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 9 additions & 0 deletions playground/src/main/kotlin/PlaygroundApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ fun main() {
get("/") {
val generationSettings = call.queryParameters.receiveGenerationSettings()
.copy(inputSpec = sampleOpenApiSpec) // set the sample spec
.run {
// if no settings in query params we configure default
// to ensure something is generated with just the sample spec
if (call.queryParameters.isEmpty()) {
copy(genTypes = setOf(CodeGenerationType.HTTP_MODELS))
} else {
this
}
}

call.respondHtml {
mainLayout {
Expand Down
8 changes: 2 additions & 6 deletions playground/src/main/kotlin/lib/GenerationSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ data class GenerationSettings(
* Can be used for both query and form parameters.
*/
fun Parameters.receiveGenerationSettings() = GenerationSettings(
genTypes = this.getAll("genTypes")?.map { CodeGenerationType.valueOf(it) }?.toSet() ?: setOf(
CodeGenerationType.HTTP_MODELS
),
genTypes = this.getAll("genTypes")?.map { CodeGenerationType.valueOf(it) }?.toSet() ?: emptySet(),

serializationLibrary = this["serializationLibrary"]?.let { SerializationLibrary.valueOf(it) }
?: SerializationLibrary.default,

modelOptions = this.getAll("modelOptions")?.map { ModelCodeGenOptionType.valueOf(it) }?.toSet() ?: setOf(
ModelCodeGenOptionType.SEALED_INTERFACES_FOR_ONE_OF
),
modelOptions = this.getAll("modelOptions")?.map { ModelCodeGenOptionType.valueOf(it) }?.toSet() ?: emptySet(),

controllerTarget = this["controllerTarget"]?.let { ControllerCodeGenTargetType.valueOf(it) }
?: ControllerCodeGenTargetType.default,
Expand Down

0 comments on commit 35bd3e8

Please sign in to comment.