Skip to content

Commit 2e588ff

Browse files
committed
chore(python): fix generated path parameters
Part of #16
1 parent d8e70cf commit 2e588ff

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

examples/python/routes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_v1_categories_count():
2222
finally:
2323
conn.close()
2424

25-
@router.get('/v1/collections/:collectionId/categories/count')
25+
@router.get('/v1/collections/{collectionId}/categories/count')
2626
def get_v1_collections_collection_id_categories_count():
2727
conn = psycopg2.connect(
2828
database = os.getenv('DB_NAME'),
@@ -46,7 +46,7 @@ def get_list_v1_categories():
4646
def post_v1_categories():
4747
pass
4848

49-
@router.get('/v1/categories/:categoryId')
49+
@router.get('/v1/categories/{categoryId}')
5050
def get_v1_categories_category_id():
5151
conn = psycopg2.connect(
5252
database = os.getenv('DB_NAME'),
@@ -62,11 +62,11 @@ def get_v1_categories_category_id():
6262
finally:
6363
conn.close()
6464

65-
@router.put('/v1/categories/:categoryId')
65+
@router.put('/v1/categories/{categoryId}')
6666
def put_v1_categories_category_id():
6767
pass
6868

69-
@router.delete('/v1/categories/:categoryId')
69+
@router.delete('/v1/categories/{categoryId}')
7070
def delete_v1_categories_category_id():
7171
pass
7272

src/templates/routes.py.ejs

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ function generate_method_name(method, path) {
1212
return `${method}${name}`
1313
}
1414
15+
// "/categories/:categoryId" => "/categories/{categoryId}"
16+
function convertToFastApiPath(path) {
17+
return path.replace(/:([_a-zA-Z]+)/g, '{$1}')
18+
}
19+
20+
1521
endpoints.forEach(function(endpoint) {
16-
const path = endpoint.path
22+
const path = convertToFastApiPath(endpoint.path)
1723
1824
endpoint.methods.forEach(function(method) {
1925
const hasGetOne = method.name === 'get'

0 commit comments

Comments
 (0)