diff --git a/src/fileReader.ts b/src/fileReader.ts index 661a96a..85d6189 100644 --- a/src/fileReader.ts +++ b/src/fileReader.ts @@ -1,9 +1,9 @@ import * as yaml from 'js-yaml'; -export type TJSON = { +export type JSON = { [key: string]: unknown; }; -export type TFileReader = (buffer: Buffer) => TJSON; +export type FileReader = (buffer: Buffer) => JSON; -export const fromJSON: TFileReader = buffer => JSON.parse(buffer.toString()); -export const fromYaml: TFileReader = buffer => yaml.safeLoad(buffer.toString()); +export const fromJSON: FileReader = buffer => JSON.parse(buffer.toString()); +export const fromYaml: FileReader = buffer => yaml.safeLoad(buffer.toString()); diff --git a/src/fs.ts b/src/fs.ts index ae61dc0..de20a63 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -1,38 +1,38 @@ import * as fs from 'fs-extra'; import * as path from 'path'; -export type TFile = { +export type File = { type: 'FILE'; name: string; content: string; }; -export const file = (name: string, content: string): TFile => ({ +export const file = (name: string, content: string): File => ({ type: 'FILE', name, content, }); -export type TDirectory = { +export type Directory = { type: 'DIRECTORY'; name: string; - content: TFSEntity[]; + content: FSEntity[]; }; -export const directory = (name: string, content: TFSEntity[]): TDirectory => ({ +export const directory = (name: string, content: FSEntity[]): Directory => ({ type: 'DIRECTORY', name, content, }); -export type TFSEntity = TFile | TDirectory; +export type FSEntity = File | Directory; -export type TBuffer = { +export type BufferWithName = { buffer: Buffer; fileName: string; }; -export const write = async (destination: string, entity: TFSEntity): Promise => { +export const write = async (destination: string, entity: FSEntity): Promise => { switch (entity.type) { case 'FILE': { const filePath = path.resolve(destination, entity.name); @@ -50,7 +50,7 @@ export const write = async (destination: string, entity: TFSEntity): Promise string): TFSEntity => { +export const map = (entity: FSEntity, f: (content: string) => string): FSEntity => { switch (entity.type) { case 'FILE': { return file(entity.name, f(entity.content)); @@ -61,7 +61,7 @@ export const map = (entity: TFSEntity, f: (content: string) => string): TFSEntit } }; -export const read = async (_pathToFile: string, cwd: string): Promise => { +export const read = async (_pathToFile: string, cwd: string): Promise => { const pathToFile = path.isAbsolute(_pathToFile) ? _pathToFile : path.resolve(cwd, _pathToFile); return { buffer: await fs.readFile(pathToFile), diff --git a/src/index.ts b/src/index.ts index 3c93ce2..67bf4ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ -import { SwaggerObject, TSwaggerObject } from './schema/2.0/swagger'; +import { SwaggerObject } from './schema/2.0/swagger'; import * as prettier from 'prettier'; -import { map, read, TFSEntity, write } from './fs'; -import { TSerializer } from './utils'; +import { map, read, FSEntity, write } from './fs'; +import { Serializer } from './utils'; import * as fs from 'fs-extra'; import { fromNullable, getOrElse, Option, map as mapOption } from 'fp-ts/lib/Option'; import * as path from 'path'; import { head, last } from 'fp-ts/lib/Array'; -import { TFileReader } from './fileReader'; +import { FileReader } from './fileReader'; import { isLeft, Right } from 'fp-ts/lib/Either'; import * as del from 'del'; import { pipe } from 'fp-ts/lib/pipeable'; @@ -15,7 +15,7 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; const log = console.log.bind(console, '[SWAGGER-CODEGEN-TS]:'); -export type TGenerateOptions = { +export type GenerateOptions = { /** * Paths to spec files */ @@ -27,7 +27,7 @@ export type TGenerateOptions = { /** * Spec serializer */ - serialize: TSerializer; + serialize: Serializer; /** * Path to prettier config */ @@ -36,16 +36,16 @@ export type TGenerateOptions = { * Buffer to JSON converter * @param buffer - File Buffer */ - fileReader: TFileReader; + fileReader: FileReader; }; const cwd = process.cwd(); const resolvePath = (p: string) => (path.isAbsolute(p) ? p : path.resolve(cwd, p)); -const serializeDecode = (serializer: TSerializer) => async ( - decoded: Right, +const serializeDecode = (serializer: Serializer) => async ( + decoded: Right, out: string, -): Promise => serializer(path.basename(out), decoded.right); +): Promise => serializer(path.basename(out), decoded.right); const getPrettierConfig = async (pathToPrettierConfig?: string): Promise> => fromNullable( @@ -58,16 +58,16 @@ const getPrettierConfig = async (pathToPrettierConfig?: string): Promise): TFSEntity => +const formatSerialized = (serialized: FSEntity, prettierConfig: Option): FSEntity => pipe( prettierConfig, mapOption(config => map(serialized, content => prettier.format(content, config))), getOrElse(() => serialized), ); -const writeFormatted = (out: string, formatted: TFSEntity) => write(path.dirname(out), formatted); +const writeFormatted = (out: string, formatted: FSEntity) => write(path.dirname(out), formatted); -export const generate = async (options: TGenerateOptions): Promise => { +export const generate = async (options: GenerateOptions): Promise => { const out = resolvePath(options.out); const isPathExist = await fs.pathExists(out); diff --git a/src/language/typescript.ts b/src/language/typescript.ts index 494afea..0e2be2e 100644 --- a/src/language/typescript.ts +++ b/src/language/typescript.ts @@ -1,21 +1,21 @@ import { - TAllOfSchemaObject, - TBodyParameterObject, - TDefinitionsObject, - TNonArrayItemsObject, - TOperationObject, - TParametersDefinitionsObject, - TPathItemObject, - TPathParameterObject, - TPathsObject, - TQueryParameterObject, - TReferenceSchemaObject, - TResponseObject, - TResponsesObject, - TSchemaObject, - TSwaggerObject, + AllOfSchemaObject, + BodyParameterObject, + DefinitionsObject, + NonArrayItemsObject, + OperationObject, + ParametersDefinitionsObject, + PathItemObject, + PathParameterObject, + PathsObject, + QueryParameterObject, + ReferenceSchemaObject, + ResponseObject, + ResponsesObject, + SchemaObject, + SwaggerObject, } from '../schema/2.0/swagger'; -import { directory, file, TDirectory, TFile } from '../fs'; +import { directory, file, Directory, File } from '../fs'; import * as path from 'path'; import { array, flatten, getMonoid as getArrayMonoid, uniq } from 'fp-ts/lib/Array'; import { fromArray, groupBy, head, NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; @@ -24,7 +24,7 @@ import { getOperationParametersInPath, getOperationParametersInQuery, groupPathsByTag, - TSerializer, + Serializer, } from '../utils'; import { fromNullable, @@ -49,7 +49,7 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { Eq, eqString, getStructEq } from 'fp-ts/lib/Eq'; import { intercalate } from 'fp-ts/lib/Foldable'; -const EMPTY_DEPENDENCIES: TDependency[] = []; +const EMPTY_DEPENDENCIES: Dependency[] = []; const EMPTY_REFS: string[] = []; const SUCCESSFUL_CODES = ['200', '201', 'default']; @@ -58,40 +58,40 @@ const concatIf = (condition: boolean, as: A[], a: A[]): A[] => concatIfL(cond const unless = (condition: boolean, a: string): string => (condition ? '' : a); const when = (condition: boolean, a: string): string => (condition ? a : ''); -type TDependency = { +type Dependency = { name: string; path: string; }; -type TSerializedType = { +type SerializedType = { type: string; io: string; - dependencies: TDependency[]; + dependencies: Dependency[]; refs: string[]; }; -const serializedType = (type: string, io: string, dependencies: TDependency[], refs: string[]): TSerializedType => ({ +const serializedType = (type: string, io: string, dependencies: Dependency[], refs: string[]): SerializedType => ({ type, io, dependencies, refs, }); -type TSerializedParameter = TSerializedType & { +type SerializedParameter = SerializedType & { isRequired: boolean; }; const serializedParameter = ( type: string, io: string, isRequired: boolean, - dependencies: TDependency[], + dependencies: Dependency[], refs: string[], -): TSerializedParameter => ({ +): SerializedParameter => ({ type, io, isRequired, dependencies, refs, }); -type TSerializedPathParameter = TSerializedParameter & { +type SerializedPathParameter = SerializedParameter & { name: string; }; const serializedPathParameter = ( @@ -99,9 +99,9 @@ const serializedPathParameter = ( type: string, io: string, isRequired: boolean, - dependencies: TDependency[], + dependencies: Dependency[], refs: string[], -): TSerializedPathParameter => ({ +): SerializedPathParameter => ({ name, type, io, @@ -109,31 +109,31 @@ const serializedPathParameter = ( dependencies, refs, }); -const dependency = (name: string, path: string): TDependency => ({ +const dependency = (name: string, path: string): Dependency => ({ name, path, }); const dependencyOption = dependency('Option', 'fp-ts/lib/Option'); const dependencyCreateOptionFromNullable = dependency('optionFromNullable', 'io-ts-types/lib/optionFromNullable'); -const OPTION_DEPENDENCIES: TDependency[] = [dependencyOption, dependencyCreateOptionFromNullable]; +const OPTION_DEPENDENCIES: Dependency[] = [dependencyOption, dependencyCreateOptionFromNullable]; -const monoidDependencies = getArrayMonoid(); +const monoidDependencies = getArrayMonoid(); const monoidRefs = getArrayMonoid(); -const monoidSerializedType = getStructMonoid({ +const monoidSerializedType = getStructMonoid({ type: monoidString, io: monoidString, dependencies: monoidDependencies, refs: monoidRefs, }); -const monoidSerializedParameter = getStructMonoid({ +const monoidSerializedParameter = getStructMonoid({ type: monoidString, io: monoidString, dependencies: monoidDependencies, isRequired: monoidAny, refs: monoidRefs, }); -const setoidSerializedTypeWithoutDependencies: Eq = getStructEq>({ +const setoidSerializedTypeWithoutDependencies: Eq = getStructEq>({ type: eqString, io: eqString, }); @@ -159,7 +159,7 @@ const getRelativeOutRefPath = (cwd: string, blockName: string, outFileName: stri const getRelativeClientPath = (cwd: string): string => `${getRelativeRoot(cwd)}/${CLIENT_DIRECTORY}/${CLIENT_FILENAME}`; const getRelativeUtilsPath = (cwd: string): string => `${getRelativeRoot(cwd)}/${UTILS_DIRECTORY}/${UTILS_FILENAME}`; -export const serialize: TSerializer = (name: string, swaggerObject: TSwaggerObject): TDirectory => +export const serialize: Serializer = (name: string, swaggerObject: SwaggerObject): Directory => directory(name, [ directory(CLIENT_DIRECTORY, [file(`${CLIENT_FILENAME}.ts`, client)]), directory(UTILS_DIRECTORY, [file(`${UTILS_FILENAME}.ts`, utils)]), @@ -172,13 +172,13 @@ export const serialize: TSerializer = (name: string, swaggerObject: TSwaggerObje serializePaths(swaggerObject.paths, swaggerObject.parameters), ]); -const serializeDefinitions = (definitions: TDefinitionsObject): TDirectory => +const serializeDefinitions = (definitions: DefinitionsObject): Directory => directory(DEFINITIONS_DIRECTORY, [ ...serializeDictionary(definitions, (name, definition) => serializeDefinition(name, definition, `${ROOT_DIRECTORY}/${DEFINITIONS_DIRECTORY}`), ), ]); -const serializePaths = (paths: TPathsObject, parameters: Option): TDirectory => +const serializePaths = (paths: PathsObject, parameters: Option): Directory => directory( CONTROLLERS_DIRECTORY, serializeDictionary(groupPathsByTag(paths, parameters), (name, group) => @@ -186,7 +186,7 @@ const serializePaths = (paths: TPathsObject, parameters: Option { +const serializeDefinition = (name: string, definition: SchemaObject, cwd: string): File => { const serialized = serializeSchemaObject(definition, name, cwd); const dependencies = serializeDependencies(serialized.dependencies); @@ -202,7 +202,7 @@ const serializeDefinition = (name: string, definition: TSchemaObject, cwd: strin ); }; -const serializePathGroup = (name: string, group: Record, cwd: string): TFile => { +const serializePathGroup = (name: string, group: Record, cwd: string): File => { const groupName = `${name}Controller`; const serialized = foldSerialized( serializeDictionary(group, (url, item) => serializePath(url, item, groupName, cwd)), @@ -210,7 +210,7 @@ const serializePathGroup = (name: string, group: Record const dependencies = serializeDependencies([ ...serialized.dependencies, dependency('asks', 'fp-ts/lib/Reader'), - dependency('TAPIClient', getRelativeClientPath(cwd)), + dependency('APIClient', getRelativeClientPath(cwd)), ]); return file( `${groupName}.ts`, @@ -221,13 +221,13 @@ const serializePathGroup = (name: string, group: Record ${serialized.type} }; - export const ${decapitalize(groupName)} = asks((e: { apiClient: TAPIClient }): ${groupName} => ({ + export const ${decapitalize(groupName)} = asks((e: { apiClient: APIClient }): ${groupName} => ({ ${serialized.io} })); `, ); }; -const serializePath = (url: string, item: TPathItemObject, rootName: string, cwd: string): TSerializedType => { +const serializePath = (url: string, item: PathItemObject, rootName: string, cwd: string): SerializedType => { const get = pipe( item.get, map(operation => serializeOperationObject(url, 'GET', operation, rootName, cwd)), @@ -260,7 +260,7 @@ const serializePath = (url: string, item: TPathItemObject, rootName: string, cwd return foldSerialized(operations); }; -const is$ref = (a: TReferenceSchemaObject | TAllOfSchemaObject): a is TReferenceSchemaObject => +const is$ref = (a: ReferenceSchemaObject | AllOfSchemaObject): a is ReferenceSchemaObject => Object.prototype.hasOwnProperty.bind(a)('$ref'); const getDefName = (name: string, prefix: string): string => `${camelize(prefix, true)}${name}`; const getImportAsDef = (name: string, prefix: string): string => `${name} as ${getDefName(name, prefix)}`; @@ -270,7 +270,7 @@ const getDefIFSameName = (isSameOutName: boolean, prefix: string) => (name: stri const importAsFile = (isSameOutName: boolean, prefix: string) => (name: string) => !isSameOutName ? name : getImportAsDef(name, prefix); -const serializeSchemaObject = (schema: TSchemaObject, rootName: string, cwd: string): TSerializedType => { +const serializeSchemaObject = (schema: SchemaObject, rootName: string, cwd: string): SerializedType => { switch (schema.type) { case undefined: { if (is$ref(schema)) { @@ -434,7 +434,7 @@ const serializeSchemaObject = (schema: TSchemaObject, rootName: string, cwd: str } }; -const serializeEnum = (enumValue: Array): TSerializedType => { +const serializeEnum = (enumValue: Array): SerializedType => { const type = enumValue.map(value => `'${value}'`).join(' | '); const io = enumValue.length === 1 @@ -443,7 +443,7 @@ const serializeEnum = (enumValue: Array): TSerialized return serializedType(type, io, [dependency('union', 'io-ts'), dependency('literal', 'io-ts')], EMPTY_REFS); }; -const serializeAdditionalProperties = (properties: TSchemaObject, rootName: string, cwd: string): TSerializedType => { +const serializeAdditionalProperties = (properties: SchemaObject, rootName: string, cwd: string): SerializedType => { const additional = serializeSchemaObject(properties, rootName, cwd); return serializedType( `{ [key: string]: ${additional.type} }`, @@ -456,10 +456,10 @@ const serializeAdditionalProperties = (properties: TSchemaObject, rootName: stri const serializeOperationObject = ( url: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS', - operation: TOperationObject, + operation: OperationObject, rootName: string, cwd: string, -): TSerializedType => { +): SerializedType => { const pathParameters = getOperationParametersInPath(operation); const queryParameters = getOperationParametersInQuery(operation); const bodyParameters = getOperationParametersInBody(operation); @@ -560,7 +560,7 @@ const serializeOperationObject = ( return serializedType(type, io, dependencies, serializedParameters.refs); }; -const serializeOperationResponses = (responses: TResponsesObject, rootName: string, cwd: string): TSerializedType => { +const serializeOperationResponses = (responses: ResponsesObject, rootName: string, cwd: string): SerializedType => { const serializedResponses = uniqSerializedWithoutDependencies( array.compact( SUCCESSFUL_CODES.map(code => @@ -591,16 +591,16 @@ const serializeOperationResponses = (responses: TResponsesObject, rootName: stri const serializeOperationResponse = ( code: string, - response: TResponseObject, + response: ResponseObject, rootName: string, cwd: string, -): Option => +): Option => pipe( response.schema, map(schema => serializeSchemaObject(schema, rootName, cwd)), ); -const serializePathParameter = (parameter: TPathParameterObject): TSerializedPathParameter => { +const serializePathParameter = (parameter: PathParameterObject): SerializedPathParameter => { const serializedParameterType = serializeParameter(parameter); return serializedPathParameter( @@ -613,14 +613,14 @@ const serializePathParameter = (parameter: TPathParameterObject): TSerializedPat ); }; -const serializePathParameterDescription = (parameter: TPathParameterObject): string => +const serializePathParameterDescription = (parameter: PathParameterObject): string => `@param { ${serializeParameter(parameter).type} } ${parameter.name} ${pipe( parameter.description, map(d => '- ' + d), toUndefined, )}`; -const serializeQueryParameter = (parameter: TQueryParameterObject): TSerializedParameter => { +const serializeQueryParameter = (parameter: QueryParameterObject): SerializedParameter => { const isRequired = pipe( parameter.required, getOrElse(constFalse), @@ -642,7 +642,7 @@ const serializeQueryParameter = (parameter: TQueryParameterObject): TSerializedP ); }; -const serializeQueryParameters = (parameters: NonEmptyArray): TSerializedParameter => { +const serializeQueryParameters = (parameters: NonEmptyArray): SerializedParameter => { const serializedParameters = parameters.map(serializeQueryParameter); const intercalated = intercalateSerializedParameter( serializedParameter(';', ',', false, EMPTY_DEPENDENCIES, EMPTY_REFS), @@ -658,11 +658,7 @@ const serializeQueryParameters = (parameters: NonEmptyArray { +const serializeBodyParameter = (parameter: BodyParameterObject, rootName: string, cwd: string): SerializedParameter => { const isRequired = pipe( parameter.required, getOrElse(constFalse), @@ -677,10 +673,10 @@ const serializeBodyParameter = ( ); }; const serializeBodyParameters = ( - parameters: NonEmptyArray, + parameters: NonEmptyArray, rootName: string, cwd: string, -): TSerializedParameter => { +): SerializedParameter => { // according to spec there can be only one body parameter const serializedBodyParameter = serializeBodyParameter(head(parameters), rootName, cwd); const { type, isRequired, io, dependencies, refs } = serializedBodyParameter; @@ -693,17 +689,14 @@ const serializeBodyParameters = ( ); }; -const serializeParametersDescription = ( - query: TQueryParameterObject[], - body: TBodyParameterObject[], -): Option => { +const serializeParametersDescription = (query: QueryParameterObject[], body: BodyParameterObject[]): Option => { const parameters = [...query, ...body]; return parameters.length === 0 ? none : some(hasRequiredParameters(parameters) ? '@param { object } parameters' : '@param { object } [parameters]'); }; -const serializeParameter = (parameter: TPathParameterObject | TQueryParameterObject): TSerializedParameter => { +const serializeParameter = (parameter: PathParameterObject | QueryParameterObject): SerializedParameter => { const isRequired = typeof parameter.required === 'boolean' ? parameter.required @@ -735,7 +728,7 @@ const serializeParameter = (parameter: TPathParameterObject | TQueryParameterObj } }; -const serializeNonArrayItemsObject = (items: TNonArrayItemsObject): TSerializedType => { +const serializeNonArrayItemsObject = (items: NonArrayItemsObject): SerializedType => { switch (items.type) { case 'string': { return serializedType('string', 'string', [dependency('string', 'io-ts')], EMPTY_REFS); @@ -754,13 +747,13 @@ const serializeDictionary = (dictionary: Record, serializeValue Object.keys(dictionary).map(name => serializeValue(name, dictionary[name])); const getIOName = (name: string): string => `${name}IO`; -const getOperationName = (operation: TOperationObject, httpMethod: string) => +const getOperationName = (operation: OperationObject, httpMethod: string) => pipe( operation.operationId, getOrElse(() => httpMethod), ); -const serializeDependencies = (dependencies: TDependency[]): string => +const serializeDependencies = (dependencies: Dependency[]): string => pipe( pipe( dependencies, @@ -778,18 +771,18 @@ const client = ` import { report } from '../utils/utils'; import { left } from 'fp-ts/lib/Either'; - export type TAPIRequest = { + export type APIRequest = { url: string; query?: object; body?: unknown; }; - export type TFullAPIRequest = TAPIRequest & { + export type FullAPIRequest = APIRequest & { method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'; }; - export type TAPIClient = { - readonly request: (request: TFullAPIRequest) => LiveData; + export type APIClient = { + readonly request: (request: FullAPIRequest) => LiveData; }; export class ResponseValidationError extends Error { @@ -857,7 +850,7 @@ const utils = ` export const report: (validation: Validation) => string[] = fold(fail, ok); `; -const hasRequiredParameters = (parameters: Array): boolean => +const hasRequiredParameters = (parameters: Array): boolean => parameters.some(p => pipe( p.required, @@ -865,7 +858,7 @@ const hasRequiredParameters = (parameters: Array +const serializeRequired = (name: string, type: string, io: string, isRequired: boolean): SerializedType => isRequired ? serializedType(`${name}: ${type}`, `${name}: ${io}`, EMPTY_DEPENDENCIES, EMPTY_REFS) : serializedType( @@ -883,13 +876,13 @@ const serializeJSDOC = (lines: string[]): string => */`, ); -const serializeURL = (url: string, pathParameters: TSerializedPathParameter[]): string => +const serializeURL = (url: string, pathParameters: SerializedPathParameter[]): string => pathParameters.reduce( (acc, p) => acc.replace(`{${p.name}}`, `\$\{encodeURIComponent(${p.io}.toString())\}`), `\`${url}\``, ); -const toObjectType = (serialized: TSerializedType, recursion: Option): TSerializedType => { +const toObjectType = (serialized: SerializedType, recursion: Option): SerializedType => { const io = `type({ ${serialized.io} })`; return serializedType( `{ ${serialized.type} }`, diff --git a/src/schema/2.0/swagger.ts b/src/schema/2.0/swagger.ts index f6eef4a..f347128 100644 --- a/src/schema/2.0/swagger.ts +++ b/src/schema/2.0/swagger.ts @@ -8,25 +8,23 @@ export const numberOption = optionFromNullable(t.number); export const stringArrayOption = optionFromNullable(t.array(t.string)); export const primitiveArrayOption = optionFromNullable(t.array(t.union([t.string, t.boolean, t.number]))); -export type TDictionary = { - [key: string]: A; -}; +export interface Dictionary extends Record {} -export type TContactObject = { +export interface ContactObject { name: Option; url: Option; email: Option; -}; +} export const ContactObject = t.type( { name: stringOption, url: stringOption, email: stringOption, }, - 'TContactObject', + 'ContactObject', ); -export type TLicenseObject = { +export type LicenseObject = { name: string; url: Option; }; @@ -35,15 +33,15 @@ export const LicenseObject = t.type( name: t.string, url: stringOption, }, - 'TLicenseObject', + 'LicenseObject', ); -export type TInfoObject = { +export type InfoObject = { title: string; description: Option; termsOfService: Option; - contact: Option; - license: Option; + contact: Option; + license: Option; version: string; }; export const InfoObject = t.type( @@ -55,10 +53,10 @@ export const InfoObject = t.type( license: optionFromNullable(LicenseObject), version: t.string, }, - 'TInfoObject', + 'InfoObject', ); -export type TExternalDocumentationObject = { +export type ExternalDocumentationObject = { description: Option; url: string; }; @@ -67,29 +65,29 @@ export const ExternalDocumentationObject = t.type( description: stringOption, url: t.string, }, - 'TExternalDocumentationObject', + 'ExternalDocumentationObject', ); -export type TReferenceObject = { +export type ReferenceObject = { $ref: string; }; export const ReferenceObject = t.type( { $ref: t.string, }, - 'TReferenceObject', + 'ReferenceObject', ); //#region Schema Object -export type TObjectSchemaObject = { +export type ObjectSchemaObject = { type: 'object'; - properties: Option>; + properties: Option>; required: Option; - additionalProperties: Option; + additionalProperties: Option; }; -export type TStringPropertySchemaObject = { +export type StringPropertySchemaObject = { type: 'string'; format: Option; enum: Option>; @@ -100,10 +98,10 @@ export const StringPropertySchemaObject = t.type( format: stringOption, enum: primitiveArrayOption, }, - 'TStringPropertySchemaObject', + 'StringPropertySchemaObject', ); -export type TNumberPropertySchemaObject = { +export type NumberPropertySchemaObject = { type: 'number'; format: Option; }; @@ -112,10 +110,10 @@ export const NumberPropertySchemaObject = t.type( type: t.literal('number'), format: stringOption, }, - 'TNumberPropertySchemaObject', + 'NumberPropertySchemaObject', ); -export type TIntegerPropertySchemaObject = { +export type IntegerPropertySchemaObject = { type: 'integer'; format: Option; }; @@ -124,43 +122,43 @@ export const IntegerPropertySchemaObject = t.type( type: t.literal('integer'), format: stringOption, }, - 'TIntegerPropertySchemaObject', + 'IntegerPropertySchemaObject', ); -export type TBooleanPropertySchemaObject = { +export type BooleanPropertySchemaObject = { type: 'boolean'; }; export const BooleanPropertySchemaObject = t.type( { type: t.literal('boolean'), }, - 'TBooleanPropertySchemaObject', + 'BooleanPropertySchemaObject', ); -export type TAllOfSchemaObject = { - allOf: TSchemaObject[]; +export type AllOfSchemaObject = { + allOf: SchemaObject[]; description: Option; type: undefined; }; -export type TReferenceSchemaObject = TReferenceObject & { +export type ReferenceSchemaObject = ReferenceObject & { type: undefined; }; -export type TReferenceOrAllOfSchemeObject = TReferenceSchemaObject | TAllOfSchemaObject; +export type ReferenceOrAllOfSchemeObject = ReferenceSchemaObject | AllOfSchemaObject; -export type TArraySchemaObject = { +export type ArraySchemaObject = { type: 'array'; - items: TSchemaObject; -}; - -export type TSchemaObject = - | TReferenceOrAllOfSchemeObject - | TObjectSchemaObject - | TStringPropertySchemaObject - | TNumberPropertySchemaObject - | TIntegerPropertySchemaObject - | TBooleanPropertySchemaObject - | TArraySchemaObject; -export const SchemaObject = t.recursion('SchemaObject', SchemaObject => { + items: SchemaObject; +}; + +export type SchemaObject = + | ReferenceOrAllOfSchemeObject + | ObjectSchemaObject + | StringPropertySchemaObject + | NumberPropertySchemaObject + | IntegerPropertySchemaObject + | BooleanPropertySchemaObject + | ArraySchemaObject; +export const SchemaObject = t.recursion('SchemaObject', SchemaObject => { const ArraySchemaObject = t.type({ type: t.literal('array'), items: SchemaObject, @@ -168,7 +166,7 @@ export const SchemaObject = t.recursion('SchemaObject', const ObjectSchemaObject = t.type({ required: stringArrayOption, type: t.literal('object'), - properties: optionFromNullable(t.record(t.string, SchemaObject, 'TDictionary')), + properties: optionFromNullable(t.record(t.string, SchemaObject, 'Dictionary')), additionalProperties: optionFromNullable(SchemaObject), }); const ReferenceOrAllOfSchemaObject = t.union([ @@ -198,12 +196,12 @@ export const SchemaObject = t.recursion('SchemaObject', //#endregion -export type TDefinitionsObject = TDictionary; -export const DefinitionsObject = t.record(t.string, SchemaObject, 'TDefinitionsObject'); +export type DefinitionsObject = Dictionary; +export const DefinitionsObject = t.record(t.string, SchemaObject, 'DefinitionsObject'); //#region Items Object -export type TBaseItemsObject = { +export type BaseItemsObject = { format: Option; collectionFormat: Option<'csv' | 'ssv' | 'tsv' | 'pipes'>; maximum: Option; @@ -238,7 +236,7 @@ export const BaseItemsObjectProps = { multipleOf: numberOption, }; -export type TStringItemsObject = TBaseItemsObject & { +export type StringItemsObject = BaseItemsObject & { type: 'string'; }; export const StringItemsObject = t.type( @@ -246,10 +244,10 @@ export const StringItemsObject = t.type( ...BaseItemsObjectProps, type: t.literal('string'), }, - 'TStringItemsObject', + 'StringItemsObject', ); -export type TNumberItemsObject = TBaseItemsObject & { +export type NumberItemsObject = BaseItemsObject & { type: 'number'; }; export const NumberItemsObject = t.type( @@ -257,10 +255,10 @@ export const NumberItemsObject = t.type( ...BaseItemsObjectProps, type: t.literal('number'), }, - 'TNumberItemsObject', + 'NumberItemsObject', ); -export type TIntegerItemsObject = TBaseItemsObject & { +export type IntegerItemsObject = BaseItemsObject & { type: 'integer'; }; export const IntegerItemsObject = t.type( @@ -268,10 +266,10 @@ export const IntegerItemsObject = t.type( ...BaseItemsObjectProps, type: t.literal('integer'), }, - 'TIntegerItemsObject', + 'IntegerItemsObject', ); -export type TBooleanItemsObject = TBaseItemsObject & { +export type BooleanItemsObject = BaseItemsObject & { type: 'boolean'; }; export const BooleanItemsObject = t.type( @@ -279,21 +277,21 @@ export const BooleanItemsObject = t.type( ...BaseItemsObjectProps, type: t.literal('boolean'), }, - 'TBooleanItemsObject', + 'BooleanItemsObject', ); -export type TArrayItemsObject = TBaseItemsObject & { +export type ArrayItemsObject = BaseItemsObject & { type: 'array'; - items: Option; + items: Option; }; -export type TItemsObject = - | TArrayItemsObject - | TStringItemsObject - | TNumberItemsObject - | TIntegerItemsObject - | TBooleanItemsObject; -export const ItemsObject = t.recursion('ItemsObject', ItemsObject => { +export type ItemsObject = + | ArrayItemsObject + | StringItemsObject + | NumberItemsObject + | IntegerItemsObject + | BooleanItemsObject; +export const ItemsObject = t.recursion('ItemsObject', ItemsObject => { const ArrayItemsObject = t.type({ ...BaseItemsObjectProps, type: t.literal('array'), @@ -308,15 +306,15 @@ export const ItemsObject = t.recursion('ItemsObject', ItemsObject ]) as any; }); -export type TNonArrayItemsObject = TStringItemsObject | TNumberItemsObject | TIntegerItemsObject | TBooleanItemsObject; +export type NonArrayItemsObject = StringItemsObject | NumberItemsObject | IntegerItemsObject | BooleanItemsObject; export const NonArrayItemsObject = t.union( [StringItemsObject, NumberItemsObject, IntegerItemsObject, BooleanItemsObject], - 'TNonArrayItemsObject', + 'NonArrayItemsObject', ); //#endregion -export type TBaseParameterObjectProps = { +export type BaseParameterObjectProps = { name: string; description: Option; }; @@ -327,7 +325,7 @@ const BaseParameterObjectProps = { //#region Path Parameter Object -export type TBasePathParameterObjectProps = TBaseParameterObjectProps & { +export type BasePathParameterObjectProps = BaseParameterObjectProps & { in: 'path'; required: true; format: Option; @@ -339,7 +337,7 @@ const BasePathParameterObjectProps = { format: stringOption, }; -export type TStringPathParameterObject = TBasePathParameterObjectProps & { +export type StringPathParameterObject = BasePathParameterObjectProps & { type: 'string'; }; const StringPathParameterObject = t.type( @@ -347,10 +345,10 @@ const StringPathParameterObject = t.type( ...BasePathParameterObjectProps, type: t.literal('string'), }, - 'TStringPathParameterObject', + 'StringPathParameterObject', ); -export type TNumberPathParameterObject = TBasePathParameterObjectProps & { +export type NumberPathParameterObject = BasePathParameterObjectProps & { type: 'number'; }; const NumberPathParameterObject = t.type( @@ -358,10 +356,10 @@ const NumberPathParameterObject = t.type( ...BasePathParameterObjectProps, type: t.literal('number'), }, - 'TNumberPathParameterObject', + 'NumberPathParameterObject', ); -export type TIntegerPathParameterObject = TBasePathParameterObjectProps & { +export type IntegerPathParameterObject = BasePathParameterObjectProps & { type: 'integer'; }; const IntegerPathParameterObject = t.type( @@ -369,10 +367,10 @@ const IntegerPathParameterObject = t.type( ...BasePathParameterObjectProps, type: t.literal('integer'), }, - 'TIntegerPathParameterObject', + 'IntegerPathParameterObject', ); -export type TBooleanPathParameterObject = TBasePathParameterObjectProps & { +export type BooleanPathParameterObject = BasePathParameterObjectProps & { type: 'boolean'; }; const BooleanPathParameterObject = t.type( @@ -380,12 +378,12 @@ const BooleanPathParameterObject = t.type( ...BasePathParameterObjectProps, type: t.literal('boolean'), }, - 'TBooleanPathParameterObject', + 'BooleanPathParameterObject', ); -export type TArrayPathParameterObject = TBasePathParameterObjectProps & { +export type ArrayPathParameterObject = BasePathParameterObjectProps & { type: 'array'; - items: TNonArrayItemsObject; + items: NonArrayItemsObject; }; const ArrayPathParameterObject = t.type( { @@ -393,15 +391,15 @@ const ArrayPathParameterObject = t.type( type: t.literal('array'), items: NonArrayItemsObject, }, - 'TArrayPathParameterObject', + 'ArrayPathParameterObject', ); -export type TPathParameterObject = - | TStringPathParameterObject - | TNumberPathParameterObject - | TIntegerPathParameterObject - | TBooleanPathParameterObject - | TArrayPathParameterObject; +export type PathParameterObject = + | StringPathParameterObject + | NumberPathParameterObject + | IntegerPathParameterObject + | BooleanPathParameterObject + | ArrayPathParameterObject; export const PathParameterObject = t.union( [ @@ -411,14 +409,14 @@ export const PathParameterObject = t.union( BooleanPathParameterObject, ArrayPathParameterObject, ], - 'TPathParameterObject', + 'PathParameterObject', ); //#endregion //#region Query Parameter Object -export type TBaseQueryParameterObjectProps = { +export type BaseQueryParameterObjectProps = { name: string; in: 'query'; description: Option; @@ -432,7 +430,7 @@ const BaseQueryParameterObjectProps = { required: booleanOption, }; -export type TStringQueryParameterObject = TBaseQueryParameterObjectProps & { +export type StringQueryParameterObject = BaseQueryParameterObjectProps & { type: 'string'; }; const StringQueryParameterObject = t.type( @@ -440,10 +438,10 @@ const StringQueryParameterObject = t.type( ...BaseQueryParameterObjectProps, type: t.literal('string'), }, - 'TStringQueryParameterObject', + 'StringQueryParameterObject', ); -export type TNumberQueryParameterObject = TBaseQueryParameterObjectProps & { +export type NumberQueryParameterObject = BaseQueryParameterObjectProps & { type: 'number'; }; const NumberQueryParameterObject = t.type( @@ -451,10 +449,10 @@ const NumberQueryParameterObject = t.type( ...BaseQueryParameterObjectProps, type: t.literal('number'), }, - 'TNumberQueryParameterObject', + 'NumberQueryParameterObject', ); -export type TIntegerQueryParameterObject = TBaseQueryParameterObjectProps & { +export type IntegerQueryParameterObject = BaseQueryParameterObjectProps & { type: 'integer'; }; const IntegerQueryParameterObject = t.type( @@ -462,10 +460,10 @@ const IntegerQueryParameterObject = t.type( ...BaseQueryParameterObjectProps, type: t.literal('integer'), }, - 'TIntegerQueryParameterObject', + 'IntegerQueryParameterObject', ); -export type TBooleanQueryParameterObject = TBaseQueryParameterObjectProps & { +export type BooleanQueryParameterObject = BaseQueryParameterObjectProps & { type: 'boolean'; }; const BooleanQueryParameterObject = t.type( @@ -473,12 +471,12 @@ const BooleanQueryParameterObject = t.type( ...BaseQueryParameterObjectProps, type: t.literal('boolean'), }, - 'TBooleanQueryParameterObject', + 'BooleanQueryParameterObject', ); -export type TArrayQueryParameterObject = TBaseQueryParameterObjectProps & { +export type ArrayQueryParameterObject = BaseQueryParameterObjectProps & { type: 'array'; - items: TNonArrayItemsObject; + items: NonArrayItemsObject; }; const ArrayQueryParameterObject = t.type( { @@ -486,15 +484,15 @@ const ArrayQueryParameterObject = t.type( type: t.literal('array'), items: NonArrayItemsObject, }, - 'TArrayQueryParameterObject', + 'ArrayQueryParameterObject', ); -export type TQueryParameterObject = - | TStringQueryParameterObject - | TNumberQueryParameterObject - | TIntegerQueryParameterObject - | TBooleanQueryParameterObject - | TArrayQueryParameterObject; +export type QueryParameterObject = + | StringQueryParameterObject + | NumberQueryParameterObject + | IntegerQueryParameterObject + | BooleanQueryParameterObject + | ArrayQueryParameterObject; export const QueryParameterObject = t.union( [ @@ -504,12 +502,12 @@ export const QueryParameterObject = t.union( BooleanQueryParameterObject, ArrayQueryParameterObject, ], - 'TQueryParameterObject', + 'QueryParameterObject', ); //#endregion -export type THeaderParameterObject = { +export type HeaderParameterObject = { name: string; in: 'header'; description: Option; @@ -522,9 +520,9 @@ export const HeaderParameterObject = t.type( description: stringOption, required: booleanOption, }, - 'THeaderParameterObject', + 'HeaderParameterObject', ); -export type TFormDataParameterObject = { +export type FormDataParameterObject = { name: string; in: 'formData'; description: Option; @@ -537,15 +535,15 @@ export const FormDataParameterObject = t.type( description: stringOption, required: booleanOption, }, - 'TFormDataParameterObject', + 'FormDataParameterObject', ); //#region Body Parameter Object -export type TBodyParameterObject = TBaseParameterObjectProps & { +export type BodyParameterObject = BaseParameterObjectProps & { in: 'body'; required: Option; - schema: TSchemaObject; + schema: SchemaObject; }; export const BodyParameterObject = t.type( @@ -555,26 +553,26 @@ export const BodyParameterObject = t.type( required: booleanOption, schema: SchemaObject, }, - 'TBodyParameterObject', + 'BodyParameterObject', ); //#endregion -export type TParameterObject = - | TPathParameterObject - | TQueryParameterObject - | THeaderParameterObject - | TFormDataParameterObject - | TBodyParameterObject; +export type ParameterObject = + | PathParameterObject + | QueryParameterObject + | HeaderParameterObject + | FormDataParameterObject + | BodyParameterObject; export const ParameterObject = t.union( [PathParameterObject, QueryParameterObject, HeaderParameterObject, FormDataParameterObject, BodyParameterObject], - 'TParameterObject', + 'ParameterObject', ); -export type TExampleObject = TDictionary; -export const ExampleObject = t.record(t.string, t.string, 'TExampleObject'); +export type ExampleObject = Dictionary; +export const ExampleObject = t.record(t.string, t.string, 'ExampleObject'); -export type THeaderObject = TItemsObject & { +export type HeaderObject = ItemsObject & { description: Option; }; export const HeaderObject = t.intersection( @@ -584,17 +582,17 @@ export const HeaderObject = t.intersection( description: stringOption, }), ], - 'THeaderObject', + 'HeaderObject', ); -export type THeadersObject = TDictionary; -export const HeadersObject = t.record(t.string, HeaderObject, 'THeadersObject'); +export type HeadersObject = Dictionary; +export const HeadersObject = t.record(t.string, HeaderObject, 'HeadersObject'); -export type TResponseObject = { +export type ResponseObject = { description: string; - schema: Option; - headers: Option; - examples: Option; + schema: Option; + headers: Option; + examples: Option; }; export const ResponseObject = t.type( { @@ -603,28 +601,28 @@ export const ResponseObject = t.type( headers: optionFromNullable(HeadersObject), examples: optionFromNullable(ExampleObject), }, - 'TResponseObject', + 'ResponseObject', ); -export type TResponsesObject = TDictionary; -export const ResponsesObject = t.record(t.string, ResponseObject, 'TResponsesObject'); +export type ResponsesObject = Dictionary; +export const ResponsesObject = t.record(t.string, ResponseObject, 'ResponsesObject'); -export type TSecurityRequirementObject = TDictionary; -export const SecurityRequirementObject = t.record(t.string, t.array(t.string), 'TSecurityRequirementObject'); +export type SecurityRequirementObject = Dictionary; +export const SecurityRequirementObject = t.record(t.string, t.array(t.string), 'SecurityRequirementObject'); -export type TOperationObject = { +export type OperationObject = { tags: Option; summary: Option; description: Option; - externalDocs: Option; + externalDocs: Option; operationId: Option; consumes: Option; produces: Option; - parameters: Option>; - responses: TResponsesObject; + parameters: Option>; + responses: ResponsesObject; schemes: Option; deprecated: Option; - security: Option; + security: Option; }; export const OperationObject = t.type( { @@ -641,19 +639,19 @@ export const OperationObject = t.type( deprecated: booleanOption, security: optionFromNullable(t.array(SecurityRequirementObject)), }, - 'TOperationObject', + 'OperationObject', ); -export type TPathItemObject = { +export type PathItemObject = { $ref: Option; - get: Option; - put: Option; - post: Option; - delete: Option; - options: Option; - head: Option; - patch: Option; - parameters: Option>; + get: Option; + put: Option; + post: Option; + delete: Option; + options: Option; + head: Option; + patch: Option; + parameters: Option>; }; export const PathItemObject = t.type( { @@ -667,31 +665,31 @@ export const PathItemObject = t.type( patch: optionFromNullable(OperationObject), parameters: optionFromNullable(t.array(t.union([ParameterObject, ReferenceObject]))), }, - 'TPathItemObject', + 'PathItemObject', ); -export type TPathsObject = TDictionary; -export const PathsObject = t.record(t.string, PathItemObject, 'TPathsObject'); +export type PathsObject = Dictionary; +export const PathsObject = t.record(t.string, PathItemObject, 'PathsObject'); -export type TParametersDefinitionsObject = TDictionary; -export const ParametersDefinitionsObject = t.record(t.string, ParameterObject, 'TParametersDefinitionsObject'); +export type ParametersDefinitionsObject = Dictionary; +export const ParametersDefinitionsObject = t.record(t.string, ParameterObject, 'ParametersDefinitionsObject'); -export type TResponsesDefinitionsObject = TDictionary; -export const ResponsesDefinitionsObject = t.record(t.string, ResponseObject, 'TResponsesDefinitionsObject'); +export type ResponsesDefinitionsObject = Dictionary; +export const ResponsesDefinitionsObject = t.record(t.string, ResponseObject, 'ResponsesDefinitionsObject'); -export type TScopesObject = TDictionary; -export const ScopesObject = t.record(t.string, t.string, 'TScopesObject'); +export type ScopesObject = Dictionary; +export const ScopesObject = t.record(t.string, t.string, 'ScopesObject'); //#region SecuritySchemeObject -export type TBaseSecuritySchemeObjectProps = { +export type BaseSecuritySchemeObjectProps = { description: Option; }; const BaseSecuritySchemeObjectProps = { description: stringOption, }; -export type TBasicSecuritySchemeObject = TBaseSecuritySchemeObjectProps & { +export type BasicSecuritySchemeObject = BaseSecuritySchemeObjectProps & { type: 'basic'; }; const BasicSecuritySchemeObject = t.type( @@ -699,10 +697,10 @@ const BasicSecuritySchemeObject = t.type( ...BaseSecuritySchemeObjectProps, type: t.literal('basic'), }, - 'TBasicSecuritySchemeObject', + 'BasicSecuritySchemeObject', ); -export type TApiKeySecuritySchemeObject = TBaseSecuritySchemeObjectProps & { +export type ApiKeySecuritySchemeObject = BaseSecuritySchemeObjectProps & { type: 'apiKey'; in: 'query' | 'header'; name: string; @@ -714,14 +712,14 @@ const ApiKeySecuritySchemeObject = t.type( in: t.union([t.literal('query'), t.literal('header')]), name: t.string, }, - 'TApiKeySecuritySchemeObject', + 'ApiKeySecuritySchemeObject', ); -export type TImplicitOAuth2SecuritySchemeObject = TBaseSecuritySchemeObjectProps & { +export type ImplicitOAuth2SecuritySchemeObject = BaseSecuritySchemeObjectProps & { type: 'oauth2'; flow: 'implicit'; authorizationUrl: string; - scopes: TScopesObject; + scopes: ScopesObject; }; const ImplicitOAuth2SecuritySchemeObject = t.type( { @@ -731,13 +729,13 @@ const ImplicitOAuth2SecuritySchemeObject = t.type( authorizationUrl: t.string, scopes: ScopesObject, }, - 'TImplicitOAuth2SecuritySchemeObject', + 'ImplicitOAuth2SecuritySchemeObject', ); -export type TPasswordOAuth2SecuritySchemeObject = TBaseSecuritySchemeObjectProps & { +export type PasswordOAuth2SecuritySchemeObject = BaseSecuritySchemeObjectProps & { type: 'oauth2'; flow: 'password'; tokenUrl: string; - scopes: TScopesObject; + scopes: ScopesObject; }; const PasswordOAuth2SecuritySchemeObject = t.type( { @@ -747,13 +745,13 @@ const PasswordOAuth2SecuritySchemeObject = t.type( tokenUrl: t.string, scopes: ScopesObject, }, - 'TPasswordOAuth2SecuritySchemeObject', + 'PasswordOAuth2SecuritySchemeObject', ); -export type TApplicationOAuth2SecuritySchemeObject = TBaseSecuritySchemeObjectProps & { +export type ApplicationOAuth2SecuritySchemeObject = BaseSecuritySchemeObjectProps & { type: 'oauth2'; flow: 'application'; tokenUrl: string; - scopes: TScopesObject; + scopes: ScopesObject; }; const ApplicationOAuth2SecuritySchemeObject = t.type( { @@ -763,13 +761,13 @@ const ApplicationOAuth2SecuritySchemeObject = t.type( tokenUrl: t.string, scopes: ScopesObject, }, - 'TApplicationOAuth2SecuritySchemeObject', + 'ApplicationOAuth2SecuritySchemeObject', ); -export type TAccessCodeOAuth2SecuritySchemeObject = TBaseSecuritySchemeObjectProps & { +export type AccessCodeOAuth2SecuritySchemeObject = BaseSecuritySchemeObjectProps & { type: 'oauth2'; flow: 'accessCode'; tokenUrl: string; - scopes: TScopesObject; + scopes: ScopesObject; }; const AccessCodeOAuth2SecuritySchemeObject = t.type( { @@ -779,13 +777,13 @@ const AccessCodeOAuth2SecuritySchemeObject = t.type( tokenUrl: t.string, scopes: ScopesObject, }, - 'TAccessCodeOAuth2SecuritySchemeObject', + 'AccessCodeOAuth2SecuritySchemeObject', ); -export type TOAuth2SecuritySchemeObject = - | TImplicitOAuth2SecuritySchemeObject - | TPasswordOAuth2SecuritySchemeObject - | TApplicationOAuth2SecuritySchemeObject - | TAccessCodeOAuth2SecuritySchemeObject; +export type OAuth2SecuritySchemeObject = + | ImplicitOAuth2SecuritySchemeObject + | PasswordOAuth2SecuritySchemeObject + | ApplicationOAuth2SecuritySchemeObject + | AccessCodeOAuth2SecuritySchemeObject; const OAuth2SecuritySchemeObject = t.union( [ ImplicitOAuth2SecuritySchemeObject, @@ -793,27 +791,24 @@ const OAuth2SecuritySchemeObject = t.union( ApplicationOAuth2SecuritySchemeObject, AccessCodeOAuth2SecuritySchemeObject, ], - 'TOAuth2SecuritySchemeObject', + 'OAuth2SecuritySchemeObject', ); -export type TSecuritySchemeObject = - | TBasicSecuritySchemeObject - | TApiKeySecuritySchemeObject - | TOAuth2SecuritySchemeObject; +export type SecuritySchemeObject = BasicSecuritySchemeObject | ApiKeySecuritySchemeObject | OAuth2SecuritySchemeObject; const SecuritySchemeObject = t.union( [BasicSecuritySchemeObject, ApiKeySecuritySchemeObject, OAuth2SecuritySchemeObject], - 'TSecuritySchemeObject', + 'SecuritySchemeObject', ); //#endregion -export type TSecurityDefinitionsObject = TDictionary; -export const SecurityDefinitionsObject = t.record(t.string, SecuritySchemeObject, 'TSecurityDefinitionsObject'); +export type SecurityDefinitionsObject = Dictionary; +export const SecurityDefinitionsObject = t.record(t.string, SecuritySchemeObject, 'SecurityDefinitionsObject'); -export type TTagObject = { +export type TagObject = { name: string; description: Option; - externalDocs: Option; + externalDocs: Option; }; export const TagObject = t.type( { @@ -821,25 +816,25 @@ export const TagObject = t.type( description: stringOption, externalDocs: optionFromNullable(ExternalDocumentationObject), }, - 'TTagObject', + 'TagObject', ); -export type TSwaggerObject = { +export type SwaggerObject = { basePath: Option; consumes: Option; - definitions: Option; - externalDocs: Option; + definitions: Option; + externalDocs: Option; host: Option; - info: TInfoObject; - parameters: Option; - paths: TPathsObject; + info: InfoObject; + parameters: Option; + paths: PathsObject; produces: Option; - responses: Option; + responses: Option; schemes: Option; - security: Option; - securityDefinitions: Option; + security: Option; + securityDefinitions: Option; swagger: string; - tags: Option; + tags: Option; }; export const SwaggerObject = t.type( { @@ -859,5 +854,5 @@ export const SwaggerObject = t.type( swagger: t.string, tags: optionFromNullable(t.array(TagObject)), }, - 'TSwaggerObject', + 'SwaggerObject', ); diff --git a/src/utils.ts b/src/utils.ts index c76cbb1..668bdff 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,28 +1,28 @@ import { array, uniq, flatten, last } from 'fp-ts/lib/Array'; import { - TPathItemObject, - TOperationObject, - TPathsObject, - TDictionary, - TParameterObject, - TPathParameterObject, - TReferenceObject, - TBodyParameterObject, - TSwaggerObject, - TParametersDefinitionsObject, - TQueryParameterObject, + PathItemObject, + OperationObject, + PathsObject, + Dictionary, + ParameterObject, + PathParameterObject, + ReferenceObject, + BodyParameterObject, + SwaggerObject, + ParametersDefinitionsObject, + QueryParameterObject, } from './schema/2.0/swagger'; import { constant, Endomorphism, identity, tuple } from 'fp-ts/lib/function'; import { getStructEq, eqString } from 'fp-ts/lib/Eq'; -import { TFSEntity } from './fs'; +import { FSEntity } from './fs'; import { camelize } from '@devexperts/utils/dist/string/string'; import { alt, map, mapNullable, option, Option, some, chain, getOrElse } from 'fp-ts/lib/Option'; import { pipe } from 'fp-ts/lib/pipeable'; -export type TSerializer = (name: string, schema: TSwaggerObject) => TFSEntity; +export type Serializer = (name: string, schema: SwaggerObject) => FSEntity; -export const getOperationsFromPath = (path: TPathItemObject): TDictionary => { - const result: TDictionary = {}; +export const getOperationsFromPath = (path: PathItemObject): Dictionary => { + const result: Dictionary = {}; const operations = array.compact([ pipe( path.get, @@ -59,24 +59,24 @@ export const getOperationsFromPath = (path: TPathItemObject): TDictionary { +export const getTagsFromPath = (path: PathItemObject): string[] => { const operations = getOperationsFromPath(path); const tags = flatten(array.compact(Object.keys(operations).map(key => operations[key].tags))); return uniq(eqString)(tags); }; -type TParam = TParameterObject | TReferenceObject; -const paramSetoid = getStructEq({ +type Param = ParameterObject | ReferenceObject; +const paramSetoid = getStructEq({ name: eqString, $ref: eqString, }); -const addPathParametersToTag = (pathParams: TParam[]): Endomorphism => tagParams => +const addPathParametersToTag = (pathParams: Param[]): Endomorphism => tagParams => uniq(paramSetoid)([...pathParams, ...tagParams]); -const resolveTagParameter = (fileParameters: TParametersDefinitionsObject) => ( - parameter: TParam, -): Option => { +const resolveTagParameter = (fileParameters: ParametersDefinitionsObject) => ( + parameter: Param, +): Option => { if (!isOperationReferenceParameterObject(parameter)) { return some(parameter); } @@ -87,13 +87,13 @@ const resolveTagParameter = (fileParameters: TParametersDefinitionsObject) => ( }; const getTagWithResolvedParameters = ( - addPathParametersToTag: Endomorphism, - resolveTagParameter: (parameter: TParam) => Option, -) => (tag: TOperationObject): TOperationObject => ({ + addPathParametersToTag: Endomorphism, + resolveTagParameter: (parameter: Param) => Option, +) => (tag: OperationObject): OperationObject => ({ ...tag, parameters: pipe( tag.parameters, - alt(constant(some([]))), + alt(constant(some([]))), map(addPathParametersToTag), map(parameters => parameters.map(resolveTagParameter)), chain(array.sequence(option)), @@ -101,11 +101,11 @@ const getTagWithResolvedParameters = ( }); export const groupPathsByTag = ( - paths: TPathsObject, - parameters: Option, -): TDictionary> => { + paths: PathsObject, + parameters: Option, +): Dictionary> => { const keys = Object.keys(paths); - const result: TDictionary> = {}; + const result: Dictionary> = {}; const resolveTagParam = pipe( parameters, map(resolveTagParameter), @@ -125,9 +125,9 @@ export const groupPathsByTag = ( map(resolveTagParam => getTagWithResolvedParameters(addPathParamsToTag, resolveTagParam)), ), ), - getOrElse>(() => identity), + getOrElse>(() => identity), ); - const pathWithParams: TPathItemObject = pipe( + const pathWithParams: PathItemObject = pipe( pathParams, map(() => ({ ...path, @@ -161,40 +161,38 @@ export const groupPathsByTag = ( return result; }; -const isOperationReferenceParameterObject = (parameter: TParam): parameter is TReferenceObject => +const isOperationReferenceParameterObject = (parameter: Param): parameter is ReferenceObject => typeof (parameter as any)['$ref'] === 'string'; -const isOperationNonReferenceParameterObject = (parameter: TParam): parameter is TParameterObject => +const isOperationNonReferenceParameterObject = (parameter: Param): parameter is ParameterObject => !isOperationReferenceParameterObject(parameter); -const isPathParameterObject = (parameter: TParameterObject): parameter is TPathParameterObject => - parameter.in === 'path'; -const isOperationPathParameterObject = (parameter: TParam): parameter is TPathParameterObject => +const isPathParameterObject = (parameter: ParameterObject): parameter is PathParameterObject => parameter.in === 'path'; +const isOperationPathParameterObject = (parameter: Param): parameter is PathParameterObject => isOperationNonReferenceParameterObject(parameter) && isPathParameterObject(parameter); -export const getOperationParametersInPath = (operation: TOperationObject): TPathParameterObject[] => +export const getOperationParametersInPath = (operation: OperationObject): PathParameterObject[] => pipe( operation.parameters, map(parameters => parameters.filter(isOperationPathParameterObject)), - getOrElse(constant([])), + getOrElse(constant([])), ); -const isQueryParameterObject = (parameter: TParameterObject): parameter is TQueryParameterObject => +const isQueryParameterObject = (parameter: ParameterObject): parameter is QueryParameterObject => parameter.in === 'query'; -const isOperationQueryParameterObject = (parameter: TParam): parameter is TQueryParameterObject => +const isOperationQueryParameterObject = (parameter: Param): parameter is QueryParameterObject => isOperationNonReferenceParameterObject(parameter) && isQueryParameterObject(parameter); -export const getOperationParametersInQuery = (operation: TOperationObject): TQueryParameterObject[] => +export const getOperationParametersInQuery = (operation: OperationObject): QueryParameterObject[] => pipe( operation.parameters, map(parameters => parameters.filter(isOperationQueryParameterObject)), - getOrElse(constant([])), + getOrElse(constant([])), ); -const isBodyParameterObject = (parameter: TParameterObject): parameter is TBodyParameterObject => - parameter.in === 'body'; -const isOperationBodyParameterObject = (parameter: TParam): parameter is TBodyParameterObject => +const isBodyParameterObject = (parameter: ParameterObject): parameter is BodyParameterObject => parameter.in === 'body'; +const isOperationBodyParameterObject = (parameter: Param): parameter is BodyParameterObject => isOperationNonReferenceParameterObject(parameter) && isBodyParameterObject(parameter); -export const getOperationParametersInBody = (operation: TOperationObject): TBodyParameterObject[] => +export const getOperationParametersInBody = (operation: OperationObject): BodyParameterObject[] => pipe( operation.parameters, map(parameters => parameters.filter(isOperationBodyParameterObject)), - getOrElse(constant([])), + getOrElse(constant([])), );