mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
Cleaning up some coverage and a few bits.
This commit is contained in:
@@ -6,6 +6,8 @@ package v3
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pb33f/libopenapi/datamodel"
|
"github.com/pb33f/libopenapi/datamodel"
|
||||||
|
v2 "github.com/pb33f/libopenapi/datamodel/high/v2"
|
||||||
|
lowv2 "github.com/pb33f/libopenapi/datamodel/low/v2"
|
||||||
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
|
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -364,7 +366,18 @@ func TestStripeAsDoc(t *testing.T) {
|
|||||||
lowDoc, err = lowv3.CreateDocument(info)
|
lowDoc, err = lowv3.CreateDocument(info)
|
||||||
assert.Len(t, err, 23)
|
assert.Len(t, err, 23)
|
||||||
d := NewDocument(lowDoc)
|
d := NewDocument(lowDoc)
|
||||||
fmt.Println(d)
|
assert.NotNil(t, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestK8sAsDoc(t *testing.T) {
|
||||||
|
data, _ := ioutil.ReadFile("../../../test_specs/k8s.json")
|
||||||
|
info, _ := datamodel.ExtractSpecInfo(data)
|
||||||
|
var err []error
|
||||||
|
lowSwag, err := lowv2.CreateDocument(info)
|
||||||
|
d := v2.NewSwaggerDocument(lowSwag)
|
||||||
|
assert.Len(t, err, 1)
|
||||||
|
assert.NotNil(t, d)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAsanaAsDoc(t *testing.T) {
|
func TestAsanaAsDoc(t *testing.T) {
|
||||||
|
|||||||
@@ -323,8 +323,8 @@ func TestSpecIndex_BurgerShopMixedRef(t *testing.T) {
|
|||||||
|
|
||||||
index := NewSpecIndex(&rootNode)
|
index := NewSpecIndex(&rootNode)
|
||||||
|
|
||||||
assert.Len(t, index.allRefs, 4)
|
assert.Len(t, index.allRefs, 5)
|
||||||
assert.Len(t, index.allMappedRefs, 4)
|
assert.Len(t, index.allMappedRefs, 5)
|
||||||
assert.Equal(t, 5, index.GetPathCount())
|
assert.Equal(t, 5, index.GetPathCount())
|
||||||
assert.Equal(t, 5, index.GetOperationCount())
|
assert.Equal(t, 5, index.GetOperationCount())
|
||||||
assert.Equal(t, 1, index.GetComponentSchemaCount())
|
assert.Equal(t, 1, index.GetComponentSchemaCount())
|
||||||
@@ -631,10 +631,12 @@ func TestSpecIndex_parameterReferencesHavePaths(t *testing.T) {
|
|||||||
yml := `paths:
|
yml := `paths:
|
||||||
/:
|
/:
|
||||||
parameters:
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/param1'
|
||||||
- $ref: '#/components/parameters/param1'
|
- $ref: '#/components/parameters/param1'
|
||||||
- $ref: 'paramour.yaml#/components/parameters/param3'
|
- $ref: 'paramour.yaml#/components/parameters/param3'
|
||||||
get:
|
get:
|
||||||
parameters:
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/param2'
|
||||||
- $ref: '#/components/parameters/param2'
|
- $ref: '#/components/parameters/param2'
|
||||||
- name: test
|
- name: test
|
||||||
in: query
|
in: query
|
||||||
@@ -674,7 +676,7 @@ components:
|
|||||||
assert.Equal(t, "$.components.parameters.param2", params["/"]["get"]["#/components/parameters/param2"].Path)
|
assert.Equal(t, "$.components.parameters.param2", params["/"]["get"]["#/components/parameters/param2"].Path)
|
||||||
}
|
}
|
||||||
if assert.Contains(t, params["/"]["get"], "test") {
|
if assert.Contains(t, params["/"]["get"], "test") {
|
||||||
assert.Equal(t, "$.paths./.get.parameters[1]", params["/"]["get"]["test"].Path)
|
assert.Equal(t, "$.paths./.get.parameters[2]", params["/"]["get"]["test"].Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ func TestResolver_ResolveComponents_MixedRef(t *testing.T) {
|
|||||||
assert.NotNil(t, resolver)
|
assert.NotNil(t, resolver)
|
||||||
|
|
||||||
circ := resolver.Resolve()
|
circ := resolver.Resolve()
|
||||||
assert.Len(t, circ, 2)
|
assert.Len(t, circ, 10)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,12 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/Error'
|
||||||
|
"400":
|
||||||
|
description: Unexpected error. Sorry.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: 'https://raw.githubusercontent.com/daveshanley/vacuum/main/model/test_files/burgershop.openapi.yaml'
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
Error:
|
Error:
|
||||||
|
|||||||
9
test_specs/single-definition.yaml
Normal file
9
test_specs/single-definition.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Thing:
|
||||||
|
type: object
|
||||||
|
description: A thing that does nothing.
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
description: I am pointless.
|
||||||
@@ -493,32 +493,21 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
|
|||||||
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", segs[i-1], segs[i])
|
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", segs[i-1], segs[i])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cleaned = append(cleaned, fmt.Sprintf("%s%s", segs[i], segs[i]))
|
|
||||||
continue
|
|
||||||
} else {
|
} else {
|
||||||
intVal, err := strconv.ParseInt(segs[i], 10, 32)
|
intVal, err := strconv.ParseInt(segs[i], 10, 32)
|
||||||
if err == nil && intVal <= 99 {
|
if err == nil && intVal <= 99 {
|
||||||
segs[i] = fmt.Sprintf("[%d]", intVal)
|
segs[i] = fmt.Sprintf("[%d]", intVal)
|
||||||
if i < len(cleaned) {
|
|
||||||
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", segs[i-1], segs[i])
|
|
||||||
} else {
|
|
||||||
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", cleaned[len(cleaned)-1], segs[i])
|
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", cleaned[len(cleaned)-1], segs[i])
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err == nil && intVal > 99 {
|
if err == nil && intVal > 99 {
|
||||||
segs[i] = fmt.Sprintf("['%d']", intVal)
|
segs[i] = fmt.Sprintf("['%d']", intVal)
|
||||||
if i < len(cleaned) {
|
|
||||||
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", segs[i-1], segs[i])
|
|
||||||
} else {
|
|
||||||
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", cleaned[len(cleaned)-1], segs[i])
|
cleaned[len(cleaned)-1] = fmt.Sprintf("%s%s", cleaned[len(cleaned)-1], segs[i])
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cleaned = append(cleaned, segs[i])
|
cleaned = append(cleaned, segs[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := strconv.ParseInt(name, 10, 32)
|
_, err := strconv.ParseInt(name, 10, 32)
|
||||||
var replaced string
|
var replaced string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -621,11 +621,17 @@ func TestConvertComponentIdIntoFriendlyPathSearch_Crazy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertComponentIdIntoFriendlyPathSearch_Simple(t *testing.T) {
|
func TestConvertComponentIdIntoFriendlyPathSearch_Simple(t *testing.T) {
|
||||||
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#//~1fresh~1pizza/get")
|
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/~1fresh~1pizza/get")
|
||||||
assert.Equal(t, "$.['/fresh/pizza'].get", path)
|
assert.Equal(t, "$['/fresh/pizza'].get", path)
|
||||||
assert.Equal(t, "get", segment)
|
assert.Equal(t, "get", segment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertComponentIdIntoFriendlyPathSearch_Params(t *testing.T) {
|
||||||
|
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/why/0")
|
||||||
|
assert.Equal(t, "$.why[0]", path)
|
||||||
|
assert.Equal(t, "0", segment)
|
||||||
|
}
|
||||||
|
|
||||||
func TestConvertComponentIdIntoFriendlyPathSearch_Crazy_Github(t *testing.T) {
|
func TestConvertComponentIdIntoFriendlyPathSearch_Crazy_Github(t *testing.T) {
|
||||||
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/paths/~1crazy~1ass~1references/get/responses/404/content/application~1xml;%20charset=utf-8/schema")
|
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/paths/~1crazy~1ass~1references/get/responses/404/content/application~1xml;%20charset=utf-8/schema")
|
||||||
assert.Equal(t, "$.paths['/crazy/ass/references'].get.responses['404'].content['application/xml; charset=utf-8'].schema", path)
|
assert.Equal(t, "$.paths['/crazy/ass/references'].get.responses['404'].content['application/xml; charset=utf-8'].schema", path)
|
||||||
@@ -650,6 +656,12 @@ func TestConvertComponentIdIntoFriendlyPathSearch_CrazyShort(t *testing.T) {
|
|||||||
assert.Equal(t, "/crazy/ass/references", segment)
|
assert.Equal(t, "/crazy/ass/references", segment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertComponentIdIntoFriendlyPathSearch_Short(t *testing.T) {
|
||||||
|
segment, path := ConvertComponentIdIntoFriendlyPathSearch("/~1crazy~1ass~1references")
|
||||||
|
assert.Equal(t, "$['/crazy/ass/references']", path)
|
||||||
|
assert.Equal(t, "/crazy/ass/references", segment)
|
||||||
|
}
|
||||||
|
|
||||||
func TestConvertComponentIdIntoFriendlyPathSearch_Array(t *testing.T) {
|
func TestConvertComponentIdIntoFriendlyPathSearch_Array(t *testing.T) {
|
||||||
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/paths/~1crazy~1ass~1references/get/parameters/0")
|
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/paths/~1crazy~1ass~1references/get/parameters/0")
|
||||||
assert.Equal(t, "$.paths['/crazy/ass/references'].get.parameters[0]", path)
|
assert.Equal(t, "$.paths['/crazy/ass/references'].get.parameters[0]", path)
|
||||||
|
|||||||
Reference in New Issue
Block a user