Ejemplo n.º 1
0
 def test_schema_uses_ref_in_parameters_and_request_body_if_available_v3(
         self, spec_fixture):
     spec_fixture.spec.components.schema("Pet", schema=PetSchema)
     spec_fixture.spec.path(
         path="/pet",
         operations={
             "get": {
                 "parameters": [{
                     "in": "query",
                     "schema": PetSchema
                 }]
             },
             "post": {
                 "requestBody": {
                     "content": {
                         "application/json": {
                             "schema": PetSchema
                         }
                     }
                 }
             },
         },
     )
     p = get_paths(spec_fixture.spec)["/pet"]
     assert "schema" in p["get"]["parameters"][0]
     post = p["post"]
     schema_ref = post["requestBody"]["content"]["application/json"][
         "schema"]
     assert schema_ref == {"$ref": self.ref_path(spec_fixture.spec) + "Pet"}
Ejemplo n.º 2
0
 def test_schema_partially_v2(self, spec_fixture):
     spec_fixture.spec.components.schema("Pet", schema=PetSchema)
     spec_fixture.spec.path(
         path="/parents",
         operations={
             "get": {
                 "responses": {
                     "200": {
                         "schema": {
                             "type": "object",
                             "properties": {
                                 "mother": PetSchema,
                                 "father": PetSchema,
                             },
                         }
                     }
                 }
             }
         },
     )
     get = get_paths(spec_fixture.spec)["/parents"]["get"]
     assert get["responses"]["200"]["schema"] == {
         "type": "object",
         "properties": {
             "mother": {
                 "$ref": self.ref_path(spec_fixture.spec) + "Pet"
             },
             "father": {
                 "$ref": self.ref_path(spec_fixture.spec) + "Pet"
             },
         },
     }
Ejemplo n.º 3
0
 def test_schema_array_uses_ref_if_available_v2(self, spec_fixture):
     spec_fixture.spec.components.schema("Pet", schema=PetSchema)
     spec_fixture.spec.path(
         path="/pet",
         operations={
             "get": {
                 "parameters": [{
                     "in": "body",
                     "name": "body",
                     "schema": {
                         "type": "array",
                         "items": PetSchema
                     },
                 }],
                 "responses": {
                     "200": {
                         "schema": {
                             "type": "array",
                             "items": PetSchema
                         }
                     }
                 },
             }
         },
     )
     get = get_paths(spec_fixture.spec)["/pet"]["get"]
     assert len(get["parameters"]) == 1
     resolved_schema = {
         "type": "array",
         "items": {
             "$ref": self.ref_path(spec_fixture.spec) + "Pet"
         },
     }
     assert get["parameters"][0]["schema"] == resolved_schema
     assert get["responses"]["200"]["schema"] == resolved_schema
Ejemplo n.º 4
0
 def test_schema_uses_ref_in_parameters_and_request_body_if_available_v2(
         self, spec_fixture):
     spec_fixture.spec.components.schema("Pet", schema=PetSchema)
     spec_fixture.spec.path(
         path="/pet",
         operations={
             "get": {
                 "parameters": [{
                     "in": "query",
                     "schema": PetSchema
                 }]
             },
             "post": {
                 "parameters": [{
                     "in": "body",
                     "schema": PetSchema
                 }]
             },
         },
     )
     p = get_paths(spec_fixture.spec)["/pet"]
     assert "schema" not in p["get"]["parameters"][0]
     post = p["post"]
     assert len(post["parameters"]) == 1
     assert (post["parameters"][0]["schema"]["$ref"] == self.ref_path(
         spec_fixture.spec) + "Pet")
Ejemplo n.º 5
0
    def test_schema_expand_parameters_v3(self, spec_fixture):
        spec_fixture.spec.path(
            path="/pet",
            operations={
                "get": {
                    "parameters": [{
                        "in": "query",
                        "schema": PetSchema
                    }]
                },
                "post": {
                    "requestBody": {
                        "description": "a pet schema",
                        "required": True,
                        "content": {
                            "application/json": {
                                "schema": PetSchema
                            }
                        },
                    }
                },
            },
        )
        p = get_paths(spec_fixture.spec)["/pet"]
        get = p["get"]
        assert get["parameters"] == spec_fixture.openapi.schema2parameters(
            PetSchema, default_in="query")

        post = p["post"]
        post_schema = spec_fixture.openapi.resolve_schema_dict(PetSchema)
        assert (post["requestBody"]["content"]["application/json"]["schema"] ==
                post_schema)
        assert post["requestBody"]["description"] == "a pet schema"
        assert post["requestBody"]["required"]
Ejemplo n.º 6
0
 def test_schema_expand_parameters_v2(self, spec_fixture):
     spec_fixture.spec.path(
         path="/pet",
         operations={
             "get": {
                 "parameters": [{
                     "in": "query",
                     "schema": PetSchema
                 }]
             },
             "post": {
                 "parameters": [{
                     "in": "body",
                     "description": "a pet schema",
                     "required": True,
                     "name": "pet",
                     "schema": PetSchema,
                 }]
             },
         },
     )
     p = get_paths(spec_fixture.spec)["/pet"]
     get = p["get"]
     assert get["parameters"] == spec_fixture.openapi.schema2parameters(
         PetSchema, default_in="query")
     post = p["post"]
     assert post["parameters"] == spec_fixture.openapi.schema2parameters(
         PetSchema,
         default_in="body",
         required=True,
         name="pet",
         description="a pet schema",
     )
Ejemplo n.º 7
0
 def test_schema_uses_ref_if_available_v2(self, spec_fixture):
     spec_fixture.spec.components.schema("Pet", schema=PetSchema)
     spec_fixture.spec.path(
         path="/pet",
         operations={"get": {
             "responses": {
                 "200": {
                     "schema": PetSchema
                 }
             }
         }})
     get = get_paths(spec_fixture.spec)["/pet"]["get"]
     assert (get["responses"]["200"]["schema"]["$ref"] == self.ref_path(
         spec_fixture.spec) + "Pet")
Ejemplo n.º 8
0
 def test_schema_array_uses_ref_if_available_v3(self, spec_fixture):
     spec_fixture.spec.components.schema("Pet", schema=PetSchema)
     spec_fixture.spec.path(
         path="/pet",
         operations={
             "get": {
                 "parameters": [{
                     "in": "body",
                     "name": " body",
                     "content": {
                         "application/json": {
                             "schema": {
                                 "type": "array",
                                 "items": PetSchema
                             }
                         }
                     },
                 }],
                 "responses": {
                     "200": {
                         "content": {
                             "application/json": {
                                 "schema": {
                                     "type": "array",
                                     "items": PetSchema
                                 }
                             }
                         }
                     }
                 },
             }
         },
     )
     p = get_paths(spec_fixture.spec)["/pet"]
     assert "get" in p
     op = p["get"]
     resolved_schema = {
         "type": "array",
         "items": {
             "$ref": self.ref_path(spec_fixture.spec) + "Pet"
         },
     }
     request_schema = op["parameters"][0]["content"]["application/json"][
         "schema"]
     assert request_schema == resolved_schema
     response_schema = op["responses"]["200"]["content"][
         "application/json"]["schema"]
     assert response_schema == resolved_schema
Ejemplo n.º 9
0
 def test_schema_v2(self, spec_fixture, pet_schema):
     spec_fixture.spec.path(
         path="/pet",
         operations={
             "get": {
                 "responses": {
                     "200": {
                         "schema": pet_schema,
                         "description": "successful operation",
                     }
                 }
             }
         },
     )
     get = get_paths(spec_fixture.spec)["/pet"]["get"]
     assert get["responses"]["200"][
         "schema"] == spec_fixture.openapi.schema2jsonschema(PetSchema)
     assert get["responses"]["200"]["description"] == "successful operation"