Bilal68
3 years agoOccasional Visitor
sharing the schemas in "ApiOkResponse" decorator
Hi I have an issue related to examples in end-points I am trying to add schemas in two of my end-points and sharing the schema as $ref property among them, but it gives me "could not resolve reference" error, but works fine when its passed to the one of them.
export default function GetGraphDataDecorators() {
let example1 = {
request: {},
response: {
"message": "Success",
"data": [
{
"status": "onDuty",
"startedAt": "2022-07-22T18:57:46.682Z",
"lastStartedAt": "2022-07-22T19:00:32.024Z",
"totalSecondsSpentSoFar": 166
},
{
"status": "offDuty",
"startedAt": "2022-07-22T19:01:13.372Z",
"lastStartedAt": "2022-07-22T19:09:08.322Z",
"totalSecondsSpentSoFar": 475
},
{
"status": "onDriving",
"startedAt": "2022-07-22T19:09:08.322Z",
"lastStartedAt": "2022-07-22T19:10:31.383Z",
"totalSecondsSpentSoFar": 83
},
]
}
}
const GetGraphDataDecorators: Array<CombineDecoratorType> = [
Get('graph/:driverId'),
ApiParam({
name: "driverId",
allowEmptyValue: false,
}),
ApiQuery({
name: "date",
required: false,
}),
ApiOkResponse({
content: {
'application/json': {
schema: {
type: 'array', items: { $ref: getSchemaPath(GraphDataResponseModel) },
},
examples: {
"example 1": { value: example1.response }
},
},
},
})
];
return CombineDecorators(GetGraphDataDecorators);
}
export function GetDriverGraphDataDecorators() {
let example2 = {
request: {},
response: {
"message": "Success",
"data": [
{
"status": "onDuty",
"startedAt": "2022-07-22T18:57:46.682Z",
"lastStartedAt": "2022-07-22T19:00:32.024Z",
"totalSecondsSpentSoFar": 166
},
{
"status": "offDuty",
"startedAt": "2022-07-22T19:01:13.372Z",
"lastStartedAt": "2022-07-22T19:09:08.322Z",
"totalSecondsSpentSoFar": 475
},
{
"status": "onDriving",
"startedAt": "2022-07-22T19:09:08.322Z",
"lastStartedAt": "2022-07-22T19:10:31.383Z",
"totalSecondsSpentSoFar": 83
}
]
}
}
const GetDriverGraphDataDecorators: Array<CombineDecoratorType> = [
Get('graph'),
ApiQuery({
name: "date",
required: false,
}),
ApiOkResponse({
content: {
'application/json': {
schema: {
type: 'array', items: { $ref: getSchemaPath(GraphDataResponseModel) },
},
examples: {
"example 1": { value: example2.response }
},
},
},
})
];
return CombineDecorators(GetDriverGraphDataDecorators);
}