Skip to content

Commit

Permalink
add path schema test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wim-De-Clercq committed Dec 5, 2024
1 parent 230fe9b commit 1c0c8e4
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/data/openapi/schemas_via_path_references/cat/paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cat:
get:
summary: Get a cat
responses:
200:
content:
application/json:
schema:
$ref: './schemas.yaml#/CatDetails'
cats:
get:
summary: Get all cats
responses:
200:
content:
application/json:
schema:
$ref: './schemas.yaml#/CatList'

41 changes: 41 additions & 0 deletions tests/data/openapi/schemas_via_path_references/cat/schemas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CatInfo:
type: object
required:
- cat_id
properties:
cat_id:
type: string
description: ID of this cat
details:
$ref: "#/CatDetails"

CatDetails:
type: object
required:
- name
- birthYear
properties:
name:
type: string
description: Name of this cat
birthYear:
type: number
description: Year of this cat's birth


CatList:
type: array
items:
$ref: "#/CatShort"

CatShort:
type: object
required:
- cat_id
properties:
cat_id:
type: string
description: ID of this cat
name:
type: string
description: Name of this cat
9 changes: 9 additions & 0 deletions tests/data/openapi/schemas_via_path_references/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
openapi: 3.1.0
info:
title: "Entity Schemas"
version: '1'
paths:
/cat:
$ref: "./cat/paths.yaml#/cat"
/cats:
$ref: "./cat/paths.yaml#/cats"
22 changes: 22 additions & 0 deletions tests/main/openapi/test_main_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,28 @@ def test_main_openapi_reference_same_hierarchy_directory():
)


@freeze_time("2019-07-26")
def test_main_openapi_schemas_via_path_references():
with TemporaryDirectory() as output_dir:
with chdir(OPEN_API_DATA_PATH / "schemas_via_path_references"):
output_file: Path = Path(output_dir) / "output.py"
return_code: Exit = main(
[
"--input",
"./openapi.yaml",
"--output",
str(output_file),
"--input-file-type",
"openapi",
"--openapi-scopes",
"paths",
]
)
assert return_code == Exit.OK
output_data = output_file.read_text()
print("data is:", output_data)


@freeze_time('2019-07-26')
def test_main_multiple_required_any_of():
with TemporaryDirectory() as output_dir:
Expand Down

0 comments on commit 1c0c8e4

Please sign in to comment.