OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Python] Server port remains 8080 regardless of value in spec
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 (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
The server port generated by the python-flask generator remains 8080 in __main__.py, regardless of the values used in the spec yaml file. According to the mustache template, the server port should be replaced, though?
openapi-generator version
OpenAPI generator 4.3.1 installed with Homebrew
OpenAPI declaration file content or url
Spec snippet:
openapi: 3.0.3
servers:
- url: 'http://localhost:8082'
info:
version: 0.0.1
title: Test API
paths:
/resources:
get:
summary: List resources
responses:
'200':
description: OK
I also tried with server variables
openapi: 3.0.3
servers:
- url: 'http://localhost:{port}'
variables:
port:
default: '8082'
info:
version: 0.0.1
title: Test API
paths:
/resources:
get:
summary: List resources
responses:
'200':
description: OK
Generation Details
Without server variables:
openapi-generator generate -i spec.yaml -o python-server -g python-flask
With server variables:
openapi-generator generate -i spec.yaml -o python-server -g python-flask --server-variables port=8082
The code __main__.py generated has 8080 as the application port:
#!/usr/bin/env python3
import connexion
from openapi_server import encoder
def main():
app = connexion.App(__name__, specification_dir='./openapi/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('openapi.yaml',
arguments={'title': 'Test API'},
pythonic_params=True)
app.run(port=8080)
if __name__ == '__main__':
main()
I would expect the port to be 8082, as in written in the spec
Steps to reproduce
Use the spec and generation command above to generate the python server stubs.
Related issues/PRs
Suggest a fix
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 python-flask main.mustache template referenced in the issue and compare it with the generated main.py output from the provided spec and generation command. Confirm that the generated server uses the 8082 value from the OpenAPI server definition or server variable instead of the hard-coded 8080, and check both reproduction commands.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100