OpenAPITools / OpenAPITools/openapi-generator
[BUG][PYTHON] ValueError thrown in generated Flask server stub
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?
See bug description.
- Have you validated the input using an OpenAPI validator (example)?
Yes, this file passes validation.
- Have you tested with the latest master to confirm the issue still exists?
Yes, version 5.4.0
- Have you searched for related issues/PRs?
Yes, no related issues on value error.
- What's the actual output vs expected output?
(venv) megretson@moonshot Back-end % python -m game_server
Traceback (most recent call last):
File "/Users/megretson/.pyenv/versions/3.8.6/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/megretson/.pyenv/versions/3.8.6/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/megretson/Projects/JHU/Back-end/game_server/__main__.py", line 19, in <module>
main()
File "/Users/megretson/Projects/JHU/Back-end/game_server/__main__.py", line 11, in main
app.add_api('openapi.yaml',
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/connexion/apps/flask_app.py", line 73, in add_api
self.app.register_blueprint(api.blueprint)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 98, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 1168, in register_blueprint
blueprint.register(self, options, first_registration)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/blueprints.py", line 256, in register
deferred(state)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/blueprints.py", line 294, in <lambda>
self.record(lambda s: s.add_url_rule(rule, endpoint, view_func, **options))
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/blueprints.py", line 81, in add_url_rule
self.app.add_url_rule(
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 98, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 1275, in add_url_rule
rule = self.url_rule_class(rule, methods=methods, **options)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/werkzeug/routing.py", line 666, in __init__
raise ValueError("urls must start with a leading slash")
ValueError: urls must start with a leading slash
Expected output: running server
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
- Attached is the yaml file used for this example
- Code is generated with the command
java -jar openapi-generator-cli.jar generate -i ./Back-end/sync_definition.yaml -g python-flask -o Back-end --package-name game_server --api-package game_server - All dependencies installed into venv.
- Using Openapi-generator 5.4.0
- Running the generated code via
python3 -m game_server
Output:
(venv) megretson@moonshot Back-end % python -m game_server
Traceback (most recent call last):
File "/Users/megretson/.pyenv/versions/3.8.6/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/megretson/.pyenv/versions/3.8.6/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/megretson/Projects/JHU/Back-end/game_server/__main__.py", line 19, in <module>
main()
File "/Users/megretson/Projects/JHU/Back-end/game_server/__main__.py", line 11, in main
app.add_api('openapi.yaml',
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/connexion/apps/flask_app.py", line 73, in add_api
self.app.register_blueprint(api.blueprint)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 98, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 1168, in register_blueprint
blueprint.register(self, options, first_registration)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/blueprints.py", line 256, in register
deferred(state)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/blueprints.py", line 294, in <lambda>
self.record(lambda s: s.add_url_rule(rule, endpoint, view_func, **options))
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/blueprints.py", line 81, in add_url_rule
self.app.add_url_rule(
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 98, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/flask/app.py", line 1275, in add_url_rule
rule = self.url_rule_class(rule, methods=methods, **options)
File "/Users/megretson/Projects/JHU/Back-end/venv/lib/python3.8/site-packages/werkzeug/routing.py", line 666, in __init__
raise ValueError("urls must start with a leading slash")
ValueError: urls must start with a leading slash
openapi-generator version
5.4.0
OpenAPI declaration file content or url
openapi: 3.0.0
servers:
- url: our_clue_game_will_live_here.com
description: This is the server for game state
info:
description: This is the synchronous API definition for our server
version: 1.0.0
title: Game Server
paths:
/game:
post:
summary: Create a new game
description: 'Create a new game'
operationId: createGame
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/game'
'405':
description: Invalid input
/game/{gameId}:
get:
summary: Find game by ID
description: Returns a game
operationId: getGameById
parameters:
- name: gameId
in: path
description: ID of game to return
required: true
schema:
$ref: "#/components/schemas/game_board_id"
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/game'
'400':
description: Invalid ID supplied
'404':
description: Game not found
/game/{gameId}/player:
post:
summary: Create a new player
description: 'Create a new player'
operationId: createPlayer
parameters:
- name: gameId
in: path
description: ID of game to return
required: true
schema:
$ref: "#/components/schemas/game_board_id"
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/player'
'405':
description: Invalid input
/game/{gameId}/player/{playerId}:
get:
summary: Find a player
description: 'Find a player'
operationId: findPlayer
parameters:
- name: gameId
in: path
description: ID of game to return
required: true
schema:
$ref: "#/components/schemas/game_board_id"
- name: playerId
in: path
description: ID of player to return
required: true
schema:
$ref: "#/components/schemas/player_id"
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/player'
'405':
description: Invalid input
/game/{gameId}/player/{playerId}/move:
post:
summary: Create a new player move
description: 'Create a new player move'
operationId: movePlayer
parameters:
- name: gameId
in: path
description: ID of game to return
required: true
schema:
$ref: "#/components/schemas/game_board_id"
- name: playerId
in: path
description: ID of player to return
required: true
schema:
$ref: "#/components/schemas/player_id"
- name: move
in: query
description: attempted move
required: true
schema:
$ref: "#/components/schemas/move"
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/game'
'405':
description: Invalid input / illegal move
/game/{gameId}/player/{playerId}/accusation:
post:
summary: Make an accusation
description: 'Create a new player accusation'
operationId: makeAccusation
parameters:
- name: gameId
in: path
description: ID of game to return
required: true
schema:
$ref: "#/components/schemas/game_board_id"
- name: playerId
in: path
description: ID of player to return
required: true
schema:
$ref: "#/components/schemas/player_id"
- name: accusation
in: query
description: the player's accusation
required: true
schema:
$ref: "#/components/schemas/card_set"
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/card_set'
'405':
description: Invalid input
/game/{gameId}/player/{playerId}/suggestion:
post:
summary: Make a suggestion
description: 'Create a new player suggestion'
operationId: makeSuggestion
parameters:
- name: gameId
in: path
description: ID of game to return
required: true
schema:
$ref: "#/components/schemas/game_board_id"
- name: playerId
in: path
description: ID of player to return
required: true
schema:
$ref: "#/components/schemas/player_id"
- name: suggestion
in: query
description: the player's suggestion
required: true
schema:
$ref: "#/components/schemas/card_set"
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/rebuttal_card'
'405':
description: Invalid input
components:
schemas:
player:
description: An object which stores a player's unique ID, and which character they currently are
type: object
properties:
player_id:
$ref: "#/components/schemas/player_id"
character_name:
type: string
format: enum
player_id:
type: string
format: UUID
description: a unique identifier for a player
game_board_id:
type: string
format: UUID
description: a unique identifier for a game board
sent_at:
type: string
format: date-time
description: Date and time when the message was sent.
move:
type: number
format: integer
description: a numerical value representing the room or hallway the player is attempting to move to
card_set:
description: A set of cards representing a possible crime
type: object
properties:
player:
$ref: "#/components/schemas/player"
room:
type: string
format: enum
weapon:
type: string
format: enum
character_name:
type: string
format: enum
rebuttal_card:
description: The card someone responds to a suggestion with
type: object
properties:
player:
$ref: "#/components/schemas/player"
card:
type: string
format: enum
game:
title: a Game
description: A game playable on the the server
type: object
properties:
game_board_id:
$ref: "#/components/schemas/game_board_id"
status:
type: string
description: pet status in the store
deprecated: true
enum:
- active
- finished
Generation Details
java -jar openapi-generator-cli.jar generate -i ./Back-end/sync_definition.yaml -g python-flask -o Back-end --package-name game_server --api-package game_server
Steps to reproduce
Bug description describes reproduction steps.
Related issues/PRs
None found
Suggest a fix
Always possible this is some issue with this yaml? Otherwise, this feels like it might be a versioning issue. I am attaching here my pip frozen for arguments sake.
megretson@moonshot Back-end % pip freeze
appdirs==1.4.4
attrs==21.4.0
certifi==2021.10.8
charset-normalizer==2.0.12
click==7.1.2
clickclick==20.10.2
connexion==2.12.0
distlib==0.3.1
filelock==3.0.12
Flask==1.1.2
game-server==1.0.0
idna==3.3
importlib-resources==5.4.0
inflection==0.5.1
itsdangerous==1.1.0
Jinja2==2.11.3
jsonschema==4.4.0
MarkupSafe==2.0.1
pbr==5.5.1
pyrsistent==0.18.1
python-dateutil==2.8.2
PyYAML==5.4.1
requests==2.27.1
six==1.15.0
stevedore==3.2.2
swagger-ui-bundle==0.0.9
urllib3==1.26.9
virtualenv==20.0.35
virtualenv-clone==0.5.4
virtualenvwrapper==4.8.4
Werkzeug==1.0.1
zipp==3.7.0
Thanks!
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
Start with the supplied OpenAPI declaration, especially the servers URL, and reproduce the failure using the python-flask generator command and python3 -m game_server. Trace the generated server startup through app.add_api and verify that the generated application starts without the leading-slash ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, java, python
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100