Commit b3c2b09
authored
Add tests for responses with examples (#166)
### Motivation
The OpenAPI specification allows for specifying examples along side a
schema in a content map[^1]. The example can be an object with some
defined fields, but none of these fields are mandatory in OpenAPI
3.0.3[^2].
However, it looks like we're failing to parse documents that don't have
the `value` field.
Specifically we can't parse this spec unless we add the `value` field:
```diff
responses:
MyResponse:
description: Some response
content:
application/json:
schema:
type: string
examples:
application/json:
summary: "a hello response"
+ value: "hello"
```
This is used in the wild—notably in the Github API.
This appears to be because the model used in OpenAPIKit expects `value`
to be non-optional[^3].
### Modifications
Add some tests, one with an `XCTExpectFailure`, to track this.
### Result
We have tests that we can use to track this incompatibility with such
OpenAPI documents.
### Test Plan
This patch is tests only.
[^1]: https://spec.openapis.org/oas/v3.0.3#mediaTypeObject
[^2]: https://spec.openapis.org/oas/v3.0.3#exampleObject
[^3]:
https://github.com/mattpolzin/OpenAPIKit/blob/main/Sources/OpenAPIKit/Example.swift#L19
---------
Signed-off-by: Si Beaumont <[email protected]>1 parent 3c0fcab commit b3c2b09
File tree
1 file changed
+79
-0
lines changed- Tests/OpenAPIGeneratorReferenceTests
1 file changed
+79
-0
lines changedLines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
772 | 772 | | |
773 | 773 | | |
774 | 774 | | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
775 | 854 | | |
776 | 855 | | |
777 | 856 | | |
| |||
0 commit comments