Added item example rendering to schema renderer

Addresses https://github.com/pb33f/wiretap/issues/90
This commit is contained in:
quobix
2024-04-30 17:41:04 -04:00
parent 9d1ca6f541
commit 2999542014
2 changed files with 78 additions and 1 deletions

View File

@@ -1034,6 +1034,54 @@ properties:
assert.Equal(t, `{"count":9934}`, string(rendered))
}
func TestRenderSchema_Items_WithExample(t *testing.T) {
testObject := `type: object
properties:
args:
type: object
properties:
arrParam:
type: string
example: test,test2
arrParamExploded:
type: array
items:
type: string
example: "1"`
compiled := getSchema([]byte(testObject))
schema := make(map[string]any)
wr := createSchemaRenderer()
wr.DiveIntoSchema(compiled, "pb33f", schema, 0)
rendered, _ := json.Marshal(schema["pb33f"])
assert.Equal(t, `{"args":{"arrParam":"test,test2","arrParamExploded":["1"]}}`, string(rendered))
}
func TestRenderSchema_Items_WithExamples(t *testing.T) {
testObject := `type: object
properties:
args:
type: object
properties:
arrParam:
type: string
example: test,test2
arrParamExploded:
type: array
items:
type: string
examples:
- 1
- 2`
compiled := getSchema([]byte(testObject))
schema := make(map[string]any)
wr := createSchemaRenderer()
wr.DiveIntoSchema(compiled, "pb33f", schema, 0)
rendered, _ := json.Marshal(schema["pb33f"])
assert.Equal(t, `{"args":{"arrParam":"test,test2","arrParamExploded":["1","2"]}}`, string(rendered))
}
func TestCreateRendererUsingDefaultDictionary(t *testing.T) {
assert.NotNil(t, CreateRendererUsingDefaultDictionary())
}