0

我对我的 Swagger YAML 文件感到困惑,我 99% 肯定是正确的,但显然不是,但不确定问题可能出在哪里:

/**
* @openapi
* components:
*   schemas:
*     ViewMedicationDto:
*       type: array
*       items:
*         type: object
*         properties:
*           _type:
*             type: string
*           id:
*             type: string
*           pui:
*             type: string
*           medicationType:
*             type: string
*           tradeName:
*             type: string
*           medicationTags: []
*           createdOn:
*             type: string
*           updatedOn:
*             type: string
*         example:
*           - _type: ViewMedicationDto
*           id: 61ae82c8f95692912cc423ed
*           pui: test_danielcortes_821205_59909
*           medicationType: Rescue
*           tradeName: Accolate
*           medicationTags: [ [Object], [Object] ]
*           createdOn: 2021-12-06T21:38:16.359Z
*           updatedOn: 2021-12-06T21:38:16.359Z
*/
export class ViewMedicationDto implements DtoInterface {
readonly _type = 'ViewMedicationDto';

readonly id: ID
readonly pui: string

readonly medicationType: MedicationType
readonly tradeName: string

readonly medicationTags?: ITag[]

readonly createdOn?: Date
readonly updatedOn?: Date

constructor(id: ID, pui: string,
medicationType: MedicationType, tradeName: string,
medicationTags?: ITag[],
createdOn?: Date, updatedOn?: Date) {
this.id = id
this.pui = pui

this.medicationType = medicationType
this.tradeName = tradeName

this.medicationTags = medicationTags

this.createdOn = createdOn
this.updatedOn = updatedOn
}

}

我认为这是medicationTags问题所在,但是当我删除它时,它不会呈现静止状态。

更新

我试图像这样遵循以下解决方案:

/**
* @openapi
* components:
*   schemas:
*     ViewMedicationDto:
*       type: array
*       items:
*         type: object
*         properties:
*           _type:
*             type: string
*           id:
*             type: string
*           pui:
*             type: string
*           medicationType:
*             type: string
*           tradeName:
*             type: string
*           medicationTags:
*             type: array
*             items:
*               type: object
*           createdOn:
*             type: string
*           updatedOn:
*             type: string
*         example:
*           _type: ViewMedicationDto
*           id: 61ae82c8f95692912cc423ed
*           pui: test_danielcortes_821205_59909
*           medicationType: Rescue
*           tradeName: Accolate
*           medicationTags: [{}, {}]
*           createdOn: 2021-12-06T21:38:16.359Z
*           updatedOn: 2021-12-06T21:38:16.359Z
*/
4

1 回答 1

0

你是对的,一个问题是medicationTags语法。另一个问题是example语法。

尝试这个:

*     ViewMedicationDto:
*       type: array
*       items:
*         type: object
*         properties:
*           ...
*           medicationTags:
*             type: array
*             items:
*               type: object   # Assuming that ITag is an object
*           createdOn:
*             type: string
*           updatedOn:
*             type: string
*         example:
*           _type: ViewMedicationDto     # <--- No leading dash here
*           id: 61ae82c8f95692912cc423ed
*           pui: test_danielcortes_821205_59909
*           medicationType: Rescue
*           tradeName: Accolate
*           medicationTags: [ {}, {} ]   # <--- TODO: add a proper ITag JSON array example
*           createdOn: 2021-12-06T21:38:16.359Z
*           updatedOn: 2021-12-06T21:38:16.359Z
于 2021-12-06T23:08:29.780 回答