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

de.lancom.openapi.entity.Link.kt Maven / Gradle / Ivy

Go to download

This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes

There is a newer version: 2.1.1
Show newest version
/*****************************************************************************
**   C A U T I O N                                                          **
**   This file is auto-generated!                                           **
**   If you want to make changes, please see the README.md file.            **
**   Please do not edit this file directly!                                 **
*****************************************************************************/
package de.lancom.openapi.entity

import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import de.lancom.openapi.field.Field
import de.lancom.openapi.jackson.EntityDeserializer
import de.lancom.openapi.jackson.EntitySerializer
import de.lancom.openapi.jackson.ReferenceParser
import de.lancom.openapi.jackson.Wrapper
import de.lancom.openapi.refs.Referenceable
import de.lancom.openapi.tools.toYamlString

// hint:9A1BF04C
@Suppress("PropertyName")
@JsonSerialize(using = Link.Companion.Serializer::class)
@JsonDeserialize(using = Link.Companion.Deserializer::class)
data class Link(
    val _operationId: Field = Field.unset(),
    val _operationRef: Field = Field.unset(),
    val _parameters: Field?> = Field.unset(),
    val _requestBody: Field = Field.unset(),
    val _description: Field = Field.unset(),
    val _server: Field = Field.unset(),
    val _extensions: Field> = Field.unset(),
) : Referenceable {

    ///////////////////////
    //
    // operationId
    //
    ///////////////////////

    // hint:3A7F9B2E
    val operationId: String?
        get() = _operationId.orNull

    // hint:F0C48D71
    fun setOperationIdField(operationId: Field): Link {
        return copy(_operationId = operationId)
    }

    // hint:8E56A4D9
    fun updateOperationIdField(updater: (Field) -> Field): Link {
        return setOperationIdField(updater(_operationId))
    }

    // hint:B1D730FC
    fun updateOperationId(updater: (String?) -> String?): Link {
        return updateOperationIdField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeOperationIdField(operationIdFieldToMerge: Field): Link {
        return mergeOperationId(operationIdFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeOperationId(operationIdToMerge: String?): Link {
        return if (operationIdToMerge == null) {
            this
        } else {
            val oldOperationId = _operationId.orNull
            if (oldOperationId == null) {
                setOperationIdField(Field(operationIdToMerge))
            } else {
                // hint:2F684DAC
                setOperationId(operationIdToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setOperationId(operationId: String?): Link {
        return setOperationIdField(Field(operationId))
    }

    // hint:D465F782
    fun unsetOperationId(): Link {
        return setOperationIdField(Field.unset())
    }

    // hint:47C9A0F6
    fun addOperationId(operationId: String): Link {
        if (this.operationId != null) {
            throw IllegalStateException("Field operationId of Entity Link is already set to '${this.operationId}', refused to add new value '$operationId'")
        }
        return setOperationId(operationId)
    }

    ///////////////////////
    //
    // operationRef
    //
    ///////////////////////

    // hint:3A7F9B2E
    val operationRef: String?
        get() = _operationRef.orNull

    // hint:F0C48D71
    fun setOperationRefField(operationRef: Field): Link {
        return copy(_operationRef = operationRef)
    }

    // hint:8E56A4D9
    fun updateOperationRefField(updater: (Field) -> Field): Link {
        return setOperationRefField(updater(_operationRef))
    }

    // hint:B1D730FC
    fun updateOperationRef(updater: (String?) -> String?): Link {
        return updateOperationRefField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeOperationRefField(operationRefFieldToMerge: Field): Link {
        return mergeOperationRef(operationRefFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeOperationRef(operationRefToMerge: String?): Link {
        return if (operationRefToMerge == null) {
            this
        } else {
            val oldOperationRef = _operationRef.orNull
            if (oldOperationRef == null) {
                setOperationRefField(Field(operationRefToMerge))
            } else {
                // hint:2F684DAC
                setOperationRef(operationRefToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setOperationRef(operationRef: String?): Link {
        return setOperationRefField(Field(operationRef))
    }

    // hint:D465F782
    fun unsetOperationRef(): Link {
        return setOperationRefField(Field.unset())
    }

    // hint:47C9A0F6
    fun addOperationRef(operationRef: String): Link {
        if (this.operationRef != null) {
            throw IllegalStateException("Field operationRef of Entity Link is already set to '${this.operationRef}', refused to add new value '$operationRef'")
        }
        return setOperationRef(operationRef)
    }

    ///////////////////////
    //
    // parameters
    //
    ///////////////////////

    // hint:3A7F9B2E
    val parameters: Map?
        get() = _parameters.orNull

    // hint:F0C48D71
    fun setParametersField(parameters: Field?>): Link {
        return copy(_parameters = parameters)
    }

    // hint:8E56A4D9
    fun updateParametersField(updater: (Field?>) -> Field?>): Link {
        return setParametersField(updater(_parameters))
    }

    // hint:B1D730FC
    fun updateParameters(updater: (Map?) -> Map?): Link {
        return updateParametersField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeParametersField(parametersFieldToMerge: Field?>): Link {
        return mergeParameters(parametersFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeParameters(parametersToMerge: Map?): Link {
        return if (parametersToMerge == null) {
            this
        } else {
            val oldParameters = _parameters.orNull
            if (oldParameters == null) {
                setParametersField(Field(parametersToMerge))
            } else {
                // hint:70A3D8B6
                setParameters(de.lancom.openapi.tools.mergeMap(oldParameters, parametersToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setParameters(parameters: Map?): Link {
        return setParametersField(Field(parameters))
    }

    // hint:D465F782
    fun unsetParameters(): Link {
        return setParametersField(Field.unset())
    }

    // hint:5C81D396
    fun addParameters(parameters: Map?): Link {
        return mergeParameters(parameters)
    }

    // hint:1A6B37F8
    fun addParameters(vararg parameters: Pair): Link {
        return addParameters(parameters.toMap())
    }

    // hint:9D0E4CA5
    fun addParameter(key: String, value: String?): Link {
        return addParameters(key to value)
    }

    // hint:B8F25E73
    fun addParameter(pair: Pair): Link {
        return addParameters(mapOf(pair))
    }

    ///////////////////////
    //
    // requestBody
    //
    ///////////////////////

    // hint:3A7F9B2E
    val requestBody: RequestBodyJson?
        get() = _requestBody.orNull

    // hint:F0C48D71
    fun setRequestBodyField(requestBody: Field): Link {
        return copy(_requestBody = requestBody)
    }

    // hint:8E56A4D9
    fun updateRequestBodyField(updater: (Field) -> Field): Link {
        return setRequestBodyField(updater(_requestBody))
    }

    // hint:B1D730FC
    fun updateRequestBody(updater: (RequestBodyJson?) -> RequestBodyJson?): Link {
        return updateRequestBodyField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeRequestBodyField(requestBodyFieldToMerge: Field): Link {
        return mergeRequestBody(requestBodyFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeRequestBody(requestBodyToMerge: RequestBodyJson?): Link {
        return if (requestBodyToMerge == null) {
            this
        } else {
            val oldRequestBody = _requestBody.orNull
            if (oldRequestBody == null) {
                setRequestBodyField(Field(requestBodyToMerge))
            } else {
                // hint:E91B4F65
                setRequestBody(oldRequestBody.mergeEntity(requestBodyToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setRequestBody(requestBody: RequestBodyJson?): Link {
        return setRequestBodyField(Field(requestBody))
    }

    // hint:D465F782
    fun unsetRequestBody(): Link {
        return setRequestBodyField(Field.unset())
    }

    // hint:47C9A0F6
    fun addRequestBody(requestBody: RequestBodyJson): Link {
        if (this.requestBody != null) {
            throw IllegalStateException("Field requestBody of Entity Link is already set to '${this.requestBody}', refused to add new value '$requestBody'")
        }
        return setRequestBody(requestBody)
    }

    ///////////////////////
    //
    // description
    //
    ///////////////////////

    // hint:3A7F9B2E
    val description: String?
        get() = _description.orNull

    // hint:F0C48D71
    fun setDescriptionField(description: Field): Link {
        return copy(_description = description)
    }

    // hint:8E56A4D9
    fun updateDescriptionField(updater: (Field) -> Field): Link {
        return setDescriptionField(updater(_description))
    }

    // hint:B1D730FC
    fun updateDescription(updater: (String?) -> String?): Link {
        return updateDescriptionField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeDescriptionField(descriptionFieldToMerge: Field): Link {
        return mergeDescription(descriptionFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeDescription(descriptionToMerge: String?): Link {
        return if (descriptionToMerge == null) {
            this
        } else {
            val oldDescription = _description.orNull
            if (oldDescription == null) {
                setDescriptionField(Field(descriptionToMerge))
            } else {
                // hint:2F684DAC
                setDescription(descriptionToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setDescription(description: String?): Link {
        return setDescriptionField(Field(description))
    }

    // hint:D465F782
    fun unsetDescription(): Link {
        return setDescriptionField(Field.unset())
    }

    // hint:47C9A0F6
    fun addDescription(description: String): Link {
        if (this.description != null) {
            throw IllegalStateException("Field description of Entity Link is already set to '${this.description}', refused to add new value '$description'")
        }
        return setDescription(description)
    }

    ///////////////////////
    //
    // server
    //
    ///////////////////////

    // hint:3A7F9B2E
    val server: Server?
        get() = _server.orNull

    // hint:F0C48D71
    fun setServerField(server: Field): Link {
        return copy(_server = server)
    }

    // hint:8E56A4D9
    fun updateServerField(updater: (Field) -> Field): Link {
        return setServerField(updater(_server))
    }

    // hint:B1D730FC
    fun updateServer(updater: (Server?) -> Server?): Link {
        return updateServerField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeServerField(serverFieldToMerge: Field): Link {
        return mergeServer(serverFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeServer(serverToMerge: Server?): Link {
        return if (serverToMerge == null) {
            this
        } else {
            val oldServer = _server.orNull
            if (oldServer == null) {
                setServerField(Field(serverToMerge))
            } else {
                // hint:E91B4F65
                setServer(oldServer.mergeEntity(serverToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setServer(server: Server?): Link {
        return setServerField(Field(server))
    }

    // hint:D465F782
    fun unsetServer(): Link {
        return setServerField(Field.unset())
    }

    // hint:47C9A0F6
    fun addServer(server: Server): Link {
        if (this.server != null) {
            throw IllegalStateException("Field server of Entity Link is already set to '${this.server}', refused to add new value '$server'")
        }
        return setServer(server)
    }

    ///////////////////////
    //
    // extensions
    //
    ///////////////////////

    // hint:3A7F9B2E
    val extensions: Map
        get() = _extensions.orNull ?: emptyMap()

    // hint:F0C48D71
    fun setExtensionsField(extensions: Field>): Link {
        return copy(_extensions = extensions)
    }

    // hint:8E56A4D9
    fun updateExtensionsField(updater: (Field>) -> Field>): Link {
        return setExtensionsField(updater(_extensions))
    }

    // hint:B1D730FC
    fun updateExtensions(updater: (Map) -> Map): Link {
        return updateExtensionsField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeExtensionsField(extensionsFieldToMerge: Field>): Link {
        return mergeExtensions(extensionsFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeExtensions(extensionsToMerge: Map?): Link {
        return if (extensionsToMerge == null) {
            this
        } else {
            val oldExtensions = _extensions.orNull
            if (oldExtensions == null) {
                setExtensionsField(Field(extensionsToMerge))
            } else {
                // hint:70A3D8B6
                setExtensions(de.lancom.openapi.tools.mergeMap(oldExtensions, extensionsToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setExtensions(extensions: Map): Link {
        return setExtensionsField(Field(extensions))
    }

    // hint:D465F782
    fun unsetExtensions(): Link {
        return setExtensionsField(Field.unset())
    }

    // hint:5C81D396
    fun addExtensions(extensions: Map): Link {
        return mergeExtensions(extensions)
    }

    // hint:1A6B37F8
    fun addExtensions(vararg extensions: Pair): Link {
        return addExtensions(extensions.toMap())
    }

    // hint:9D0E4CA5
    fun addExtension(key: String, value: Extension?): Link {
        return addExtensions(key to value)
    }

    // hint:B8F25E73
    fun addExtension(pair: Pair): Link {
        return addExtensions(mapOf(pair))
    }

    // hint:6A81E3FD
    override val entityDescriptor: EntityDescriptor by lazy {
        EntityDescriptor(
            entity = this,
            jsonNode = null,
            map = mapOf(
                "operationId" to _operationId,
                "operationRef" to _operationRef,
                "parameters" to _parameters,
                "requestBody" to _requestBody,
                "description" to _description,
                "server" to _server,
            ),
            flatMap = listOf(
                _extensions,
            ),
            flatten = listOf(
            ),
        )
    }

    override fun toString(): String {
        return this.toYamlString()
    }

    // hint:A0E5F382
    override fun mergeEntity(other: Entity?): Link {
        return when (other) {
            null ->
                this

            is Link ->
                merge(other)

            else ->
                TODO()
        }
    }

    // hint:716BFD54
    fun merge(other: Link?): Link {
        if (other == null) return this
        return this
            .mergeOperationIdField(other._operationId)
            .mergeOperationRefField(other._operationRef)
            .mergeParametersField(other._parameters)
            .mergeRequestBodyField(other._requestBody)
            .mergeDescriptionField(other._description)
            .mergeServerField(other._server)
            .mergeExtensionsField(other._extensions)
    }

    companion object : ReferenceParser {

        class Serializer : EntitySerializer(Link::class.java, Link)
        class Deserializer : EntityDeserializer(Link::class.java, Link)

        // hint:5F72B6D8
        override fun parseWrapper(wrapper: Wrapper): Link {
            return de.lancom.openapi.jackson.extensionParser(wrapper, ::parseWrapperWithExtensions)
        }

        // hint:2C0E94A7
        fun parseWrapperWithExtensions(wrapper: Wrapper, extensions: Field>): Link {
            return Link(
                _operationId = wrapper["operationId"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _operationRef = wrapper["operationRef"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _parameters = wrapper["parameters"].getNullOrElse {
                    getMap {
                        getNullOrElse {
                            getString()
                        }
                    }
                },
                _requestBody = wrapper["requestBody"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getSingle(RequestBodyJson::parseEntityOpt)
                        }
                    }
                },
                _description = wrapper["description"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _server = wrapper["server"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getSingle(Server::parseEntityOpt)
                        }
                    }
                },
                _extensions = extensions,
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy