OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Python] [JavaScript] SyntaxError: Due to Unescaped Characters in openapi.yaml Resource Path

Open
#17,973 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have an issue when the openapi.yaml file contains the unescaped curly braces in a path parameter (i.e., /IndicatorCategories(SSID='{SSID}',name='{name}')). This results in a syntax error in the resulting Python SDK code, as the API client in Python cannot correctly interpret the unescaped characters.

The same also was true for JavaScript.

openapi-generator version

openapi-generator-cli 7.2.0

OpenAPI declaration file content or url
/IndicatorCategories(SSID='{SSID}',name='{name}'):
Steps to reproduce
  1. Define a resource path in the openapi.yaml file like /IndicatorCategories(SSID='{SSID}',name='{name}')
  2. Generate the Python SDK code
openapi-generator generate -i ~/Downloads/Indicator_Related_APIs.yaml -g python -o ~/Downloads/GeneratedPythonClient/python-client-sdk
  1. Notice that a SyntaxError arises in the generated Python SDK code
File "build/bdist.macosx-10.9-universal2/egg/openapi_client/api/indicator_categories_api.py", line 760
    resource_path='/IndicatorCategories(SSID='{SSID}',name='{name}')',
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Related issues/PRs

None found

Suggest a fix

A temporary fix could be manually modifying the resource path in the Python SDK by using a Python f-string or another method to correctly escape the SSID and name variables. However, a preferable resolution would involve the openapi-generator correctly handling this case directly. Here's the temporary fix in Python:

resource_path = f"/IndicatorCategories(SSID='{SSID}',name='{name}')"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the openapi.yaml path /IndicatorCategories(SSID='{SSID}',name='{name}') and reproduce it using the documented openapi-generator command for the Python SDK. Inspect the generated indicator_categories_api.py at the reported resource_path line, then check the corresponding JavaScript output. Done means both generated SDKs represent this path without a syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.