mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 04:20:14 +00:00
first level testing for rending v3 model in place.
Now onto some hardening tests, lets re-render each spec after reading to check for failures.
This commit is contained in:
@@ -4,10 +4,7 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -159,7 +156,7 @@ func TestNewDocument_Components_Links(t *testing.T) {
|
||||
assert.Equal(t, "$response.body#/id", h.Components.Links["LocateBurger"].Parameters["burgerId"])
|
||||
|
||||
wentLow := h.Components.Links["LocateBurger"].GoLow()
|
||||
assert.Equal(t, 305, wentLow.OperationId.ValueNode.Line)
|
||||
assert.Equal(t, 310, wentLow.OperationId.ValueNode.Line)
|
||||
assert.Equal(t, 20, wentLow.OperationId.ValueNode.Column)
|
||||
}
|
||||
|
||||
@@ -174,7 +171,7 @@ func TestNewDocument_Components_Callbacks(t *testing.T) {
|
||||
)
|
||||
assert.Equal(
|
||||
t,
|
||||
293,
|
||||
298,
|
||||
h.Components.Callbacks["BurgerCallback"].GoLow().FindExpression("{$request.query.queryUrl}").ValueNode.Line,
|
||||
)
|
||||
assert.Equal(
|
||||
@@ -187,7 +184,7 @@ func TestNewDocument_Components_Callbacks(t *testing.T) {
|
||||
|
||||
for k := range h.Components.GoLow().Callbacks.Value {
|
||||
if k.Value == "BurgerCallback" {
|
||||
assert.Equal(t, 290, k.KeyNode.Line)
|
||||
assert.Equal(t, 295, k.KeyNode.Line)
|
||||
assert.Equal(t, 5, k.KeyNode.Column)
|
||||
}
|
||||
}
|
||||
@@ -203,17 +200,17 @@ func TestNewDocument_Components_Schemas(t *testing.T) {
|
||||
a := h.Components.Schemas["Error"]
|
||||
abcd := a.Schema().Properties["message"].Schema().Example
|
||||
assert.Equal(t, "No such burger as 'Big-Whopper'", abcd)
|
||||
assert.Equal(t, 428, goLow.Schemas.KeyNode.Line)
|
||||
assert.Equal(t, 433, goLow.Schemas.KeyNode.Line)
|
||||
assert.Equal(t, 3, goLow.Schemas.KeyNode.Column)
|
||||
assert.Equal(t, 431, a.Schema().GoLow().Description.KeyNode.Line)
|
||||
assert.Equal(t, 436, a.Schema().GoLow().Description.KeyNode.Line)
|
||||
|
||||
b := h.Components.Schemas["Burger"]
|
||||
assert.Len(t, b.Schema().Required, 2)
|
||||
assert.Equal(t, "golden slices of happy fun joy", b.Schema().Properties["fries"].Schema().Description)
|
||||
assert.Equal(t, int64(2), b.Schema().Properties["numPatties"].Schema().Example)
|
||||
assert.Equal(t, 443, goLow.FindSchema("Burger").Value.Schema().Properties.KeyNode.Line)
|
||||
assert.Equal(t, 448, goLow.FindSchema("Burger").Value.Schema().Properties.KeyNode.Line)
|
||||
assert.Equal(t, 7, goLow.FindSchema("Burger").Value.Schema().Properties.KeyNode.Column)
|
||||
assert.Equal(t, 445, b.Schema().GoLow().FindProperty("name").ValueNode.Line)
|
||||
assert.Equal(t, 450, b.Schema().GoLow().FindProperty("name").ValueNode.Line)
|
||||
|
||||
f := h.Components.Schemas["Fries"]
|
||||
assert.Equal(t, "salt", f.Schema().Properties["seasoning"].Schema().Items.A.Schema().Example)
|
||||
@@ -224,12 +221,12 @@ func TestNewDocument_Components_Schemas(t *testing.T) {
|
||||
assert.True(t, d.Schema().AdditionalProperties.(bool))
|
||||
assert.Equal(t, "drinkType", d.Schema().Discriminator.PropertyName)
|
||||
assert.Equal(t, "some value", d.Schema().Discriminator.Mapping["drink"])
|
||||
assert.Equal(t, 511, d.Schema().Discriminator.GoLow().PropertyName.ValueNode.Line)
|
||||
assert.Equal(t, 516, d.Schema().Discriminator.GoLow().PropertyName.ValueNode.Line)
|
||||
assert.Equal(t, 23, d.Schema().Discriminator.GoLow().PropertyName.ValueNode.Column)
|
||||
|
||||
pl := h.Components.Schemas["SomePayload"]
|
||||
assert.Equal(t, "is html programming? yes.", pl.Schema().XML.Name)
|
||||
assert.Equal(t, 518, pl.Schema().XML.GoLow().Name.ValueNode.Line)
|
||||
assert.Equal(t, 523, pl.Schema().XML.GoLow().Name.ValueNode.Line)
|
||||
|
||||
ext := h.Components.Extensions
|
||||
assert.Equal(t, "loud", ext["x-screaming-baby"])
|
||||
@@ -240,7 +237,7 @@ func TestNewDocument_Components_Headers(t *testing.T) {
|
||||
h := NewDocument(lowDoc)
|
||||
assert.Len(t, h.Components.Headers, 1)
|
||||
assert.Equal(t, "this is a header example for UseOil", h.Components.Headers["UseOil"].Description)
|
||||
assert.Equal(t, 318, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 323, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 20, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Column)
|
||||
}
|
||||
|
||||
@@ -249,7 +246,7 @@ func TestNewDocument_Components_RequestBodies(t *testing.T) {
|
||||
h := NewDocument(lowDoc)
|
||||
assert.Len(t, h.Components.RequestBodies, 1)
|
||||
assert.Equal(t, "Give us the new burger!", h.Components.RequestBodies["BurgerRequest"].Description)
|
||||
assert.Equal(t, 323, h.Components.RequestBodies["BurgerRequest"].GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 328, h.Components.RequestBodies["BurgerRequest"].GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 20, h.Components.RequestBodies["BurgerRequest"].GoLow().Description.ValueNode.Column)
|
||||
assert.Len(t, h.Components.RequestBodies["BurgerRequest"].Content["application/json"].Examples, 2)
|
||||
}
|
||||
@@ -259,7 +256,7 @@ func TestNewDocument_Components_Examples(t *testing.T) {
|
||||
h := NewDocument(lowDoc)
|
||||
assert.Len(t, h.Components.Examples, 1)
|
||||
assert.Equal(t, "A juicy two hander sammich", h.Components.Examples["QuarterPounder"].Summary)
|
||||
assert.Equal(t, 341, h.Components.Examples["QuarterPounder"].GoLow().Summary.ValueNode.Line)
|
||||
assert.Equal(t, 346, h.Components.Examples["QuarterPounder"].GoLow().Summary.ValueNode.Line)
|
||||
assert.Equal(t, 16, h.Components.Examples["QuarterPounder"].GoLow().Summary.ValueNode.Column)
|
||||
}
|
||||
|
||||
@@ -269,7 +266,7 @@ func TestNewDocument_Components_Responses(t *testing.T) {
|
||||
assert.Len(t, h.Components.Responses, 1)
|
||||
assert.Equal(t, "all the dressings for a burger.", h.Components.Responses["DressingResponse"].Description)
|
||||
assert.Equal(t, "array", h.Components.Responses["DressingResponse"].Content["application/json"].Schema.Schema().Type[0])
|
||||
assert.Equal(t, 347, h.Components.Responses["DressingResponse"].GoLow().Description.KeyNode.Line)
|
||||
assert.Equal(t, 352, h.Components.Responses["DressingResponse"].GoLow().Description.KeyNode.Line)
|
||||
assert.Equal(t, 7, h.Components.Responses["DressingResponse"].GoLow().Description.KeyNode.Column)
|
||||
}
|
||||
|
||||
@@ -280,26 +277,26 @@ func TestNewDocument_Components_SecuritySchemes(t *testing.T) {
|
||||
|
||||
api := h.Components.SecuritySchemes["APIKeyScheme"]
|
||||
assert.Equal(t, "an apiKey security scheme", api.Description)
|
||||
assert.Equal(t, 359, api.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 364, api.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 20, api.GoLow().Description.ValueNode.Column)
|
||||
|
||||
jwt := h.Components.SecuritySchemes["JWTScheme"]
|
||||
assert.Equal(t, "an JWT security scheme", jwt.Description)
|
||||
assert.Equal(t, 364, jwt.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 369, jwt.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 20, jwt.GoLow().Description.ValueNode.Column)
|
||||
|
||||
oAuth := h.Components.SecuritySchemes["OAuthScheme"]
|
||||
assert.Equal(t, "an oAuth security scheme", oAuth.Description)
|
||||
assert.Equal(t, 370, oAuth.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 375, oAuth.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 20, oAuth.GoLow().Description.ValueNode.Column)
|
||||
assert.Len(t, oAuth.Flows.Implicit.Scopes, 2)
|
||||
assert.Equal(t, "read all burgers", oAuth.Flows.Implicit.Scopes["read:burgers"])
|
||||
assert.Equal(t, "https://pb33f.io/oauth", oAuth.Flows.AuthorizationCode.AuthorizationUrl)
|
||||
|
||||
// check the lowness is low.
|
||||
assert.Equal(t, 375, oAuth.Flows.GoLow().Implicit.Value.Scopes.KeyNode.Line)
|
||||
assert.Equal(t, 380, oAuth.Flows.GoLow().Implicit.Value.Scopes.KeyNode.Line)
|
||||
assert.Equal(t, 11, oAuth.Flows.GoLow().Implicit.Value.Scopes.KeyNode.Column)
|
||||
assert.Equal(t, 375, oAuth.Flows.Implicit.GoLow().Scopes.KeyNode.Line)
|
||||
assert.Equal(t, 380, oAuth.Flows.Implicit.GoLow().Scopes.KeyNode.Line)
|
||||
assert.Equal(t, 11, oAuth.Flows.Implicit.GoLow().Scopes.KeyNode.Column)
|
||||
}
|
||||
|
||||
@@ -309,7 +306,7 @@ func TestNewDocument_Components_Parameters(t *testing.T) {
|
||||
assert.Len(t, h.Components.Parameters, 2)
|
||||
bh := h.Components.Parameters["BurgerHeader"]
|
||||
assert.Equal(t, "burgerHeader", bh.Name)
|
||||
assert.Equal(t, 387, bh.GoLow().Name.KeyNode.Line)
|
||||
assert.Equal(t, 392, bh.GoLow().Name.KeyNode.Line)
|
||||
assert.Len(t, bh.Schema.Schema().Properties, 2)
|
||||
assert.Equal(t, "big-mac", bh.Example)
|
||||
assert.True(t, bh.Required)
|
||||
@@ -319,7 +316,7 @@ func TestNewDocument_Components_Parameters(t *testing.T) {
|
||||
bh.Content["application/json"].Encoding["burgerTheme"].Headers["someHeader"].Description,
|
||||
)
|
||||
assert.Len(t, bh.Content["application/json"].Schema.Schema().Properties, 2)
|
||||
assert.Equal(t, 404, bh.Content["application/json"].Encoding["burgerTheme"].GoLow().ContentType.ValueNode.Line)
|
||||
assert.Equal(t, 409, bh.Content["application/json"].Encoding["burgerTheme"].GoLow().ContentType.ValueNode.Line)
|
||||
}
|
||||
|
||||
func TestNewDocument_Paths(t *testing.T) {
|
||||
@@ -327,6 +324,10 @@ func TestNewDocument_Paths(t *testing.T) {
|
||||
h := NewDocument(lowDoc)
|
||||
assert.Len(t, h.Paths.PathItems, 5)
|
||||
|
||||
testBurgerShop(t, h, true)
|
||||
}
|
||||
|
||||
func testBurgerShop(t *testing.T, h *Document, checkLines bool) {
|
||||
burgersOp := h.Paths.PathItems["/burgers"]
|
||||
|
||||
assert.Len(t, burgersOp.GetOperations(), 1)
|
||||
@@ -337,39 +338,44 @@ func TestNewDocument_Paths(t *testing.T) {
|
||||
assert.Nil(t, burgersOp.Head)
|
||||
assert.Nil(t, burgersOp.Options)
|
||||
assert.Nil(t, burgersOp.Trace)
|
||||
assert.Equal(t, 64, burgersOp.GoLow().Post.KeyNode.Line)
|
||||
|
||||
assert.Equal(t, "createBurger", burgersOp.Post.OperationId)
|
||||
assert.Len(t, burgersOp.Post.Tags, 1)
|
||||
assert.Equal(t, "A new burger for our menu, yummy yum yum.", burgersOp.Post.Description)
|
||||
assert.Equal(t, "Give us the new burger!", burgersOp.Post.RequestBody.Description)
|
||||
assert.Len(t, burgersOp.Post.Responses.Codes, 3)
|
||||
assert.Equal(t, 63, h.Paths.GoLow().FindPath("/burgers").ValueNode.Line)
|
||||
if checkLines {
|
||||
assert.Equal(t, 64, burgersOp.GoLow().Post.KeyNode.Line)
|
||||
assert.Equal(t, 63, h.Paths.GoLow().FindPath("/burgers").ValueNode.Line)
|
||||
}
|
||||
|
||||
okResp := burgersOp.Post.Responses.FindResponseByCode(200)
|
||||
assert.Len(t, okResp.Headers, 1)
|
||||
assert.Equal(t, "A tasty burger for you to eat.", okResp.Description)
|
||||
assert.Equal(t, 69, burgersOp.Post.GoLow().Description.ValueNode.Line)
|
||||
assert.Len(t, okResp.Content["application/json"].Examples, 2)
|
||||
assert.Equal(
|
||||
t,
|
||||
"a cripsy fish sammich filled with ocean goodness.",
|
||||
okResp.Content["application/json"].Examples["filetOFish"].Summary,
|
||||
)
|
||||
assert.Equal(t, 74, burgersOp.Post.Responses.GoLow().FindResponseByCode("200").ValueNode.Line)
|
||||
|
||||
assert.Equal(t, 80, okResp.Content["application/json"].GoLow().Schema.KeyNode.Line)
|
||||
assert.Equal(t, 15, okResp.Content["application/json"].GoLow().Schema.KeyNode.Column)
|
||||
|
||||
assert.Equal(t, 77, okResp.GoLow().Description.KeyNode.Line)
|
||||
assert.Len(t, okResp.Links, 2)
|
||||
assert.Equal(t, "locateBurger", okResp.Links["LocateBurger"].OperationId)
|
||||
assert.Equal(t, 305, okResp.Links["LocateBurger"].GoLow().OperationId.ValueNode.Line)
|
||||
assert.Len(t, burgersOp.Post.Security[0].Requirements, 1)
|
||||
assert.Len(t, burgersOp.Post.Security[0].Requirements["OAuthScheme"], 2)
|
||||
assert.Equal(t, "read:burgers", burgersOp.Post.Security[0].Requirements["OAuthScheme"][0])
|
||||
assert.Equal(t, 118, burgersOp.Post.Security[0].GoLow().Requirements.ValueNode.Line)
|
||||
assert.Len(t, burgersOp.Post.Servers, 1)
|
||||
assert.Equal(t, "https://pb33f.io", burgersOp.Post.Servers[0].URL)
|
||||
|
||||
if checkLines {
|
||||
assert.Equal(t, 69, burgersOp.Post.GoLow().Description.ValueNode.Line)
|
||||
assert.Equal(t, 74, burgersOp.Post.Responses.GoLow().FindResponseByCode("200").ValueNode.Line)
|
||||
assert.Equal(t, 80, okResp.Content["application/json"].GoLow().Schema.KeyNode.Line)
|
||||
assert.Equal(t, 15, okResp.Content["application/json"].GoLow().Schema.KeyNode.Column)
|
||||
assert.Equal(t, 77, okResp.GoLow().Description.KeyNode.Line)
|
||||
assert.Equal(t, 310, okResp.Links["LocateBurger"].GoLow().OperationId.ValueNode.Line)
|
||||
assert.Equal(t, 118, burgersOp.Post.Security[0].GoLow().Requirements.ValueNode.Line)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestStripeAsDoc(t *testing.T) {
|
||||
@@ -405,55 +411,55 @@ func TestAsanaAsDoc(t *testing.T) {
|
||||
assert.Equal(t, 118, len(d.Paths.PathItems))
|
||||
}
|
||||
|
||||
func TestDigitalOceanAsDoc(t *testing.T) {
|
||||
data, _ := ioutil.ReadFile("../../../test_specs/digitalocean.yaml")
|
||||
info, _ := datamodel.ExtractSpecInfo(data)
|
||||
var err []error
|
||||
|
||||
baseURL, _ := url.Parse("https://raw.githubusercontent.com/digitalocean/openapi/main/specification")
|
||||
config := datamodel.DocumentConfiguration{
|
||||
AllowFileReferences: true,
|
||||
AllowRemoteReferences: true,
|
||||
BaseURL: baseURL,
|
||||
}
|
||||
|
||||
lowDoc, err = lowv3.CreateDocumentFromConfig(info, &config)
|
||||
if err != nil {
|
||||
for e := range err {
|
||||
fmt.Println(err[e])
|
||||
}
|
||||
panic("broken something")
|
||||
}
|
||||
d := NewDocument(lowDoc)
|
||||
assert.NotNil(t, d)
|
||||
assert.Equal(t, 183, len(d.Paths.PathItems))
|
||||
|
||||
}
|
||||
|
||||
func TestDigitalOceanAsDocFromSHA(t *testing.T) {
|
||||
data, _ := ioutil.ReadFile("../../../test_specs/digitalocean.yaml")
|
||||
info, _ := datamodel.ExtractSpecInfo(data)
|
||||
var err []error
|
||||
|
||||
baseURL, _ := url.Parse("https://raw.githubusercontent.com/digitalocean/openapi/82e1d558e15a59edc1d47d2c5544e7138f5b3cbf/specification")
|
||||
config := datamodel.DocumentConfiguration{
|
||||
AllowFileReferences: true,
|
||||
AllowRemoteReferences: true,
|
||||
BaseURL: baseURL,
|
||||
}
|
||||
|
||||
lowDoc, err = lowv3.CreateDocumentFromConfig(info, &config)
|
||||
if err != nil {
|
||||
for e := range err {
|
||||
fmt.Println(err[e])
|
||||
}
|
||||
panic("broken something")
|
||||
}
|
||||
d := NewDocument(lowDoc)
|
||||
assert.NotNil(t, d)
|
||||
assert.Equal(t, 183, len(d.Paths.PathItems))
|
||||
|
||||
}
|
||||
//func TestDigitalOceanAsDoc(t *testing.T) {
|
||||
// data, _ := ioutil.ReadFile("../../../test_specs/digitalocean.yaml")
|
||||
// info, _ := datamodel.ExtractSpecInfo(data)
|
||||
// var err []error
|
||||
//
|
||||
// baseURL, _ := url.Parse("https://raw.githubusercontent.com/digitalocean/openapi/main/specification")
|
||||
// config := datamodel.DocumentConfiguration{
|
||||
// AllowFileReferences: true,
|
||||
// AllowRemoteReferences: true,
|
||||
// BaseURL: baseURL,
|
||||
// }
|
||||
//
|
||||
// lowDoc, err = lowv3.CreateDocumentFromConfig(info, &config)
|
||||
// if err != nil {
|
||||
// for e := range err {
|
||||
// fmt.Println(err[e])
|
||||
// }
|
||||
// panic("broken something")
|
||||
// }
|
||||
// d := NewDocument(lowDoc)
|
||||
// assert.NotNil(t, d)
|
||||
// assert.Equal(t, 183, len(d.Paths.PathItems))
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func TestDigitalOceanAsDocFromSHA(t *testing.T) {
|
||||
// data, _ := ioutil.ReadFile("../../../test_specs/digitalocean.yaml")
|
||||
// info, _ := datamodel.ExtractSpecInfo(data)
|
||||
// var err []error
|
||||
//
|
||||
// baseURL, _ := url.Parse("https://raw.githubusercontent.com/digitalocean/openapi/82e1d558e15a59edc1d47d2c5544e7138f5b3cbf/specification")
|
||||
// config := datamodel.DocumentConfiguration{
|
||||
// AllowFileReferences: true,
|
||||
// AllowRemoteReferences: true,
|
||||
// BaseURL: baseURL,
|
||||
// }
|
||||
//
|
||||
// lowDoc, err = lowv3.CreateDocumentFromConfig(info, &config)
|
||||
// if err != nil {
|
||||
// for e := range err {
|
||||
// fmt.Println(err[e])
|
||||
// }
|
||||
// panic("broken something")
|
||||
// }
|
||||
// d := NewDocument(lowDoc)
|
||||
// assert.NotNil(t, d)
|
||||
// assert.Equal(t, 183, len(d.Paths.PathItems))
|
||||
//
|
||||
//}
|
||||
|
||||
func TestPetstoreAsDoc(t *testing.T) {
|
||||
data, _ := ioutil.ReadFile("../../../test_specs/petstorev3.json")
|
||||
@@ -488,19 +494,12 @@ func TestDocument_MarshalYAML(t *testing.T) {
|
||||
// render the document to YAML
|
||||
r, _ := h.Render()
|
||||
|
||||
os.WriteFile("rendered.yaml", r, 0644)
|
||||
|
||||
// re-parse the document
|
||||
|
||||
//TODO: pick up in the morning here, trying to figure out why headers are being rendered (UseOil)
|
||||
|
||||
info, _ := datamodel.ExtractSpecInfo(r)
|
||||
lDoc, e := lowv3.CreateDocumentFromConfig(info, datamodel.NewOpenDocumentConfiguration())
|
||||
assert.Nil(t, e)
|
||||
|
||||
highDoc := NewDocument(lDoc)
|
||||
assert.Equal(t, "3.1.0", highDoc.Version)
|
||||
assert.Len(t, highDoc.Paths.PathItems, 5)
|
||||
testBurgerShop(t, highDoc, false)
|
||||
|
||||
}
|
||||
|
||||
@@ -586,38 +585,37 @@ func TestDocument_MarshalYAML_TestParamRefs(t *testing.T) {
|
||||
// create a new document
|
||||
yml := `openapi: 3.1.0
|
||||
paths:
|
||||
"/burgers/{burgerId}":
|
||||
get:
|
||||
operationId: locateBurger
|
||||
tags:
|
||||
- Burgers
|
||||
summary: Search a burger by ID - returns the burger with that identifier
|
||||
description: Look up a tasty burger take it and enjoy it
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/BurgerId"
|
||||
- $ref: "#/components/parameters/BurgerHeader"
|
||||
/burgers/{burgerId}:
|
||||
get:
|
||||
operationId: locateBurger
|
||||
tags:
|
||||
- Burgers
|
||||
summary: Search a burger by ID - returns the burger with that identifier
|
||||
description: Look up a tasty burger take it and enjoy it
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/BurgerId'
|
||||
- $ref: '#/components/parameters/BurgerHeader'
|
||||
components:
|
||||
parameters:
|
||||
BurgerHeader:
|
||||
in: header
|
||||
name: burgerHeader
|
||||
schema:
|
||||
properties:
|
||||
burgerTheme:
|
||||
type: string
|
||||
description: something about a theme goes in here?
|
||||
burgerTime:
|
||||
type: number
|
||||
description: number of burgers ordered so far this year.
|
||||
BurgerId:
|
||||
in: path
|
||||
name: burgerId
|
||||
schema:
|
||||
type: string
|
||||
example: big-mac
|
||||
description: the name of the burger. use this to order your tasty burger
|
||||
required: true
|
||||
`
|
||||
parameters:
|
||||
BurgerHeader:
|
||||
in: header
|
||||
name: burgerHeader
|
||||
schema:
|
||||
properties:
|
||||
burgerTheme:
|
||||
type: string
|
||||
description: something about a theme goes in here?
|
||||
burgerTime:
|
||||
type: number
|
||||
description: number of burgers ordered so far this year.
|
||||
BurgerId:
|
||||
in: path
|
||||
name: burgerId
|
||||
schema:
|
||||
type: string
|
||||
example: big-mac
|
||||
description: the name of the burger. use this to order your tasty burger
|
||||
required: true`
|
||||
|
||||
info, _ := datamodel.ExtractSpecInfo([]byte(yml))
|
||||
var err []error
|
||||
@@ -635,5 +633,48 @@ components:
|
||||
assert.Equal(t, yml, strings.TrimSpace(string(r)))
|
||||
}
|
||||
|
||||
func TestDocument_MarshalYAML_TestModifySchemas(t *testing.T) {
|
||||
|
||||
// create a new document
|
||||
yml := `openapi: 3.1.0
|
||||
components:
|
||||
schemas:
|
||||
BurgerHeader:
|
||||
properties:
|
||||
burgerTheme:
|
||||
type: string
|
||||
description: something about a theme goes in here?
|
||||
`
|
||||
|
||||
info, _ := datamodel.ExtractSpecInfo([]byte(yml))
|
||||
var err []error
|
||||
lowDoc, err = lowv3.CreateDocumentFromConfig(info, &datamodel.DocumentConfiguration{
|
||||
AllowFileReferences: true,
|
||||
AllowRemoteReferences: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic("broken something")
|
||||
}
|
||||
h := NewDocument(lowDoc)
|
||||
|
||||
// mutate the schema
|
||||
g := h.Components.Schemas["BurgerHeader"].Schema()
|
||||
ds := g.Properties["burgerTheme"].Schema()
|
||||
ds.Description = "changed"
|
||||
|
||||
// render the document to YAML and it should be identical.
|
||||
r, _ := h.Render()
|
||||
|
||||
desired := `openapi: 3.1.0
|
||||
components:
|
||||
schemas:
|
||||
BurgerHeader:
|
||||
properties:
|
||||
burgerTheme:
|
||||
type: string
|
||||
description: changed`
|
||||
|
||||
assert.Equal(t, desired, strings.TrimSpace(string(r)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user