julia-server.partial_model_oneof.mustache Maven / Gradle / Ivy
{{#oneOf}}{{#-first}}
@doc raw"""{{name}}{{#description}}
{{description}}{{/description}}
{{classname}}(; value=nothing)
"""
mutable struct {{classname}} <: OpenAPI.OneOfAPIModel
value::Any # Union{ {{/-first}}{{/oneOf}}{{#oneOf}}{{^-first}}, {{/-first}}{{{.}}}{{/oneOf}}{{#oneOf}}{{#-last}} }
{{classname}}() = new()
{{classname}}(value) = new(value)
end # type {{classname}}{{/-last}}{{/oneOf}}
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}}{{#oneOf}}{{#-first}}if{{/-first}}{{^-first}}elseif{{/-first}} discriminator == "{{.}}"
return eval(Base.Meta.parse("{{.}}"))
{{#-last}}end{{/-last}}{{/oneOf}}{{/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