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

feat: add simplified channel parameter #816

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
238 changes: 0 additions & 238 deletions src/models/v3/channel-parameter-schema.ts

This file was deleted.

9 changes: 7 additions & 2 deletions src/models/v3/channel-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { SchemaInterface } from '../schema';
import type { ExtensionsInterface } from '../extensions';

import type { v3 } from '../../spec-types';
import { ParameterSchema } from './channel-parameter-schema';
import { Schema } from './schema';
jonaslagoni marked this conversation as resolved.
Show resolved Hide resolved

export class ChannelParameter extends BaseModel<v3.ParameterObject, { id: string }> implements ChannelParameterInterface {
id(): string {
Expand All @@ -24,7 +24,12 @@ export class ChannelParameter extends BaseModel<v3.ParameterObject, { id: string

schema(): SchemaInterface | undefined {
if (!this.hasSchema()) return undefined;
return this.createModel(ParameterSchema, this._json, { pointer: `${this._meta.pointer}` });
return this.createModel(Schema, {
type: 'string',
enum: this._json.enum,
jonaslagoni marked this conversation as resolved.
Show resolved Hide resolved
default: this._json.default,
examples: this._json.examples
}, { pointer: `${this._meta.pointer}` });
}

hasLocation(): boolean {
Expand Down
7 changes: 3 additions & 4 deletions test/models/v3/channel-parameter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Schema } from '../../../src/models/v3/schema';
import { serializeInput, assertDescription, assertExtensions } from './utils';

import type { v3 } from '../../../src/spec-types';
import { ParameterSchema } from '../../../src/models/v3/channel-parameter-schema';

describe('ChannelParameter model', function() {
describe('.id()', function() {
Expand Down Expand Up @@ -72,19 +71,19 @@ describe('ChannelParameter model', function() {
it('should be able to access enum values', function() {
const doc = serializeInput<v3.ParameterObject>({ enum: ['test'] });
const d = new ChannelParameter(doc);
expect(d.schema()).toBeInstanceOf(ParameterSchema);
expect(d.schema()).toBeInstanceOf(Schema);
expect(d.schema()?.enum()).toEqual(['test']);
});
it('should be able to access examples values', function() {
const doc = serializeInput<v3.ParameterObject>({ examples: ['test'] });
const d = new ChannelParameter(doc);
expect(d.schema()).toBeInstanceOf(ParameterSchema);
expect(d.schema()).toBeInstanceOf(Schema);
expect(d.schema()?.examples()).toEqual(['test']);
});
it('should be able to access default value', function() {
const doc = serializeInput<v3.ParameterObject>({ default: 'test' });
const d = new ChannelParameter(doc);
expect(d.schema()).toBeInstanceOf(ParameterSchema);
expect(d.schema()).toBeInstanceOf(Schema);
expect(d.schema()?.default()).toEqual('test');
});

Expand Down