chore(oas): replace requestBody with $ref to req class JSDoc OAS (#2867)

### What

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

### Why

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

### How

Declare a new @schema JSDoc for each class-validator 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.

### Out-of-scope

requestBody of type `multipart/form-data` used for file uploads. These will be address as part of CORE-934
- [create-upload.ts](https://github.com/medusajs/medusa/blob/58d23a7b45b6dde8bdeed0bb268139a0017f1649/packages/medusa/src/api/routes/admin/uploads/create-upload.ts#L87-L90)
- [create-protected-upload.ts](https://github.com/medusajs/medusa/blob/58d23a7b45b6dde8bdeed0bb268139a0017f1649/packages/medusa/src/api/routes/admin/uploads/create-protected-upload.ts#L87-L90)

Path Parameter and Query Parameter. These will need more research and experimentation, part of CORE-931

---

Resolves CORE-853
This commit is contained in:
Patrick
2022-12-21 09:08:16 -05:00
committed by GitHub
parent 8a60a73389
commit b700c6ba5b
112 changed files with 3443 additions and 2998 deletions
@@ -14,21 +14,7 @@ import { EntityManager } from "typeorm"
* content:
* application/json:
* schema:
* type: object
* required:
* - resource_id
* - resource_type
* - value
* properties:
* resource_id:
* type: string
* description: The ID of the resource which the Note relates to.
* resource_type:
* type: string
* description: The type of resource which the Note relates to.
* value:
* type: string
* description: The content of the Note to create.
* $ref: "#/components/schemas/AdminPostNotesReq"
* x-codeSamples:
* - lang: JavaScript
* label: JS Client
@@ -104,6 +90,24 @@ export default async (req, res) => {
res.status(200).json({ note: result })
}
/**
* @schema AdminPostNotesReq
* type: object
* required:
* - resource_id
* - resource_type
* - value
* properties:
* resource_id:
* type: string
* description: The ID of the resource which the Note relates to.
* resource_type:
* type: string
* description: The type of resource which the Note relates to.
* value:
* type: string
* description: The content of the Note to create.
*/
export class AdminPostNotesReq {
@IsString()
@IsNotEmpty()