0

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

4

1 回答 1

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")
 *     )
 * )
 */
于 2017-10-27T17:06:22.290 回答