Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

带path-parameters路径的GET和POST方法,如果POST的Body和GET的Response中存在相同名称的对象,生成的model有问题(其他) #41

Closed
BangXinWei opened this issue Nov 24, 2021 · 1 comment

Comments

@BangXinWei
Copy link

BangXinWei commented Nov 24, 2021

path-parameters
/test/{index} 的 get接口的 response 存在test名称的对象
/test/{index} 的 post接口的 Body 也存在test名称的对象

swagger.json 如下
{ "swagger": "2.0", "info": { "title": "unknown", "version": "last", "description": "unknown" }, "basePath": "", "tags": [ { "name": "公共分类", "description": "公共分类" } ], "schemes": [ "http" ], "paths": { "/test/{index}": { "get": { "tags": [ "公共分类" ], "summary": "testGet", "description": "", "parameters": [ { "name": "index", "in": "path", "description": "", "required": true, "type": "string" } ], "responses": { "200": { "description": "successful operation", "schema": { "type": "object", "properties": { "test": { "type": "object", "properties": { "get": { "type": "string" } }, "required": [ "get" ] } }, "required": [ "test" ], "title": "TestIndex" } } } }, "post": { "tags": [ "公共分类" ], "summary": "testPost", "description": "", "consumes": [ "application/json" ], "parameters": [ { "name": "index", "in": "path", "description": "", "required": true, "type": "string" }, { "name": "TestIndexBody", "in": "body", "schema": { "type": "object", "properties": { "test": { "type": "object", "properties": { "post": { "type": "string" } }, "required": [ "post" ] } }, "required": [ "test" ] } } ], "responses": { "200": { "description": "successful operation", "schema": { "type": "object", "title": "title", "properties": {} } } } } } } }

这种情况下,生成的model有问题
model 中 get的test 是 models.TestIndexTest 类型, model中定义的类型是 TestindexTest。注意大小写,是不一样的,如下图
image

image

这个定义的TestindexTest,是post中的test的类型,也不是get中test字段的类型。

@BangXinWei
Copy link
Author

测试可以通过设置title指定类型名称,避免这个问题

@gogoyqj gogoyqj closed this as completed Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants