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

de.lancom.openapi.entity.RawExtension.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.JsonNode
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 = RawExtension.Companion.Serializer::class)
@JsonDeserialize(using = RawExtension.Companion.Deserializer::class)
data class RawExtension(
    val _jsonNode: Field = Field.unset(),
) : Extension {

    ///////////////////////
    //
    // jsonNode
    //
    ///////////////////////

    // hint:3A7F9B2E
    val jsonNode: JsonNode
        get() = _jsonNode.getOrError()

    // hint:F0C48D71
    fun setJsonNodeField(jsonNode: Field): RawExtension {
        return copy(_jsonNode = jsonNode)
    }

    // hint:8E56A4D9
    fun updateJsonNodeField(updater: (Field) -> Field): RawExtension {
        return setJsonNodeField(updater(_jsonNode))
    }

    // hint:B1D730FC
    fun updateJsonNode(updater: (JsonNode) -> JsonNode): RawExtension {
        return updateJsonNodeField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeJsonNodeField(jsonNodeFieldToMerge: Field): RawExtension {
        return mergeJsonNode(jsonNodeFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeJsonNode(jsonNodeToMerge: JsonNode?): RawExtension {
        return if (jsonNodeToMerge == null) {
            this
        } else {
            val oldJsonNode = _jsonNode.orNull
            if (oldJsonNode == null) {
                setJsonNodeField(Field(jsonNodeToMerge))
            } else {
                // hint:2F684DAC
                setJsonNode(jsonNodeToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setJsonNode(jsonNode: JsonNode): RawExtension {
        return setJsonNodeField(Field(jsonNode))
    }

    // hint:D465F782
    fun unsetJsonNode(): RawExtension {
        return setJsonNodeField(Field.unset())
    }

    // hint:47C9A0F6
    fun addJsonNode(jsonNode: JsonNode): RawExtension {
        return setJsonNode(jsonNode)
    }

    // hint:6A81E3FD
    override val entityDescriptor: EntityDescriptor by lazy {
        EntityDescriptor(
            entity = this,
            jsonNode = _jsonNode,
            map = mapOf(
            ),
            flatMap = listOf(
            ),
            flatten = listOf(
            ),
        )
    }

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

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

            is RawExtension ->
                merge(other)

            else ->
                TODO()
        }
    }

    // hint:716BFD54
    fun merge(other: Extension?): RawExtension {
        if (other == null) return this
        if (other !is RawExtension) TODO()
        return this
            .mergeJsonNodeField(other._jsonNode)
    }

    companion object : JsonEntityFactory {

        class Serializer : EntitySerializer(Extension::class.java, RawExtension)
        class Deserializer : EntityDeserializer(Extension::class.java, RawExtension)

        // hint:5F72B6D8
        override fun parseWrapper(wrapper: Wrapper): Extension {
            return RawExtension(
                _jsonNode = wrapper.jsonNodeFieldOrUnsetIfEmpty,
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy