ybelenko/openapi-data-mocker-interfaces 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ybelenko/openapi-data-mocker-interfaces

Composer 安装命令:

composer require ybelenko/openapi-data-mocker-interfaces

包简介

Package with OpenApiDataMocker interfaces.

README 文档

README

Coding Style

This repository holds interfaces to generate fake data from OpenAPI Specification(OAS3). Note that this is not an implementation.

Requirements

PHP 7.3 or newer. It could work with older versions, but it's not worth to support EOL(end of life) PHP.

Important notice! While PHP 8.0 declared in composer.json this package hasn't been tested against it.

Interfaces

Class Name Description
OpenAPIServer\Mock\OpenApiModelInterface All referenced components must implement that interface.
OpenAPIServer\Mock\OpenApiDataMockerInterface Basic data generator. Can mock scalar data types.
OpenAPIServer\Mock\OpenApiServerMockerInterface Enhanced data generator. Can mock server request and server response.
OpenAPIServer\Mock\Exceptions\OpenApiDataMockerException Implementation should throw exceptions inherited from that class.

OpenAPIServer\Mock\OpenApiDataMockerInterface Constants

OpenAPISpecification - Data Types

Constant Name Referenced OAS type Referenced OAS format
DATA_TYPE_INTEGER integer
DATA_TYPE_NUMBER number
DATA_TYPE_STRING string
DATA_TYPE_BOOLEAN boolean
DATA_TYPE_ARRAY array
DATA_TYPE_OBJECT object
DATA_FORMAT_INT32 int32
DATA_FORMAT_INT64 int64
DATA_FORMAT_FLOAT float
DATA_FORMAT_DOUBLE double
DATA_FORMAT_BYTE byte
DATA_FORMAT_BINARY binary
DATA_FORMAT_DATE date
DATA_FORMAT_DATE_TIME date-time
DATA_FORMAT_PASSWORD password
DATA_FORMAT_EMAIL
DATA_FORMAT_UUID

OpenAPIServer\Mock\OpenApiDataMockerInterface Methods

Method Name Description Return Type
mockData(string $dataType, ?string $dataFormat = null, ?array $options = []) Mocks OpenApi Data. mixed
mockInteger(?string $dataFormat = null, ?float $minimum = null, ?float $maximum = null, ?bool $exclusiveMinimum = false, ?bool $exclusiveMaximum = false): int Shortcut to mock integer type. Equivalent to mockData(DATA_TYPE_INTEGER)*. int
mockNumber($dataFormat = null, $minimum = null, $maximum = null, $exclusiveMinimum = false, $exclusiveMaximum = false): float Shortcut to mock number type. Equivalent to mockData(DATA_TYPE_NUMBER)*. float
mockString(?string $dataFormat = null, ?int $minLength = 0, ?int $maxLength = null, ?array $enum = null, ?string $pattern = null): string Shortcut to mock string type. Equivalent to mockData(DATA_TYPE_STRING)*. string
mockBoolean(): bool Shortcut to mock boolean type. Equivalent to mockData(DATA_TYPE_BOOLEAN)* bool
mockArray(array $items, ?int $minItems = 0, ?int $maxItems = null, ?bool $uniqueItems = false): array Shortcut to mock array type. Equivalent to mockData(DATA_TYPE_ARRAY)*. array
mockObject(array $properties, ?int $minProperties = 0, ?int $maxProperties = null, $additionalProperties = null, ?array $required = null): object Shortcut to mock object type. Equivalent to mockData(DATA_TYPE_OBJECT)*. object
mockSchemaObject(array $schema) Mocks OpenApi Schema Object. mixed

* constant class is omitted, so mockData(DATA_TYPE_INTEGER) means mockData(\OpenAPIServer\Mock\OpenApiDataMockerInterface\DATA_TYPE_INTEGER).

OpenAPIServer\Mock\OpenApiModelInterface Methods

Method Name Description Return Type
static getOpenApiSchema(): array Gets OAS 3.0 schema mapped to current class. array
static createFromData($data): OpenApiModelInterface Creates new instance from provided data. OpenAPIServer\Mock\OpenApiModelInterface
jsonSerialize() inherited from JsonSerializable Serializes the object to a value that can be serialized natively by json_encode(). mixed

OpenAPIServer\Mock\OpenApiServerMockerInterface Methods

Same methods as OpenAPIServer\Mock\OpenApiDataMockerInterface + following methods:

Method Name Description Return Type
setServer(?string $url = null, ?array $variables = null): void Sets base url for mocked requests. void
mockRequest(string $path, string $method, ?array $parameters = null, ?array $requestBody = null, ?array $security = null, ?array $callbacks = null): ServerRequestInterface Mocks PSR-7 server request. Psr\Http\Message\ServerRequestInterface
mockResponse(string $httpStatusCode = '200', ?array $headers = null, ?string $contentMediaType = null, ?array $contentSchema = null): ResponseInterface Mocks PSR-7 server response. Psr\Http\Message\ResponseInterface

OpenAPIServer\Mock\Exceptions\OpenApiDataMockerException

This class makes possible to catch exceptions related to mocking feature only. It's highly encouraged not to throw builtin PHP exceptions like Exception, InvalidArgumentException etc. Use this class or extend it with your own exceptions to fit your needs.

Related Packages

Copyright

While author of this package is top contributor to OpenAPI-Generator project he's not member of OpenAPI Initiative (OAI).

ybelenko/openapi-data-mocker-interfaces 适用场景与选型建议

ybelenko/openapi-data-mocker-interfaces 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.35k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「faker」 「data」 「mock」 「fake」 「swagger」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ybelenko/openapi-data-mocker-interfaces 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ybelenko/openapi-data-mocker-interfaces 我们能提供哪些服务?
定制开发 / 二次开发

基于 ybelenko/openapi-data-mocker-interfaces 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 34
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-18