-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Metadata to `$ref` schemas This allows things like descriptions or nullability to be applied to a reference to another schema. * Minor updates based on PR feedback. * Use `(Metadata, Structure<Schema>)` instead of `SchemaStructure`. * Break long line onto multiple lines.
- Loading branch information
Showing
7 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Tests/SwaggerParserTests/Fixtures/test_pointer_metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "", | ||
"description": "", | ||
"version": "1.0.0" | ||
}, | ||
"host": "api.test.com", | ||
"schemes": ["https"], | ||
"produces": ["application/json"], | ||
"paths": {}, | ||
"definitions": { | ||
"Foo": { | ||
"properties": { | ||
"bar": { | ||
"$ref": "#/definitions/Bar", | ||
"description": "A nullable reference to Bar.", | ||
"x-nullable": true | ||
} | ||
} | ||
}, | ||
"Bar": { | ||
"properties": { | ||
"baz": { | ||
"type" : "string" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import XCTest | ||
@testable import SwaggerParser | ||
|
||
class StructureSchemaTests: XCTestCase { | ||
func testPointerMetadata() throws { | ||
let jsonString = try fixture(named: "test_pointer_metadata.json") | ||
let swagger = try Swagger(JSONString: jsonString) | ||
|
||
guard | ||
let fooDefinition = swagger.definitions.first(where: { $0.name == "Foo" }), | ||
case .object(let foo) = fooDefinition.structure else | ||
{ | ||
return XCTFail("Foo is not an object schema.") | ||
} | ||
|
||
guard | ||
let barProperty = foo.properties["bar"], | ||
case .structure(let metadata, let barReference) = barProperty, | ||
case .object(let bar) = barReference.structure else | ||
{ | ||
return XCTFail("Bar property is not a reference to an object schema.") | ||
} | ||
|
||
guard | ||
let bazProperty = bar.properties["baz"], | ||
case .string = bazProperty else | ||
{ | ||
return XCTFail("Baz property is not a string.") | ||
} | ||
|
||
XCTAssertEqual(metadata.description, "A nullable reference to Bar.") | ||
XCTAssertTrue(metadata.nullable) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters