swagger-api / swagger-api/swagger-codegen

[PYTHON] Handling multiple responses with codegen

未关闭
#8,167 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Mustache
星标
17.8k
派生
6k
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用提供的 swagger.json,并运行所述的 Swagger Codegen 2.3.1 Python 生成命令。检查生成的 swagger_client 对 200 和 204 响应的处理,重点关注空的 204 响应。完成的标准是,生成的客户端接受 204 响应,而不会尝试将其反序列化为 QueuedTask,同时保留 200 响应的行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。