mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Refactored version directory names
3.0 and 2.0 do not work, there are multiple versions and anything with a period in it sucks from my point of view, v2 and v3 feel much better from a DX perspective.
This commit is contained in:
96
datamodel/low/v2/parameter.go
Normal file
96
datamodel/low/v2/parameter.go
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
ParametersLabel = "parameters"
|
||||
)
|
||||
|
||||
type Parameter struct {
|
||||
Name low.NodeReference[string]
|
||||
In low.NodeReference[string]
|
||||
Type low.NodeReference[string]
|
||||
Format low.NodeReference[string]
|
||||
Description low.NodeReference[string]
|
||||
Required low.NodeReference[bool]
|
||||
AllowEmptyValue low.NodeReference[bool]
|
||||
Schema low.NodeReference[*base.SchemaProxy]
|
||||
Items low.NodeReference[*Items]
|
||||
CollectionFormat low.NodeReference[string]
|
||||
Default low.NodeReference[any]
|
||||
Maximum low.NodeReference[int]
|
||||
ExclusiveMaximum low.NodeReference[bool]
|
||||
Minimum low.NodeReference[int]
|
||||
ExclusiveMinimum low.NodeReference[bool]
|
||||
MaxLength low.NodeReference[int]
|
||||
MinLength low.NodeReference[int]
|
||||
Pattern low.NodeReference[string]
|
||||
MaxItems low.NodeReference[int]
|
||||
MinItems low.NodeReference[int]
|
||||
UniqueItems low.NodeReference[bool]
|
||||
Enum low.NodeReference[[]low.ValueReference[string]]
|
||||
MultipleOf low.NodeReference[int]
|
||||
Extensions map[low.KeyReference[string]]low.ValueReference[any]
|
||||
}
|
||||
|
||||
func (p *Parameter) FindExtension(ext string) *low.ValueReference[any] {
|
||||
return low.FindItemInMap[any](ext, p.Extensions)
|
||||
}
|
||||
|
||||
func (p *Parameter) Build(root *yaml.Node, idx *index.SpecIndex) error {
|
||||
p.Extensions = low.ExtractExtensions(root)
|
||||
sch, sErr := base.ExtractSchema(root, idx)
|
||||
if sErr != nil {
|
||||
return sErr
|
||||
}
|
||||
if sch != nil {
|
||||
p.Schema = *sch
|
||||
}
|
||||
items, iErr := low.ExtractObject[*Items](ItemsLabel, root, idx)
|
||||
if iErr != nil {
|
||||
return iErr
|
||||
}
|
||||
p.Items = items
|
||||
|
||||
_, ln, vn := utils.FindKeyNodeFull(DefaultLabel, root.Content)
|
||||
if vn != nil {
|
||||
var n map[string]interface{}
|
||||
err := vn.Decode(&n)
|
||||
if err != nil {
|
||||
var k []interface{}
|
||||
err = vn.Decode(&k)
|
||||
if err != nil {
|
||||
var j interface{}
|
||||
_ = vn.Decode(&j)
|
||||
p.Default = low.NodeReference[any]{
|
||||
Value: j,
|
||||
KeyNode: ln,
|
||||
ValueNode: vn,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
p.Default = low.NodeReference[any]{
|
||||
Value: k,
|
||||
KeyNode: ln,
|
||||
ValueNode: vn,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
p.Default = low.NodeReference[any]{
|
||||
Value: n,
|
||||
KeyNode: ln,
|
||||
ValueNode: vn,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user