OpenAPITools / OpenAPITools/openapi-generator
[BUG][python] Query Param of type String restricted by Enum triggers AttributeError (str has no attribute value)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [ x] Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- [ x] Have you tested with the latest master to confirm the issue still exists?
- [x ] Have you searched for related issues/PRs?
- [x ] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The python generator produces stubs which fail with an AttributeError on a query parameter of type string restricted by an enum.
openapi-generator version
I tested this on the current v7.0.0-beta as well as with todays trunk using the python (was python-nextgen) generator. This worked with the python and python-experimental generators of v6.0.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: ""
version: ""
paths:
/items:
get:
operationId: getHidden
summary: Get all hidden
description: Returns all hidden entries
parameters:
- $ref: "#/components/parameters/hidden"
responses:
200:
description: OK
components:
parameters:
hidden:
name: hidden
in: query
schema:
type: string
enum:
- only
- 'true'
Generation Details
# java -jar openapi-generator-7.0.0-beta/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i openapi-schema.yaml -g python
# java -jar openapi-generator-master-2023-07-11/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i openapi-schema.yaml -g python
Steps to reproduce
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
configuration = openapi_client.Configuration(
host = "http://localhost"
)
with openapi_client.ApiClient(configuration) as api_client:
api_instance = openapi_client.DefaultApi(api_client)
api_instance.get_hidden(hidden='only')
results in
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
File "./openapi_client/api/default_api.py", line 74, in get_hidden
return self.get_hidden_with_http_info(hidden, **kwargs) # noqa: E501
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
File "./openapi_client/api/default_api.py", line 149, in get_hidden_with_http_info
_query_params.append(('hidden', _params['hidden'].value))
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'value'
Related issues/PRs
Possible related to Issue #14524
Suggest a fix
Sorry
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the supplied OpenAPI YAML and the Python generator CLI command to reproduce the failure, then inspect the generated openapi_client/api/default_api.py code at get_hidden_with_http_info. Trace why the string enum query value is accessed through .value; done means passing hidden='only' no longer raises AttributeError and the generated request handles the query parameter correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100