You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start a local web server that responds to requests with the requested resource path.
# ${PWD}/echo_server.pyimporthttp.serverimportsocketserverport=80# Create a custom request handler that responds to all requestsclassCustomHandler(http.server.SimpleHTTPRequestHandler):
defdo_GET(self):
# Extract the requested API pathapi_path=self.pathself.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(api_path.encode('utf-8'))
# Create a socket server with the custom request handlerwithsocketserver.TCPServer(('', port), CustomHandler) ashttpd:
print(f"Server running on port {port}")
# Start the serverhttpd.serve_forever()
$ python3 echo_server.py
Server running on port 80
Install the generated client:
$ cd python
$ python3 setup.py install --user
This creates an EnumValue model:
classEnumValue(str, Enum):
""" EnumValue """""" allowed enum values """A='a'B='b'@classmethoddeffrom_json(cls, json_str: str) ->EnumValue:
"""Create an instance of EnumValue from a JSON string"""returnEnumValue(json.loads(json_str))
Make requests to an endpoint that uses an Enum type as a path parameter:
Bug Report Checklist
Description
When an
Enum
of strings is used as a path parameter, the request path contains a stringified constant variable name instead of the underlying string.openapi-generator version
openapitools/openapi-generator-cli:latest
OpenAPI declaration file content or url
Generation Details
Generating using the Python client generator with default settings.
Steps to reproduce
Start a local web server that responds to requests with the requested resource path.
Install the generated client:
This creates an
EnumValue
model:Make requests to an endpoint that uses an Enum type as a path parameter:
This code outputs the following:
I expect it to output:
Related issues/PRs
I don't think there is an open issue that matches this one.
Suggest a fix
As a workaround in my own project, I updated
api_client.mustache
to check if path parameters are instances ofaenum.Enum
and dereference them:Would probably need to do the same for query parameters, too.
The text was updated successfully, but these errors were encountered: