Skip to content

Commit

Permalink
feat: support format in primitive parameters in typescript-swagger-2
Browse files Browse the repository at this point in the history
BREAKING CHANGE: operations now require format types (Integer, Date etc.)
  • Loading branch information
raveclassic committed Nov 15, 2019
1 parent 1b69a1f commit cf5cb6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/language/typescript/2.0/serializers/parameter-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Ref } from '../../../../utils/ref';
import { ParameterObject } from '../../../../schema/2.0/parameter-object';
import {
getSerializedArrayType,
getSerializedIntegerType,
getSerializedStringType,
SERIALIZED_BOOLEAN_TYPE,
SERIALIZED_NUMBER_TYPE,
SERIALIZED_STRING_TYPE,
SERIALIZED_UNKNOWN_TYPE,
} from '../../common/data/serialized-type';
import { serializeItemsObject } from './items-object';
Expand All @@ -14,6 +15,7 @@ import { fromSerializedType, SerializedParameter } from '../../common/data/seria
import { pipe } from 'fp-ts/lib/pipeable';
import { either, option } from 'fp-ts';
import { constFalse } from 'fp-ts/lib/function';
import { utilsRef } from '../../common/bundled/utils';

export const serializeParameterObject = (
from: Ref,
Expand All @@ -27,12 +29,17 @@ export const serializeParameterObject = (
case 'formData': {
switch (parameterObject.type) {
case 'string': {
return right(toSerializedParameter(SERIALIZED_STRING_TYPE));
return right(toSerializedParameter(getSerializedStringType(parameterObject.format)));
}
case 'number':
case 'integer': {
case 'number': {
return right(toSerializedParameter(SERIALIZED_NUMBER_TYPE));
}
case 'integer': {
return pipe(
utilsRef,
either.map(utilsRef => toSerializedParameter(getSerializedIntegerType(from, utilsRef))),
);
}
case 'boolean': {
return right(toSerializedParameter(SERIALIZED_BOOLEAN_TYPE));
}
Expand Down
2 changes: 2 additions & 0 deletions src/schema/2.0/parameter-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ const BaseArrayParameterObjectProps = {

export interface BaseNonArrayParameterObject {
readonly type: 'string' | 'number' | 'integer' | 'boolean';
readonly format: Option<string>;
}

const BaseNonArrayParameterObjectProps = {
type: union([literal('string'), literal('number'), literal('integer'), literal('boolean')]),
format: optionFromNullable(string),
};

export interface BodyParameterObject extends BaseParameterObject {
Expand Down
4 changes: 4 additions & 0 deletions test/specs/2.0/yaml/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ paths:
in: query
required: true
type: number
- name: currenttime
in: query
type: string
format: date-time
operationId: test
responses:
200:
Expand Down

0 comments on commit cf5cb6a

Please sign in to comment.