标签: openapi

/components/parameters 中的 openApi 3 allOf

我正在尝试使用 open api 3 创建一个 swagger 文档,但是当我尝试allOf在参数定义中使用关键字时出现错误

components:
  parameters:
    idParam:
      name: id
      in: path
      description: ID of the boxx
      required: true
      schema:
        type: string
        format: int65
    dataSourceID:
      allOf:
        - $ref: '#/components/parameters/idParam'
        - name: dataSourceID
          description: ID of the data source
Run Code Online (Sandbox Code Playgroud)

components.parameters['dataSourceID'] 处的架构错误

不应该有额外的属性

附加属性:allOf

是否可以重用另一个参数的值?也许以不同的方式?

swagger swagger-editor openapi

3
推荐指数
1
解决办法
2891
查看次数

如何在 swagger 2.0 中定义 basePath

查看 swagger 文档,特别是我没有找到如何定义 host 和 basePath 属性的注释。知道在哪里设置它们吗?

参考文档: Swagger-2.X---Annotations

这是使用变量生成的 json: petstore.swagger.io/v2/swagger.json

swagger-ui swagger-2.0 openapi

3
推荐指数
1
解决办法
5365
查看次数

模型 OpenAPI 2.0 文件下载,类型字符串:二进制与类型文件

我有点困惑如何使用 Swagger/OpenAPI v2 对文件下载进行建模。以这个小例子为例:

/files/{name}.zip:
  get:
    summary: Returns the requested ZIP file as "file download" i.e. with content-disposition = attachment
    produces:
      - application/zip
    parameters:
      - name: name
        in: path
        required: true
        type: string
    responses:
      200:
        description: OK
        schema:
          type: file      # <- what is it?
        headers:
          Content-Disposition:
            type: string
            description: the value is `attachment; filename="name.zip"`
Run Code Online (Sandbox Code Playgroud)

我使用什么作为响应类型?是type: string&format: binary还是干脆type: file

我在看https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-typeshttps://github.com/OAI/OpenAPI-Specification/blob/master/版本/2.0.md#response-object(响应数据类型file)但我不清楚两者有何不同。应该在什么时候使用?

此外,Content-Disposition标题的使用对选择一个或另一个有影响吗?

自我注意,也看了

swagger swagger-2.0 openapi

3
推荐指数
1
解决办法
6063
查看次数

OpenAPI 模式的媒体类型是什么?

每当搜索此内容时,我都会找到有关如何指定模式定义的资源的媒体类型的资源,但我看不到有关模式本身的实际媒体类型是什么的答案。

鉴于 HTTP 的工作方式,对我来说,如果我使用 Accept 标头请求正确的内容类型,我的服务器可以适当地响应是有意义的。

因此,如果我请求/productsAccept: application/json我将获得 JSON 格式的产品,但如果我请求openapi-whatever我将获得 OpenAPI 模式。

我可能可以使用application/openapi+jsonapplication/openapi+yaml,但在实际规范中我看不到任何有关它的信息。

我不确定我是否真的想使用 Accept 标头来解决这个差异,但我当然想在任何情况下都使用正确的 Content-Type 标头进行响应。

media-type swagger openapi

3
推荐指数
1
解决办法
1460
查看次数

如何在 SwaggerHub 中的不同 API 之间进行引用?

我正在使用 SwaggerHub 和 OpenAPI 3.0.0。我在 SwaggerHub 中有两个 API。

第一个有以下访问链接:https : //app.swaggerhub.com/apis/myapipath/1.0.0并包含一个名为components/schemas/ApiOffer.

在第二个 API 中,我希望该属性offer成为$ref该定义的一个。我用:

components:
  schemas:
    Offerers:
      type: object
      required:
        - offererId
        - overview
      properties:
        offererId:
          $ref: '#/components/schemas/OfferersId'
        overview:
          $ref: '#/components/schemas/OfferersOverview'
        offer:
          $ref: 'https://app.swaggerhub.com/apis/myapipath/1.0.0#/components/schemas/ApiOffer'
Run Code Online (Sandbox Code Playgroud)

但得到以下错误:

“无法解析引用,因为:无法解析指针:文档中不存在 /components/schemas/ApiOffer”

即使/components/schemas/ApiOffer定义存在。

如何更正我的引用以使其指向其他 API?

swagger openapi swaggerhub

3
推荐指数
1
解决办法
510
查看次数

Swagger OpenAPI 使用带有模式的对象而不是数组

我正在使用L5 SwaggerfromDarkOnLine使用 OpenApi 原理图生成 Swagger 文档。

使用模式我可以做

@OA\Property(property="certification", type="array", @OA\Items(ref="#/components/schemas/Certification"))
Run Code Online (Sandbox Code Playgroud)

它工作得很好,显示为

"certification": [
    {
      "certification_id": 0,
      "name": "string"
    }
  ],
