Skip to content

Commit 7a4aeb2

Browse files
docs: update swagger examples for external endpoints
Signed-off-by: kirill-tolochko <kirill.tolochko.work@gmail.com>
1 parent 8ac03bf commit 7a4aeb2

2 files changed

Lines changed: 69 additions & 12 deletions

File tree

api-gateway/src/api/service/external.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { InternalException, PolicyEngine } from '#helpers';
2-
import { Examples, ExternalDocumentDTO, InternalServerErrorDTO, ResponseDTOWithSyncEvents } from '#middlewares';
2+
import { Examples, ExternalDocumentDTO, InternalServerErrorDTO, ObjectExamples, ResponseDTOWithSyncEvents } from '#middlewares';
33
import { PinoLogger } from '@guardian/common';
44
import { Body, Controller, DefaultValuePipe, HttpCode, HttpStatus, Param, ParseBoolPipe, Post, Query } from '@nestjs/common';
5-
import { ApiBody, ApiExtraModels, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
5+
import { ApiBody, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
66

77
@Controller('external')
88
@ApiTags('external')
@@ -20,7 +20,12 @@ export class ExternalApi {
2020
})
2121
@ApiBody({
2222
description: 'Object that contains a VC Document.',
23-
type: ExternalDocumentDTO
23+
type: ExternalDocumentDTO,
24+
examples: {
25+
'Request Body': {
26+
value: ObjectExamples.EXTERNAL_REQUEST_BODY_EXAMPLE
27+
}
28+
}
2429
})
2530
@ApiParam({
2631
name: 'policyId',
@@ -46,7 +51,6 @@ export class ExternalApi {
4651
type: InternalServerErrorDTO,
4752
example: { code: 500, message: 'Error message' }
4853
})
49-
@ApiExtraModels(ExternalDocumentDTO, InternalServerErrorDTO)
5054
@HttpCode(HttpStatus.OK)
5155
async receiveExternalDataCustom(
5256
@Param('policyId') policyId: string,
@@ -71,7 +75,12 @@ export class ExternalApi {
7175
})
7276
@ApiBody({
7377
description: 'Object that contains a VC Document.',
74-
type: ExternalDocumentDTO
78+
type: ExternalDocumentDTO,
79+
examples: {
80+
'Request Body': {
81+
value: ObjectExamples.EXTERNAL_REQUEST_BODY_EXAMPLE
82+
}
83+
}
7584
})
7685
@ApiOkResponse({
7786
description: 'Successful operation.',
@@ -83,7 +92,6 @@ export class ExternalApi {
8392
type: InternalServerErrorDTO,
8493
example: { code: 500, message: 'Error message' }
8594
})
86-
@ApiExtraModels(ExternalDocumentDTO, InternalServerErrorDTO)
8795
@HttpCode(HttpStatus.OK)
8896
async receiveExternalData(
8997
@Body() document: ExternalDocumentDTO
@@ -106,7 +114,12 @@ export class ExternalApi {
106114
})
107115
@ApiBody({
108116
description: 'Object that contains a VC Document.',
109-
type: ExternalDocumentDTO
117+
type: ExternalDocumentDTO,
118+
examples: {
119+
'Request Body': {
120+
value: ObjectExamples.EXTERNAL_REQUEST_BODY_EXAMPLE
121+
}
122+
}
110123
})
111124
@ApiQuery({
112125
name: 'history',
@@ -132,14 +145,13 @@ export class ExternalApi {
132145
@ApiOkResponse({
133146
description: 'Successful operation.',
134147
type: ResponseDTOWithSyncEvents,
135-
example: { result: 'ok' }
148+
example: ObjectExamples.EXTERNAL_SYNC_EVENTS_RESPONSE_EXAMPLE
136149
})
137150
@ApiInternalServerErrorResponse({
138151
description: 'Internal server error.',
139152
type: InternalServerErrorDTO,
140153
example: { code: 500, message: 'Error message' }
141154
})
142-
@ApiExtraModels(ExternalDocumentDTO, ResponseDTOWithSyncEvents, InternalServerErrorDTO)
143155
@HttpCode(HttpStatus.OK)
144156
async receiveExternalDataCustomWithSyncEvents(
145157
@Param('policyId') policyId: string,
@@ -165,7 +177,12 @@ export class ExternalApi {
165177
})
166178
@ApiBody({
167179
description: 'Object that contains a VC Document.',
168-
type: ExternalDocumentDTO
180+
type: ExternalDocumentDTO,
181+
examples: {
182+
'Request Body': {
183+
value: ObjectExamples.EXTERNAL_REQUEST_BODY_EXAMPLE
184+
}
185+
}
169186
})
170187
@ApiQuery({
171188
name: 'history',
@@ -177,14 +194,13 @@ export class ExternalApi {
177194
@ApiOkResponse({
178195
description: 'Successful operation.',
179196
type: ResponseDTOWithSyncEvents,
180-
example: { result: 'ok' }
197+
example: ObjectExamples.EXTERNAL_SYNC_EVENTS_RESPONSE_EXAMPLE
181198
})
182199
@ApiInternalServerErrorResponse({
183200
description: 'Internal server error.',
184201
type: InternalServerErrorDTO,
185202
example: { code: 500, message: 'Error message' }
186203
})
187-
@ApiExtraModels(ExternalDocumentDTO, ResponseDTOWithSyncEvents, InternalServerErrorDTO)
188204
@HttpCode(HttpStatus.OK)
189205
async receiveExternalDataWithSyncEvents(
190206
@Query('history', new DefaultValuePipe(false), ParseBoolPipe) history: boolean,

api-gateway/src/middlewares/validation/examples.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,45 @@ export enum Examples {
2121
USER_NAME_SR_2 = 'Verra'
2222
}
2323

24+
const EXTERNAL_REQUEST_BODY_EXAMPLE = {
25+
owner: 'string',
26+
policyTag: 'string',
27+
document: {
28+
id: '8f457a5a-c02b-4a18-a7d3-20e4def1bf7f',
29+
'@context': [
30+
'https://www.w3.org/2018/credentials/v1'
31+
],
32+
type: [
33+
'VerifiableCredential',
34+
'a2274869-4a41-4446-8efd-dacde5a81221'
35+
],
36+
credentialSubject: [
37+
{
38+
id: 'did:hedera:testnet:4YZuEXk95TMt2WfuAB5UYJMQSgSfUgBNutnZioUVAxkR_0.0.1774462341919',
39+
field0: 'value0',
40+
field1: 'value1',
41+
policyId: '69c42569ae73da728c8d9027',
42+
accountId: '0.0.1774462367074'
43+
}
44+
],
45+
issuer: 'did:hedera:testnet:4YZuEXk95TMt2WfuAB5UYJMQSgSfUgBNutnZioUVAxkR_0.0.1774462341919',
46+
issuanceDate: '2026-03-25T17:12:17.150Z',
47+
proof: {
48+
type: 'Ed25519Signature2018',
49+
created: '2026-03-25T17:12:17.150Z',
50+
verificationMethod: 'did:hedera:testnet:4YZuEXk95TMt2WfuAB5UYJMQSgSfUgBNutnZioUVAxkR_0.0.1774462341919#did-root-key',
51+
proofPurpose: 'assertionMethod',
52+
jws: 'eyJhbGciOiJFZERTQSJ9..signature'
53+
}
54+
}
55+
};
56+
57+
const EXTERNAL_SYNC_EVENTS_RESPONSE_EXAMPLE = {
58+
response: {},
59+
result: null,
60+
steps: []
61+
};
62+
2463
const PERMISSIONS_SR = [
2564
'ACCOUNTS_STANDARD_REGISTRY_READ',
2665
'DEMO_KEY_CREATE',
@@ -169,6 +208,8 @@ const PROFILE_DID_DOCUMENT_SAMPLE = {
169208

170209
export const ObjectExamples = {
171210
PERMISSION_SR: PERMISSIONS_SR,
211+
EXTERNAL_REQUEST_BODY_EXAMPLE: EXTERNAL_REQUEST_BODY_EXAMPLE,
212+
EXTERNAL_SYNC_EVENTS_RESPONSE_EXAMPLE: EXTERNAL_SYNC_EVENTS_RESPONSE_EXAMPLE,
172213

173214
CONTRACTS_LIST_RESPONSE_WIPE: [
174215
{

0 commit comments

Comments
 (0)