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松弛来进行更多实时讨论。
关于javascript - AsyncAPI的架构验证,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56359340/