Run Code Online (Sandbox Code Playgroud)

. 但是它创建了一个带有方括号的数组块,里面有多个对象。

如何使用相同的工作但丢失数组。就像是

@OA\Property(property="certification", type="object", @OA\Items(ref="#/components/schemas/Certification")),
Run Code Online (Sandbox Code Playgroud)

以便删除方括号并仅显示对象。

"certification": {
      "certification_id": 0,
      "name": "string"
 }
Run Code Online (Sandbox Code Playgroud)

swagger swagger-php openapi

3
推荐指数
1
解决办法
3257
查看次数

OpenAPI 3 -- 属性在写入时是可选的,但在读取时是必需的

我的资源有一个 ID(典型情况)。

它还有一个slug,一个人类可读但仍然是唯一的标识符(主要用于美化 URL)。

创建资源时,此slug可选的。如果客户端提供了一个,它正在被使用;否则,服务器生成一个。

但是,在读取资源时需要slug

我们确实希望这种区别是明确的,因此任何阅读 OpenAPI 规范的工具都知道确切期望什么。

这当然可以使用与allOf修饰符链接的不同模式的混合来实现(参见下面的示例),但我想避免必须执行这种组合(假设它首先与工具一起工作)。

所以我的问题是:

在 OpenAPI >= 3.0.2 中有没有办法声明属性 required-readOnly 和 optional-writeOnly?

使用组合的解决方案:

openapi: 3.0.2
info:
  title: Person API
  version: 1.0.0

paths: 
  '/persons/{person-slug}':
    get:
      parameters:
        - $ref: '#/components/parameters/PersonSlug'
      responses:
        200:
          description: Information on a person.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SlugRead'
                  - $ref: '#/components/schemas/Person'
    post:
      parameters:
        - $ref: '#/components/parameters/PersonSlug'
      responses:
        200:
          description: Information on a person.
          content:
            application/json:
              schema:
                allOf: …
Run Code Online (Sandbox Code Playgroud)

rest swagger openapi

3
推荐指数
1
解决办法
2287
查看次数

Node.js server generated automatically doesn't start (Swagger/OpenAPI)

I have generated a nodejs-server by Swagger Editor, but when I run "npm start" the server doesn't start and return no error.

First time I've run "npm start" all dependencies has been installed, but "node index.js" doesn't start the server.

Second time I've tried "npm start":

dev01@dev01:~/nodejs-server$ npm start

> back-end-rota-exata@1.0.0 prestart /home/dev01/nodejs-server
> npm install


> back-end-rota-exata@1.0.0 start /home/dev01/nodejs-server
> node index.js

dev01@dev01:~/nodejs-server$ 
Run Code Online (Sandbox Code Playgroud)

Then I've tried just "node index.js" too:

dev01@dev01:~/nodejs-server$ node index
dev01@dev01:~/nodejs-server$ 
Run Code Online (Sandbox Code Playgroud)

And nothing happens...

This is …

node.js swagger openapi

3
推荐指数
1
解决办法
1597
查看次数

YYYYMMDD yaml 定义上的日期格式

我有一个要求,其中请求以 YYYYMMDD 格式传递日期。基于 swagger 文档,在字符串类型下定义的日期归档。但是,它遵循 RFC 3339,第 5.6 节,文档(例如 2018-03-20 作为格式)

下面的代码不适用于 yaml。

dateOfBirth:
          type: string
          minLength: 8
          maxLength: 8
          format: date
          example: 19000101
          description: Birth date of the  member in YYYYMMDD format.
Run Code Online (Sandbox Code Playgroud)

如何为 YYYYMMDD 的日期格式定义 YAML 定义。

rest swagger openapi

3
推荐指数
1
解决办法
3899
查看次数

从 OpenAPI 3 生成 Java Spring API

我试图从 OpenAPI v3 YAML 文件生成 Spring REST 接口。构建 说:

Successfully generated code to property(class java.lang.String, property(class java.lang.String, fixed(class java.lang.String, /home/zolv/workspaces/main/generation-test/src/main/java)))

Deprecated Gradle features were used in this build, making it 
incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
Run Code Online (Sandbox Code Playgroud)

但是输出目录中没有生成代码。

我遵循了OpenAPI 生成器 gradle 插件文档文档。

我的 build.gradle:

plugins {
  id 'java-library'
  id "org.openapi.generator" version "4.1.1"
}

repositories {
  jcenter()
}

dependencies {
    implementation "org.openapitools:openapi-generator-gradle-plugin:3.3.4"
}

openApiGenerate {
  generatorName = "spring"
  inputSpec = "$rootDir/docs/openapi/api.yml".toString() …
Run Code Online (Sandbox Code Playgroud)

java spring gradle openapi openapi-generator

3
推荐指数
1
解决办法
1万
查看次数