mirror of https://github.com/zulip/zulip.git
test_openapi: Make testing.yml a full conformant specification.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
465ea4ac51
commit
86c39e5792
|
@ -1,118 +1,107 @@
|
||||||
test1:
|
openapi: 3.0.1
|
||||||
responses:
|
info:
|
||||||
"200":
|
title: Test API
|
||||||
content:
|
version: 1.0.0
|
||||||
application/json:
|
servers:
|
||||||
schema:
|
- url: "http://localhost:9991/api/v1"
|
||||||
type: object
|
paths:
|
||||||
additionalProperties: false
|
/test1:
|
||||||
properties:
|
get:
|
||||||
top_array:
|
responses:
|
||||||
type: array
|
"200":
|
||||||
items:
|
description: OK
|
||||||
oneOf:
|
content:
|
||||||
- type: object
|
application/json:
|
||||||
properties:
|
schema:
|
||||||
obj:
|
type: object
|
||||||
oneOf:
|
additionalProperties: false
|
||||||
- type: array
|
properties:
|
||||||
items:
|
top_array:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
oneOf:
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
obj:
|
||||||
|
oneOf:
|
||||||
|
- type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
str3:
|
||||||
|
type: string
|
||||||
|
- type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
str1:
|
||||||
type: string
|
type: string
|
||||||
- type: object
|
str2:
|
||||||
properties:
|
|
||||||
str3:
|
|
||||||
type: string
|
|
||||||
- type: array
|
|
||||||
items:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
str1:
|
|
||||||
type: string
|
|
||||||
str2:
|
|
||||||
type: string
|
|
||||||
example:
|
|
||||||
{
|
|
||||||
"top_array":
|
|
||||||
[
|
|
||||||
{"obj": {"str3": "test"}},
|
|
||||||
[{"str1": "success", "str2": "success"}],
|
|
||||||
],
|
|
||||||
}
|
|
||||||
test2:
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
top_array:
|
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
oneOf:
|
|
||||||
- type: object
|
|
||||||
properties:
|
|
||||||
obj:
|
|
||||||
oneOf:
|
|
||||||
- type: array
|
|
||||||
items:
|
|
||||||
type: string
|
type: string
|
||||||
- type: object
|
/test2:
|
||||||
additionalProperties: false
|
get:
|
||||||
properties:
|
responses:
|
||||||
str3:
|
"200":
|
||||||
type: string
|
description: OK
|
||||||
- type: array
|
content:
|
||||||
items:
|
application/json:
|
||||||
type: object
|
schema:
|
||||||
properties:
|
type: object
|
||||||
str1:
|
additionalProperties: false
|
||||||
type: string
|
properties:
|
||||||
str2:
|
top_array:
|
||||||
type: string
|
type: array
|
||||||
example:
|
items:
|
||||||
{
|
oneOf:
|
||||||
"top_array":
|
- type: object
|
||||||
[
|
properties:
|
||||||
{"obj": {"str3": "test", "str4": "extraneous"}},
|
obj:
|
||||||
[{"str1": "success", "str2": "success"}],
|
oneOf:
|
||||||
],
|
- type: array
|
||||||
}
|
items:
|
||||||
test3:
|
type: string
|
||||||
responses:
|
- type: object
|
||||||
"200":
|
additionalProperties: false
|
||||||
content:
|
properties:
|
||||||
application/json:
|
str3:
|
||||||
schema:
|
type: string
|
||||||
type: object
|
- type: array
|
||||||
additionalProperties: false
|
items:
|
||||||
properties:
|
type: object
|
||||||
top_array:
|
properties:
|
||||||
type: array
|
str1:
|
||||||
items:
|
type: string
|
||||||
oneOf:
|
str2:
|
||||||
- type: object
|
type: string
|
||||||
properties:
|
/test3:
|
||||||
obj:
|
get:
|
||||||
oneOf:
|
responses:
|
||||||
- type: array
|
"200":
|
||||||
items:
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
top_array:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
oneOf:
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
obj:
|
||||||
|
oneOf:
|
||||||
|
- type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
- type: object
|
||||||
|
- type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
str1:
|
||||||
|
type: string
|
||||||
|
str2:
|
||||||
type: string
|
type: string
|
||||||
- type: object
|
|
||||||
- type: array
|
|
||||||
items:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
str1:
|
|
||||||
type: string
|
|
||||||
str2:
|
|
||||||
type: string
|
|
||||||
example:
|
|
||||||
{
|
|
||||||
"top_array":
|
|
||||||
[
|
|
||||||
{"obj": {"str3": "test"}},
|
|
||||||
[{"str1": "success", "str2": "success"}],
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
|
@ -132,14 +132,19 @@ class OpenAPIToolsTest(ZulipTestCase):
|
||||||
# 'deep' opaque object. Also the parameters are a heterogeneous
|
# 'deep' opaque object. Also the parameters are a heterogeneous
|
||||||
# mix of arrays and objects to verify that our descent logic
|
# mix of arrays and objects to verify that our descent logic
|
||||||
# correctly gets to the the deeply nested objects.
|
# correctly gets to the the deeply nested objects.
|
||||||
with open(os.path.join(os.path.dirname(OPENAPI_SPEC_PATH), "testing.yaml")) as test_file:
|
test_filename = os.path.join(os.path.dirname(OPENAPI_SPEC_PATH), "testing.yaml")
|
||||||
|
with open(test_filename) as test_file:
|
||||||
test_dict = yaml.safe_load(test_file)
|
test_dict = yaml.safe_load(test_file)
|
||||||
openapi_spec.openapi()["paths"]["testing"] = test_dict
|
with patch("zerver.openapi.openapi.openapi_spec", OpenAPISpec(test_filename)):
|
||||||
try:
|
|
||||||
validate_against_openapi_schema(
|
validate_against_openapi_schema(
|
||||||
(test_dict["test1"]["responses"]["200"]["content"]["application/json"]["example"]),
|
{
|
||||||
"testing",
|
"top_array": [
|
||||||
"test1",
|
{"obj": {"str3": "test"}},
|
||||||
|
[{"str1": "success", "str2": "success"}],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"/test1",
|
||||||
|
"get",
|
||||||
"200",
|
"200",
|
||||||
)
|
)
|
||||||
with self.assertRaisesRegex(
|
with self.assertRaisesRegex(
|
||||||
|
@ -147,13 +152,14 @@ class OpenAPIToolsTest(ZulipTestCase):
|
||||||
r"\{'obj': \{'str3': 'test', 'str4': 'extraneous'\}\} is not valid under any of the given schemas",
|
r"\{'obj': \{'str3': 'test', 'str4': 'extraneous'\}\} is not valid under any of the given schemas",
|
||||||
):
|
):
|
||||||
validate_against_openapi_schema(
|
validate_against_openapi_schema(
|
||||||
(
|
{
|
||||||
test_dict["test2"]["responses"]["200"]["content"]["application/json"][
|
"top_array": [
|
||||||
"example"
|
{"obj": {"str3": "test", "str4": "extraneous"}},
|
||||||
]
|
[{"str1": "success", "str2": "success"}],
|
||||||
),
|
],
|
||||||
"testing",
|
},
|
||||||
"test2",
|
"/test2",
|
||||||
|
"get",
|
||||||
"200",
|
"200",
|
||||||
)
|
)
|
||||||
with self.assertRaisesRegex(
|
with self.assertRaisesRegex(
|
||||||
|
@ -162,10 +168,10 @@ class OpenAPIToolsTest(ZulipTestCase):
|
||||||
):
|
):
|
||||||
# Checks for opaque objects
|
# Checks for opaque objects
|
||||||
validate_schema(
|
validate_schema(
|
||||||
test_dict["test3"]["responses"]["200"]["content"]["application/json"]["schema"]
|
test_dict["paths"]["/test3"]["get"]["responses"]["200"]["content"][
|
||||||
|
"application/json"
|
||||||
|
]["schema"]
|
||||||
)
|
)
|
||||||
finally:
|
|
||||||
openapi_spec.openapi()["paths"].pop("testing", None)
|
|
||||||
|
|
||||||
def test_live_reload(self) -> None:
|
def test_live_reload(self) -> None:
|
||||||
# Force the reload by making the last update date < the file's last
|
# Force the reload by making the last update date < the file's last
|
||||||
|
|
Loading…
Reference in New Issue