Skip to content

Commit fd1deac

Browse files
committed
chore: add openapi spec
1 parent a301e1a commit fd1deac

File tree

13 files changed

+779
-318
lines changed

13 files changed

+779
-318
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ terraform.tfstate.backup
160160
.mirrord
161161
requirements.txt
162162
/documents
163+
164+
.cursor

Makefile

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,40 @@ addlicense:
148148
-ignore "**/templates/**" \
149149
-ignore "aperag/readers/**" \
150150
-ignore "aperag/vectorstore/**" \
151-
.
151+
.
152+
153+
.PHONY: install-redocly
154+
install-redocly:
155+
@echo "Installing redocly..."
156+
@npm install -g @redocly/cli
157+
158+
.PHONY: merge-openapi
159+
merge-openapi:
160+
@echo "Merging OpenAPI files..."
161+
@cd aperag && redocly bundle ./api/openapi.yaml > ./api/openapi.merged.yaml
162+
163+
.PHONY: generate-models
164+
generate-models: merge-openapi
165+
@echo "Generating Python models from OpenAPI specification..."
166+
@datamodel-codegen \
167+
--input aperag/api/openapi.merged.yaml \
168+
--input-file-type openapi \
169+
--output aperag/views/models.py \
170+
--output-model-type pydantic.BaseModel \
171+
--target-python-version 3.11 \
172+
--use-standard-collections \
173+
--use-schema-description
174+
@rm aperag/api/openapi.merged.yaml
175+
@echo "Models generated successfully in aperag/models directory"
176+
177+
.PHONY: dependencies
178+
dependencies: ## Install dependencies.
179+
ifeq (, $(shell which redocly))
180+
npm install @redocly/cli -g
181+
endif
182+
ifeq (, $(shell which openapi-generator-cli))
183+
npm install @openapitools/openapi-generator-cli -g
184+
endif
185+
ifeq (, $(shell which datamodel-codegen))
186+
pip install datamodel-code-generator
187+
endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
bot:
2+
type: object
3+
properties:
4+
id:
5+
type: string
6+
format: uuid
7+
title:
8+
type: string
9+
description:
10+
type: string
11+
gmt_created:
12+
type: string
13+
format: date-time
14+
gmt_updated:
15+
type: string
16+
format: date-time
17+
18+
botList:
19+
description: BotList is bot list
20+
properties:
21+
items:
22+
description: Items is the list of Bot objects in the list
23+
items:
24+
$ref: '#/bot'
25+
type: array
26+
pageResult:
27+
$ref: './common.yaml#/pageResult'
28+
required:
29+
- items
30+
type: object
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
collectionSource:
2+
type: object
3+
properties:
4+
category:
5+
type: string
6+
enum:
7+
- upload
8+
- tencent
9+
- oss
10+
- local
11+
- s3
12+
- ftp
13+
- email
14+
- url
15+
- github
16+
upload:
17+
type: object
18+
local:
19+
type: object
20+
properties:
21+
path:
22+
type: string
23+
oss:
24+
type: object
25+
properties:
26+
access_key_id:
27+
type: string
28+
access_key_secret:
29+
type: string
30+
buckets:
31+
type: array
32+
items:
33+
type: object
34+
bucket:
35+
type: string
36+
endpoint:
37+
type: string
38+
region:
39+
type: string
40+
dir:
41+
type: string
42+
s3:
43+
type: object
44+
properties:
45+
access_key_id:
46+
type: string
47+
access_key_secret:
48+
type: string
49+
buckets:
50+
type: array
51+
items:
52+
type: object
53+
bucket:
54+
type: string
55+
region:
56+
type: string
57+
dir:
58+
type: string
59+
ftp:
60+
type: object
61+
properties:
62+
path:
63+
type: string
64+
host:
65+
type: string
66+
port:
67+
type: number
68+
username:
69+
type: string
70+
email:
71+
type: object
72+
properties:
73+
pop_server:
74+
type: string
75+
port:
76+
type: number
77+
email_address:
78+
type: string
79+
email_password:
80+
type: string
81+
detect_spam:
82+
type: boolean
83+
url:
84+
type: object
85+
properties:
86+
url:
87+
type: string
88+
name:
89+
type: string
90+
feishu:
91+
type: object
92+
properties:
93+
app_id:
94+
type: string
95+
app_secret:
96+
type: string
97+
space_id:
98+
type: string
99+
node_id:
100+
type: string
101+
method:
102+
type: string
103+
target_format:
104+
type: string
105+
106+
collectionCreate:
107+
type: object
108+
properties:
109+
title:
110+
type: string
111+
description:
112+
type: string
113+
source:
114+
$ref: '#/collectionSource'
115+
116+
collection:
117+
description: Collection is a collection of documents
118+
properties:
119+
id:
120+
type: string
121+
title:
122+
type: string
123+
description:
124+
type: string
125+
source:
126+
$ref: '#/collectionSource'
127+
128+
collectionList:
129+
description: CollectionList is collection list
130+
properties:
131+
items:
132+
description: Items is the list of Collection objects in the list
133+
items:
134+
$ref: '#/collection'
135+
type: array
136+
pageResult:
137+
$ref: './common.yaml#/pageResult'
138+
required:
139+
- items
140+
type: object
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pageResult:
2+
description: PageResult info
3+
properties:
4+
first:
5+
description: a link to the first page of results. This link is optional for collections that cannot be indexed directly to a given page
6+
type: string
7+
last:
8+
description: a link to the last page of results. This link is optional for collections that cannot be indexed directly to a given page
9+
type: string
10+
next:
11+
description: a link to the next page of results. A response that does not contain a next link does not have further data to fetch
12+
type: string
13+
prev:
14+
description: a link to the previous page of results. A response that does not contain a prev link has no previous data. This link is optional for collections that cannot be traversed backward
15+
type: string
16+
totalSize:
17+
description: the total count of items in the list irrespective of pagination
18+
type: integer
19+
type: object

aperag/api/openapi.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
openapi: 3.0.0
2+
info:
3+
title: ApeRAG API
4+
description: ApeRAG API Documentation
5+
version: 1.0.0
6+
servers:
7+
- url: /api/v1
8+
description: API v1
9+
components:
10+
securitySchemes:
11+
BearerAuth:
12+
type: http
13+
scheme: bearer
14+
paths:
15+
/bots:
16+
$ref: './paths/bots.yaml#/bots'
17+
/bots/{bot_id}:
18+
$ref: './paths/bots.yaml#/bot'
19+
/collections:
20+
$ref: './paths/collections.yaml#/collections'
21+
/collections/{collection_id}:
22+
$ref: './paths/collections.yaml#/collection'
23+
/config:
24+
$ref: './paths/config.yaml#/config'

aperag/api/paths/bots.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
bots:
2+
get:
3+
summary: List bots
4+
description: Get a list of bots
5+
security:
6+
- BearerAuth: []
7+
parameters:
8+
- name: page
9+
in: query
10+
schema:
11+
type: integer
12+
default: 1
13+
- name: page_size
14+
in: query
15+
schema:
16+
type: integer
17+
default: 10
18+
responses:
19+
'200':
20+
description: List of bots
21+
content:
22+
application/json:
23+
schema:
24+
$ref: '../components/schemas/bot.yaml#/botList'
25+
post:
26+
summary: Create a new bot
27+
description: Create a new bot
28+
security:
29+
- BearerAuth: []
30+
requestBody:
31+
required: true
32+
content:
33+
application/json:
34+
schema:
35+
$ref: '../components/schemas/bot.yaml#/bot'
36+
responses:
37+
'201':
38+
description: Bot created successfully
39+
40+
bot:
41+
get:
42+
summary: Get bot details
43+
description: Get details of a specific bot
44+
security:
45+
- BearerAuth: []
46+
parameters:
47+
- name: bot_id
48+
in: path
49+
required: true
50+
schema:
51+
type: string
52+
responses:
53+
'200':
54+
description: Bot details
55+
content:
56+
application/json:
57+
schema:
58+
$ref: '../components/schemas/bot.yaml#/bot'
59+
'404':
60+
description: Bot not found
61+
delete:
62+
summary: Delete a bot
63+
description: Delete a bot
64+
security:
65+
- BearerAuth: []
66+
parameters:
67+
- name: bot_id
68+
in: path
69+
required: true
70+
schema:
71+
type: string
72+
responses:
73+
'204':
74+
description: Bot deleted successfully

0 commit comments

Comments
 (0)