mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
lookups are performed inline now. keeps things simpler, however it has a performance knock, so it's time to refine async building were possible.
37 lines
977 B
Go
37 lines
977 B
Go
package v3
|
|
|
|
import (
|
|
"github.com/pb33f/libopenapi/datamodel/low"
|
|
"github.com/pb33f/libopenapi/index"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type RequestBody struct {
|
|
Description low.NodeReference[string]
|
|
Content low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*MediaType]]
|
|
Required low.NodeReference[bool]
|
|
Extensions map[low.KeyReference[string]]low.ValueReference[any]
|
|
}
|
|
|
|
func (rb *RequestBody) FindContent(cType string) *low.ValueReference[*MediaType] {
|
|
return FindItemInMap[*MediaType](cType, rb.Content.Value)
|
|
}
|
|
|
|
func (rb *RequestBody) Build(root *yaml.Node, idx *index.SpecIndex) error {
|
|
rb.Extensions = ExtractExtensions(root)
|
|
|
|
// handle content, if set.
|
|
con, cL, cN, cErr := ExtractMapFlat[*MediaType](ContentLabel, root, idx)
|
|
if cErr != nil {
|
|
return cErr
|
|
}
|
|
if con != nil {
|
|
rb.Content = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*MediaType]]{
|
|
Value: con,
|
|
KeyNode: cL,
|
|
ValueNode: cN,
|
|
}
|
|
}
|
|
return nil
|
|
}
|