【问题标题】:Is there a way to convert swagger inspector yaml result into php attributes?有没有办法将 swagger 检查器 yaml 结果转换为 php 属性?
【发布时间】:2022-11-11 21:27:46
【问题描述】:

Swagger 检查器是一个很棒的工具,它只需提供一个 URL 就可以创建 openapi 文档。

但它创建了一个 yaml 文件,我想在 PHP 属性中获取它,因为我主要在我的应用程序中使用 PHP 属性。 我希望能够在 PHP 属性中生成它,或者能够将 yaml 转换为 PHP 属性。

我得到什么:

openapi: 3.0.1
info:
  title: defaultTitle
  description: defaultDescription
  version: '0.1'
servers:
  - url: http://localhost.fr:8002
paths:
  /api/package:
    post:
      description: Auto generated using Swagger Inspector
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                software:
                  type: array
                  items:
                    type: object
                    properties:
                      package:
                        type: string
                      version:
                        type: string
...

我想要什么:

<?php

use OpenApi\Attributes as OA;

#[OA\Post(
    path: '/api/package',
    requestBody: new OA\RequestBody(
        description: 'Add a new package',
        required: true,
        content: new OA\MediaType(
            mediaType: 'multipart/form-data',
            schema: new OA\Schema(
                properties: [
                    new OA\Property(
                        property: 'package',
                        type: 'string',
                    ),
                    new OA\Property(
                        property: 'version',
                        type: 'string',
                    ),
                ]
            )
        )
    )
)]
class AddPackage
{
}

【问题讨论】:

    标签: swagger openapi swagger-inspector


    【解决方案1】:

    你试过这个库吗? https://github.com/cebe/php-openapi

    请参阅自述文件中有关读取文件的此部分,https://github.com/cebe/php-openapi#reading-api-description-files

    【讨论】:

    • 虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。请edit回答所有相关信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2013-08-13
    • 2021-04-07
    • 2013-07-22
    相关资源
    最近更新 更多