Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/fixtures/xquik-openapi31.yaml
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 24 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand Down