OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[ ] [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'
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'
Faced the same problem. The type hint for parameter is StrictStr, but the code inside tries to access value attribute. I would expect the type hint to be a enum.
Bug Report Checklist
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
Generation Details
Steps to reproduce
results in
Related issues/PRs
Possible related to Issue #14524
Suggest a fix
Sorry