Skip to content

Commit

Permalink
Merge pull request #5 from musicorum-app/swagger-docs
Browse files Browse the repository at this point in the history
Add swagger docs
  • Loading branch information
MysteryMS authored Dec 12, 2023
2 parents 6383b45 + d4d6843 commit c3aaa09
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 4 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ repositories {
}

dependencies {
// OpenAPI docs
implementation("io.ktor:ktor-server-openapi:$ktor_version")

// Swagger
implementation("io.ktor:ktor-server-swagger:$ktor_version")

// Ktor
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
implementation("io.ktor:ktor-server-auth-jvm:$ktor_version")
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/io/musicorum/api/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.musicorum.api.koin.installKoin
import io.musicorum.api.plugins.configureHTTP
import io.musicorum.api.realms.auth.createAuthRoutes
import io.musicorum.api.realms.collages.routes.createCollagesRoutes
import io.musicorum.api.realms.docs.createDocsRoute
import io.musicorum.api.realms.resources.createResourcesRoutes
import io.musicorum.api.security.configureSecurity

Expand All @@ -29,5 +30,5 @@ fun Application.module() {
createResourcesRoutes()
createAuthRoutes()
createCollagesRoutes()

createDocsRoute()
}
4 changes: 2 additions & 2 deletions src/main/kotlin/io/musicorum/api/plugins/StatusPages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package io.musicorum.api.plugins
import io.ktor.http.*
import io.ktor.serialization.*
import io.ktor.server.application.*
import io.ktor.server.plugins.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.response.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException

fun Application.installStatusPages() {
install(StatusPages) {
Expand All @@ -21,10 +19,12 @@ fun Application.installStatusPages() {
println(cause.message)
println(cause.cause)
return@exception call.respond(
HttpStatusCode.BadRequest,
ExceptionResponse("Serialization error: " + cause.message)
)
}
call.respond(
HttpStatusCode.BadRequest,
ExceptionResponse(cause.message ?: "Unknown error")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ object ThemeDataSerializer : KSerializer<ThemeData> {
val data = decoder.decodeSerializableValue(InputTheme.serializer())

val r = when (data.name) {
ThemeEnum.ClassicCollage -> ThemeData(data.name, Json.decodeFromJsonElement<GridTheme.GenerationData>(data.options))
ThemeEnum.ClassicCollage -> ThemeData(
data.name,
Json.decodeFromJsonElement<GridTheme.GenerationData>(data.options)
)
}

println("END")
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/io/musicorum/api/realms/docs/Routes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.musicorum.api.realms.docs

import io.ktor.server.application.*
import io.ktor.server.plugins.swagger.*
import io.ktor.server.routing.*

fun Application.createDocsRoute() {
routing {
swaggerUI(path = "documentation", swaggerFile = "openapi/documentation.yaml")
}
}
264 changes: 264 additions & 0 deletions src/main/resources/openapi/documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
openapi: "3.0.3"
info:
title: "api API"
description: "api API"
version: "1.0.0"
servers:
- url: "https://api"
paths:
/collages:
get:
description: ""
responses:
"200":
description: "OK"
content:
'*/*':
schema:
type: "array"
items:
$ref: "#/components/schemas/Collage"
post:
description: ""
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/CollagePayloadReq"
required: true
responses:
"200":
description: "OK"
content:
'*/*':
schema: {}
/workers:
get:
description: ""
responses:
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/WorkersResponse"
/resources/artists:
post:
description: ""
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/ArtistResourcesRequest"
required: true
responses:
"200":
description: "OK"
content:
'*/*':
schema:
type: "array"
items:
$ref: "#/components/schemas/ArtistResource"
/auth/clients:
get:
description: ""
responses:
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/Map_String"
post:
description: ""
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/ClientCreationDAO"
required: true
responses:
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/Client"
components:
schemas:
Instant:
type: "object"
properties: {}
Collage:
type: "object"
properties:
id:
type: "string"
theme:
type: "string"
enum:
- "ClassicCollage"
file:
type: "string"
duration:
type: "integer"
format: "int64"
createdAt:
$ref: "#/components/schemas/Instant"
IGenerationData:
type: "object"
properties: {}
ThemeData:
type: "object"
properties:
name:
type: "string"
enum:
- "ClassicCollage"
options:
$ref: "#/components/schemas/IGenerationData"
CollagePayloadReq:
type: "object"
properties:
user:
type: "string"
theme:
$ref: "#/components/schemas/ThemeData"
hideUsername:
type: "boolean"
ExceptionResponse:
type: "object"
properties:
message:
type: "string"
CollageResponse:
type: "object"
properties:
duration:
type: "integer"
format: "int64"
file:
type: "string"
id:
type: "string"
url:
type: "string"
SerializableWorker:
type: "object"
properties:
name:
type: "string"
engine:
type: "string"
availableThemes:
type: "array"
items:
type: "string"
WorkersResponse:
type: "object"
properties:
workers:
type: "array"
items:
$ref: "#/components/schemas/SerializableWorker"
ArtistResourcesRequest:
type: "object"
properties:
artists:
type: "array"
items:
type: "string"
Image:
type: "object"
properties:
hash:
type: "string"
size:
type: "string"
enum:
- "EXTRA_SMALL"
- "SMALL"
- "MEDIUM"
- "LARGE"
- "EXTRA_LARGE"
url:
type: "string"
ColorPalette:
type: "object"
properties:
vibrant:
type: "string"
darkVibrant:
type: "string"
lightVibrant:
type: "string"
muted:
type: "string"
darkMuted:
type: "string"
lightMuted:
type: "string"
ImageResource:
type: "object"
properties:
hash:
type: "string"
explicit:
type: "boolean"
active:
type: "boolean"
source:
type: "string"
enum:
- "SPOTIFY"
- "LASTFM"
- "DEEZER"
images:
type: "array"
items:
$ref: "#/components/schemas/Image"
colorPalette:
$ref: "#/components/schemas/ColorPalette"
createdAt:
type: "string"
ArtistResource:
type: "object"
properties:
hash:
type: "string"
name:
type: "string"
resources:
type: "array"
items:
$ref: "#/components/schemas/ImageResource"
preferredResource:
type: "string"
createdAt:
type: "string"
updatedAt:
type: "string"
Map:
type: "object"
properties: {}
Map_String:
type: "string"
ClientCreationDAO:
type: "object"
properties:
name:
type: "string"
Client:
type: "object"
properties:
id:
type: "string"
name:
type: "string"
key:
type: "string"
createdAt:
$ref: "#/components/schemas/Instant"
updatedAt:
$ref: "#/components/schemas/Instant"

0 comments on commit c3aaa09

Please sign in to comment.