Gab*_*res 7 jsonschema swagger openapi
围绕这个主题有一些问题,但我没有找到正确的方法。
我想要的是在一个地方定义所有参数并重用它,而不需要再次编写。我已经通过使用“allOf”得到了这一点,但这限制了“additionalProperties”的使用。
我的架构具有以下结构:
SchemaBase:
type: object
properties:
foo:
type: string
SchemaFull:
allOf:
- $ref: '#/components/schemas/SchemaBase'
- type: object
properties:
bar:
type: string
Run Code Online (Sandbox Code Playgroud)
我尝试使用using 定义,但在 OpenApi 版本 3 中似乎不再使用了。
这是一个解决方案,但它不是我正在寻找的,因为这是针对属性的,而不是整个架构。
你需要components这样使用:
openapi: 3.0.1
info:
title: OAS 3
version: 1.0.0
tags:
- name: example
paths:
/exe:
post:
requestBody:
content:
application/json:
schema:
additionalProperties: false
allOf:
- $ref: '#/components/schemas/SchemaBase'
- type: object
properties:
bar:
type: string
responses:
200:
description: Foo
content: {}
components:
schemas:
SchemaBase:
type: object
properties:
foo:
type: string
Run Code Online (Sandbox Code Playgroud)
您可以在这里看到并使用它: https: //editor.swagger.io/
JSON 架构映射:
{
"additionalProperties": false,
"allOf": [
{ "$ref": "#/definitions/SchemaBase" },
{
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
],
"definitions": {
"SchemaBase": {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9368 次 |
| 最近记录: |