Skip to content

Commit

Permalink
fix: Check API responses are provided correctly in Swagger document […
Browse files Browse the repository at this point in the history
…DEV-3133] (#359)

* Remove the custom implementation of JSON.stringify
because this custom method is written incorrectly and doesn't allow to
show swagger.json in SwaggerUI.

* Fix login/logout dynamic custom button panel.

* Revert code.

* Update custom-button.ts.

* Return a response DeactivatedDidResolution instead
of boolean type in `/did/deactivate/{did}` endpoint.

* Return resourceMetadata instead of
requestResourcePayload in `/resource/create/{did}`.

* Order swagger (OpenAPI) tags.

* Change updateUnencryptedStatusList method response
format to swagger return type.

* Update package-lock.json

* Remove duplicated code.

* Update package-lock.json

---------

Co-authored-by: Ankur Banerjee <ankurdotb@users.noreply.github.com>
  • Loading branch information
abdulla-ashurov and ankurdotb committed Sep 7, 2023
1 parent a5ead7b commit 5b13ffa
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 35 deletions.
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions src/controllers/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StatusCodes } from 'http-status-codes';

import { IdentityServiceStrategySetup } from '../services/identity/index.js';
import { generateDidDoc, getQueryParams, validateSpecCompliantPayload } from '../helpers/helpers.js';
import { DIDMetadataDereferencingResult, DefaultResolverUrl } from '@cheqd/did-provider-cheqd';

export class IssuerController {
public static createValidator = [
Expand Down Expand Up @@ -390,7 +391,7 @@ export class IssuerController {
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/DidResult'
* $ref: '#/components/schemas/DeactivatedDidResolution'
* 400:
* $ref: '#/components/schemas/InvalidRequest'
* 401:
Expand All @@ -407,11 +408,21 @@ export class IssuerController {
}

try {
const did = await new IdentityServiceStrategySetup(response.locals.customerId).agent.deactivateDid(
const deactivated = await new IdentityServiceStrategySetup(response.locals.customerId).agent.deactivateDid(
request.params.did,
response.locals.customerId
);
return response.status(StatusCodes.OK).json(did);

if (!deactivated) {
return response.status(StatusCodes.BAD_REQUEST).json({deactivated: false});
}

const result = await new IdentityServiceStrategySetup(response.locals.customerId).agent.resolveDid(
request.params.did,
response.locals.customerId
)

return response.status(StatusCodes.OK).json(result);
} catch (error) {
return response.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
error: `${error}`,
Expand Down Expand Up @@ -445,6 +456,10 @@ export class IssuerController {
* responses:
* 200:
* description: The request was successful.
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ResourceMetadata'
* 400:
* $ref: '#/components/schemas/InvalidRequest'
* 401:
Expand Down Expand Up @@ -490,8 +505,14 @@ export class IssuerController {
response.locals.customerId
);
if (result) {
const url = new URL(
`${process.env.RESOLVER_URL || DefaultResolverUrl}${did}?` +
`resourceId=${resourcePayload.id}&resourceMetadata=true`,
);
const didDereferencing = (await (await fetch(url)).json()) as DIDMetadataDereferencingResult;

return response.status(StatusCodes.CREATED).json({
resource: resourcePayload,
resource: didDereferencing.contentStream.linkedResourceMetadata[0],
});
} else {
return response.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
Expand Down
1 change: 0 additions & 1 deletion src/controllers/revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ export class RevocationController {
error: result.error?.message || result.error.toString(),
} as UpdateUnencryptedStatusListUnsuccessfulResponseBody);
}

// construct formatted response
const formatted = {
updated: true,
Expand Down
23 changes: 19 additions & 4 deletions src/static/swagger-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@
},
"tags": [
{
"name": "Credential",
"externalDocs": {
"url": "https://github.com/cheqd/credential-service#readme"
}
"name": "Account"
},
{
"name": "Key"
},
{
"name": "DID"
},
{
"name": "Resource"
},
{
"name": "Credential"
},
{
"name": "Presentation"
},
{
"name": "Credential Status"
}
],
"externalDocs": {
Expand Down
79 changes: 73 additions & 6 deletions src/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@
},
"tags": [
{
"name": "Credential",
"externalDocs": {
"url": "https://github.com/cheqd/credential-service#readme"
}
"name": "Account"
},
{
"name": "Key"
},
{
"name": "DID"
},
{
"name": "Resource"
},
{
"name": "Credential"
},
{
"name": "Presentation"
},
{
"name": "Credential Status"
}
],
"externalDocs": {
Expand Down Expand Up @@ -669,7 +684,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DidResult"
"$ref": "#/components/schemas/DeactivatedDidResolution"
}
}
}
Expand Down Expand Up @@ -720,7 +735,14 @@
},
"responses": {
"200": {
"description": "The request was successful."
"description": "The request was successful.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ResourceMetadata"
}
}
}
},
"400": {
"$ref": "#/components/schemas/InvalidRequest"
Expand Down Expand Up @@ -2710,6 +2732,24 @@
}
}
},
"DeactivatedDidResolution": {
"type": "object",
"properties": {
"@context": {
"type": "string",
"example": "https://w3id.org/did-resolution/v1"
},
"didDidResolutionMetadata": {
"$ref": "#/components/schemas/DidResolutionMetadata"
},
"didDocument": {
"$ref": "#/components/schemas/DidDocument"
},
"didDocumentMetadata": {
"$ref": "#/components/schemas/DeactivatedDidDocumentMetadata"
}
}
},
"DidDocumentMetadata": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2737,6 +2777,33 @@
}
}
},
"DeactivatedDidDocumentMetadata": {
"type": "object",
"properties": {
"created": {
"type": "string",
"example": "2021-09-01T12:00:00Z"
},
"deactivated": {
"type": "boolean",
"example": true
},
"updated": {
"type": "string",
"example": "2021-09-10T12:00:00Z"
},
"versionId": {
"type": "string",
"example": "3ccde6ba-6ba5-56f2-9f4f-8825561a9860"
},
"linkedResourceMetadata": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ResourceMetadata"
}
}
}
},
"ResourceMetadata": {
"type": "object",
"properties": {
Expand Down
31 changes: 31 additions & 0 deletions src/types/swagger-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,18 @@
* $ref: '#/components/schemas/DidDocument'
* didDocumentMetadata:
* $ref: '#/components/schemas/DidDocumentMetadata'
* DeactivatedDidResolution:
* type: object
* properties:
* '@context':
* type: string
* example: https://w3id.org/did-resolution/v1
* didDidResolutionMetadata:
* $ref: '#/components/schemas/DidResolutionMetadata'
* didDocument:
* $ref: '#/components/schemas/DidDocument'
* didDocumentMetadata:
* $ref: '#/components/schemas/DeactivatedDidDocumentMetadata'
* DidDocumentMetadata:
* type: object
* properties:
Expand All @@ -932,6 +944,25 @@
* type: array
* items:
* $ref: '#/components/schemas/ResourceMetadata'
* DeactivatedDidDocumentMetadata:
* type: object
* properties:
* created:
* type: string
* example: "2021-09-01T12:00:00Z"
* deactivated:
* type: boolean
* example: true
* updated:
* type: string
* example: "2021-09-10T12:00:00Z"
* versionId:
* type: string
* example: 3ccde6ba-6ba5-56f2-9f4f-8825561a9860
* linkedResourceMetadata:
* type: array
* items:
* $ref: '#/components/schemas/ResourceMetadata'
* ResourceMetadata:
* type: object
* properties:
Expand Down

0 comments on commit 5b13ffa

Please sign in to comment.