Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NewToolAI committed Dec 5, 2024
1 parent de38014 commit f70f60c
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 185 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,目前支持

- 1.x.x版本相对于0.x.x使用方式发生了变化,请参照下面的使用方法。

- docapi建立更新文档需要使用API服务项目环境
- docapi建立更新文档需要使用API服务依赖环境

## 特性

Expand All @@ -40,18 +40,30 @@ DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,目前支持

- [2024-12-02] windows操作系统测试通过 (需要使用power shell 或 windows terminal);新的模型名称提供方式,防止环境变量冲突 (参照下面使用方法)。

- [2024-12-05] 支持Django,4.2.x版本测试通过
- [2024-12-05] 支持Django 3, 4, 5 版本, 并测试通过

## 安装

```bash
pip install -U docapi
```

```bash
pip install -U "docapi[all]"
```

```bash
pip install -U "docapi[flask]"
```

```bash
pip install -U "docapi[django]"
```

#### pypi官方源安装

```bash
pip install -U docapi -i https://pypi.org/simple
pip install -U docapi[all] -i https://pypi.org/simple
```

#### github源码安装
Expand Down Expand Up @@ -107,7 +119,7 @@ docapi serve

- Flask (>=3.0.0)

- Django (>=4.2.0)
- Django (3, 4, 5)

## API Web页面

Expand All @@ -121,8 +133,10 @@ docapi serve

- ~~支持自定义文档模版。~~

- ~~多线程加速请求~~
- ~~支持多线程加速请求~~

- ~~支持Windows操作系统.~~

- ~~支持django框架。~~

- 支持更多的模型和api框架。
28 changes: 21 additions & 7 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ DocAPI is a Python package that automatically generates API documentation using
pip install -U docapi
```

```bash
pip install -U "docapi[all]"
```

```bash
pip install -U "docapi[flask]"
```

```bash
pip install -U "docapi[django]"
```

#### Install from PyPI Official Repository

```bash
Expand Down Expand Up @@ -106,22 +118,24 @@ docapi serve

- Flask (>=3.0.0)

- Django (>=4.2.0)
- Django (3, 4, 5)

## API Web Page

![image](assets/example1.png)

## TODO

- ~~Support large models like Wenxin Yiyan and Zhipu AI.~~
- ~~Supports large models such as Wenxin Yiyan and Zhipu AI.~~

- ~~Supports online web page display for documents.~~

- ~~Enable online web page documentation display.~~
- ~~Supports custom document templates.~~

- ~~Add support for custom documentation templates.~~
- ~~Supports multi-threaded request acceleration.~~

- ~~Implement multi-threading for accelerated requests.~~
- ~~Supports Windows operating system.~~

- ~~Support Windows OS.~~
- ~~Supports Django framework.~~

- ~~Add support for Django framework.~~
- Supports more models and API frameworks.
2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 使用方法 (Usage)

**注意:docapi建立更新文档需要使用API服务项目环境**
**注意:docapi建立更新文档需要使用API服务依赖环境**

**Note: The docapi tool requires the API service project environment to generate and update documentation.**

Expand Down
Binary file modified assets/example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 17 additions & 11 deletions docapi/scanner/django_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import hashlib
import inspect

import django
from django.urls import get_resolver
from django.urls import URLPattern, URLResolver

from docapi.scanner.base_scanner import BaseScanner


class DjangoScanner(BaseScanner):

def scan(self, manager_path):
import django
from django.urls import get_resolver

project_path = Path(manager_path).parent.resolve()

sys.path.insert(0, str(project_path))
Expand All @@ -23,28 +23,34 @@ def scan(self, manager_path):

resolver = get_resolver()
structures = {}
self._extract_routes(resolver.url_patterns, structures, prefix='')
self._extract_routes(resolver.url_patterns, structures, prefix='/')
structures = self._sort_structures(structures)

return structures

def _extract_routes(self, patterns, structures, prefix):
from django.urls import URLPattern, URLResolver

for pattern in patterns:
if isinstance(pattern, URLPattern):
url = prefix + str(pattern.pattern)

if url.startswith('/admin'):
continue

view_func = pattern.callback
comments = inspect.getcomments(view_func)

try:
comments = inspect.getcomments(view_func) or ''
except (TypeError, OSError):
comments = ''

try:
code = inspect.getsource(view_func)
except (TypeError, OSError):
code = ''

if comments:
code = comments + code

if url.startswith('admin/'):
continue
code = f'# API Path: {url.rstrip("/")}\n\n' + comments + code

md5 = hashlib.md5(code.encode()).hexdigest()
path = str(Path(inspect.getfile(view_func)).resolve())
Expand All @@ -53,7 +59,7 @@ def _extract_routes(self, patterns, structures, prefix):
structures[path] = []

structures[path].append({
'url': url,
'url': url.rstrip('/'),
'md5': md5,
'code': code
})
Expand Down
65 changes: 35 additions & 30 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f70f60c

Please sign in to comment.