Skip to content

Commit 9bbf051

Browse files
committed
feat(python): add support for boolean type for body arguments
Part of #49
1 parent 60d3522 commit 9bbf051

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

docker/categories.postgres.sql

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CREATE TABLE categories (
33
name varchar(50) NOT NULL,
44
name_ru varchar(50) DEFAULT NULL,
55
slug varchar(50) NOT NULL,
6+
hidden boolean,
67
created_at timestamp NOT NULL,
78
created_by bigint NOT NULL,
89
updated_at timestamp NOT NULL,

examples/js/express/mysql/endpoints.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
, name
3838
, name_ru
3939
, slug
40+
, hidden
4041
FROM categories
4142
dto:
4243
name: CategoryDto
@@ -50,6 +51,7 @@
5051
( name
5152
, name_ru
5253
, slug
54+
, hidden
5355
, created_at
5456
, created_by
5557
, updated_at
@@ -59,6 +61,7 @@
5961
( :b.name
6062
, :b.name_ru
6163
, :b.slug
64+
, :b.hidden
6265
, NOW()
6366
, :b.user_id
6467
, NOW()
@@ -69,6 +72,8 @@
6972
fields:
7073
user_id:
7174
type: integer
75+
hidden:
76+
type: boolean
7277

7378
- path: /v1/categories/:categoryId
7479
get:
@@ -77,6 +82,7 @@
7782
, name
7883
, name_ru
7984
, slug
85+
, hidden
8086
FROM categories
8187
WHERE id = :p.categoryId
8288
dto:
@@ -90,13 +96,16 @@
9096
SET name = :b.name
9197
, name_ru = :b.name_ru
9298
, slug = :b.slug
99+
, hidden = :b.hidden
93100
, updated_at = NOW()
94101
, updated_by = :b.user_id
95102
WHERE id = :p.categoryId
96103
dto:
97104
fields:
98105
user_id:
99106
type: integer
107+
hidden:
108+
type: boolean
100109
delete:
101110
query: >-
102111
DELETE

examples/python/fastapi/postgres/routes.py

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CreateCategoryDto(BaseModel):
1515
name: Optional[str] = None
1616
name_ru: Optional[str] = None
1717
slug: Optional[str] = None
18+
hidden: Optional[bool] = None
1819
user_id: Optional[int] = None
1920

2021

@@ -85,6 +86,7 @@ def get_list_v1_categories(conn=Depends(db_connection)):
8586
, name
8687
, name_ru
8788
, slug
89+
, hidden
8890
FROM categories
8991
""")
9092
return cur.fetchall()
@@ -104,6 +106,7 @@ def post_v1_categories(body: CreateCategoryDto, conn=Depends(db_connection)):
104106
( name
105107
, name_ru
106108
, slug
109+
, hidden
107110
, created_at
108111
, created_by
109112
, updated_at
@@ -113,6 +116,7 @@ def post_v1_categories(body: CreateCategoryDto, conn=Depends(db_connection)):
113116
( %(name)s
114117
, %(name_ru)s
115118
, %(slug)s
119+
, %(hidden)s
116120
, NOW()
117121
, %(user_id)s
118122
, NOW()
@@ -122,6 +126,7 @@ def post_v1_categories(body: CreateCategoryDto, conn=Depends(db_connection)):
122126
"name": body.name,
123127
"name_ru": body.name_ru,
124128
"slug": body.slug,
129+
"hidden": body.hidden,
125130
"user_id": body.user_id
126131
})
127132
finally:
@@ -139,6 +144,7 @@ def get_v1_categories_category_id(categoryId, conn=Depends(db_connection)):
139144
, name
140145
, name_ru
141146
, slug
147+
, hidden
142148
FROM categories
143149
WHERE id = %(categoryId)s
144150
""", {
@@ -163,13 +169,15 @@ def put_v1_categories_category_id(body: CreateCategoryDto, categoryId, conn=Depe
163169
SET name = %(name)s
164170
, name_ru = %(name_ru)s
165171
, slug = %(slug)s
172+
, hidden = %(hidden)s
166173
, updated_at = NOW()
167174
, updated_by = %(user_id)s
168175
WHERE id = %(categoryId)s
169176
""", {
170177
"name": body.name,
171178
"name_ru": body.name_ru,
172179
"slug": body.slug,
180+
"hidden": body.hidden,
173181
"user_id": body.user_id,
174182
"categoryId": categoryId
175183
})

src/templates/routes.py.ejs

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ function extractProperties(queryAst) {
9191
function findOutType(fieldsInfo, fieldName) {
9292
const defaultType = 'str'
9393
const hasTypeInfo = fieldsInfo.hasOwnProperty(fieldName) && fieldsInfo[fieldName].hasOwnProperty('type')
94-
if (hasTypeInfo && fieldsInfo[fieldName].type === 'integer') {
94+
if (!hasTypeInfo) {
95+
return defaultType
96+
}
97+
if (fieldsInfo[fieldName].type === 'integer') {
9598
return 'int'
9699
}
100+
if (fieldsInfo[fieldName].type === 'boolean') {
101+
return 'bool'
102+
}
97103
return defaultType
98104
}
99105

tests/crud.hurl

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ POST {{ SERVER_URL }}/v1/categories
1313
{
1414
"name": "Sport",
1515
"slug": "sport",
16+
"hidden": true,
1617
"user_id": 1
1718
}
1819
HTTP 204
@@ -33,6 +34,7 @@ jsonpath "$.id" == 1
3334
jsonpath "$.name" == "Sport"
3435
jsonpath "$.name_ru" == null
3536
jsonpath "$.slug" == "sport"
37+
jsonpath "$.hidden" == true
3638

3739

3840
# GET should return a list of values
@@ -45,6 +47,7 @@ jsonpath "$[0].id" == 1
4547
jsonpath "$[0].name" == "Sport"
4648
jsonpath "$[0].name_ru" == null
4749
jsonpath "$[0].slug" == "sport"
50+
jsonpath "$[0].hidden" == true
4851

4952

5053
# PUT should update an object
@@ -53,6 +56,7 @@ PUT {{ SERVER_URL }}/v1/categories/1
5356
"name": "Fauna",
5457
"name_ru": "Фауна",
5558
"slug": "fauna",
59+
"hidden": false,
5660
"user_id": 1
5761
}
5862
HTTP 204
@@ -65,6 +69,7 @@ header "Content-Type" contains "application/json"
6569
jsonpath "$.name" == "Fauna"
6670
jsonpath "$.name_ru" == "Фауна"
6771
jsonpath "$.slug" == "fauna"
72+
jsonpath "$.hidden" == false
6873

6974

7075
# DELETE should remove an object

0 commit comments

Comments
 (0)