All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.io.github.tabilzad.ktor.DataBag.kt Maven / Gradle / Ivy

There is a newer version: 0.6.5-alpha
Show newest version
package io.github.tabilzad.ktor

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty

// Internal
data class PluginConfiguration(
    val isEnabled: Boolean,
    val buildPath: String,
    val saveInBuild: Boolean,
    val modulePath: String,
    val format: String,
    val title: String,
    val description: String,
    val version: String,
    val filePath: String?,
    val requestBody: Boolean,
    val hideTransients: Boolean,
    val hidePrivateFields: Boolean,
    val deriveFieldRequirementFromTypeNullability: Boolean
)
interface OpenApiSpecParam {
    val name: String
    val `in`: String
    val required: Boolean
}

internal data class KtorRouteSpec(
    val path: String,
    val queryParameters: List?,
    val method: String,
    val body: OpenApiSpec.ObjectType,
    val summary: String?,
    val description: String?,
    val tags: Set?,
    val responses: Map?
)

sealed class KtorElement {
    abstract var path: String?
    abstract var tags: Set?

    abstract fun newInstance(tags: Set?): KtorElement
}

enum class ExpType(val labels: List) {
    ROUTE(listOf("route")),
    METHOD(listOf("get", "post", "put", "patch", "delete")),
    RECEIVE(listOf("receive"))
}

internal data class EndPoint(
    override var path: String?,
    val method: String = "",
    var body: OpenApiSpec.ObjectType = OpenApiSpec.ObjectType(type = "object"),
    var queryParameters: Set? = null,
    var description: String? = null,
    var summary: String? = null,
    override var tags: Set? = null,
    var responses: Map? = null
) : KtorElement() {
    override fun newInstance(tags: Set?): EndPoint {
        return copy(tags = tags)
    }
}

data class DocRoute(
    override var path: String? = "/",
    val children: MutableList = mutableListOf(),
    override var tags: Set? = null
) : KtorElement() {
    override fun newInstance(tags: Set?): DocRoute {
        return copy(tags = tags)
    }
}

enum class ContentType {
    @JsonProperty("application/json")
    APPLICATION_JSON;
}

internal typealias ContentSchema = Map

internal typealias BodyContent = Map

data class OpenApiComponents(
    val schemas: Map
)

// External
data class OpenSpecPath(
    val path: String,
)
data class OpenApiSpec(
    val openapi: String = "3.1.0",
    val info: Info,
    val paths: Map>,
    val components: OpenApiComponents
) {
    data class Info(
        val title: String,
        val description: String,
        val version: String
    )

    data class Server(
        val url: String,
        val description: String
    )

    data class Path(
        val summary: String? = null,
        val description: String? = null,
        val tags: List? = null,
        val responses: Map? = null,
        val parameters: List? = null,
        val requestBody: RequestBody? = null
    )

    data class RequestBody(
        val required: Boolean,
        val content: BodyContent
    )

    interface NamedObject{
        var fqName: String?
    }
    data class ObjectType(
        var type: String?,
        var properties: MutableMap? = null,
        var items: ObjectType? = null,
        var enum: List? = null,
        @JsonIgnore
        override var fqName: String? = null,
        var description: String? = null,
        @JsonProperty("\$ref")
        var ref: String? = null,
        @JsonIgnore
        var contentBodyRef: String? = null,
        var additionalProperties: ObjectType? = null,
        var oneOf: List? = null,
        var required: MutableList? = null
    ) : NamedObject

    data class PathParam(
        override val name: String,
        override val `in`: String,
        override val required: Boolean = true,
        val schema: SchemaType,
    ) : OpenApiSpecParam


    data class SchemaRef(
        val `$ref`: String? = null,
        val type: String? = null
    )

    data class SchemaType(
        val type: String? = null,
        val items: SchemaRef? = null,
        val `$ref`: String? = null,
    )

    data class ResponseDetails(
        val description: String,
        val content: BodyContent
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy