Skip to content

Commit

Permalink
fix and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Oct 6, 2023
1 parent 0501206 commit 85bcae5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/models/v3/channel-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export class ChannelParameter extends BaseModel<v3.ParameterObject, { id: string
}

schema(): SchemaInterface | undefined {
if (!this.hasSchema()) return undefined;
if (!this.hasSchema()) {
return this.createModel(Schema, {
type: 'string',
}, { pointer: `${this._meta.pointer}` });
}
return this.createModel(Schema, {
type: 'string',
description: this._json.description,
Expand Down
11 changes: 9 additions & 2 deletions test/models/v3/channel-parameter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 85bcae5

Please sign in to comment.