From c9f56b1d38d0bba0d3a187967b52c7c1019d8b10 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Wed, 26 Jul 2023 12:12:40 +0200 Subject: [PATCH] feat: add simplified channel parameter (#816) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maciej UrbaƄczyk --- src/models/v3/channel-parameter.ts | 21 +++++++++++----- src/spec-types/v3.ts | 4 ++- test/models/v3/channel-parameter.spec.ts | 32 +++++++++++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/models/v3/channel-parameter.ts b/src/models/v3/channel-parameter.ts index b5fc343e4..54099a351 100644 --- a/src/models/v3/channel-parameter.ts +++ b/src/models/v3/channel-parameter.ts @@ -1,12 +1,10 @@ import { BaseModel } from '../base'; -import { Schema } from './schema'; - import { hasDescription, description, extensions } from './mixins'; +import { Schema } from './schema'; import type { ChannelParameterInterface } from '../channel-parameter'; import type { SchemaInterface } from '../schema'; import type { ExtensionsInterface } from '../extensions'; - import type { v3 } from '../../spec-types'; export class ChannelParameter extends BaseModel implements ChannelParameterInterface { @@ -15,12 +13,23 @@ export class ChannelParameter extends BaseModel export interface ParameterObject extends SpecificationExtensions { description?: string; - schema?: SchemaObject; + enum?: string[]; + default?: string; + examples?: string[]; location?: string; } diff --git a/test/models/v3/channel-parameter.spec.ts b/test/models/v3/channel-parameter.spec.ts index 66c6c76a1..16eb510e5 100644 --- a/test/models/v3/channel-parameter.spec.ts +++ b/test/models/v3/channel-parameter.spec.ts @@ -43,12 +43,23 @@ describe('ChannelParameter model', function() { }); describe('.hasSchema()', function() { - it('should return true when there is a value', function() { - const doc = serializeInput({ schema: {} }); + it('should return true if enum are sat', function() { + const doc = serializeInput({ enum: ['test'] }); + const d = new ChannelParameter(doc); + expect(d.hasSchema()).toEqual(true); + }); + it('should return true if default are sat', function() { + const doc = serializeInput({ default: 'test' }); const d = new ChannelParameter(doc); expect(d.hasSchema()).toEqual(true); }); + it('should return true if examples are sat', function() { + const doc = serializeInput({ examples: ['test'] }); + const d = new ChannelParameter(doc); + expect(d.hasSchema()).toEqual(true); + }); + it('should return false when there is no value', function() { const doc = serializeInput({}); const d = new ChannelParameter(doc); @@ -57,10 +68,23 @@ describe('ChannelParameter model', function() { }); describe('.schema()', function() { - it('should return the value', function() { - const doc = serializeInput({ schema: {} }); + it('should be able to access enum values', function() { + const doc = serializeInput({ enum: ['test'] }); + const d = new ChannelParameter(doc); + expect(d.schema()).toBeInstanceOf(Schema); + expect(d.schema()?.enum()).toEqual(['test']); + }); + it('should be able to access examples values', function() { + const doc = serializeInput({ examples: ['test'] }); + const d = new ChannelParameter(doc); + expect(d.schema()).toBeInstanceOf(Schema); + expect(d.schema()?.examples()).toEqual(['test']); + }); + it('should be able to access default value', function() { + const doc = serializeInput({ default: 'test' }); const d = new ChannelParameter(doc); expect(d.schema()).toBeInstanceOf(Schema); + expect(d.schema()?.default()).toEqual('test'); }); it('should return undefined when there is no value', function() {