相关疑难解决方法(0)

JSON模式:"allof"带有"additionalProperties"

假设我们有模式跟随模式(来自这里的教程):

{
  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city":           { "type": "string" },
        "state":          { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  },

  "type": "object",

  "properties": {
    "billing_address": { "$ref": "#/definitions/address" },
    "shipping_address": {
      "allOf": [
        { "$ref": "#/definitions/address" },
        { "properties":
          { "type": { "enum": [ "residential", "business" ] } },
          "required": ["type"]
        }
      ]
    } 

  }
}
Run Code Online (Sandbox Code Playgroud)

这是有效的实例:

{
      "shipping_address": {
        "street_address": "1600 Pennsylvania Avenue …
Run Code Online (Sandbox Code Playgroud)

javascript json jsonschema

54
推荐指数
4
解决办法
2万
查看次数

Swagger:不允许的附加属性:allOf

我试图通过使用allOf. 这是我的 swagger yaml 文件。

swagger: '2.0'
info:
  title: Test API
  version: '1'
basePath: /api/v1
schemes:
  - https
produces:
  - application/json

paths:
  /users:
    get:
      summary: Collection of users
      tags:
        - users
      responses:
        200:
          description: A list of Users
          schema:
            $ref: "#/definitions/Users"        
        500:
          $ref: "#/responses/BadRequest"

definitions:
  User:
    required:
      - username
    properties:
      firstName:
        type: string
      lastName:
        type: string
      username:
        type: string
  Users:
    type: array
    items:
      $ref: "#/definitions/User"

responses:
  NonSuccess:
    description: Generic response for all non-success responses
    schema:
      type: object
      required: …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-2.0 swagger-editor

2
推荐指数
1
解决办法
8670
查看次数