From 0a8e0f617822fc3d96108842dc55e3bec9e04084 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 4 Jun 2022 17:12:05 +0600 Subject: [PATCH] complete swagger templates --- repos/ktor/kv.yml | 2 +- repos/ktor/kvs.yml | 222 ++++++++++++++++++ .../key/values/KtorKeyValuesRepoRoutes.kt | 12 +- .../key/values/KtorReadKeyValuesRepoRoutes.kt | 19 +- 4 files changed, 239 insertions(+), 16 deletions(-) create mode 100644 repos/ktor/kvs.yml diff --git a/repos/ktor/kv.yml b/repos/ktor/kv.yml index 52e2c13650e..176d40226e0 100644 --- a/repos/ktor/kv.yml +++ b/repos/ktor/kv.yml @@ -1,6 +1,6 @@ swagger: "2.0" info: - description: "This is a template for the KeyValue repositories from [microutils](https://github.com/InsanusMokrassar/MicroUtils/tree/master/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value)" + description: "This is a template for the KeyValue repositories from [microutils](https://github.com/InsanusMokrassar/MicroUtils/tree/master/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/value)" version: "0.11.0" title: "KeyValue Repo" contact: diff --git a/repos/ktor/kvs.yml b/repos/ktor/kvs.yml new file mode 100644 index 00000000000..6f61a058526 --- /dev/null +++ b/repos/ktor/kvs.yml @@ -0,0 +1,222 @@ +swagger: "2.0" +info: + description: "This is a template for the KeyValues repositories from [microutils](https://github.com/InsanusMokrassar/MicroUtils/tree/master/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values)" + version: "0.11.0" + title: "KeyValues Repo" + contact: + email: "ovsyannikov.alexey95@gmail.com" +tags: + - name: "Read" + description: "Operations with `get` request in most cases" + - name: "Write" + description: "Operations with `post` request in most cases" + +parameters: + KeyInQuery: + in: "query" + name: "key" + allOf: + - $ref: "#/definitions/Key" + KeyInBody: + in: "body" + name: "body" + allOf: + - $ref: "#/definitions/Key" + KeysInBody: + in: "body" + name: "body" + type: array + items: + $ref: "#/definitions/Key" + ValuesInBody: + in: "body" + name: "body" + type: array + items: + $ref: "#/definitions/Value" + PaginationInQueryPage: + in: "query" + type: integer + name: "ppage" + description: "Page of pagination" + required: false + PaginationInQuerySize: + in: "query" + type: integer + name: "psize" + description: "Size of each page in pagination" + required: false + ReversedInQuery: + in: "query" + type: boolean + name: "reversed" + description: "If passed, will tell to reverse the result pages" + required: false + ValueInQuery: + in: "query" + name: "value" + allOf: + - $ref: "#/definitions/Value" + ValueInBody: + in: "body" + name: "body" + allOf: + - $ref: "#/definitions/Value" + MapInBody: + in: "body" + name: "body" + allOf: + - $ref: "#/definitions/Map" + + +definitions: + Key: + type: integer + description: "REWRITE THIS TYPE AS KEY IN SWAGGER FILE" + Value: + type: integer + description: "REWRITE THIS TYPE AS VALUE IN SWAGGER FILE" + Map: + type: object + description: "Map of objects" + PaginationResult: + type: object + properties: + page: + type: integer + description: "Page of pagination" + pagesNumber: + type: integer + description: "Count of pages with the size from this pagination" + size: + type: integer + description: "Size of each page in pagination" + results: + type: array + description: "Array of all elements on that page. Size of pagination and size of array can be different and it can be interpreted like current page is the last one" + items: + type: object + +paths: + /get: + get: + tags: + - "Read" + parameters: + - $ref: "#/parameters/KeyInQuery" + required: true + - $ref: "#/parameters/PaginationInQueryPage" + - $ref: "#/parameters/PaginationInQuerySize" + - $ref: "#/parameters/ReversedInQuery" + responses: + "200": + description: "Elements by query" + schema: + allOf: + - $ref: "#/definitions/PaginationResult" + - properties: + results: + items: + $ref: "#/definitions/Value" + /keys: + get: + tags: + - "Read" + parameters: + - $ref: "#/parameters/PaginationInQueryPage" + - $ref: "#/parameters/PaginationInQuerySize" + - $ref: "#/parameters/ReversedInQuery" + - $ref: "#/parameters/ValueInQuery" + required: false + responses: + "200": + description: "Pagination with elements" + schema: + allOf: + - $ref: "#/definitions/PaginationResult" + - properties: + results: + items: + $ref: "#/definitions/Key" + /contains: + get: + tags: + - "Read" + parameters: + - $ref: "#/parameters/KeyInQuery" + required: true + - $ref: "#/parameters/ValueInQuery" + required: false + responses: + "200": + description: "Object with key and optionally availability in repo" + schema: + type: boolean + /count: + get: + tags: + - "Read" + responses: + "200": + description: "Amount of objects in repo" + schema: + type: integer + + + /add: + post: + tags: + - "Write" + parameters: + - allOf: + - $ref: "#/parameters/MapInBody" + - additionalProperties: + $ref: "#/definitions/Value" + description: "Map with new elements to add. Use keys as a keys of this map. That values will be added to the end of current data by their keys" + responses: + "200": + description: "Will return 200 if everything has been completed ok" + /set: + post: + tags: + - "Write" + parameters: + - allOf: + - $ref: "#/parameters/MapInBody" + - additionalProperties: + $ref: "#/definitions/Value" + description: "Map with new elements to set. Use keys as a keys of this map. That values will overwrite all exists data by their keys" + responses: + "200": + description: "Will return 200 if everything has been completed ok" + /remove: + post: + tags: + - "Write" + parameters: + - allOf: + - $ref: "#/parameters/MapInBody" + - additionalProperties: + $ref: "#/definitions/Value" + description: "Map with data to remove. Removing will be processed by each value for its key" + responses: + "200": + description: "Objects with keys and values from body has been unset" + /clear: + post: + tags: + - "Write" + parameters: + - $ref: "#/parameters/KeyInBody" + responses: + "200": + description: "Data with corresponding key has been removed" + /clearWithValues: + post: + tags: + - "Write" + parameters: + - $ref: "#/parameters/ValueInBody" + responses: + "200": + description: "Will remove value from all keys data" diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorKeyValuesRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorKeyValuesRepoRoutes.kt index 6fd6eff3f01..541ca5fd7ce 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorKeyValuesRepoRoutes.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorKeyValuesRepoRoutes.kt @@ -8,22 +8,22 @@ import kotlinx.serialization.* inline fun Route.configureKeyValuesRepoRoutes ( originalRepo: KeyValuesRepo, - noinline idDeserializer: suspend (String) -> Key, + noinline keyDeserializer: suspend (String) -> Key, noinline valueDeserializer: suspend (String) -> Value ) { - configureReadKeyValuesRepoRoutes(originalRepo, idDeserializer, valueDeserializer) + configureReadKeyValuesRepoRoutes(originalRepo, keyDeserializer, valueDeserializer) configureWriteKeyValuesRepoRoutes(originalRepo) } inline fun Route.configureKeyValuesRepoRoutes( originalRepo: KeyValuesRepo, - idsSerializer: DeserializationStrategy, + keySerializer: DeserializationStrategy, valueSerializer: DeserializationStrategy, serialFormat: StringFormat ) = configureKeyValuesRepoRoutes( originalRepo, { - serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent()) + serialFormat.decodeFromString(keySerializer, it.decodeURLQueryComponent()) }, { serialFormat.decodeFromString(valueSerializer, it.decodeURLQueryComponent()) @@ -32,13 +32,13 @@ inline fun Route.configureKeyValuesRepo inline fun Route.configureKeyValuesRepoRoutes( originalRepo: KeyValuesRepo, - idsSerializer: DeserializationStrategy, + keySerializer: DeserializationStrategy, valueSerializer: DeserializationStrategy, serialFormat: BinaryFormat ) = configureKeyValuesRepoRoutes( originalRepo, { - serialFormat.decodeHex(idsSerializer, it) + serialFormat.decodeHex(keySerializer, it) }, { serialFormat.decodeHex(valueSerializer, it) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorReadKeyValuesRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorReadKeyValuesRepoRoutes.kt index 73e98c29d47..555c9d5404a 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorReadKeyValuesRepoRoutes.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorReadKeyValuesRepoRoutes.kt @@ -7,6 +7,7 @@ import dev.inmo.micro_utils.pagination.extractPagination import dev.inmo.micro_utils.repos.ReadKeyValuesRepo import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.containsRoute +import dev.inmo.micro_utils.repos.ktor.common.countRoute import dev.inmo.micro_utils.repos.ktor.common.one_to_many.* import io.ktor.http.* import io.ktor.server.application.call @@ -20,14 +21,14 @@ import kotlinx.serialization.* @OptIn(InternalAPI::class) inline fun Route.configureReadKeyValuesRepoRoutes ( originalRepo: ReadKeyValuesRepo, - noinline idDeserializer: suspend (String) -> Key, + noinline keyDeserializer: suspend (String) -> Key, noinline valueDeserializer: suspend (String) -> Value ) { val paginationWithValuesTypeInfo = typeInfo>() val paginationWithKeysTypeInfo = typeInfo>() get(getRoute) { - val key = idDeserializer( + val key = keyDeserializer( call.getQueryParameterOrSendError(keyParameterName) ?: return@get ) val pagination = call.request.queryParameters.extractPagination @@ -53,7 +54,7 @@ inline fun Route.configureReadKeyValuesRepoRoutes ( } get(containsRoute) { - val key = idDeserializer( + val key = keyDeserializer( call.getQueryParameterOrSendError(keyParameterName) ?: return@get ) val value = call.getQueryParameter(valueParameterName) ?.let { @@ -65,9 +66,9 @@ inline fun Route.configureReadKeyValuesRepoRoutes ( ) } - get(dev.inmo.micro_utils.repos.ktor.common.countRoute) { + get(countRoute) { val id = call.getQueryParameter(keyParameterName) ?.let { - idDeserializer(it) + keyDeserializer(it) } call.respond( id ?.let { originalRepo.count(it) } ?: originalRepo.count() @@ -77,13 +78,13 @@ inline fun Route.configureReadKeyValuesRepoRoutes ( inline fun Route.configureReadKeyValuesRepoRoutes( originalRepo: ReadKeyValuesRepo, - idsSerializer: DeserializationStrategy, + keySerializer: DeserializationStrategy, valueSerializer: DeserializationStrategy, serialFormat: StringFormat ) = configureReadKeyValuesRepoRoutes( originalRepo, { - serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent()) + serialFormat.decodeFromString(keySerializer, it.decodeURLQueryComponent()) }, { serialFormat.decodeFromString(valueSerializer, it.decodeURLQueryComponent()) @@ -92,13 +93,13 @@ inline fun Route.configureReadKeyValuesRepoRoutes( inline fun Route.configureReadKeyValuesRepoRoutes( originalRepo: ReadKeyValuesRepo, - idsSerializer: DeserializationStrategy, + keySerializer: DeserializationStrategy, valueSerializer: DeserializationStrategy, serialFormat: BinaryFormat ) = configureReadKeyValuesRepoRoutes( originalRepo, { - serialFormat.decodeHex(idsSerializer, it) + serialFormat.decodeHex(keySerializer, it) }, { serialFormat.decodeHex(valueSerializer, it)