招摇过市规格无效:招摇过市规格位于;昂首阔步.yml“;对于swagger规范2.0无效
我正试着大摇大摆。下面是招摇过市规格无效:招摇过市规格位于;昂首阔步.yml“;对于swagger规范2.0无效,swagger,swagger-2.0,go-swagger,Swagger,Swagger 2.0,Go Swagger,我正试着大摇大摆。下面是swagger.yml文件 swagger: "2.0" basePath: /myapp/api info: description: My description title: My title version: 0.1.0 produces: - application/json consumes: - application/json schemes: - http paths: /contract: get
swagger.yml
文件
swagger: "2.0"
basePath: /myapp/api
info:
description: My description
title: My title
version: 0.1.0
produces:
- application/json
consumes:
- application/json
schemes:
- http
paths:
/contract:
get:
operationId: "Get contract"
description: Get information
parameters:
- in: path
name: contractId
description: ID
required: true
schema:
type: integer
responses:
200:
description: Information...
schema:
$ref: "#/definitions/contract"
404:
description: "Not found."
post:
operationId: "Create"
parameters:
- in: body
name: contractId
schema:
$ref: '#/definitions/requestBodies/contract'
responses:
200:
description: Success...
400:
description: Problem...
definitions:
contract:
title: Contract
type: object
properties:
name:
title: Name
type: string
services:
title: Services
type: array
items:
title: Service
$ref: '#/definitions/service'
xyz:
title: Xyz
$ref: '#/definitions/virtualMachine'
service:
title: Service
type: object
properties:
containerName:
title: ContainerName
type: string
...
contracts:
title: Contracts
type: array
items:
title: Contract
$ref: '#/definitions/contract'
xyz:
title: Xyz
type: object
properties:
serverId:
title: ServerID
type: string
contractId:
title: ContractID
type: uuid
...
requestBodies:
contract:
content:
application/json:
schema:
$ref: '#/definitions/contract'
当我尝试生成文档时,出现以下错误:
swagger generate server -f swagger.yml
2020/10/26 15:43:31 validating spec /home/dalton/workspace/.../.../swagger.yml
The swagger spec at "/home/dalton/workspace/.../.../swagger.yml" is invalid against swagger specification 2.0. see errors :
- definitions.requestBodies.contract in body is a forbidden property
- "definitions.xyz.properties.contractId.type" must validate at least one schema (anyOf)
- definitions.xyz.properties.contractId.type in body must be of type array: "string"
我做错了什么?要使此代码通过Swagger验证,我必须:
- 删除
参数中的construcd
(get方法)李>schema
- 删除requestbody定义并更改
参数中的contract
(post方法)李>schema
- 更改Xyz定义中的
的类型(uuid类型不受Swagger版本2的支持)compractid
swagger: "2.0"
basePath: /myapp/api
info:
description: My description
title: My title
version: 0.1.0
produces:
- application/json
consumes:
- application/json
schemes:
- http
paths:
/contract:
get:
operationId: "Get contract"
description: Get information
parameters:
- in: path
name: contractId
description: ID
required: true
type: integer
responses:
200:
description: Information...
schema:
$ref: "#/definitions/contract"
404:
description: "Not found."
post:
operationId: "Create"
parameters:
- in: body
name: contractId
schema:
$ref: '#/definitions/contract'
responses:
200:
description: Success...
400:
description: Problem...
definitions:
contract:
title: Contract
type: object
properties:
name:
title: Name
type: string
services:
title: Services
type: array
items:
title: Service
$ref: '#/definitions/service'
xyz:
title: Xyz
$ref: '#/definitions/virtualMachine'
service:
title: Service
type: object
properties:
containerName:
title: ContainerName
type: string
...
contracts:
title: Contracts
type: array
items:
title: Contract
$ref: '#/definitions/contract'
xyz:
title: Xyz
type: object
properties:
serverId:
title: ServerID
type: string
contractId:
title: ContractID
type: string
format: uuid
也许您可以尝试在线编辑您的swagger.yml。您的定义混合了OpenAPI 2.0和3.0语法,因此会出现错误。它应该是“2.0”还是“openapi:3.0.0”?嗨,海伦。我不知道两者之间的区别。我必须在Go中记录一个代码。我想尝试去招摇过市,但我找不到一个好的教程。因此,我正在尝试查看不同的教程,并根据我的代码进行调整。你知道一个好的参考资料吗?我一步一步地修改了一些信息,更新了问题和输出(错误)。