相关疑难解决方法(0)

OpenApi 3.0:对现有类的引用

我想使用库中的类作为属性的类型。说是吧foo.lib.Foo。将其正确定义为属性类型的正确方法是什么?

SomeDto:
  type: object
  properties:
     foo:
        $ref: `foo.lib.Foo`??? 
Run Code Online (Sandbox Code Playgroud)

swagger openapi

6
推荐指数
1
解决办法
5672
查看次数

按照swagger规范,如何将嵌套对象的json定义为yaml?

我在swagger yaml中定义对象数组时遇到问题.每当我尝试定义类型时,Swagger编辑器都会给出错误:yaml的数组部分.我定义了它,但它不正确,因为它给出了一个错误.以下是我试图在招摇的yaml中定义的json.

{
    "CountryCombo": {
        "options": {
            "option": [{
                "id": "GB",
                "value": "GB Great Britain"
            }, {
                "id": "US",
                "value": "US United States"
            }, {
                "id": "AD",
                "value": "AD Andorra, Principality of"
            }]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我将这个json定义为像这样的swagger yaml,但它给出了一个错误:

CountryCombo:
    type: object
    properties:
        options:
            type: object
            properties:
                option:
                    type: array
                    items:
                        - id:
                            type: string
                            description: GB
                          value:
                            type: string
                            description: GB Great Britain
                        - id:
                            type: string
                            description: US
                          value:
                            type: string
                            description: US United States
                        - id:
                            type: string …
Run Code Online (Sandbox Code Playgroud)

json swagger swagger-ui swagger-2.0 swagger-editor

5
推荐指数
2
解决办法
8385
查看次数

Swagger 2.0 中没有类型属性的架构对象

Swagger/OpenAPI 2.0 中的 Schema 对象是否必须具有该type属性?

一方面,根据 JSON Schema Draft 4 规范,不指定type属性是可以的,这意味着实例可以是任何类型(对象、数组或基元)。

另一方面,我已经看到很多 Swagger 模式,其中包含没有type属性的Schema 对象,但是有properties属性,这清楚地表明模式作者希望实例是一个适当的对象(并且不想接受数组或原始值作为有效值)。

所有这些模式都不正确吗?或者是type: object隐含的存在properties?Swagger 或 JSON Schema 规范中都没有说明情况就是如此。事实上,我看到一些评论明确表示情况并非如此。

jsonschema swagger swagger-2.0 openapi

5
推荐指数
1
解决办法
3717
查看次数

如何在 OpenAPI 3.0 的架构中使用 $ref?

我想schema在 OpenAPI 3.0 API 定义中将以下 JSON 表示为 a :

{
get-question: {
  question-id:string
  }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经写了:

{
get-question: {
  question-id:string
  }
}
Run Code Online (Sandbox Code Playgroud)

但我在 Swagger 编辑器中收到这些错误:

Schema error at components.schemas['GetQuestion']
should have required property '$ref'
missingProperty: $ref
Jump to line 79
Schema error at components.schemas['GetQuestion']
should match exactly one schema in oneOf
Jump to line 79
Schema error at components.schemas['GetQuestion'].properties['get-questions']
should have required property '$ref'
missingProperty: $ref
Jump to line 81
Schema error at components.schemas['GetQuestion'].properties['get-questions']
should match exactly one …
Run Code Online (Sandbox Code Playgroud)

openapi

5
推荐指数
1
解决办法
5058
查看次数

OpenAPI 3 - 属性的重用

以下是 OpenAPI 3 定义的示例:

components:
  schemas:
    Foo:
      properties:
        string:
          type: string
        enumField:
          type: string
          enum: ['VALUE_1', 'VALUE_2']
    Bar:
      properties:
        enumField:
          type: string
          enum: ['VALUE_1', 'VALUE_2']
Run Code Online (Sandbox Code Playgroud)

有没有办法重用enumField或者我每次使用时都必须指定它?

swagger openapi

4
推荐指数
1
解决办法
4512
查看次数