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

de.lancom.openapi.entity.Info.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.Parser
import de.lancom.openapi.jackson.Wrapper
import de.lancom.openapi.tools.toYamlString

// hint:9A1BF04C
@Suppress("PropertyName")
@JsonSerialize(using = Info.Companion.Serializer::class)
@JsonDeserialize(using = Info.Companion.Deserializer::class)
data class Info(
    val _title: Field = Field.unset(),
    val _description: Field = Field.unset(),
    val _termsOfService: Field = Field.unset(),
    val _contact: Field = Field.unset(),
    val _license: Field = Field.unset(),
    val _version: Field = Field.unset(),
    val _extensions: Field> = Field.unset(),
) : Entity {

    ///////////////////////
    //
    // title
    //
    ///////////////////////

    // hint:3A7F9B2E
    val title: String?
        get() = _title.orNull

    // hint:F0C48D71
    fun setTitleField(title: Field): Info {
        return copy(_title = title)
    }

    // hint:8E56A4D9
    fun updateTitleField(updater: (Field) -> Field): Info {
        return setTitleField(updater(_title))
    }

    // hint:B1D730FC
    fun updateTitle(updater: (String?) -> String?): Info {
        return updateTitleField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeTitleField(titleFieldToMerge: Field): Info {
        return mergeTitle(titleFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeTitle(titleToMerge: String?): Info {
        return if (titleToMerge == null) {
            this
        } else {
            val oldTitle = _title.orNull
            if (oldTitle == null) {
                setTitleField(Field(titleToMerge))
            } else {
                // hint:2F684DAC
                setTitle(titleToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setTitle(title: String?): Info {
        return setTitleField(Field(title))
    }

    // hint:D465F782
    fun unsetTitle(): Info {
        return setTitleField(Field.unset())
    }

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

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

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

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

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

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

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

    // hint:A8BC6F23
    fun mergeDescription(descriptionToMerge: String?): Info {
        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?): Info {
        return setDescriptionField(Field(description))
    }

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

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

    ///////////////////////
    //
    // termsOfService
    //
    ///////////////////////

    // hint:3A7F9B2E
    val termsOfService: String?
        get() = _termsOfService.orNull

    // hint:F0C48D71
    fun setTermsOfServiceField(termsOfService: Field): Info {
        return copy(_termsOfService = termsOfService)
    }

    // hint:8E56A4D9
    fun updateTermsOfServiceField(updater: (Field) -> Field): Info {
        return setTermsOfServiceField(updater(_termsOfService))
    }

    // hint:B1D730FC
    fun updateTermsOfService(updater: (String?) -> String?): Info {
        return updateTermsOfServiceField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeTermsOfServiceField(termsOfServiceFieldToMerge: Field): Info {
        return mergeTermsOfService(termsOfServiceFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeTermsOfService(termsOfServiceToMerge: String?): Info {
        return if (termsOfServiceToMerge == null) {
            this
        } else {
            val oldTermsOfService = _termsOfService.orNull
            if (oldTermsOfService == null) {
                setTermsOfServiceField(Field(termsOfServiceToMerge))
            } else {
                // hint:2F684DAC
                setTermsOfService(termsOfServiceToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setTermsOfService(termsOfService: String?): Info {
        return setTermsOfServiceField(Field(termsOfService))
    }

    // hint:D465F782
    fun unsetTermsOfService(): Info {
        return setTermsOfServiceField(Field.unset())
    }

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

    ///////////////////////
    //
    // contact
    //
    ///////////////////////

    // hint:3A7F9B2E
    val contact: Contact?
        get() = _contact.orNull

    // hint:F0C48D71
    fun setContactField(contact: Field): Info {
        return copy(_contact = contact)
    }

    // hint:8E56A4D9
    fun updateContactField(updater: (Field) -> Field): Info {
        return setContactField(updater(_contact))
    }

    // hint:B1D730FC
    fun updateContact(updater: (Contact?) -> Contact?): Info {
        return updateContactField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeContactField(contactFieldToMerge: Field): Info {
        return mergeContact(contactFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeContact(contactToMerge: Contact?): Info {
        return if (contactToMerge == null) {
            this
        } else {
            val oldContact = _contact.orNull
            if (oldContact == null) {
                setContactField(Field(contactToMerge))
            } else {
                // hint:E91B4F65
                setContact(oldContact.mergeEntity(contactToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setContact(contact: Contact?): Info {
        return setContactField(Field(contact))
    }

    // hint:D465F782
    fun unsetContact(): Info {
        return setContactField(Field.unset())
    }

    // hint:47C9A0F6
    fun addContact(contact: Contact): Info {
        if (this.contact != null) {
            throw IllegalStateException("Field contact of Entity Info is already set to '${this.contact}', refused to add new value '$contact'")
        }
        return setContact(contact)
    }

    ///////////////////////
    //
    // license
    //
    ///////////////////////

    // hint:3A7F9B2E
    val license: License?
        get() = _license.orNull

    // hint:F0C48D71
    fun setLicenseField(license: Field): Info {
        return copy(_license = license)
    }

    // hint:8E56A4D9
    fun updateLicenseField(updater: (Field) -> Field): Info {
        return setLicenseField(updater(_license))
    }

    // hint:B1D730FC
    fun updateLicense(updater: (License?) -> License?): Info {
        return updateLicenseField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeLicenseField(licenseFieldToMerge: Field): Info {
        return mergeLicense(licenseFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeLicense(licenseToMerge: License?): Info {
        return if (licenseToMerge == null) {
            this
        } else {
            val oldLicense = _license.orNull
            if (oldLicense == null) {
                setLicenseField(Field(licenseToMerge))
            } else {
                // hint:E91B4F65
                setLicense(oldLicense.mergeEntity(licenseToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setLicense(license: License?): Info {
        return setLicenseField(Field(license))
    }

    // hint:D465F782
    fun unsetLicense(): Info {
        return setLicenseField(Field.unset())
    }

    // hint:47C9A0F6
    fun addLicense(license: License): Info {
        if (this.license != null) {
            throw IllegalStateException("Field license of Entity Info is already set to '${this.license}', refused to add new value '$license'")
        }
        return setLicense(license)
    }

    ///////////////////////
    //
    // version
    //
    ///////////////////////

    // hint:3A7F9B2E
    val version: String?
        get() = _version.orNull

    // hint:F0C48D71
    fun setVersionField(version: Field): Info {
        return copy(_version = version)
    }

    // hint:8E56A4D9
    fun updateVersionField(updater: (Field) -> Field): Info {
        return setVersionField(updater(_version))
    }

    // hint:B1D730FC
    fun updateVersion(updater: (String?) -> String?): Info {
        return updateVersionField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeVersionField(versionFieldToMerge: Field): Info {
        return mergeVersion(versionFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeVersion(versionToMerge: String?): Info {
        return if (versionToMerge == null) {
            this
        } else {
            val oldVersion = _version.orNull
            if (oldVersion == null) {
                setVersionField(Field(versionToMerge))
            } else {
                // hint:2F684DAC
                setVersion(versionToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setVersion(version: String?): Info {
        return setVersionField(Field(version))
    }

    // hint:D465F782
    fun unsetVersion(): Info {
        return setVersionField(Field.unset())
    }

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

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

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

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

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

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

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

    // hint:A8BC6F23
    fun mergeExtensions(extensionsToMerge: Map?): Info {
        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): Info {
        return setExtensionsField(Field(extensions))
    }

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

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

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

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

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

    // hint:6A81E3FD
    override val entityDescriptor: EntityDescriptor by lazy {
        EntityDescriptor(
            entity = this,
            jsonNode = null,
            map = mapOf(
                "title" to _title,
                "description" to _description,
                "termsOfService" to _termsOfService,
                "contact" to _contact,
                "license" to _license,
                "version" to _version,
            ),
            flatMap = listOf(
                _extensions,
            ),
            flatten = listOf(
            ),
        )
    }

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

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

            is Info ->
                merge(other)

            else ->
                TODO()
        }
    }

    // hint:716BFD54
    fun merge(other: Info?): Info {
        if (other == null) return this
        return this
            .mergeTitleField(other._title)
            .mergeDescriptionField(other._description)
            .mergeTermsOfServiceField(other._termsOfService)
            .mergeContactField(other._contact)
            .mergeLicenseField(other._license)
            .mergeVersionField(other._version)
            .mergeExtensionsField(other._extensions)
    }

    companion object : Parser {

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

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

        // hint:2C0E94A7
        fun parseWrapperWithExtensions(wrapper: Wrapper, extensions: Field>): Info {
            return Info(
                _title = wrapper["title"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _description = wrapper["description"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _termsOfService = wrapper["termsOfService"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _contact = wrapper["contact"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getSingle(Contact::parseEntityOpt)
                        }
                    }
                },
                _license = wrapper["license"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getSingle(License::parseEntityOpt)
                        }
                    }
                },
                _version = wrapper["version"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _extensions = extensions,
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy