Skip to content

Commit

Permalink
chore(oas): replace response with $ref class JSDoc (Admin O-PRI) (#3018)
Browse files Browse the repository at this point in the history
### Scope

Admin routes directories O to PRI.

### What

Move inline OAS response schema declaration under their respective class declarations in order to expose them through  `#/components/schemas`. Replace inline OAS response schema with a `$ref` reference pointing to the newly declared schema.

### Why

Having response declared as its own "named" schema will allow OAS code generators to output typed entities/DTO that can be consumed without having to reference the route/operation.

### How

Declare a new @Schema JSDoc for each "Res" class used to parse and validate request body. Move the current inline requestBody to the new @Schema.

### Test

- Ran OAS validator.
- Ran docs build script.

Expect no visible changes to the documentation.
  • Loading branch information
patrick-medusajs authored Jan 13, 2023
1 parent 9dbccd9 commit cdcbc06
Show file tree
Hide file tree
Showing 59 changed files with 303 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EntityManager } from "typeorm"
import { OrderEditService } from "../../../../services"
import {
defaultOrderEditFields,
defaultOrderEditRelations
defaultOrderEditRelations,
} from "../../../../types/order-edit"

/**
Expand Down Expand Up @@ -41,10 +41,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EntityManager } from "typeorm"
import { OrderEditService } from "../../../../services"
import {
defaultOrderEditFields,
defaultOrderEditRelations
defaultOrderEditRelations,
} from "../../../../types/order-edit"

/**
Expand Down Expand Up @@ -41,10 +41,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EntityManager } from "typeorm"
import { OrderEditService } from "../../../../services"
import {
defaultOrderEditFields,
defaultOrderEditRelations
defaultOrderEditRelations,
} from "../../../../types/order-edit"

/**
Expand Down Expand Up @@ -47,10 +47,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,7 @@ import { OrderEditService } from "../../../../services"
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* description: The ID of the deleted Order Edit Item Change.
* object:
* type: string
* description: The type of the object that was deleted.
* format: item_change
* deleted:
* type: boolean
* description: Whether or not the Order Edit Item Change was deleted.
* default: true
* $ref: "#/components/schemas/AdminOrderEditItemChangeDeleteRes"
* "400":
* $ref: "#/components/responses/400_error"
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ import { OrderEditService } from "../../../../services"
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* description: The ID of the deleted Order Edit.
* object:
* type: string
* description: The type of the object that was deleted.
* format: order_edit
* deleted:
* type: boolean
* description: Whether or not the Order Edit was deleted.
* default: true
* $ref: "#/components/schemas/AdminOrderEditDeleteRes"
* "400":
* $ref: "#/components/responses/400_error"
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ import { FindParams } from "../../../../types/common"
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
60 changes: 60 additions & 0 deletions packages/medusa/src/api/routes/admin/order-edits/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,73 @@ export default (app) => {
return app
}

/**
* @schema AdminOrderEditsRes
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
*/
export type AdminOrderEditsRes = {
order_edit: OrderEdit
}

/**
* @schema AdminOrderEditsListRes
* type: object
* properties:
* order_edits:
* type: array
* items:
* $ref: "#/components/schemas/OrderEdit"
* count:
* type: integer
* description: The total number of items available
* offset:
* type: integer
* description: The number of items skipped before these items
* limit:
* type: integer
* description: The number of items per page
*/
export type AdminOrderEditsListRes = PaginatedResponse & {
order_edits: OrderEdit[]
}

/**
* @schema AdminOrderEditDeleteRes
* type: object
* properties:
* id:
* type: string
* description: The ID of the deleted Order Edit.
* object:
* type: string
* description: The type of the object that was deleted.
* default: order_edit
* deleted:
* type: boolean
* description: Whether or not the Order Edit was deleted.
* default: true
*/
export type AdminOrderEditDeleteRes = DeleteResponse

/**
* @schema AdminOrderEditItemChangeDeleteRes
* type: object
* properties:
* id:
* type: string
* description: The ID of the deleted Order Edit Item Change.
* object:
* type: string
* description: The type of the object that was deleted.
* default: item_change
* deleted:
* type: boolean
* description: Whether or not the Order Edit Item Change was deleted.
* default: true
*/
export type AdminOrderEditItemChangeDeleteRes = {
id: string
object: "item_change"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,7 @@ import { IsOptional, IsString } from "class-validator"
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edits:
* type: array
* $ref: "#/components/schemas/OrderEdit"
* count:
* type: integer
* description: The total number of items available
* offset:
* type: integer
* description: The number of items skipped before these items
* limit:
* type: integer
* description: The number of items per page
* $ref: "#/components/schemas/AdminOrderEditsListRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { PaymentCollectionType } from "../../../../models"
import {
OrderEditService,
OrderService,
PaymentCollectionService
PaymentCollectionService,
} from "../../../../services"
import {
defaultOrderEditFields,
defaultOrderEditRelations
defaultOrderEditRelations,
} from "../../../../types/order-edit"

/**
Expand Down Expand Up @@ -46,10 +46,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ import {
* content:
* application/json:
* schema:
* type: object
* properties:
* order_edit:
* $ref: "#/components/schemas/OrderEdit"
* $ref: "#/components/schemas/AdminOrderEditsRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ import { EntityManager } from "typeorm"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
5 changes: 1 addition & 4 deletions packages/medusa/src/api/routes/admin/orders/archive-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import { EntityManager } from "typeorm"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
5 changes: 1 addition & 4 deletions packages/medusa/src/api/routes/admin/orders/cancel-claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ import { MedusaError } from "medusa-core-utils"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ import { MedusaError } from "medusa-core-utils"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ import { MedusaError } from "medusa-core-utils"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ import { Fulfillment } from "../../../../models"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
5 changes: 1 addition & 4 deletions packages/medusa/src/api/routes/admin/orders/cancel-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import { EntityManager } from "typeorm"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
5 changes: 1 addition & 4 deletions packages/medusa/src/api/routes/admin/orders/cancel-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ import { MedusaError } from "medusa-core-utils"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import { EntityManager } from "typeorm"
* content:
* application/json:
* schema:
* type: object
* properties:
* order:
* $ref: "#/components/schemas/Order"
* $ref: "#/components/schemas/AdminOrdersRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
Loading

0 comments on commit cdcbc06

Please sign in to comment.