【问题标题】:MSON to JSON-Schema "One of" issueMSON 到 JSON-Schema “一个”问题
【发布时间】:2017-10-20 12:34:16
【问题描述】:

我试图用 ApiBlueprint MSON 符号来描述一个具有可变部分的对象。 这里是 ApiBlueprint 中的简单代码:

 FORMAT: 1A

# Test API

## Services [/Service/{id}]

### GET Service info [GET]


+ Request (application/json)

    + Headers

            Authorization: JWT <token>

+ Response 200 (application/json)

    + Attributes (array[ServiceResource], fixed)



# Data Structures

## Resource (object)
### Properties

+ id: `a6vhAo3FG` (string, fixed)
+ created_at: `2016-07-01T15:11:09.553Z` (string, required)
+ updated_at: `2017-11-22T08:07:55.002Z` (string, required)


## Service (object)

### Properties
+ type: tcp_service (string, required)
- One Of
    - config (TcpService, required)
    - config (IcmpService, required)


## ServiceResource (Resource)
### Properties

- Include Service

## TcpService (object)

### Properties

+ port: `80` (number, required) 
+ request_str: `HEAD` (string, required)
+ expect_response_str: `200 OK` (string, required)

## IcmpService (object)

### Properties

+ timeout_ms: `1000` (number, required)
+ packet_size_bytes: `1000` (number, required)
+ ttl: `128` (number, required)

它在 apiary.io 中完美呈现,但在 https://json-schema-validator.herokuapp.com 中验证生成的 Json Schema 报告错误:

[ {
  "level" : "error",
  "schema" : {
    "loadingURI" : "#",
    "pointer" : "/items"
  },
  "instance" : {
    "pointer" : "/0"
  },
  "domain" : "validation",
  "keyword" : "additionalProperties",
  "message" : "object instance has properties which are not allowed by the schema: [\"config\"]",
  "unwanted" : [ "config" ]
} ]

也许我做错了什么?

有什么方法可以在 MSON 中描述对象数组,其中对象具有提供正确 JSON 架构的变体部分?

【问题讨论】:

    标签: json apiblueprint mson


    【解决方案1】:

    我相信您正在寻找fixed-type type attributefixed 表示这些值是固定的,不能是提供的示例值以外的任何值。当您使用fixed-type 时,您表示类型是固定的,但值不是。

    + Attributes (array[ServiceResource], fixed-type)
    

    【讨论】:

    • 非常感谢。我当时认为它仅在草案 MSON 规范中,并没有注意到规范中的“固定类型”。
    • 你成就了我的一天!
    猜你喜欢
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 2011-05-02
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多