Skip to content

Commit

Permalink
fix(api): make openapi swagger generate ui
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Sep 13, 2021
1 parent 36cb477 commit f83add6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
9 changes: 9 additions & 0 deletions api/apps/api/src/modules/projects/dto/protected-area.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class ProtectedAreaDto {
@ApiProperty()
id!: string;

@ApiPropertyOptional()
name?: string;
}
22 changes: 17 additions & 5 deletions api/apps/api/src/modules/projects/project.api.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Organization } from '../organizations/organization.api.entity';
import { TimeUserEntityMetadata } from '../../types/time-user-entity-metadata';
import { BaseServiceResource } from '../../types/resource.interface';
import { BBox } from 'geojson';
import { ProtectedAreaDto } from '@marxan-api/modules/projects/dto/protected-area.dto';

export const projectResource: BaseServiceResource = {
className: 'Project',
Expand Down Expand Up @@ -126,7 +127,10 @@ export class Project extends TimeUserEntityMetadata {
/**
* Bbox of the custom extent
*/
@ApiProperty()
@ApiProperty({
isArray: true,
type: Number,
})
@Column('jsonb', { name: 'bbox' })
bbox!: BBox;

Expand Down Expand Up @@ -164,26 +168,34 @@ export class Project extends TimeUserEntityMetadata {

@ApiPropertyOptional({
isArray: true,
type: ProtectedAreaDto,
})
customProtectedAreas?: string[];
customProtectedAreas?: ProtectedAreaDto[];
}

export class JSONAPIProjectData {
@ApiProperty()
@ApiProperty({
type: String,
})
type = 'projects';

@ApiProperty()
id!: string;

@ApiProperty()
@ApiProperty({
type: Project,
})
attributes!: Project;

@ApiPropertyOptional()
relationships?: Record<string, unknown>;
}

export class ProjectResultPlural {
@ApiProperty()
@ApiProperty({
isArray: true,
type: JSONAPIProjectData,
})
data!: JSONAPIProjectData[];
}

Expand Down

0 comments on commit f83add6

Please sign in to comment.