Skip to content

Commit

Permalink
fixed examples openapi definition not being properly structured
Browse files Browse the repository at this point in the history
  • Loading branch information
Wicpar committed May 15, 2020
1 parent 5499cbb commit 9355457
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.papsign.ktor.openapigen.model.operation

import com.papsign.ktor.openapigen.model.DataModel
import com.papsign.ktor.openapigen.model.info.ExampleModel
import com.papsign.ktor.openapigen.model.schema.SchemaModel

data class HeaderModel<T>(
Expand All @@ -10,6 +11,6 @@ data class HeaderModel<T>(
var allowEmptyValue: Boolean? = null,
var schema: SchemaModel<T>? = null,
var example: T? = null,
var examples: MutableMap<String, T>? = null
var examples: MutableMap<String, ExampleModel<T>>? = null
// incomplete
): DataModel
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.papsign.ktor.openapigen.model.operation

import com.papsign.ktor.openapigen.model.DataModel
import com.papsign.ktor.openapigen.model.info.ExampleModel
import com.papsign.ktor.openapigen.model.schema.SchemaModel

data class MediaTypeModel<T>(
val schema: SchemaModel<T>? = null,
val example: T? = null,
val examples: MutableMap<String, T>? = null,
val examples: MutableMap<String, ExampleModel<T>>? = null,
val encoding: Map<String, MediaTypeEncodingModel>? = null
): DataModel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.papsign.ktor.openapigen.model.operation

import com.papsign.ktor.openapigen.model.DataModel
import com.papsign.ktor.openapigen.model.info.ExampleModel
import com.papsign.ktor.openapigen.model.schema.SchemaModel
import com.papsign.ktor.openapigen.parameters.ParameterStyle

Expand All @@ -13,7 +14,7 @@ data class ParameterModel<T>(
var allowEmptyValue: Boolean? = null,
var schema: SchemaModel<T>? = null,
var example: T? = null,
var examples: MutableMap<String, T>? = null,
var examples: MutableMap<String, ExampleModel<T>>? = null,
var style: ParameterStyle<*>? = null,
var explode: Boolean = false
// incomplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.papsign.ktor.openapigen.classLogger
import com.papsign.ktor.openapigen.content.type.ContentTypeProvider
import com.papsign.ktor.openapigen.content.type.ResponseSerializer
import com.papsign.ktor.openapigen.content.type.SelectedExceptionSerializer
import com.papsign.ktor.openapigen.model.info.ExampleModel
import com.papsign.ktor.openapigen.model.operation.MediaTypeModel
import com.papsign.ktor.openapigen.model.operation.OperationModel
import com.papsign.ktor.openapigen.model.operation.StatusResponseModel
Expand Down Expand Up @@ -35,9 +36,11 @@ object ThrowOperationHandler : OperationModule {
schemas.size == 1 -> schemas.first()
else -> SchemaModel.OneSchemaModelOf(schemas)
}
val examples = it.value.mapNotNull { (_, second) -> second.example }.withIndex().associate { (idx, value) -> "Example $idx" to value }.toMutableMap()
val examples = it.value.mapNotNull { (_, second) ->
second.example
}.withIndex().associate { (idx, value) -> "Example $idx" to ExampleModel(value) }.toMutableMap()
if (examples.size <= 1) {
MediaTypeModel(schema, example = examples.values.firstOrNull())
MediaTypeModel(schema, example = examples.values.firstOrNull()?.value)
} else {
MediaTypeModel(schema, examples = examples)
}
Expand Down

0 comments on commit 9355457

Please sign in to comment.