跳至主要內容

接口文档

Moments小于 1 分钟

接口文档


需求分析

  • 通过postman令牌下载相关json数据
  • 使用postman的json数据生成接口数据
  • 将接口文档数据入库,提供搜索功能

软件设计

// 数据初始化
$this->init();

// 获取集合和环境变量数据
$this->getContent();

// 解析postman数据
$this->analysis($this->collectionContent);

编码

private function analysis($collectionContent, $parentDir = '')
{
    foreach ($collectionContent as $key => $item) {
        // 目录
        if (isset($item->item)) {
            $dir = $parentDir.$item->name.'/';
            Storage::disk('postman')->makeDirectory($dir);
            $this->debug && $this->comment($dir);
            $this->analysis($item->item, $dir);
        } else {
            $filename = $parentDir.$item->name.'.md';
            $url = $this->getUrl($parentDir, $item);
            $result = view('postman.default')
                ->with('title', $item->name)
                ->with('description', $parentDir.$item->name)
                ->with('url', $url)
                ->with('method', $item->request->method)
                ->render();
            Storage::disk('postman')->put($filename, $result);

            $sections = $this->getSections($item);
            isset($sections['headers']) && Storage::disk('postman')->append($filename, $sections['headers']);
            isset($sections['query']) && Storage::disk('postman')->append($filename, $sections['query']);
            isset($sections['urlencoded']) && Storage::disk('postman')->append($filename, $sections['urlencoded']);
            isset($sections['formdata']) && Storage::disk('postman')->append($filename, $sections['formdata']);
            isset($sections['response']) && Storage::disk('postman')->append($filename, $sections['response']);
        }
    }
}
上次编辑于:
贡献者: Moments