Swagger和JSON补丁

时间:2017-07-09 23:29:42

标签: rest swagger swagger-ui

我的数据库中有以下对象结构

cp .env.example .env
php artisan key:generate
Application key [...] set successfully.

php artisan config:clear
Configuration cache cleared!

php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!

php artisan cache:clear
Cache cleared successfully.

可以从客户端修改键值 supportedProducts

我正在使用swagger文档构建PATCH API方法以支持上述功能。但我不确定补丁对象的定义,因为文档没有提供构建PATCH的详细示例。

我当前的定义在执行时最终会出错,如下所示

// do stuff with result

2 个答案:

答案 0 :(得分:2)

对于这个简单的情况,我会使用JSON Patch对象来描述要对目标进行的操作。 这是JSON Patch Swagger API的example

_renderItem = ({item}) => 
    <Observer>{
        () => <Text style={styles.item}>{item.name}</Text>}
    </Observer>

答案 1 :(得分:1)

对于OpenApi 3.0.x,.yaml文件的结构已更改。有效的定义如下:

components:
  requestBodies:
    PatchBody:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PatchBody'

  schemas:
    PatchBody:
      type: array
      items:
        $ref: "#/components/schemas/PatchDocument"

    PatchDocument:
      type: object
      description: A JSONPatch document as defined by RFC 6902 
      required:
       - "op"
       - "path"
      properties: 
       op: 
        type: string 
        description: The operation to be performed 
        enum:
         - "add"
         - "remove"
         - "replace"
         - "move"
         - "copy"
         - "test"
       path: 
        type: string 
        description: A JSON-Pointer 
       value: 
        type: object 
        description: The value to be used within the operations.
       from: 
        type: string 
        description: A string containing a JSON Pointer value.            

    patch:
      parameters:
        - $ref:  '#/components/parameters/objectId'
      requestBody:
        $ref: '#/components/requestBodies/PatchBody'
      responses:
        ...