Skip to content

Commit

Permalink
fix: channel parameter not always returning schema (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Oct 9, 2023
1 parent d3afd33 commit 02b06ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 1 addition & 7 deletions src/models/v3/channel-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ export class ChannelParameter extends BaseModel<v3.ParameterObject, { id: string
}

hasSchema(): boolean {
return this._json && (
this._json.description !== undefined ||
this._json.default !== undefined ||
this._json.enum !== undefined ||
this._json.examples !== undefined
);
return true;
}

schema(): SchemaInterface | undefined {
if (!this.hasSchema()) return undefined;
return this.createModel(Schema, {
type: 'string',
description: this._json.description,
Expand Down
15 changes: 11 additions & 4 deletions test/models/v3/channel-parameter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ describe('ChannelParameter model', function() {
expect(d.hasSchema()).toEqual(true);
});

it('should return false when there is no value', function() {
it('should return true when there is no value', function() {
const doc = serializeInput<v3.ParameterObject>({});
const d = new ChannelParameter(doc);
expect(d.hasSchema()).toEqual(false);
expect(d.hasSchema()).toEqual(true);
});
});

Expand All @@ -87,10 +87,17 @@ describe('ChannelParameter model', function() {
expect(d.schema()?.default()).toEqual('test');
});

it('should return undefined when there is no value', function() {
it('should be able to access description value', function() {
const doc = serializeInput<v3.ParameterObject>({ description: 'test' });
const d = new ChannelParameter(doc);
expect(d.schema()).toBeInstanceOf(Schema);
expect(d.schema()?.description()).toEqual('test');
});
it('should return empty schema with type string when there is no value', function() {
const doc = serializeInput<v3.ParameterObject>({});
const d = new ChannelParameter(doc);
expect(d.schema()).toBeUndefined();
expect(d.schema()).toBeInstanceOf(Schema);
expect(d.schema()?.type()).toEqual('string');
});
});

Expand Down

0 comments on commit 02b06ab

Please sign in to comment.