javascript - AsyncAPI 的架构验证

标签 javascript validation messaging

AsyncAPI这是一个伟大的举措,我将其用于消息驱动服务。

我正在尝试使用名为 check_api 的架构验证工具.

我的java脚本文件内容是:

const check_api = require('check_api');
const options = {};
options.source = './async-api.yml';
options.convert = false;

api = {
    "asyncapi" : "1.x"
}

check_api.check_api(api, options,function(err, opts){
    console.log(err)
});

当我执行:node ./check-api.js

输出为:

[ { keyword: 'enum',
    dataPath: '/asyncapi',
    schemaPath: '#/properties/asyncapi/enum',
    params: { allowedValues: [Array] },
    message: 'should be equal to one of the allowed values',
    schema: [ '1.0.0', '1.1.0', '1.2.0' ],
    parentSchema:
     { type: 'string',
       enum: [Array],
       description: 'The AsyncAPI specification version of this document.' },
    data: '1.x' },
  { keyword: 'required',
    dataPath: '',
    schemaPath: '#/required',
    params: { missingProperty: 'info' },
    message: 'should have required property \'info\'',
    schema:
     { asyncapi: [Object],
       info: [Object],
       baseTopic: [Object],
       servers: [Object],
       topics: [Object],
       stream: [Object],
       events: [Object],
       components: [Object],
       tags: [Object],
       security: [Object],
       externalDocs: [Object] },
    parentSchema:
     { title: 'AsyncAPI 1.2.0 schema.',
       id: 'http://asyncapi.hitchhq.com/v1/schema.json#',
       '$schema': 'http://json-schema.org/draft-04/schema#',
       type: 'object',
       required: [Array],
       oneOf: [Array],
       additionalProperties: false,
       patternProperties: [Object],
       properties: [Object],
       definitions: [Object] },
    data: { asyncapi: '1.x' } },
  { keyword: 'required',
    dataPath: '',
    schemaPath: '#/oneOf/0/required',
    params: { missingProperty: 'topics' },
    message: 'should have required property \'topics\'',
    schema: [ 'topics' ],
    parentSchema: { required: [Array] },
    data: { asyncapi: '1.x' } },
  { keyword: 'required',
    dataPath: '',
    schemaPath: '#/oneOf/1/required',
    params: { missingProperty: 'stream' },
    message: 'should have required property \'stream\'',
    schema: [ 'stream' ],
    parentSchema: { required: [Array] },
    data: { asyncapi: '1.x' } },
  { keyword: 'required',
    dataPath: '',
    schemaPath: '#/oneOf/2/required',
    params: { missingProperty: 'events' },
    message: 'should have required property \'events\'',
    schema: [ 'events' ],
    parentSchema: { required: [Array] },
    data: { asyncapi: '1.x' } },
  { keyword: 'oneOf',
    dataPath: '',
    schemaPath: '#/oneOf',
    params: {},
    message: 'should match exactly one schema in oneOf',
    schema: [ [Object], [Object], [Object] ],
    parentSchema:
     { title: 'AsyncAPI 1.2.0 schema.',
       id: 'http://asyncapi.hitchhq.com/v1/schema.json#',
       '$schema': 'http://json-schema.org/draft-04/schema#',
       type: 'object',
       required: [Array],
       oneOf: [Array],
       additionalProperties: false,
       patternProperties: [Object],
       properties: [Object],
       definitions: [Object] },
    data: { asyncapi: '1.x' } } ]

似乎验证器将 api JSON 对象视为其输入,而不是从源文件中读取它。

我很高兴获得一个如何验证异步 api yaml 描述的示例。

最佳答案

请记住,AsyncAPI 现在是 2.0 版本,除了 Check API - https://www.asyncapi.com/docs/tooling/#validators 之外,还有许多不同的验证器。

如果需要,您可以加入 AsyncAPI slack 进行更多实时讨论。

关于javascript - AsyncAPI 的架构验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56359340/

相关文章:

javascript - 提交时仅在 jQuery 中显示一次消息

javascript - 使用JavaScript或jQuery将图像转换为字节数组?

asp.net - 如果客户端验证失败,如何隐藏 div(在客户端上)?

java - JMS Receive 如何在内部工作?

messaging - Google 的 Protocol Buffer 是否用于大规模生产应用程序?

Android以编程方式通过彩信发送图像(操作超时)

javascript - 是否可以添加一个链接来下载只能通过在 Facebook 上共享来下载的文件?

php javascript 压缩器

c# - ASP.NET c# 表单验证

python - 维护用户输入数据,同时返回验证错误