From 3bf62ec4fbe3b4cda333f51c299cc7aeb5c7847e Mon Sep 17 00:00:00 2001 From: Nicholas Kalar Date: Mon, 11 Aug 2025 16:33:40 -0400 Subject: [PATCH] Updated to openapi 3.1 --- build.gradle.kts | 1 + src/main/kotlin/Application.kt | 13 +- src/main/resources/openapi/documentation.yaml | 252 +++++++++++++++++- 3 files changed, 260 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9ade3bf..581853a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { implementation("io.ktor:ktor-server-default-headers") implementation("io.ktor:ktor-server-core") implementation("io.ktor:ktor-server-swagger") + implementation("io.ktor:ktor-server-cors") implementation("io.ktor:ktor-server-auth") implementation("io.ktor:ktor-server-auth-jwt") implementation("io.ktor:ktor-server-content-negotiation") diff --git a/src/main/kotlin/Application.kt b/src/main/kotlin/Application.kt index 69c9981..43d91bb 100644 --- a/src/main/kotlin/Application.kt +++ b/src/main/kotlin/Application.kt @@ -1,12 +1,22 @@ package codes.kalar +import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.plugins.contentnegotiation.* import io.ktor.serialization.kotlinx.json.* +import io.ktor.server.engine.* +import io.ktor.server.netty.* +import io.ktor.server.plugins.cors.routing.* import kotlinx.serialization.json.Json fun main(args: Array) { - io.ktor.server.netty.EngineMain.main(args) + embeddedServer(Netty, port = 8080) { + install(CORS) { + anyHost() + allowHeader(HttpHeaders.ContentType) + } + }.start(wait = true) + EngineMain.main(args) } fun Application.module() { @@ -16,6 +26,7 @@ fun Application.module() { isLenient = true }) } + configureHTTP() configureSecurity() configureSerialization() diff --git a/src/main/resources/openapi/documentation.yaml b/src/main/resources/openapi/documentation.yaml index 1529d0b..323fc32 100644 --- a/src/main/resources/openapi/documentation.yaml +++ b/src/main/resources/openapi/documentation.yaml @@ -1,10 +1,252 @@ -openapi: "3.0.3" +openapi: 3.1.0 info: - title: "Application API" - description: "Application API" - version: "1.0.0" + title: "LMS APIs" + description: "Library Management System APIs" + version: "0.0.1" servers: - url: "http://0.0.0.0:8080" paths: /items: - $ref: "./endpoints/items.yaml" \ No newline at end of file + get: + description: "Search for item in collection" + parameters: + - name: "title" + in: "path" + required: false + schema: + type: string + example: title=Dune-Messiah + - name: "id" + in: "path" + required: false + schema: + type: string + example: id=27 + responses: + "200": + description: "OK" + content: + application/json: + schema: + $ref: "#/components/schemas/CollectionItem" + "400": + description: "Bad Request" + "404": + description: "Not Found" + + post: + description: "The method to add items to the collection." + requestBody: + description: "A JSON object that represents an item." + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CollectionItem" + responses: + "200": + description: "OK" + "400": + description: "Bad Request" + + patch: + description: "The method to update an item." + requestBody: + description: "The JSON object that represents a modified item." + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CollectionItem" + responses: + "200": + description: "OK" + "400": + description: "Bad Request" + "404": + description: "Not Found" + + delete: + description: "The method to soft delete an item." + parameters: + - name: "id" + in: "path" + required: false + schema: + type: string + example: id=27 + responses: + "200": + description: "OK" + "400": + description: "Bad Request" + +components: + schemas: + CollectionItem: + type: "object" + properties: + id: + type: "integer" + format: "int64" + description: "The unique ID of the item." + example: 27 + title: + type: "string" + description: "The title of the item." + example: "The Fellowship of the Ring" + author: + type: "array" + description: "The creator(s) behind the media." + example: [ "J.R.R. Tolkien" ] + publisher: + type: "string" + description: "The company who published the media." + example: "" + publishingDate: + type: "string" + description: "The date the book was published in yyyy-MM-DD format. 9999-12-31 for unknown." + example: "" + locNumber: + type: "string" + description: "The Library of Congress categorization number." + example: "" + deweyDecimalNumber: + type: "string" + description: "The Dewey Decimal Number." + example: "" + isbn: + type: "integer" + format: "int64" + description: "The ISBN number assigned to the book. Also known as the barcode." + example: "" + sortTitle: + type: "string" + description: "The tite of the book with any articles moved to the end for sorting purposes." + example: "Fellowship of the Ring, The" + format: + type: "string" + description: "The format the media is in. E.g. book, magazine, dvd, 8-track, etc." + example: "book" + language: + type: "string" + description: "The two letter abbreviation of the language the media is in." + example: "" + pageCount: + type: "integer" + format: "int32" + description: "The number of pages the media has. 0 if not a book/magazine." + categories: + type: "array" + description: "A list of the subjects/categories the media falls into." + example: [ "Fantasy", "High Fantasy", "Linguistics" ] + description: + type: "string" + description: "A short synopsis or blurb about the media." + example: "" + priceInCents: + type: "integer" + format: "int32" + description: "The cost of the item, in cents. E.g. $20 is 2000." + example: "" + coverImageUri: + type: "string" + description: "The path to find the cover image for the item." + example: "" + isCheckedIn: + type: "boolean" + description: "A flag to show if the item is checked in (true) or checked out (false)." + example: true + isArchived: + type: "boolean" + description: "A flag to show if the item is 'deleted' (true) or still in circulation (false)." + example: false + isLost: + type: "boolean" + description: "A flag to show if the item is lost (true) or not yet lost (false)." + example: false + lostDate: + type: "string" + description: "A string representation of the date the item is updated to lost. yyyy-MM-DD. 9999-12-31 for not lost." + example: "9999-12-31" + NewCollectionItem: + type: "object" + properties: + title: + type: "string" + description: "The title of the item." + example: "The Fellowship of the Ring" + author: + type: "array" + description: "The creator(s) behind the media." + example: [ "J.R.R. Tolkien" ] + publisher: + type: "string" + description: "The company who published the media." + example: "" + publishingDate: + type: "string" + description: "The date the book was published in yyyy-MM-DD format. 9999-12-31 for unknown." + example: "" + locNumber: + type: "string" + description: "The Library of Congress categorization number." + example: "" + deweyDecimalNumber: + type: "string" + description: "The Dewey Decimal Number." + example: "" + isbn: + type: "integer" + format: "int64" + description: "The ISBN number assigned to the book. Also known as the barcode." + example: "" + sortTitle: + type: "string" + description: "The tite of the book with any articles moved to the end for sorting purposes." + example: "Fellowship of the Ring, The" + format: + type: "string" + description: "The format the media is in. E.g. book, magazine, dvd, 8-track, etc." + example: "book" + language: + type: "string" + description: "The two letter abbreviation of the language the media is in." + example: "" + pageCount: + type: "integer" + format: "int32" + description: "The number of pages the media has. 0 if not a book/magazine." + categories: + type: "array" + description: "A list of the subjects/categories the media falls into." + example: [ "Fantasy", "High Fantasy", "Linguistics" ] + description: + type: "string" + description: "A short synopsis or blurb about the media." + example: "" + priceInCents: + type: "integer" + format: "int32" + description: "The cost of the item, in cents. E.g. $20 is 2000." + example: "" + coverImageUri: + type: "string" + description: "The path to find the cover image for the item." + example: "" + isCheckedIn: + type: "boolean" + description: "A flag to show if the item is checked in (true) or checked out (false)." + example: true + isArchived: + type: "boolean" + description: "A flag to show if the item is 'deleted' (true) or still in circulation (false)." + example: false + isLost: + type: "boolean" + description: "A flag to show if the item is lost (true) or not yet lost (false)." + example: false + lostDate: + type: "string" + description: "A string representation of the date the item is updated to lost. yyyy-MM-DD. 9999-12-31 for not lost." + example: "9999-12-31" \ No newline at end of file