julia-server.partial_model_anyof.mustache Maven / Gradle / Ivy
{{#anyOf}}{{#-first}}
@doc raw"""{{name}}{{#description}}
{{description}}{{/description}}
{{classname}}(; value=nothing)
"""
mutable struct {{classname}} <: OpenAPI.AnyOfAPIModel
value::Any # Union{ {{/-first}}{{/anyOf}}{{#anyOf}}{{^-first}}, {{/-first}}{{{.}}}{{/anyOf}}{{#anyOf}}{{#-last}} }
{{classname}}() = new()
{{classname}}(value) = new(value)
end # type {{classname}}{{/-last}}{{/anyOf}}
function OpenAPI.property_type(::Type{ {{classname}} }, name::Symbol, json::Dict{String,Any})
{{#discriminator}}discriminator = json["{{propertyName}}"]
{{#hasDiscriminatorWithNonEmptyMapping}}{{#mappedModels}}{{#-first}}if{{/-first}}{{^-first}}elseif{{/-first}} discriminator == "{{mappingName}}"
return eval(Base.Meta.parse("{{modelName}}"))
{{#-last}}end{{/-last}}{{/mappedModels}}{{/hasDiscriminatorWithNonEmptyMapping}}{{^hasDiscriminatorWithNonEmptyMapping}}{{#anyOf}}{{#-first}}if{{/-first}}{{^-first}}elseif{{/-first}} discriminator == "{{.}}"
return eval(Base.Meta.parse("{{.}}"))
{{#-last}}end{{/-last}}{{/anyOf}}{{/hasDiscriminatorWithNonEmptyMapping}}
throw(OpenAPI.ValidationException("Invalid discriminator value: $discriminator for {{classname}}")){{/discriminator}}{{^discriminator}}
# no discriminator specified, can't determine the exact type
return fieldtype({{classname}}, name){{/discriminator}}
end