Skip to content

Commit 8e5a58a

Browse files
authored
Merge pull request go-openapi#22 from carvind/arvind-test-recursive-refs
Add test for recursive expansion
2 parents b11dbf8 + d32bc74 commit 8e5a58a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
item:
2+
type: object
3+
required:
4+
- title
5+
properties:
6+
id:
7+
type: integer
8+
format: uint64
9+
readOnly: true
10+
title:
11+
type: string
12+
minLength: 2
13+
maxLength: 80
14+
subitem:
15+
$ref: "item.yaml#/item"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
swagger: "2.0"
3+
info:
4+
title: Item API
5+
description: Item API
6+
version: "1.0.0"
7+
host: item.api.local
8+
basePath: /v1
9+
securityDefinitions:
10+
key:
11+
type: apiKey
12+
name: x-item-token
13+
in: header
14+
security:
15+
- key: []
16+
consumes:
17+
- application/json
18+
produces:
19+
- application/json
20+
schemes:
21+
- http
22+
responses:
23+
itemResponse:
24+
description: Item
25+
schema:
26+
$ref: "item.yaml#/item"
27+
paths:
28+
/item:
29+
get:
30+
operationId: GetItem
31+
responses:
32+
200:
33+
description: item detail response
34+
schema:
35+
$ref: "item.yaml#/item"
36+
default:
37+
$ref: "#/responses/itemResponse"
38+

spec_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ func TestExpandResponseLocalFile(t *testing.T) {
4646
}
4747
}
4848

49+
func TestExpandResponseRecursive(t *testing.T) {
50+
fp := filepath.Join("fixtures", "recursive_expansion", "spec.yaml")
51+
doc, err := loads.Spec(fp)
52+
if assert.NoError(t, err) {
53+
if assert.NotNil(t, doc) {
54+
validator := NewSpecValidator(doc.Schema(), strfmt.Default)
55+
res, _ := validator.Validate(doc)
56+
assert.True(t, res.IsValid())
57+
assert.Empty(t, res.Errors)
58+
}
59+
}
60+
}
61+
4962
func TestIssue52(t *testing.T) {
5063
fp := filepath.Join("fixtures", "bugs", "52", "swagger.json")
5164
jstext, _ := ioutil.ReadFile(fp)

0 commit comments

Comments
 (0)