swagger-api / swagger-api/swagger-codegen
python-flask server bug: Dashes in a header parameter should not be replaced with underscores
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The Swagger 2.0 specification allows header parameters with dashes (e.g., X-Request-ID), for example:
https://swagger.io/docs/specification/2-0/describing-parameters/
get:
summary: Checks if the server is alive.
parameters:
- in: header
name: X-Request-ID
type: string
required: true
However, when I run the python-flask code generator, it replaces the dashes in the header parameter name with underscores (X_Request_ID):
get:
summary: "Checks if the server is alive."
operationId: "status_get"
parameters:
- name: "X_Request_ID"
in: "header"
required: true
type: "string"
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Input:
swagger: "2.0"
info:
description: ""
version: "1.0.0"
title: "Bug demo"
paths:
/ping:
get:
summary: Checks if the server is alive.
parameters:
- in: header
name: X-Request-ID
type: string
required: true
responses:
200:
description: "success"
schema:
type: "string"
Generated output
---
swagger: "2.0"
info:
description: ""
version: "1.0.0"
title: "Bug demo"
paths:
/ping:
get:
summary: "Checks if the server is alive."
operationId: "ping_get"
parameters:
- name: "X_Request_ID"
in: "header"
required: true
type: "string"
responses:
200:
description: "success"
schema:
type: "string"
x-swagger-router-controller: "swagger_server.controllers.default_controller"
definitions: {}
Command line used for generation
N/A - I used the https://editor.swagger.io/ and selected Generate Server -> python-flask
Steps to reproduce
- Copy the schema fragment from the
https://swagger.io/docs/specification/2-0/describing-parameters/
to the swagger editor
https://editor.swagger.io/ - Generate python-flask code (Generate Server -> python-flask)
- Download the python-flask-server-generated.zip file and unzip it.
Review python-flask-server\swagger_server\swagger\swagger.yaml - Observe that the header parameters name was changed.
Related issues/PRs
N/A
Suggest a fix/enhancement
N/A
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 in the python-flask server generator using the Swagger 2.0 header parameter example, then inspect the generated python-flask-server/swagger_server/swagger/swagger.yaml output. Compare the X-Request-ID input with the generated X_Request_ID value; done means the generated header parameter preserves its dashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100