swagger-api / swagger-api/swagger-codegen

[PYTHON] Handling multiple responses with codegen

Open
#8,167 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I have different type of responses for different status code , consider the contents of swagger.json to be

{
	"swagger": "2.0",
	"info": {
		"title": "My Api",
		"description": "Api for Queue",
		"version": "v1"
	},
	"host": "localhost:8000",
	"schemes": ["http"],
	"basePath": "/api",
	"consumes": ["application/json"],
	"produces": ["application/json"],
	"securityDefinitions": {},
	"security": [{}],
	"paths": {
		"/v1/{name}/get_task": {
			"get": {
				"operationId": "v1_get_task_read",
				"description": "Get the first task from queue \n---",
				"parameters": [{
					"name": "priority",
					"in": "query",
					"required": false,
					"type": "string"
				}],
				"responses": {
					"200": {
						"description": "QueuedTask Object",
						"schema": {
							"$ref": "#/definitions/QueuedTask"
						}
					},
					"204": {
						"description": "null object response"
					}
				},
				"tags": ["v1"]
			},
			"parameters": [{
				"name": "name",
				"in": "path",
				"required": true,
				"type": "string"
			}]
		}
	},
	"definitions": {
		"QueuedTask": {
			"required": ["name"],
			"type": "object",
			"properties": {
				"id": {
					"title": "ID",
					"type": "integer",
					"readOnly": true
				},
				"name": {
					"title": "Name",
					"type": "string",
					"maxLength": 16
				}
			}
		}
	}
}
Swagger codegen version 2.3.1
java -jar swagger-codegen-cli-2.3.1.jar generate -l python -i swagger.json -o outs

swagger_client produced inside outs directory doesn't support None object for 204 response. It tries to deserialize the empty response into QueuedTask object and breaks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the supplied swagger.json and run the stated Swagger Codegen 2.3.1 Python generation command. Inspect the generated swagger_client handling for the 200 and 204 responses, focusing on the empty 204 response. Done means the generated client accepts the 204 response without trying to deserialize it as QueuedTask, while preserving the 200 response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.