swagger-api / swagger-api/swagger-codegen
Flask codegen server does not correctly return files
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When trying to create an endpoint that returns a file, the generated server tries to serialize the file into JSON, after which it fails.
The error is TypeError: Object of type TextIOWrapper is not JSON serializable
Swagger-codegen version
I am using http://editor.swagger.io/#/ to generate the flask server
Swagger declaration file content or url
If you post the code inline, please wrap it with
swagger: '2.0'
basePath: /api/v1
schemes:
- http
paths:
/test/featureFile:
post:
tags:
- cukegen
summary: Generate feature file from Postman files
description: Generate feature file from Postman files
operationId: generateFeatureFile
consumes:
- multipart/form-data
produces:
- multipart/form-data
parameters:
- name: featureFileName
in: formData
description: Name of Feature file to generate
required: false
type: string
- name: postmanCollectionFile
in: formData
description: Postman Collection file to upload
required: true
type: file
- name: postmanEnvironmentFile
in: formData
description: Postman Environment file to upload
required: true
type: file
responses:
'200':
description: Succesful operation
schema:
type: file
'400':
description: Invalid Parameter(s)
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
definitions:
ErrorResponse:
type: object
properties:
errorMessage:
type: string
Steps to reproduce
Try to return a file from the cukegen controller endpoint and call the API.
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 generated Flask server and the cukegen controller endpoint described in the issue, using the supplied Swagger declaration to reproduce the request. Confirm the response path for the file-returning endpoint and verify that calling it returns the file without the TextIOWrapper JSON serialization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100