[英]Failing to add examples to YAML file
Purpose: Add examples to yaml file so it will be exposed in Postman collection.目的:将示例添加到 yaml 文件中,以便在 Postman 集合中公开。
I'm trying to add 2 simple example but keep getting errors.我正在尝试添加 2 个简单示例,但不断出现错误。 The current error is: missed comma between flow collection entries.当前的错误是:流集合条目之间缺少逗号。
Can you please assist?你能帮忙吗?
swagger: "2.0" info: description: "Test" version: "1.4.4" title: "my-test" host: "somehost" basePath: "/somepath" schemes: - "https" tags: - name: Recommend description: helloWorld paths: /hello: post: description: "some description" operationId: "example-test" tags: ["example-test"] produces: "application/json" parameters: name: "myRequest" in: "body" description: "bla" required: true schema: $ref: "#/definitions/myRequest" examples: {ex1: $ref: "#/components/examples/test1", ex2: $ref: "#/components/examples/test2" } responses: "204": description: "All good" definitions: myRequest: type: object required: - name - lastname properties: name: type: string lastname: type: string components: examples: test1: value: name: test1 lastname: test1 test2: value: name: test2 lastname: test2
You are mixing up OpenAPI 2.0 and 3.0 syntax.您正在混淆 OpenAPI 2.0 和 3.0 语法。
Multiple examples
are supported in OpenAPI 3.0 only.仅 OpenAPI 3.0 支持多个examples
。 The correct syntax is:正确的语法是:
openapi: 3.0.0
...
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
requestBody: # <------
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/myRequest"
examples: # <------
ex1:
$ref: "#/components/examples/test1"
ex2:
$ref: "#/components/examples/test2"
responses:
"204":
description: "All good"
components:
schemas:
myRequest:
...
examples:
test1:
value:
name: test1
lastname: test1
test2:
value:
name: test2
lastname: test2
If you use OpenAPI 2.0 ( swagger: '2.0
), you can only define a single example, and this example must be specified inline, it cannot be $ref
erenced.如果你使用 OpenAPI 2.0 ( swagger: '2.0
),你只能定义一个例子,并且这个例子必须内联指定,它不能被$ref
引用。
swagger: "2.0"
...
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
produces:
- "application/json" # <---- Note the leading dash here
parameters:
- name: "myRequest" # <---- Note the leading dash here
in: "body"
description: "bla"
required: true
schema:
$ref: "#/definitions/myRequest"
responses:
"204":
description: "All good"
definitions:
myRequest:
type: object
required:
- name
- lastname
properties:
name:
type: string
lastname:
type: string
example: # <---- Example value for a schema
name: test1
lastname: test1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.