Skip to content

Commit

Permalink
fix: Product list (Stripe) OpenAPI schema (#554)
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Jul 2, 2024
1 parent 0b9cb33 commit 81ff8ce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

23 changes: 21 additions & 2 deletions src/controllers/admin/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ dotenv.config();
export class ProductController {
static productListValidator = [
check('prices').optional().isBoolean().withMessage('prices should be a boolean').bail(),
check('limit').optional().isInt({ min: 1, max: 100 }).withMessage('limit should be between 1 and 100').bail(),
check('limit')
.optional()
.isInt({ min: 1, max: 100 })
.default(DEFAULT_PAGINATION_LIST_LIMIT)
.withMessage('limit should be between 1 and 100')
.bail(),
check('cursor')
.optional()
.isString()
Expand Down Expand Up @@ -46,6 +51,20 @@ export class ProductController {
* type: boolean
* description: If setup to true - returns the list of products with prices inside. Default - true
* required: false
* - in: query
* name: limit
* schema:
* type: integer
* minimum: 1
* maximum: 100
* description: Restrict the response to only include items from 1 to 100. Default - 10
* required: false
* - in: query
* name: cursor
* schema:
* type: string
* description: Cursor for pagination, this only goes forward, i.e., Stripe's equivalent of 'starting_after'
* required: false
* responses:
* 200:
* description: A list of products
Expand All @@ -67,7 +86,7 @@ export class ProductController {
const stripe = response.locals.stripe as Stripe;
// Get query parameters
const prices = request.query.prices === 'false' ? false : true;
const limit = Number(request.query.limit) ?? DEFAULT_PAGINATION_LIST_LIMIT;
const limit = Number(request.query.limit) || DEFAULT_PAGINATION_LIST_LIMIT;
const cursor = request.query.cursor as string | undefined;

try {
Expand Down
20 changes: 20 additions & 0 deletions src/static/swagger-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,26 @@
"description": "If setup to true - returns the list of products with prices inside. Default - true",
"required": false
}
},
{
"in": "query",
"name": "limit",
"schema": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"description": "Restrict the response to only include items from 1 to 100. Default - 10",
"required": false
}
},
{
"in": "query",
"name": "cursor",
"schema": {
"type": "string",
"description": "Cursor for pagination, this only goes forward, i.e., Stripe's equivalent of 'starting_after'",
"required": false
}
}
],
"responses": {
Expand Down

0 comments on commit 81ff8ce

Please sign in to comment.