Swagger 打开API生成器更改多部分/表单数据的函数定义签名
我已经编写了一个POST API,它创建了一个具有基本属性的实体Swagger 打开API生成器更改多部分/表单数据的函数定义签名,swagger,openapi,openapi-generator,servicestack-openapi,Swagger,Openapi,Openapi Generator,servicestack Openapi,我已经编写了一个POST API,它创建了一个具有基本属性的实体 post: operationId: createEntity summary: Create an Entity parameters: - $ref: '#/components/parameters/organizationKey' tags: - Entity requestBody: required: true content: application/j
post:
operationId: createEntity
summary: Create an Entity
parameters:
- $ref: '#/components/parameters/organizationKey'
tags:
- Entity
requestBody:
required: true
content:
application/json:
schema:
"$ref": "#/components/schemas/EntityParams"
引用的模式EntityParams如下所示
type: object
properties:
attr1:
type: string
example: 'Meguro Office'
attr2:
type: string
example: office
attr3:
type: string
example: office
根据上面的规范,如果我生成openapi函数,我会得到如下签名
createEntity: async (organizationKey: string, entityParams: EntityParams, options: any = {})
上面的签名非常有效
那么问题出在哪里:我不得不改变api以适应图像上传。因此,我在EntityParams中添加了image upload参数,并将内容类型更改为多部分/表单数据,如下所示
type: object
properties:
attr1:
type: string
example: 'Meguro Office'
attr2:
type: string
example: office
attr3:
type: string
example: office
thumbnail:
type: string
format: binary
并将api规范更改如下
post:
operationId: createEntity
summary: Create an Entity
parameters:
- $ref: '#/components/parameters/organizationKey'
tags:
- Entity
requestBody:
required: true
content:
multipart/form-data:
schema:
"$ref": "#/components/schemas/EntityParams"
完成此更改后,openapi生成器正在创建具有以下签名的api函数
createEntity: async (organizationKey: string, attr1: string, attr2: string, attr3: string, thumbnail: any?)
上述语法的问题是,在调用此函数时,我必须手动显式地传递所有键及其值。当内容类型为应用程序json时,情况并非如此。前面的签名帮助开发人员只传递包含属性键的对象。
我找不到任何解决办法。此外,我不想使用此签名,因为它不可伸缩(如果有更多属性,该怎么办?我不想手动将它们作为函数参数传递)
请让我知道如何解决这个问题。我尝试了样式和分解选项。但是他们就是不工作