承接 psx/asyncapi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-04-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固