From 1c0c8e49f976b577f951350aca6484199c2fd979 Mon Sep 17 00:00:00 2001 From: Wim De Clercq Date: Thu, 5 Dec 2024 13:46:03 +0100 Subject: [PATCH] add path schema test case. --- .../cat/paths.yaml | 19 +++++++++ .../cat/schemas.yaml | 41 +++++++++++++++++++ .../schemas_via_path_references/openapi.yaml | 9 ++++ tests/main/openapi/test_main_openapi.py | 22 ++++++++++ 4 files changed, 91 insertions(+) create mode 100644 tests/data/openapi/schemas_via_path_references/cat/paths.yaml create mode 100644 tests/data/openapi/schemas_via_path_references/cat/schemas.yaml create mode 100644 tests/data/openapi/schemas_via_path_references/openapi.yaml diff --git a/tests/data/openapi/schemas_via_path_references/cat/paths.yaml b/tests/data/openapi/schemas_via_path_references/cat/paths.yaml new file mode 100644 index 0000000..39d57e9 --- /dev/null +++ b/tests/data/openapi/schemas_via_path_references/cat/paths.yaml @@ -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' + \ No newline at end of file diff --git a/tests/data/openapi/schemas_via_path_references/cat/schemas.yaml b/tests/data/openapi/schemas_via_path_references/cat/schemas.yaml new file mode 100644 index 0000000..759fffb --- /dev/null +++ b/tests/data/openapi/schemas_via_path_references/cat/schemas.yaml @@ -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 \ No newline at end of file diff --git a/tests/data/openapi/schemas_via_path_references/openapi.yaml b/tests/data/openapi/schemas_via_path_references/openapi.yaml new file mode 100644 index 0000000..65effe4 --- /dev/null +++ b/tests/data/openapi/schemas_via_path_references/openapi.yaml @@ -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" \ No newline at end of file diff --git a/tests/main/openapi/test_main_openapi.py b/tests/main/openapi/test_main_openapi.py index ce752e3..2a3a2b3 100644 --- a/tests/main/openapi/test_main_openapi.py +++ b/tests/main/openapi/test_main_openapi.py @@ -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: