Skip to content

Commit 02b06ab

Browse files
authored
fix: channel parameter not always returning schema (#868)
1 parent d3afd33 commit 02b06ab

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/models/v3/channel-parameter.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@ export class ChannelParameter extends BaseModel<v3.ParameterObject, { id: string
1313
}
1414

1515
hasSchema(): boolean {
16-
return this._json && (
17-
this._json.description !== undefined ||
18-
this._json.default !== undefined ||
19-
this._json.enum !== undefined ||
20-
this._json.examples !== undefined
21-
);
16+
return true;
2217
}
2318

2419
schema(): SchemaInterface | undefined {
25-
if (!this.hasSchema()) return undefined;
2620
return this.createModel(Schema, {
2721
type: 'string',
2822
description: this._json.description,

test/models/v3/channel-parameter.spec.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ describe('ChannelParameter model', function() {
6060
expect(d.hasSchema()).toEqual(true);
6161
});
6262

63-
it('should return false when there is no value', function() {
63+
it('should return true when there is no value', function() {
6464
const doc = serializeInput<v3.ParameterObject>({});
6565
const d = new ChannelParameter(doc);
66-
expect(d.hasSchema()).toEqual(false);
66+
expect(d.hasSchema()).toEqual(true);
6767
});
6868
});
6969

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

90-
it('should return undefined when there is no value', function() {
90+
it('should be able to access description value', function() {
91+
const doc = serializeInput<v3.ParameterObject>({ description: 'test' });
92+
const d = new ChannelParameter(doc);
93+
expect(d.schema()).toBeInstanceOf(Schema);
94+
expect(d.schema()?.description()).toEqual('test');
95+
});
96+
it('should return empty schema with type string when there is no value', function() {
9197
const doc = serializeInput<v3.ParameterObject>({});
9298
const d = new ChannelParameter(doc);
93-
expect(d.schema()).toBeUndefined();
99+
expect(d.schema()).toBeInstanceOf(Schema);
100+
expect(d.schema()?.type()).toEqual('string');
94101
});
95102
});
96103

0 commit comments

Comments
 (0)