mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 04:20:24 +00:00
This is a large update, I realized that extensions are not being hashed correctly, and because I have the same code everywhere, it means running back through the stack and cleaning up the invalid code that will break if multiple extensions are used in different positions in the raw spec. At the same time, I realized that the v2 model has the same primitive/enum issues that are part cleaned up in v3. This is a breaking changhe because enums are now []any and not []string, as well as primitives for bool, int etc are all pointers now instead of the copied values. This will break any consumers.
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v2
|
|
|
|
import (
|
|
low "github.com/pb33f/libopenapi/datamodel/low/v2"
|
|
)
|
|
|
|
// Items is a high-level representation of a Swagger / OpenAPI 2 Items object, backed by a low level one.
|
|
// Items is a limited subset of JSON-Schema's items object. It is used by parameter definitions that are not
|
|
// located in "body"
|
|
// - https://swagger.io/specification/v2/#itemsObject
|
|
type Items struct {
|
|
Type string
|
|
Format string
|
|
CollectionFormat string
|
|
Items *Items
|
|
Default any
|
|
Maximum int
|
|
ExclusiveMaximum bool
|
|
Minimum int
|
|
ExclusiveMinimum bool
|
|
MaxLength int
|
|
MinLength int
|
|
Pattern string
|
|
MaxItems int
|
|
MinItems int
|
|
UniqueItems bool
|
|
Enum []any
|
|
MultipleOf int
|
|
low *low.Items
|
|
}
|
|
|
|
// NewItems creates a new high-level Items instance from a low-level one.
|
|
func NewItems(items *low.Items) *Items {
|
|
i := new(Items)
|
|
i.low = items
|
|
if !items.Type.IsEmpty() {
|
|
i.Type = items.Type.Value
|
|
}
|
|
if !items.Format.IsEmpty() {
|
|
i.Format = items.Format.Value
|
|
}
|
|
if !items.Items.IsEmpty() {
|
|
i.Items = NewItems(items.Items.Value)
|
|
}
|
|
if !items.CollectionFormat.IsEmpty() {
|
|
i.CollectionFormat = items.CollectionFormat.Value
|
|
}
|
|
if !items.Default.IsEmpty() {
|
|
i.Default = items.Default.Value
|
|
}
|
|
if !items.Maximum.IsEmpty() {
|
|
i.Maximum = items.Maximum.Value
|
|
}
|
|
if !items.ExclusiveMaximum.IsEmpty() {
|
|
i.ExclusiveMaximum = items.ExclusiveMaximum.Value
|
|
}
|
|
if !items.Minimum.IsEmpty() {
|
|
i.Minimum = items.Minimum.Value
|
|
}
|
|
if !items.ExclusiveMinimum.IsEmpty() {
|
|
i.ExclusiveMinimum = items.ExclusiveMinimum.Value
|
|
}
|
|
if !items.MaxLength.IsEmpty() {
|
|
i.MaxLength = items.MaxLength.Value
|
|
}
|
|
if !items.MinLength.IsEmpty() {
|
|
i.MinLength = items.MinLength.Value
|
|
}
|
|
if !items.Pattern.IsEmpty() {
|
|
i.Pattern = items.Pattern.Value
|
|
}
|
|
if !items.MinItems.IsEmpty() {
|
|
i.MinItems = items.MinItems.Value
|
|
}
|
|
if !items.MaxItems.IsEmpty() {
|
|
i.MaxItems = items.MaxItems.Value
|
|
}
|
|
if !items.UniqueItems.IsEmpty() {
|
|
i.UniqueItems = items.UniqueItems.Value
|
|
}
|
|
if !items.Enum.IsEmpty() {
|
|
var enums []any
|
|
for e := range items.Enum.Value {
|
|
enums = append(enums, items.Enum.Value[e].Value)
|
|
}
|
|
i.Enum = enums
|
|
}
|
|
if !items.MultipleOf.IsEmpty() {
|
|
i.MultipleOf = items.MultipleOf.Value
|
|
}
|
|
return i
|
|
}
|
|
|
|
// GoLow returns the low-level Items object that was used to create the high-level one.
|
|
func (i *Items) GoLow() *low.Items {
|
|
return i.low
|
|
}
|