Does anyone know of a good OpenAPI documentation g...
# ktor
m
Does anyone know of a good OpenAPI documentation generator for Ktor? I see this small amount of documentation, but it's not super clear on how it works even with the attached
swagger-codegen-generators
. I'm open to suggestions for how to do this; trying to explore the options that are out there
a
You can try Ktor plugin for IntelliJ IDEA Ultimate.
d
@Mark Vogel I have updated this repo recently with OpenAPI doc generator. https://github.com/CodeWithDino/ktor-server-boilerplate/commit/f652dd24a5ca2639798eb192e0fbf49e913a448b
r
I'm using Tegral Ktor plugins. It's the only thing I found that worked. https://tegral.zoroark.guru/docs/modules/core/openapi/ktor
⬆️ This is very close to what I expect Ktor to support natively in the future @Aleksei Tirman [JB]
Here's an actual Ktor Resource I have defined in a production backend
Copy code
@Resource("{id}")
@Serializable
data class FileResource(val parent: FilesResource = FilesResource(), val id: FileId) {

    // Swagger data
    object Get : ResourceDescription by describeResource({

        operationId = "getFile"

        summary = "Gets an existing file's download URL"

        tags += "File"

        "id" pathParameter {
            description = "The id of the file to get"
            example = "file-id.pdf"
            required = true
        }

        200 response {
            json { schema(DownloadResponse("http://…/file-id.pdf")) }
        }

    })

    // Swagger data
    object Delete : ResourceDescription by describeResource({

        operationId = "deleteFile"

        summary = "Deletes an existing file"

        tags += "File"

        "id" pathParameter {
            description = "The id of the file to delete"
            example = "file-id.pdf"
            required = true
        }

        200 response {
            description = "File deleted"
        }

    })

    @Serializable
    data class DownloadResponse(val url: String)

}
m
This is great! Thank you for all the replies I will definitely be trying these out
105 Views