Open angelgonzalbez opened 9 months ago
Hey! We have encountered the same issue in my team recently. It seems that the package datamodel-code-generator brings in a version of black that displays that error. We solved the issue by forcing our local version of black to 23.3.0
.
It worked as described with Docker. thank you. @r-whites
FROM python:3.11-slim
RUN pip install fastapi-code-generator black==23.3.0
WORKDIR /local
ENTRYPOINT ["fastapi-codegen"]
$ docker build -t fastapi-code-generator-container .
$ docker run --rm -v "${PWD}:/local" fastapi-code-generator-container --input /local/openapi.yml --output app
Hello, I'm forcing black to version 23.3.0 as described above, but I'm still getting exactly the same error. I've installed both black
and fastapi-code-generator
using pipx, if that matters at all.
Anybody else still running into this, or have any ideas?
I had this same error, downgrading to the black version as suggested here using poetry worked for me.
I was also facing the same issue, also downgrading black to 23.3.0 helped me here.
Using python 3.11.7 or 3.10.7 in pyenv venv in macOS
(openapi-srv) ➜ openapi-srv fastapi-codegen --input api.yaml --output app3 ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /Users/myuser/.pyenv/versions/3.11.7/envs/openapi-srv/lib/python3.11/site-packages/fastapi_cod │ │ e_generator/main.py:86 in main │ │ │ │ 83 │ │ │ generate_routers=generate_routers, │ │ 84 │ │ │ specify_tags=specify_tags, │ │ 85 │ │ ) │ │ ❱ 86 │ return generate_code( │ │ 87 │ │ input_name, │ │ 88 │ │ input_text, │ │ 89 │ │ encoding, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ custom_visitors = [] │ │ │ │ disable_timestamp = False │ │ │ │ encoding = 'utf-8' │ │ │ │ enum_field_as_literal = None │ │ │ │ f = <_io.TextIOWrapper name='api.yaml' mode='r' encoding='utf-8'> │ │ │ │ generate_routers = False │ │ │ │ input_file = 'api.yaml' │ │ │ │ input_name = 'api.yaml' │ │ │ │ input_text = 'openapi: "3.0.0"\ninfo:\n version: 1.0.0\n title: Swagger │ │ │ │ Petstore\n license:\n '+3415 │ │ │ │ model_file = None │ │ │ │ model_path = PosixPath('models.py') │ │ │ │ output_dir = PosixPath('app3') │ │ │ │ specify_tags = None │ │ │ │ template_dir = None │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /Users/myuser/.pyenv/versions/3.11.7/envs/openapi-srv/lib/python3.11/site-packages/fastapi_cod │ │ e_generator/main.py:138 in generate_code │ │ │ │ 135 │ else: │ │ 136 │ │ parser = OpenAPIParser(input_text) │ │ 137 │ with chdir(output_dir): │ │ ❱ 138 │ │ models = parser.parse() │ │ 139 │ output = output_dir / model_path │ │ 140 │ if not models: │ │ 141 │ │ # if no models (schemas), just generate an empty model file. │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ custom_visitors = [] │ │ │ │ disable_timestamp = False │ │ │ │ encoding = 'utf-8' │ │ │ │ enum_field_as_literal = None │ │ │ │ generate_routers = False │ │ │ │ input_name = 'api.yaml' │ │ │ │ input_text = 'openapi: "3.0.0"\ninfo:\n version: 1.0.0\n title: Swagger │ │ │ │ Petstore\n license:\n '+3415 │ │ │ │ model_path = PosixPath('models.py') │ │ │ │ output_dir = PosixPath('app3') │ │ │ │ parser = <fastapi_code_generator.parser.OpenAPIParser object at 0x10366b150> │ │ │ │ specify_tags = None │ │ │ │ template_dir = PosixPath('/Users/myuser/.pyenv/versions/3.11.7/envs/openapi-srv/… │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /Users/myuser/.pyenv/versions/3.11.7/envs/openapi-srv/lib/python3.11/site-packages/datamodel_c │ │ ode_generator/parser/base.py:884 in parse │ │ │ │ 881 │ │ │ │ self.imports.append(IMPORTANNOTATIONS) │ │ 882 │ │ │ │ 883 │ │ if format: │ │ ❱ 884 │ │ │ code_formatter: Optional[CodeFormatter] = CodeFormatter( │ │ 885 │ │ │ │ self.target_python_version, │ │ 886 │ │ │ │ settings_path, │ │ 887 │ │ │ │ self.wrap_stringliteral, │ │ │ │ ╭────────────────────────────────────── locals ───────────────────────────────────────╮ │ │ │ format = True │ │ │ │ self = <fastapi_code_generator.parser.OpenAPIParser object at 0x10366b150> │ │ │ │ settings_path = None │ │ │ │ with_import = True │ │ │ ╰─────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /Users/myuser/.pyenv/versions/3.11.7/envs/openapi-srv/lib/python3.11/site-packages/datamodel_c │ │ ode_generator/format.py:108 in init │ │ │ │ 105 │ │ if TYPE_CHECKING: │ │ 106 │ │ │ self.black_mode: black.FileMode │ │ 107 │ │ else: │ │ ❱ 108 │ │ │ self.black_mode = black.FileMode( │ │ 109 │ │ │ │ target_versions={BLACK_PYTHON_VERSION[python_version]}, │ │ 110 │ │ │ │ line_length=config.get("line-length", black.DEFAULT_LINE_LENGTH), │ │ 111 │ │ │ │ string_normalization=not skip_string_normalization │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ black_kwargs = {'experimental_string_processing': False} │ │ │ │ config = {} │ │ │ │ experimental_string_processing = False │ │ │ │ path = PosixPath('/Users/myuser/PycharmProjects/openapi-srv/pyp… │ │ │ │ pyproject_toml = { │ │ │ │ │ 'tool': { │ │ │ │ │ │ 'poetry': { │ │ │ │ │ │ │ 'name': 'openapi-srv', │ │ │ │ │ │ │ 'version': '0.1.0', │ │ │ │ │ │ │ 'description': '', │ │ │ │ │ │ │ 'authors': ['Your Name you@example.com'], │ │ │ │ │ │ │ 'readme': 'README.md', │ │ │ │ │ │ │ 'dependencies': { │ │ │ │ │ │ │ │ 'python': '^3.11', │ │ │ │ │ │ │ │ 'fastapi-code-generator': '^0.4.4' │ │ │ │ │ │ │ } │ │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ 'build-system': { │ │ │ │ │ │ 'requires': ['poetry-core'], │ │ │ │ │ │ 'build-backend': 'poetry.core.masonry.api' │ │ │ │ │ } │ │ │ │ } │ │ │ │ python_version = <PythonVersion.PY_37: '3.7'> │ │ │ │ root = PosixPath('/Users/myuser/PycharmProjects/openapi-srv') │ │ │ │ self = <datamodel_code_generator.format.CodeFormatter object at │ │ │ │ 0x10398aa90> │ │ │ │ settings_path = PosixPath('/Users/myuser/PycharmProjects/openapi-srv/app… │ │ │ │ skip_string_normalization = True │ │ │ │ value = '/Users/myuser/PycharmProjects/openapi-srv/pyproject.tom… │ │ │ │ wrap_string_literal = False │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: Mode.init() got an unexpected keyword argument 'experimental_string_processing'
api.yaml content: openapi: "3.0.0" info: version: 1.0.0 title: Swagger Petstore license: name: MIT servers: