【问题标题】:Where to put @SWG\Definition to be reused with Swagger-PHP and Nelmio API-DOC Bundle将@SWG\Definition 放在哪里以便与 Swagger-PHP 和 Nelmio API-DOC Bundle 一起重用
【发布时间】:2017-10-27 16:18:14
【问题描述】:

我想在某处写一个@SWG\Definition 并在我的 Symfony 3 应用程序中的多个 REST API 操作的 @SWG\Response 注释中的 @SWG\Schema 中引用它。我正在使用 Nelmio 的 api-doc-bundle 的 dev-master 版本,但我似乎可以找到任何暗示该定义应该去哪里的东西。 Swagger-PHP 文档敦促尽可能不要重复,我想遵循该建议。有什么提示吗?

【问题讨论】:

    标签: php symfony swagger-php nelmioapidocbundle


    【解决方案1】:

    典型的...最后分解并询问然后很快找出解决方案...

    我发现我可以在 Symfony 的 app/config/config.yml 中预加载文档数据。

    nelmio_api_doc:
        documentation:
            definitios:
                Error: 
                    type: object
                    properties:
                        success:
                            type: boolean
                            example: false
                        error:
                            type: string
                            example: message
    

    现在我可以在我的所有 REST 操作中使用类似的东西

    /**
     *  @API\Operation(
     *     ...
     *     @SWG\Response(
     *         response="default",
     *         description="Failure",
     *         @SWG\Schema(ref="#definitions/Error")
     *     )
     * )
     */
    

    【讨论】:

    • 这种方法的问题在于似乎没有办法使用@API\Model() 触发实体定义的生成。
    猜你喜欢
    • 2018-06-17
    • 2015-11-25
    • 2018-03-17
    • 1970-01-01
    • 2018-01-04
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多