# Documenting files routes

Routes that handle files require manual documentation in Swagger, but nothing too complex. In the <mark style="color:blue;">`uploadImages()`</mark> route, two decorators should be employed:

* <mark style="color:blue;">`@ApiConsumes()`</mark> - Receives the format of the body, in this case it is <mark style="color:blue;">multipart/form-data</mark>
* <mark style="color:blue;">`@ApiBody()`</mark> - Receives the type of a file, which will be manually represented in a **schema**.

First, back in <mark style="color:purple;">file.constants</mark>, let's create a constant for the body format when sending files.

```typescript
export const MULTIPART_FORMDATA_KEY = 'multipart/form-data';
```

Then, we'll create two decorators to represent, respectively, a file and an array of files, in swagger. So, let's begin with the first one in <mark style="color:purple;">files</mark>/<mark style="color:purple;">swagger</mark>/<mark style="color:purple;">decorators</mark>/<mark style="color:purple;">api-file-property.decorator</mark>. You may notice that this part involves the syntax of the **Swagger schema**.

```typescript
export const ApiFileProperty = () =>
  ApiProperty({ type: 'string', format: 'binary' });
```

> I recommend this Swagger [official doc](https://swagger.io/docs/specification/data-models/data-types/) as a further read about this syntax, if desired.

And then the next one, in <mark style="color:purple;">api-files-property.decorator</mark>.

```typescript
export const ApiFilesProperty = () =>
  ApiProperty({ type: 'array', items: { type: 'string', format: 'binary' } });
```

We created them in order to more easily create the schemas to map files. And that's exactly what we'll do now, so create the file <mark style="color:purple;">files</mark>/<mark style="color:purple;">swagger</mark>/<mark style="color:purple;">schemas</mark>/<mark style="color:purple;">file.schema</mark>.

```typescript
export class FileSchema {
  @ApiFileProperty()
  file: File;
}
```

And also, the file <mark style="color:purple;">files.schema</mark>.

```typescript
export class FilesSchema {
  @ApiFilesProperty()
  files: File[];
}
```

We have all the necessary pieces in hand. We can then go back to the <mark style="color:blue;">`ProductsController`</mark> and make the adjustments. Over the <mark style="color:blue;">`uploadImages()`</mark> route, add these decorators:

```typescript
@ApiConsumes(MULTIPART_FORMDATA_KEY)
@ApiBody({ type: FilesSchema })
```

And, to indicate that the <mark style="color:blue;">`downloadImage()`</mark> route returns a file, add over it:

```typescript
@ApiOkResponse({ type: FileSchema })
```

And we're done, the lacking documentation was added to the file-related routes.

<mark style="color:green;">**Commit**</mark> - Integrating file routes with swagger
