Skip to content

Commit

Permalink
fix(input-descriptor-to-credential): fixing Swagger UI crashing (#181)
Browse files Browse the repository at this point in the history
* fix(input-descriptor-to-credential): fixing Swagger UI crashing the service

* feat(input-descriptor-to-credential): disabling NestJS Swagger CLI
  • Loading branch information
artursudnik authored Sep 26, 2023
1 parent 1e30222 commit cdd82db
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
54 changes: 52 additions & 2 deletions apps/input-descriptor-to-credential/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
}
},
"responses": {
"201": {
"description": ""
"default": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InputDescriptorToCredentialResponseDto"
}
}
}
}
}
}
Expand Down Expand Up @@ -50,6 +57,49 @@
}
},
"required": ["constraints"]
},
"CredentialType": {
"type": "string",
"enum": ["VerifiableCredential", "VerifiablePresentation", "StatusList2021Credential", "EWFRole"]
},
"CredentialDto": {
"type": "object",
"properties": {
"@context": {
"type": "array",
"items": {
"type": "string"
}
},
"credentialSubject": {
"type": "object"
},
"id": {
"type": "string"
},
"issuanceDate": {
"type": "string"
},
"type": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CredentialType"
}
},
"issuer": {
"type": "string"
}
},
"required": ["@context", "credentialSubject", "id", "issuanceDate", "type", "issuer"]
},
"InputDescriptorToCredentialResponseDto": {
"type": "object",
"properties": {
"credential": {
"$ref": "#/components/schemas/CredentialDto"
}
},
"required": ["credential"]
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions apps/input-descriptor-to-credential/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"introspectComments": true
}
}
]
"plugins": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import { Body, Controller, Post } from '@nestjs/common';
import { ConverterService } from './converter.service';
import { InputDesciptorToCredentialDto, InputDescriptorToCredentialResponseDto } from './dtos';
import { CredentialDto } from './dtos/credential.dto';
import { ApiResponse } from '@nestjs/swagger';

@Controller('converter')
export class ConverterController {
constructor(private readonly converterService: ConverterService) {}

@Post('input-descriptor-to-credential')
@ApiResponse({ type: InputDescriptorToCredentialResponseDto })
async inputDescriptorToCredential(
@Body() inputDesciptorToCredentialDto: InputDesciptorToCredentialDto
): Promise<InputDescriptorToCredentialResponseDto> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
*/

import { Credential, CredentialType } from '@ew-did-registry/credentials-interface';
import { ApiProperty } from '@nestjs/swagger';

export class CredentialDto implements Credential<Record<string, unknown>> {
@ApiProperty()
'@context': Array<string | Record<string, unknown>>;
@ApiProperty()
credentialSubject: Record<string, unknown>;
@ApiProperty()
id: string;
@ApiProperty()
issuanceDate: string;
@ApiProperty({ enum: CredentialType, enumName: 'CredentialType', isArray: true })
type: CredentialType[];
@ApiProperty()
issuer: string;
[x: string]: unknown;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

import { CredentialDto } from './credential.dto';
import { Type } from 'class-transformer';
import { ValidateNested } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class InputDescriptorToCredentialResponseDto {
@Type(() => CredentialDto)
@ValidateNested()
@ApiProperty({ type: CredentialDto })
credential: CredentialDto;

constructor(props: Partial<InputDescriptorToCredentialResponseDto>) {
Expand Down

0 comments on commit cdd82db

Please sign in to comment.