Skip to content

app: Add logic to handle $ref in parameters BNCH-125141 BNCH-125943 #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: peter.goldstein/fix
Choose a base branch
from

Conversation

peter-goldstein
Copy link

@peter-goldstein peter-goldstein commented May 23, 2025

The following is valid in the openapi spec:

paths:
  foos:
    get:
      parameters:
      - $ref: '#/components/parameters/barParam'

components:
  parameters:
    barParam:
      example: baz
      in: query
      name: bar
      schema:
        type: string

In December of 2020, when we diverged from the upstream branch, the client generator could not yet handle $ref in the parameters list. They added that feature in August 2022 but we never pulled it in.

In this PR, I try to pull in the same implementation from the upstream while modifying our repo as little as possible. Only the tests are really hand-written.

Testing

  • Update unit tests
  • Apply to our spec and see the missing $ref defined parameters in the generated methods

- Set ruler to 120 characters, which is the configured value in black
- Set up vscode to use pytest with the same configuration as task unit
- Turn off mypy in tests. They are so noncompliant that it's useless
This builds a library of parameter references from the openapi spec and
gives a utility for looking them up.
This builds the actual Parameters object from the OpenAPI spec, using
the logic we just added to schemas.
Intead of ignoring reference-typed parameters, look them up in the
Parameters object.
@peter-goldstein peter-goldstein marked this pull request as ready for review May 23, 2025 15:42
@peter-goldstein peter-goldstein changed the title app: Add logic to handle $ref in parameters BNCH-125141 app: Add logic to handle $ref in parameters BNCH-125141 BNCH-125943 May 23, 2025
* Update code to be editable

Fix the prod/1.x branch so it's possible to run the client library
generator from a local clone.

#### Changes to make it work at all:

`pyproject.toml`
- We'll use python 3.9 because 3.7 is dead-dead
- PyYAML <6 isn't installable anymore, thanks to PEP 517
- shellingham 1.5.0 was yanked, so we need a later version
- Include type annotations for PyYAML for good measure

#### Changes to make the generated output match what's already published:

`poetry.lock`
- Downgrade black so it tolerates leading and trailing spaces in triple-
quoted strings
- Upgrade autoflake to match the version in aurelia
- Upgrade isort to match the version in aurelia

`openapi_python_client/templates/pyproject.toml`
- Enforce line length of 110 characters
- Configure isort to use the same settings as in aurelia (don't separate
by "from foo import" vs "import"; don't separate constants-style imports
from other imports)

`openapi_python_client/__init__.py`
- Run autoflake from outside the generated client package. This sidesteps
an issue where [autoflake will crash if it runs against a file called
types.py](https://discuss.python.org/t/my-python-dont-work/80726). We
have a file called types.py.

* Run poetry lock

* Fix unit tests

* Fix flake8

* Remove difficult-to-fix checks and add todo's

* Pin the black version
@peter-goldstein peter-goldstein force-pushed the BNCH-125141-ref-parameters branch from 2937710 to 37d6a1a Compare May 24, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant