OpenApi 在嵌套对象中需要 属性 不工作
OpenApi required property in nested objects not working
我需要描述一个 api 在请求正文中有一个具有必填字段的对象,其中一个字段是一个对象本身,它具有另一组必填字段。
我正在使用 open api v3 和 swagger 编辑器 (https://editor.swagger.io/)
将 .yaml 文件放入编辑器后,我生成了一个 html 客户端(> 生成客户端 > html)。然后我打开在 .zip 文件中生成的静态页面 index.html 获取此架构:
Table of Contents
body
secureoauthservicesv2Nested_nestedobj
body
id
Integer id of nested obj
nestedobj
secureoauthservicesv2Nested_nestedobj
secureoauthservicesv2Nested_nestedobj
nested object
field1 (optional)
String
field2 (optional)
String
我希望 field1 是必需的,field2 是可选的,但事实并非如此。
这是我的 .yaml 文件
openapi: 3.0.0
info:
title: Example API
description: Example API specification
version: 0.0.1
servers:
- url: https://example/api
paths:
/secure/oauth/services/v2/Nested:
post:
summary: Try nested
description: Used to post Nested obj
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- id
- nestedobj
properties:
id:
type: integer
description: id of nested obj
nestedobj:
type: object
required:
- field1
description: nested object
properties:
field1:
type: string
field2:
type: string
responses:
'200':
description: Nested object OK
已解决!
我使用了组件和架构,但我认为这可能是一个错误,在 swagger editor repo 上打开了一个问题:
https://github.com/swagger-api/swagger-editor/issues/1952
openapi: 3.0.0
info:
title: Example API
description: Example API specification
version: 0.0.2
servers:
- url: https://example/api
paths:
/secure/oauth/services/v2/Nested:
post:
summary: Try nested
description: Used to post Nested obj
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- id
- nestedobj
properties:
id:
type: integer
description: id of nested obj
nestedobj:
$ref: '#/components/schemas/nestedobj'
responses:
'200':
description: Nested object OK
components:
schemas:
element:
type: object
required:
- fieldArray1
properties:
fieldArray1:
type: string
description: field array
fieldArray2:
type: number
nestedobj:
type: object
required:
- field1
description: nested object
properties:
field1:
$ref: '#/components/schemas/woah'
field2:
type: string
woah:
type: object
required:
- woahthis
description: woah this
properties:
field3:
type: array
items:
$ref: '#/components/schemas/element'
woahthis:
type: number
description: numeber woah this
编辑 23/08/21:
我在 2019 年 4 月在 swagger-codegen github 中打开了一个 bug 但它仍然没有任何响应
我需要描述一个 api 在请求正文中有一个具有必填字段的对象,其中一个字段是一个对象本身,它具有另一组必填字段。
我正在使用 open api v3 和 swagger 编辑器 (https://editor.swagger.io/) 将 .yaml 文件放入编辑器后,我生成了一个 html 客户端(> 生成客户端 > html)。然后我打开在 .zip 文件中生成的静态页面 index.html 获取此架构:
Table of Contents
body
secureoauthservicesv2Nested_nestedobj
body
id
Integer id of nested obj
nestedobj
secureoauthservicesv2Nested_nestedobj
secureoauthservicesv2Nested_nestedobj
nested object
field1 (optional)
String
field2 (optional)
String
我希望 field1 是必需的,field2 是可选的,但事实并非如此。
这是我的 .yaml 文件
openapi: 3.0.0
info:
title: Example API
description: Example API specification
version: 0.0.1
servers:
- url: https://example/api
paths:
/secure/oauth/services/v2/Nested:
post:
summary: Try nested
description: Used to post Nested obj
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- id
- nestedobj
properties:
id:
type: integer
description: id of nested obj
nestedobj:
type: object
required:
- field1
description: nested object
properties:
field1:
type: string
field2:
type: string
responses:
'200':
description: Nested object OK
已解决!
我使用了组件和架构,但我认为这可能是一个错误,在 swagger editor repo 上打开了一个问题: https://github.com/swagger-api/swagger-editor/issues/1952
openapi: 3.0.0
info:
title: Example API
description: Example API specification
version: 0.0.2
servers:
- url: https://example/api
paths:
/secure/oauth/services/v2/Nested:
post:
summary: Try nested
description: Used to post Nested obj
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- id
- nestedobj
properties:
id:
type: integer
description: id of nested obj
nestedobj:
$ref: '#/components/schemas/nestedobj'
responses:
'200':
description: Nested object OK
components:
schemas:
element:
type: object
required:
- fieldArray1
properties:
fieldArray1:
type: string
description: field array
fieldArray2:
type: number
nestedobj:
type: object
required:
- field1
description: nested object
properties:
field1:
$ref: '#/components/schemas/woah'
field2:
type: string
woah:
type: object
required:
- woahthis
description: woah this
properties:
field3:
type: array
items:
$ref: '#/components/schemas/element'
woahthis:
type: number
description: numeber woah this
编辑 23/08/21: 我在 2019 年 4 月在 swagger-codegen github 中打开了一个 bug 但它仍然没有任何响应