Skip to content

Commit b5f5b53

Browse files
committedAug 17, 2020
Added a unit test to verify that local references work correctly (#14)
1 parent 1971332 commit b5f5b53

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
 

‎src/test/java/com/github/bjansen/ssv/SwaggerValidatorTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ void checkUnknownDefinition() throws IOException {
164164
assertTrue(e.getMessage().contains("Unknown definition /definitions/Blablabla"));
165165
}
166166

167+
@Test
168+
void should_support_references_to_definitions_in_same_file() throws IOException, ProcessingException {
169+
// Given
170+
SwaggerValidator validator = buildValidator("/references/spec-issue14.json");
171+
JsonNode sample = buildSample("/references/sample-issue14.json");
172+
173+
// When
174+
final ProcessingReport report = validator.validate(sample, "/definitions/Response");
175+
176+
// Then
177+
assertTrue(report.isSuccess());
178+
}
179+
167180
private SwaggerValidator buildValidator(String pathToSpec) throws IOException {
168181
InputStream spec = getClass().getResourceAsStream(pathToSpec);
169182
return SwaggerValidator.forYamlSchema(new InputStreamReader(spec));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"asyncRequestId": "qsdf",
3+
"result": {
4+
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Sample API",
5+
"version": "1"
6+
},
7+
"definitions": {
8+
"Response": {
9+
"type": "object",
10+
"required": [
11+
"asyncRequestId",
12+
"result"
13+
],
14+
"properties": {
15+
"asyncRequestId": {
16+
"type": "string"
17+
},
18+
"beginTime": {
19+
"type": "string",
20+
"format": "date-time"
21+
},
22+
"endTime": {
23+
"type": "string",
24+
"format": "date-time"
25+
},
26+
"id": {
27+
"type": "string"
28+
},
29+
"name": {
30+
"type": "string"
31+
},
32+
"result": {
33+
"$ref": "#/definitions/AsyncResult"
34+
},
35+
"sceuid": {
36+
"type": "string"
37+
},
38+
"type": {
39+
"type": "string"
40+
},
41+
"userId": {
42+
"type": "string"
43+
},
44+
"version": {
45+
"type": "string"
46+
}
47+
}
48+
},
49+
"AsyncResult": {
50+
"type": "object",
51+
"properties": {
52+
"status": {
53+
"type": "string"
54+
}
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)