Skip to content

Commit

Permalink
Ad test for circular ref
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanty committed Jun 15, 2024
1 parent 6d7f84e commit 5dc1ee3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
30 changes: 30 additions & 0 deletions end_to_end_tests/__snapshots__/test_end_to_end.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# serializer version: 1
# name: test_documents_with_errors[circular-body-ref.yaml]
'''
Generating /Users/dylan/projects/openapi-python-client/test-documents-with-errors
Warning(s) encountered while generating. Client was generated, but some pieces may be missing

WARNING parsing POST / within default. Endpoint will not be generated.

Circular $ref in request body


If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose

'''
# ---
# name: test_documents_with_errors[optional-path-param.yaml]
'''
Generating /Users/dylan/projects/openapi-python-client/test-documents-with-errors
Warning(s) encountered while generating. Client was generated, but some pieces may be missing

WARNING parsing GET /{optional} within default. Endpoint will not be generated.

Path parameter must be required

Parameter(name='optional', param_in=<ParameterLocation.PATH: 'path'>, description=None, required=False, deprecated=False, allowEmptyValue=False, style=None, explode=False, allowReserved=False, param_schema=Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), example=None, examples=None, content=None)

If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose

'''
# ---
20 changes: 20 additions & 0 deletions end_to_end_tests/documents_with_errors/circular-body-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
openapi: "3.1.0"
info:
title: "Circular Body Ref"
version: "0.1.0"
paths:
/:
post:
requestBody:
$ref: "#/components/requestBodies/body"
responses:
"200":
description: "Successful Response"
content:
"application/json":
schema:
const: "Why have a fixed response? I dunno"
components:
requestBodies:
body:
$ref: "#/components/requestBodies/body"
File renamed without changes.
12 changes: 8 additions & 4 deletions end_to_end_tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,16 @@ def test_bad_url():
assert "Could not get OpenAPI document from provided URL" in result.stdout


def test_invalid_document():
@pytest.mark.parametrize("document", ("optional-path-param.yaml", "circular-body-ref.yaml"))
def test_documents_with_errors(snapshot, document):
runner = CliRunner()
path = Path(__file__).parent / "invalid_openapi.yaml"
result = runner.invoke(app, ["generate", f"--path={path}", "--fail-on-warning"])
path = Path(__file__).parent / "documents_with_errors" / document
output_path = Path.cwd() / "test-documents-with-errors"
shutil.rmtree(output_path, ignore_errors=True)
result = runner.invoke(app, ["generate", f"--path={path}", "--fail-on-warning", f"--output-path={output_path}"])
assert result.exit_code == 1
assert "Warning(s) encountered while generating" in result.stdout
assert result.stdout == snapshot
shutil.rmtree(output_path, ignore_errors=True)


def test_custom_post_hooks():
Expand Down
16 changes: 15 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = [
{ name = "Dylan Anthony", email = "[email protected]" },
]
license = { text = "MIT" }
requires-python = ">=3.8,<4.0"
requires-python = ">=3.8.1,<4.0"
dependencies = [
"jinja2>=3.0.0,<4.0.0",
"typer>0.6,<0.13",
Expand Down Expand Up @@ -84,8 +84,6 @@ ignore_missing_imports = true
[tool.pytest.ini_options]
junit_family = "xunit2"



[tool.pdm.dev-dependencies]
dev = [
"pytest",
Expand All @@ -98,6 +96,7 @@ dev = [
"types-certifi<2021.10.9,>=2020.0.0",
"types-python-dateutil<3.0.0,>=2.0.0",
"ruamel-yaml-string>=0.1.1",
"syrupy>=4",
]

[tool.pdm.build]
Expand Down

0 comments on commit 5dc1ee3

Please sign in to comment.