Skip to content

Commit

Permalink
chore(python): fix generated path parameters
Browse files Browse the repository at this point in the history
Part of #16
  • Loading branch information
php-coder committed Sep 20, 2022
1 parent d8e70cf commit 2e588ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions examples/python/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_v1_categories_count():
finally:
conn.close()

@router.get('/v1/collections/:collectionId/categories/count')
@router.get('/v1/collections/{collectionId}/categories/count')
def get_v1_collections_collection_id_categories_count():
conn = psycopg2.connect(
database = os.getenv('DB_NAME'),
Expand All @@ -46,7 +46,7 @@ def get_list_v1_categories():
def post_v1_categories():
pass

@router.get('/v1/categories/:categoryId')
@router.get('/v1/categories/{categoryId}')
def get_v1_categories_category_id():
conn = psycopg2.connect(
database = os.getenv('DB_NAME'),
Expand All @@ -62,11 +62,11 @@ def get_v1_categories_category_id():
finally:
conn.close()

@router.put('/v1/categories/:categoryId')
@router.put('/v1/categories/{categoryId}')
def put_v1_categories_category_id():
pass

@router.delete('/v1/categories/:categoryId')
@router.delete('/v1/categories/{categoryId}')
def delete_v1_categories_category_id():
pass

8 changes: 7 additions & 1 deletion src/templates/routes.py.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ function generate_method_name(method, path) {
return `${method}${name}`
}
// "/categories/:categoryId" => "/categories/{categoryId}"
function convertToFastApiPath(path) {
return path.replace(/:([_a-zA-Z]+)/g, '{$1}')
}
endpoints.forEach(function(endpoint) {
const path = endpoint.path
const path = convertToFastApiPath(endpoint.path)
endpoint.methods.forEach(function(method) {
const hasGetOne = method.name === 'get'
Expand Down

0 comments on commit 2e588ff

Please sign in to comment.