mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 04:20:24 +00:00
added tests for v3 request_body
after a few drinks, not so easy.
This commit is contained in:
@@ -223,7 +223,7 @@ func TestPaths_Build_BadRef(t *testing.T) {
|
||||
|
||||
func TestPathItem_Build_GoodRef(t *testing.T) {
|
||||
|
||||
// this is kinda nuts, it's also not illegal, however the mechanics still need to work.
|
||||
// this is kinda nuts, it's also not illegal, however the mechanics still need to work.bfes
|
||||
yml := `"/some/path":
|
||||
description: this is some path
|
||||
get:
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
@@ -13,6 +16,10 @@ type RequestBody struct {
|
||||
Extensions map[low.KeyReference[string]]low.ValueReference[any]
|
||||
}
|
||||
|
||||
func (rb *RequestBody) FindExtension(ext string) *low.ValueReference[any] {
|
||||
return low.FindItemInMap[any](ext, rb.Extensions)
|
||||
}
|
||||
|
||||
func (rb *RequestBody) FindContent(cType string) *low.ValueReference[*MediaType] {
|
||||
return low.FindItemInMap[*MediaType](cType, rb.Content.Value)
|
||||
}
|
||||
|
||||
55
datamodel/low/3.0/request_body_test.go
Normal file
55
datamodel/low/3.0/request_body_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRequestBody_Build(t *testing.T) {
|
||||
|
||||
yml := `description: a nice request
|
||||
required: true
|
||||
content:
|
||||
fresh/fish:
|
||||
example: nice.
|
||||
x-requesto: presto`
|
||||
|
||||
var idxNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
||||
idx := index.NewSpecIndex(&idxNode)
|
||||
|
||||
var n RequestBody
|
||||
err := low.BuildModel(&idxNode, &n)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = n.Build(idxNode.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "a nice request", n.Description.Value)
|
||||
assert.True(t, n.Required.Value)
|
||||
assert.Equal(t, "nice.", n.FindContent("fresh/fish").Value.Example.Value)
|
||||
assert.Equal(t, "presto", n.FindExtension("x-requesto").Value)
|
||||
|
||||
}
|
||||
|
||||
func TestRequestBody_Fail(t *testing.T) {
|
||||
|
||||
yml := `content:
|
||||
$ref: #illegal`
|
||||
|
||||
var idxNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
||||
idx := index.NewSpecIndex(&idxNode)
|
||||
|
||||
var n RequestBody
|
||||
err := low.BuildModel(&idxNode, &n)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = n.Build(idxNode.Content[0], idx)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user