Building out highlevel model

bit by bit, step by step.
This commit is contained in:
Dave Shanley
2022-08-19 10:01:16 -04:00
parent 0bd119f152
commit 0c2c008902
19 changed files with 376 additions and 18 deletions

View File

@@ -29,6 +29,16 @@ func BenchmarkNewDocument(b *testing.B) {
}
}
func TestNewDocument_Extensions(t *testing.T) {
h := NewDocument(doc)
assert.Equal(t, "darkside", h.Extensions["x-something-something"])
}
func TestNewDocument_ExternalDocs(t *testing.T) {
h := NewDocument(doc)
assert.Equal(t, "https://pb33f.io", h.ExternalDocs.URL)
}
func TestNewDocument_Info(t *testing.T) {
highDoc := NewDocument(doc)
assert.Equal(t, "3.0.1", highDoc.Version)
@@ -45,6 +55,18 @@ func TestNewDocument_Info(t *testing.T) {
assert.Equal(t, 1, wentLow.Version.ValueNode.Line)
assert.Equal(t, 3, wentLow.Info.Value.Title.KeyNode.Line)
wentLower := highDoc.Info.Contact.GoLow()
assert.Equal(t, 8, wentLower.Name.ValueNode.Line)
assert.Equal(t, 11, wentLower.Name.ValueNode.Column)
wentLowAgain := highDoc.Info.GoLow()
assert.Equal(t, 3, wentLowAgain.Title.ValueNode.Line)
assert.Equal(t, 10, wentLowAgain.Title.ValueNode.Column)
wentOnceMore := highDoc.Info.License.GoLow()
assert.Equal(t, 12, wentOnceMore.Name.ValueNode.Line)
assert.Equal(t, 11, wentOnceMore.Name.ValueNode.Column)
}
func TestNewDocument_Servers(t *testing.T) {
@@ -67,10 +89,45 @@ func TestNewDocument_Servers(t *testing.T) {
assert.Equal(t, 5, wentLow.Servers.Value[0].Value.Description.KeyNode.Column)
assert.Equal(t, 45, wentLow.Servers.Value[0].Value.Description.ValueNode.Line)
assert.Equal(t, 18, wentLow.Servers.Value[0].Value.Description.ValueNode.Column)
// holy shit! the perfect Golang OpenAPI Model! high and low! fuck yeah!
wentLower := h.Servers[0].GoLow()
assert.Equal(t, 45, wentLower.Description.ValueNode.Line)
assert.Equal(t, 18, wentLower.Description.ValueNode.Column)
wentLowest := h.Servers[0].Variables["scheme"].GoLow()
assert.Equal(t, 50, wentLowest.Description.ValueNode.Line)
assert.Equal(t, 22, wentLowest.Description.ValueNode.Column)
}
func TestNewDocument_Tags(t *testing.T) {
h := NewDocument(doc)
assert.Len(t, h.Tags, 2)
assert.Equal(t, "Burgers", h.Tags[0].Name)
assert.Equal(t, "All kinds of yummy burgers.", h.Tags[0].Description)
assert.Equal(t, "Find out more", h.Tags[0].ExternalDocs.Description)
assert.Equal(t, "https://pb33f.io", h.Tags[0].ExternalDocs.URL)
assert.Equal(t, "somethingSpecial", h.Tags[0].Extensions["x-internal-ting"])
assert.Equal(t, int64(1), h.Tags[0].Extensions["x-internal-tong"])
assert.Equal(t, 1.2, h.Tags[0].Extensions["x-internal-tang"])
assert.True(t, h.Tags[0].Extensions["x-internal-tung"].(bool))
wentLow := h.Tags[1].GoLow()
assert.Equal(t, 39, wentLow.Description.KeyNode.Line)
assert.Equal(t, 5, wentLow.Description.KeyNode.Column)
wentLower := h.Tags[0].ExternalDocs.GoLow()
assert.Equal(t, 23, wentLower.Description.ValueNode.Line)
assert.Equal(t, 20, wentLower.Description.ValueNode.Column)
}
func TestNewDocument_Components(t *testing.T) {
h := NewDocument(doc)
assert.Len(t, h.Components.Links, 2)
assert.Equal(t, "locateBurger", h.Components.Links["LocateBurger"].OperationId)
assert.Equal(t, "$response.body#/id", h.Components.Links["LocateBurger"].Parameters["burgerId"])
assert.Len(t, h.Components.Callbacks, 1)
//assert.Equal(t, "Callback payload",
// h.Components.Callbacks["BurgerCallback"].Expression["{$request.query.queryUrl}"].Post.RequestBody.Description)
}