Skip to content

Commit

Permalink
fix(input-descriptor-to-credential): fixing Swagger UI crashing the s…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
artursudnik committed Sep 25, 2023
1 parent 1e30222 commit a1daf8e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 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
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 @@ -18,10 +18,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 a1daf8e

Please sign in to comment.