Skip to content

Commit

Permalink
fix: return proper schemas in asyncapi.schemas() method (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya authored Aug 10, 2023
1 parent bc83777 commit 933be1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/models/v3/asyncapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class AsyncAPIDocument extends BaseModel<v3.AsyncAPIObject> implements As
}

schemas() {
return null as any;
return this.__schemas(false);
}

securitySchemes(): SecuritySchemesInterface {
Expand Down
21 changes: 20 additions & 1 deletion test/models/v3/asyncapi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Components } from '../../../src/models/v3/components';
import { Info } from '../../../src/models/v3/info';
import { Messages } from '../../../src/models/v3/messages';
import { Operations } from '../../../src/models/v3/operations';
import { Schemas } from '../../../src/models/v3/schemas';
import { SecuritySchemes } from '../../../src/models/v3/security-schemes';
import { Servers } from '../../../src/models/v3/servers';

Expand Down Expand Up @@ -127,7 +128,25 @@ describe('AsyncAPIDocument model', function() {
});

describe('.schemas()', function() {
it.todo('should return a collection of schemas');
it('should return a collection of schemas', function() {
const doc = serializeInput<v3.AsyncAPIObject>({ channels: { userSignup: { address: 'user/signup', messages: { someMessage1: { payload: {}}, someMessage2: { payload: {} } } }, userLogout: { address: 'user/logout', messages: { someMessage3WithoutPayload: {} } } } });
const d = new AsyncAPIDocument(doc);
expect(d.schemas()).toBeInstanceOf(Schemas);
expect(d.schemas()).toHaveLength(2);
});

it('should return only an "used" schemas (without schemas from components)', function() {
const doc = serializeInput<v3.AsyncAPIObject>({ channels: { userSignup: { address: 'user/signup', messages: { someMessage1: { payload: {}}, someMessage2: { payload: {} } } } }, components: { schemas: { schemaOne: {}, schemaTwo: {} } } });
const d = new AsyncAPIDocument(doc);
expect(d.schemas()).toBeInstanceOf(Schemas);
expect(d.schemas()).toHaveLength(2);
});

it('should return a collection of schemas even if collection is empty', function() {
const doc = serializeInput<v3.AsyncAPIObject>({});
const d = new AsyncAPIDocument(doc);
expect(d.schemas()).toBeInstanceOf(Schemas);
});
});

describe('.securitySchemes()', function() {
Expand Down

0 comments on commit 933be1d

Please sign in to comment.