Open tankpanv opened 2 years ago
"@umijs/plugin-openapi": "^1.3.3"
我使用openapi 生成接口的时候,我服务端model是结构性的 type ArticleItem struct { CollectedData * ArticleCollectedData
ArticleFormData * ArticleFormData Highlight map[string]*HighlightItem
} 我预期生成一个也是结构性的结构比如 type ArticleItem = { article_form_data?: ArticleFormData; collected_data?: ArticleCollectedData; };
但是通过plugin-openapi生成的是一个 引用类型的声明 type ArticleItem = ArticleFormData;
` type ArticleFormData = { / 摘要 */ abstract?: string; /* 分类列表 / category?: string[]; / 清理格式后的内容 */ clean_content?: string; / content 内容 */ content?: string; /* 编辑器类型 / editor?: number; / 题材 */ genre?: number; / id */ id?: number; logo?: string; /* 是否转载 / reship_url?: string; source?: number; / 标签列表 */ tags?: string[]; /* 文章标题 / title?: string; user_name?: string; };
type ArticleItem = ArticleFormData;`
` { "swagger": "2.0", "info": { "contact": {} }, "paths": {
"/article/detail": { "get": { "description": "根据id获取文章", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "article" ], "summary": "根据id获取文章", "parameters": [ { "type": "integer", "description": " ID", "name": "id", "in": "query", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/model.ArticleItem" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/model.ArticleItem" } } } } }, "model.ArticleCollectedData": { "type": "object", "properties": { "body": { "type": "string" } } }, "model.ArticleFormData": { "type": "object", "properties": { "category": { "description": "分类列表", "type": "array", "items": { "type": "string" } } } }, "model.ArticleItem": { "type": "object", "properties": { "article_form_data": { "description": "提交的变量", "$ref": "#/definitions/model.ArticleFormData" }, "collected_data": { "$ref": "#/definitions/model.ArticleCollectedData" }, "highlight": { "type": "object", "additionalProperties": { "$ref": "#/definitions/model.HighlightItem" } } } }, "model.HighlightItem": { "type": "object", "properties": { "pos": { "type": "array", "items": { "$ref": "#/definitions/model.PosItem" } }, "rich_text": { "type": "string" }, "text": { "type": "string" } } } }
}`
"@umijs/plugin-openapi": "^1.3.3"
我使用openapi 生成接口的时候,我服务端model是结构性的 type ArticleItem struct { CollectedData * ArticleCollectedData
} 我预期生成一个也是结构性的结构比如 type ArticleItem = { article_form_data?: ArticleFormData; collected_data?: ArticleCollectedData; };
但是通过plugin-openapi生成的是一个 引用类型的声明 type ArticleItem = ArticleFormData;
下面是我用openapi生成的typing.d.ts 文件和swagger.json 的结构
` type ArticleFormData = { / 摘要 */ abstract?: string; /* 分类列表 / category?: string[]; / 清理格式后的内容 */ clean_content?: string; / content 内容 */ content?: string; /* 编辑器类型 / editor?: number; / 题材 */ genre?: number; / id */ id?: number; logo?: string; /* 是否转载 / reship_url?: string; source?: number; / 标签列表 */ tags?: string[]; /* 文章标题 / title?: string; user_name?: string; };
type ArticleItem = ArticleFormData;`
swagger.json 的model
` { "swagger": "2.0", "info": { "contact": {} }, "paths": {
}`