diff --git a/tests/fixtures/xquik-openapi31.yaml b/tests/fixtures/xquik-openapi31.yaml new file mode 100644 index 0000000..c86df85 --- /dev/null +++ b/tests/fixtures/xquik-openapi31.yaml @@ -0,0 +1,58 @@ +openapi: 3.1.0 +info: + title: Xquik API + version: "1.0" +servers: + - url: https://xquik.com +components: + securitySchemes: + apiKey: + type: apiKey + name: X-API-Key + in: header + schemas: + TweetSearchResponse: + type: object + required: + - data + properties: + data: + type: array + items: + type: object + required: + - id + - text + properties: + id: + type: string + text: + type: string +paths: + /api/v1/x/tweets/search: + get: + operationId: searchTweets + summary: Search recent public posts + security: + - apiKey: [] + parameters: + - name: q + in: query + required: true + schema: + type: string + minLength: 1 + - name: limit + in: query + required: false + schema: + type: integer + minimum: 1 + maximum: 100 + responses: + "200": + description: Search results + content: + application/json: + schema: + $ref: "#/components/schemas/TweetSearchResponse" diff --git a/tests/test_parser.py b/tests/test_parser.py index 3aceed1..b258174 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -6,7 +6,7 @@ from apighost.parser import _infer_type, get_param_pattern, parse_spec -from . import PETSTORE_YAML +from . import FIXTURES_DIR, PETSTORE_YAML def test_load_yaml(): @@ -31,6 +31,29 @@ def test_parse_endpoints(): assert ("GET", "/pets/{petId}/photos") in methods +def test_parse_xquik_openapi31_endpoint(): + """Test parsing an OpenAPI 3.1 endpoint with API key security.""" + spec = parse_spec(FIXTURES_DIR / "xquik-openapi31.yaml") + + assert spec.title == "Xquik API" + assert spec.version == "1.0" + assert spec.servers == ["https://xquik.com"] + assert len(spec.endpoints) == 1 + + endpoint = spec.endpoints[0] + assert endpoint.operation_id == "searchTweets" + assert endpoint.method == "GET" + assert endpoint.path == "/api/v1/x/tweets/search" + assert endpoint.security == [{"apiKey": []}] + assert [param.name for param in endpoint.parameters] == ["q", "limit"] + assert endpoint.parameters[0].required is True + assert endpoint.parameters[0].schema_ref["type"] == "string" + assert endpoint.parameters[1].schema_ref["type"] == "integer" + assert 200 in endpoint.responses + response_schema = endpoint.responses[200].schema_ref + assert response_schema["properties"]["data"]["type"] == "array" + + def test_parse_endpoint_details(): """Test endpoint details.""" spec = parse_spec(PETSTORE_YAML)