dsuurlant/response2schema 问题修复 & 功能扩展

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

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

dsuurlant/response2schema

最新稳定版本:1.0.5

Composer 安装命令:

composer require dsuurlant/response2schema

包简介

Generate an OpenAPI schema definition for an object based on a JSON response.

关键字:

README 文档

README

A quick 'n easy way to generate your OpenAPI spec based on a JSON object. Useful for bootstrapping your component schemas. This is intended to be a starting point for writing your specification, as the tool cannot infer types such as enum, oneOf, maximum/minimum, and so on. It also does not support generating endpoints or error responses. All it does is take your JSON object and turns it into an OpenAPI schema object, along with a simple example spec that you can expand on.

Supports generating an OpenAPI spec in JSON or yaml.

Installation

composer require dsuurlant/response2schema

Or download the phar from the Releases page.

Usage

Just point Response2Schema to your input json file, and tell it where to put the output OpenAPI spec.

It will automatically format it to json or yaml based on the extension of the output path.

./vendor/bin/response2schema response.json openapi.yaml

Or when using the phar:

./response2schema.phar response.json openapi.yaml

Example

Given a very simple response:

{
    "id": 1,  
    "name": "Example Response"
}

Response2Schema generates the following spec:

openapi: 3.0.0
info:
  title: 'OpenAPI specification automatically generated by Response2Schema.'
  description: 'Please adapt this specification to your own needs.'
  version: 1.0.0
paths:
  /resource:
    get:
      description: 'Description of the endpoint'
      operationId: getResource
      responses:
        '200':
          description: 'Description of this response.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Resource'
components:
  schemas:
    Resource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string

It will always generate the example endpoint and a schema named 'Resource'.

The best way to use this tool is to take this as a starting point, or copy-paste the schema definition to your own OpenAPI spec.

Credits

Built and maintained by Daniëlle Suurlant.

Relies heavily on the awesome PHP OpenAPI library cebe/php-openapi.

统计信息

  • 总下载量: 46.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 90
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 90
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-25