response for status

This commit is contained in:
Ryan
2021-04-11 13:53:56 -04:00
parent 6e1cdfe7c5
commit 277f3197e4
6 changed files with 88 additions and 26 deletions

View File

@ -2,7 +2,7 @@ package org.leafygreens.kompendium.models
// TODO Oof -> https://swagger.io/specification/#media-type-object // TODO Oof -> https://swagger.io/specification/#media-type-object
data class OpenApiSpecMediaType( data class OpenApiSpecMediaType(
val schema: OpenApiSpecReferencable, // TODO sheesh -> https://swagger.io/specification/#schema-object needs to be referencable val schema: OpenApiSpecSchema, // TODO sheesh -> https://swagger.io/specification/#schema-object
val example: String? = null, // TODO Enforce type? then serialize? val example: String? = null, // TODO Enforce type? then serialize?
val examples: Map<String, String>? = null, // needs to be mutually exclusive with example val examples: Map<String, String>? = null, // needs to be mutually exclusive with example
val encoding: Map<String, String>? = null // todo encoding object -> https://swagger.io/specification/#encoding-object val encoding: Map<String, String>? = null // todo encoding object -> https://swagger.io/specification/#encoding-object

View File

@ -1,14 +0,0 @@
package org.leafygreens.kompendium.models
sealed class OpenApiSpecParameterSchema(
val type: String,
)
data class OpenApiSpecParameterSchemaArray<T: OpenApiSpecParameterSchema >(
val items: T
) : OpenApiSpecParameterSchema("array")
data class OpenApiSpecParameterSchemaString(
val default: String,
val `enum`: Set<String>? = null
) : OpenApiSpecParameterSchema("string")

View File

@ -30,7 +30,7 @@ data class OpenApiSpecParameter(
val allowEmptyValue: Boolean = false, val allowEmptyValue: Boolean = false,
val style: String? = null, val style: String? = null,
val explode: Boolean? = false, val explode: Boolean? = false,
val schema: OpenApiSpecParameterSchema? = null val schema: OpenApiSpecSchema? = null
) : OpenApiSpecReferencable() ) : OpenApiSpecReferencable()
data class OpenApiSpecRequest( data class OpenApiSpecRequest(

View File

@ -0,0 +1,21 @@
package org.leafygreens.kompendium.models
sealed class OpenApiSpecSchema
sealed class OpenApiSpecSchemaTyped(
val type: String,
) : OpenApiSpecSchema()
data class OpenApiSpecSchemaArray<T: OpenApiSpecSchema >(
val items: T
) : OpenApiSpecSchemaTyped("array")
data class OpenApiSpecSchemaString(
val default: String,
val `enum`: Set<String>? = null
) : OpenApiSpecSchemaTyped("string")
// TODO In Kt 1.5 Should be able to reference external sealed classes
data class OpenApiSpecSchemaRef(
val `$ref`: String
) : OpenApiSpecSchema()

View File

@ -9,13 +9,14 @@ import org.leafygreens.kompendium.models.OpenApiSpecInfoContact
import org.leafygreens.kompendium.models.OpenApiSpecInfoLicense import org.leafygreens.kompendium.models.OpenApiSpecInfoLicense
import org.leafygreens.kompendium.models.OpenApiSpecMediaType import org.leafygreens.kompendium.models.OpenApiSpecMediaType
import org.leafygreens.kompendium.models.OpenApiSpecParameter import org.leafygreens.kompendium.models.OpenApiSpecParameter
import org.leafygreens.kompendium.models.OpenApiSpecParameterSchemaArray import org.leafygreens.kompendium.models.OpenApiSpecSchemaArray
import org.leafygreens.kompendium.models.OpenApiSpecParameterSchemaString import org.leafygreens.kompendium.models.OpenApiSpecSchemaString
import org.leafygreens.kompendium.models.OpenApiSpecPathItem import org.leafygreens.kompendium.models.OpenApiSpecPathItem
import org.leafygreens.kompendium.models.OpenApiSpecPathItemOperation import org.leafygreens.kompendium.models.OpenApiSpecPathItemOperation
import org.leafygreens.kompendium.models.OpenApiSpecReferenceObject import org.leafygreens.kompendium.models.OpenApiSpecReferenceObject
import org.leafygreens.kompendium.models.OpenApiSpecRequest import org.leafygreens.kompendium.models.OpenApiSpecRequest
import org.leafygreens.kompendium.models.OpenApiSpecResponse import org.leafygreens.kompendium.models.OpenApiSpecResponse
import org.leafygreens.kompendium.models.OpenApiSpecSchemaRef
import org.leafygreens.kompendium.models.OpenApiSpecServer import org.leafygreens.kompendium.models.OpenApiSpecServer
import org.leafygreens.kompendium.models.OpenApiSpecTag import org.leafygreens.kompendium.models.OpenApiSpecTag
@ -85,10 +86,10 @@ object TestData {
description = "Pet object that needs to be added to the store", description = "Pet object that needs to be added to the store",
content = mapOf( content = mapOf(
"application/json" to OpenApiSpecMediaType( "application/json" to OpenApiSpecMediaType(
schema = OpenApiSpecReferenceObject(`$ref` = "#/components/schemas/Pet") schema = OpenApiSpecSchemaRef(`$ref` = "#/components/schemas/Pet")
), ),
"application/xml" to OpenApiSpecMediaType( "application/xml" to OpenApiSpecMediaType(
schema = OpenApiSpecReferenceObject(`$ref` = "#/components/schemas/Pet") schema = OpenApiSpecSchemaRef(`$ref` = "#/components/schemas/Pet")
) )
), ),
required = true required = true
@ -122,10 +123,10 @@ object TestData {
description = "Pet object that needs to be added to the store", description = "Pet object that needs to be added to the store",
content = mapOf( content = mapOf(
"application/json" to OpenApiSpecMediaType( "application/json" to OpenApiSpecMediaType(
schema = OpenApiSpecReferenceObject(`$ref` = "#/components/schemas/Pet") schema = OpenApiSpecSchemaRef(`$ref` = "#/components/schemas/Pet")
), ),
"application/xml" to OpenApiSpecMediaType( "application/xml" to OpenApiSpecMediaType(
schema = OpenApiSpecReferenceObject(`$ref` = "#/components/schemas/Pet") schema = OpenApiSpecSchemaRef(`$ref` = "#/components/schemas/Pet")
) )
) )
), ),
@ -157,14 +158,38 @@ object TestData {
required = true, required = true,
style = "form", style = "form",
explode = true, explode = true,
schema = OpenApiSpecParameterSchemaArray( schema = OpenApiSpecSchemaArray(
items = OpenApiSpecParameterSchemaString( items = OpenApiSpecSchemaString(
default = "available", default = "available",
`enum` = setOf("available", "pending", "sold") `enum` = setOf("available", "pending", "sold")
) )
) )
) )
),
responses = mapOf(
"200" to OpenApiSpecResponse(
description = "successful operation",
content = mapOf(
"application/xml" to OpenApiSpecMediaType(
schema = OpenApiSpecSchemaArray(
items = OpenApiSpecSchemaRef("#/components/schemas/Pet")
) )
),
"application/json" to OpenApiSpecMediaType(
schema = OpenApiSpecSchemaArray(
items = OpenApiSpecSchemaRef("#/components/schemas/Pet")
)
)
)
),
"400" to OpenApiSpecResponse(
description = "Invalid status value",
content = mapOf()
)
),
security = listOf(mapOf(
"petstore_auth" to listOf("write:pets", "read:pets")
))
) )
) )
) )

View File

@ -118,7 +118,37 @@
"type" : "array" "type" : "array"
} }
} ], } ],
"deprecated" : false "responses" : {
"200" : {
"description" : "successful operation",
"content" : {
"application/xml" : {
"schema" : {
"items" : {
"$ref" : "#/components/schemas/Pet"
},
"type" : "array"
}
},
"application/json" : {
"schema" : {
"items" : {
"$ref" : "#/components/schemas/Pet"
},
"type" : "array"
}
}
}
},
"400" : {
"description" : "Invalid status value",
"content" : { }
}
},
"deprecated" : false,
"security" : [ {
"petstore_auth" : [ "write:pets", "read:pets" ]
} ]
} }
} }
}, },