我在 Php Laravel 中编写 API 并使用 swagger (2.0) 注释(lib: darkaonline/l5-swagger 使用 swagger-php )来生成 swagger.json,但是我有以下问题 - 当我输入时:
/**
*
* Space Schema
*
* @SWG\Get(
* path="/api/v1/client/space/schema",
* @SWG\Response(
* response=200,
* description="OK",
* @SWG\Property(property="result", type="json", example={ "aa": [ "bb", "cc" ] } )
* )
* )
然后尝试生成 swagger.json 我得到:
[Syntax Error] Expected PlainValue, got '[' in ...
但是当我不使用方括号时,例如:
@SWG\Property(property="result", type="json", example={ "ee": "ff" })
然后一切都很好。但是我需要使用方括号所以问题是:
什么是 swagger 注释中 json 字符串中 [
(方括号)的转义字符?
我还想补充一点,我的示例 json 非常大且复杂
最佳答案
我无意中找到了更好的解决方案:
更改方括号([
和 ]
):
@SWG\Property(property="result", type="json", example={ "aa": [ "bb", "cc" ] } )
大括号({
和 }
):
@SWG\Property(property="result", type="json", example={ "aa": { "bb", "cc" } } )
如您所见,我们使用大括号,但我们不使用键:值连接(仅键),因此 swagger 能够检测数组。
我们在 swagger-ui 中有漂亮且简单的格式化 json :)
https://stackoverflow.com/questions/47566656/