首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MSON到JSON-Schema的“一个”问题

MSON到JSON-Schema的“一个”问题
EN

Stack Overflow用户
提问于 2017-10-20 12:34:16
回答 1查看 1.1K关注 0票数 0

我试图用ApiBlueprint MSON表示法来描述一个具有可变部分的对象。下面是ApiBlueprint中的简单代码:

代码语言:javascript
复制
 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的验证报告了一个错误:

代码语言:javascript
复制
[ {
  "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?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-20 12:50:59

我相信你是在找 type attributefixed意味着这些值是固定的,并且不能是提供的示例值以外的任何其他值。当您使用fixed-type时,您表示类型是固定的,但是值不是固定的。

代码语言:javascript
复制
+ Attributes (array[ServiceResource], fixed-type)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46849186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档