psx/asyncapi
最新稳定版本:v0.2.1
Composer 安装命令:
composer require psx/asyncapi
包简介
Model classes to generate an AsyncAPI specification in a type-safe way
关键字:
README 文档
README
About
This library contains model classes to generate an AsyncAPI specification in a type-safe way. The models are
automatically generated based on the TypeSchema specification (s. typeschema.json). The
following example shows how you can generate an OpenAPI spec:
$info = new Info(); $info->setTitle('Account Service'); $info->setVersion('1.0.0'); $info->setDescription('This service is in charge of processing user signups :rocket:'); $message = new Message(); $message->setPayload(Record::fromArray(['$ref' => '#/components/schemas/Pet'])); $http = new HttpOperationBinding(); $http->setType('request'); $http->setMethod('POST'); $bindings = new OperationBindings(); $bindings->setHttp($http); $operation = new Operation(); $operation->setMessage($message); $operation->setBindings($bindings); $channel = new Channel(); $channel->setPublish($operation); $channels = new Channels(); $channels->put('user/signedup', $channel); $schemas = new Schemas(); $schemas->put('Pet', [ 'required' => ['id', 'name'], 'properties' => [ 'id' => ['type' => 'integer', 'format' => 'int64'], 'name' => ['type' => 'string'], 'tag' => ['type' => 'string'], ] ]); $components = new Components(); $components->setSchemas($schemas); $asyncAPI = new AsyncAPI(); $asyncAPI->setInfo($info); $asyncAPI->setChannels($channels); $asyncAPI->setComponents($components); echo json_encode($asyncAPI, JSON_PRETTY_PRINT);
This would result in the following JSON:
{
"asyncapi": "2.6.0",
"info": {
"title": "Account Service",
"description": "This service is in charge of processing user signups :rocket:",
"version": "1.0.0"
},
"channels": {
"user\/signedup": {
"publish": {
"bindings": {
"http": {
"type": "request",
"method": "POST"
}
},
"message": {
"payload": {
"$ref": "#\/components\/schemas\/Pet"
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
}
}
Contribution
If you want to suggest changes please only change the typeschema.json specification and then run
the php gen.php script to regenerate all model classes.
统计信息
- 总下载量: 866
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-04-07