我试图在swagger和swagger中创建一个可重用的对象,其中包括:
Structural error at components.schemas.Project.properties.location
should NOT have additional properties
additionalProperty: schema
Jump to line 47
我在components/schemas
部分中指定了枚举,然后使用$ref: '#/components/schemas/Registry'
引用它。我试着效仿这里的例子:https://swagger.io/docs/specification/data-models/enums/
这是完整的swagger文件:
openapi: 3.0.3
info:
title: My API
description: |-
Blah
contact:
email: support@example.com
version: 1.0.0
externalDocs:
description: Find out more about blah
url: http://blah.io
paths:
/credits-received:
post:
tags:
- Credits Received
operationId: creditsReceived
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreditsReceivedData'
required: true
responses:
'200':
description: Successful operation
components:
schemas:
CreditsReceivedData:
required:
- project
type: object
properties:
project:
$ref: '#/components/schemas/Project'
Project:
required:
- name
- registry
type: object
properties:
name:
type: string
example: "Project 1"
registry:
type: string
example: "My Registry"
schema:
$ref: '#/components/schemas/Registry'
Registry:
type: string
enum:
- My Registry 1
- My registry 2
发布于 2022-08-16 15:40:43
我解决了这个问题
registry:
type: string
example: "My Registry"
schema:
$ref: '#/components/schemas/Registry'
使用
registry:
$ref: '#/components/schemas/Registry'
基本上删除schema
属性,只需将$ref
直接放在属性下面(在本例中为registry
)。
https://stackoverflow.com/questions/73376617
复制相似问题