OpenAPITools / OpenAPITools/openapi-generator
[BUG] OpenAPI Generator’s -g python-flask generator to scaffold a Connexion/Flask server
Nobody has claimed this yet.
- 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?
- 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
OpenAPI Generator’s -g python-flask generator to scaffold a Connexion/Flask server.
A filename with single underscores (e.g. foo_bar_controller.py)
An operationId (and thus Connexion import path) with doubled underscores (e.g. foo__bar_controller) or stray symbols
This leads Connexion to throw import errors, because the module it expects doesn’t exist.
Controller file: foo_bar_controller.py
Connexion looks for module: foo__bar_controller.py (double underscore)
Server fails to start due to missing module
openapi-generator version
openapi-generator-cli 7.13.0
commit : 4b805ff
built : -999999999-01-01T00:00:00+18:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
DEBIAN_VERSION_FULL=13.0
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
openapi: 3.0.3
info:
title: Test API
version: '1.0'
paths:
/foo-bar:
get:
summary: Get FooBar
responses:
'200':
description: OK
Generation Details
Python 3.12.2
Steps to reproduce
openapi-generator-cli generate
-i openapi.yaml
-g python-flask
-o stub
Suggest a fix
regex brute force
# openapi_server/__main__.py
import re
import connexion
from connexion.resolver import RestyResolver
class CleanResolver(RestyResolver):
def resolve(self, operation):
# 1) Take the raw operationId (either from your spec or inferred by Resty)
raw = super().resolve_operation_id(operation)
# 2) Replace any non-alphanumeric/underscore/dot with underscore (drops '&', '-', etc.)
cleaned = re.sub(r'[^A-Za-z0-9_.]', '_', raw)
# 3) Collapse any runs of multiple underscores into a single one
cleaned = re.sub(r'__+', '_', cleaned)
# 4) Let RestyResolver turn that cleaned string into a function
func = self.resolve_function_from_operation_id(cleaned)
return connexion.resolver.Resolution(func, cleaned)
app = connexion.FlaskApp(__name__, specification_dir="./stub")
app.add_api(
"openapi.yaml",
resolver=CleanResolver("openapi_server.controllers"),
)
if __name__ == "__main__":
app.run(port=8080, debug=True)
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
Reproduce the issue with the supplied OpenAPI declaration using the openapi-generator-cli python-flask command, then inspect the generated openapi_server scaffold and its Connexion import paths. Confirm how single and doubled underscores or stray symbols are transformed; done means the generated server starts without missing-module import errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100