Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update @async/specs to version 4.0.0 and fix tests (#188) #202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ components:
type: string
description: Valid specification versions for the AsyncAPI document.
enum:
- '1.0.0'
- '1.1.0'
- '1.2.0'
- '2.0.0-rc1'
- '2.0.0-rc2'
- '2.0.0'
- '2.1.0'
- '2.2.0'
Expand Down
74 changes: 35 additions & 39 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@asyncapi/parser": "^1.17.2",
"@asyncapi/python-paho-template": "^0.2.13",
"@asyncapi/raml-dt-schema-parser": "^2.0.1",
"@asyncapi/specs": "^3.2.1",
"@asyncapi/specs": "^4.0.1",
"@asyncapi/ts-nats-template": "^0.10.1",
"ajv": "^8.8.2",
"ajv-formats": "^2.1.1",
Expand Down
15 changes: 12 additions & 3 deletions src/controllers/tests/convert.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const validJsonAsyncAPI2_0_0 = {
channels: {}
};

const validJsonAsyncAPI2_1_0 = {
asyncapi: '2.1.0',
info: {
title: 'Super test',
version: '1.0.0'
},
channels: {}
};

const validYamlAsyncAPI2_3_0 = `
asyncapi: 2.4.0
info:
Expand Down Expand Up @@ -67,14 +76,14 @@ describe('ConvertController', () => {
return request(app.getServer())
.post('/v1/convert')
.send({
asyncapi: validJsonAsyncAPI2_0_0,
version: '1.2.0'
asyncapi: validJsonAsyncAPI2_1_0,
version: '2.0.0'
})
.expect(422, {
type: 'https://api.asyncapi.com/problem/internal-converter-error',
title: 'Could not convert document',
status: 422,
detail: 'Cannot downgrade from 2.0.0 to 1.2.0.',
detail: 'Cannot downgrade from 2.1.0 to 2.0.0.',
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/services/convert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class ConvertService {
*/
public async convert(
spec: string | AsyncAPIDocument,
version: SpecsEnum = LAST_SPEC_VERSION,
version: SpecsEnum = LAST_SPEC_VERSION as SpecsEnum,
language?: 'json' | 'yaml' | 'yml',
): Promise<string> {
if (version === 'latest') {
version = LAST_SPEC_VERSION;
version = LAST_SPEC_VERSION as SpecsEnum;
}

try {
Expand Down
15 changes: 12 additions & 3 deletions src/services/tests/convert.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ const validJsonAsyncAPI2_0_0 = {
channels: {}
};

const validJsonAsyncAPI2_1_0 = {
asyncapi: '2.1.0',
info: {
title: 'Super test',
version: '1.0.0'
},
channels: {}
};

const validYamlAsyncAPI2_4_0 = `
asyncapi: 2.4.0
info:
Expand All @@ -23,9 +32,9 @@ describe('ConvertService', () => {

describe('.convert()', () => {
it('should throw error that the converter cannot convert to a lower version', async () => {
let err: ProblemException;
let err: ProblemException | null = null;
try {
await convertService.convert(validJsonAsyncAPI2_0_0, '1.2.0');
await convertService.convert(validJsonAsyncAPI2_1_0, '2.0.0');
} catch (e) {
err = e;
}
Expand All @@ -34,7 +43,7 @@ describe('ConvertService', () => {
type: 'internal-converter-error',
title: 'Could not convert document',
status: 422,
detail: 'Cannot downgrade from 2.0.0 to 1.2.0.',
detail: 'Cannot downgrade from 2.1.0 to 2.0.0.',
}));
});

Expand Down