From c69f6de4c928775d90efa392eceac10ff97e8f3e Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 25 May 2020 16:37:38 +0300 Subject: [PATCH] chore: remove global Dict and replace it with Record --- src/components/Parameters/Parameters.tsx | 2 +- src/services/MenuBuilder.ts | 2 +- src/services/OpenAPIParser.ts | 4 ++-- src/services/RedocNormalizedOptions.ts | 4 ++-- src/services/models/Field.ts | 2 +- src/services/models/MediaContent.ts | 2 +- src/services/models/Operation.ts | 2 +- src/services/models/Schema.ts | 2 +- src/types/index.d.ts | 5 ----- src/types/open-api.d.ts | 8 ++++---- src/utils/helpers.ts | 6 +++--- src/utils/openapi.ts | 9 +++++++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/components/Parameters/Parameters.tsx b/src/components/Parameters/Parameters.tsx index 9145f13e..453cdbc9 100644 --- a/src/components/Parameters/Parameters.tsx +++ b/src/components/Parameters/Parameters.tsx @@ -26,7 +26,7 @@ export interface ParametersProps { const PARAM_PLACES = ['path', 'query', 'cookie', 'header']; export class Parameters extends React.PureComponent { - orderParams(params: FieldModel[]): Dict { + orderParams(params: FieldModel[]): Record { const res = {}; params.forEach(param => { safePush(res, param.in, param); diff --git a/src/services/MenuBuilder.ts b/src/services/MenuBuilder.ts index e9daeedb..38f104e5 100644 --- a/src/services/MenuBuilder.ts +++ b/src/services/MenuBuilder.ts @@ -30,7 +30,7 @@ export type ExtendedOpenAPIOperation = { pathServers: Array | undefined; } & OpenAPIOperation; -export type TagsInfoMap = Dict; +export type TagsInfoMap = Record; export interface TagGroup { name: string; diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts index debb9963..e3030a59 100644 --- a/src/services/OpenAPIParser.ts +++ b/src/services/OpenAPIParser.ts @@ -298,8 +298,8 @@ export class OpenAPIParser { * returns map of definition pointer to definition name * @param $refs array of references to find derived from */ - findDerived($refs: string[]): Dict { - const res: Dict = {}; + findDerived($refs: string[]): Record { + const res: Record = {}; const schemas = (this.spec.components && this.spec.components.schemas) || {}; for (const defName in schemas) { const def = this.deref(schemas[defName]); diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 8867855b..a9952529 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -30,7 +30,7 @@ export interface RedocRawOptions { unstable_ignoreMimeParameters?: boolean; - allowedMdComponents?: Dict; + allowedMdComponents?: Record; labels?: LabelsConfigRaw; @@ -172,7 +172,7 @@ export class RedocNormalizedOptions { /* tslint:disable-next-line */ unstable_ignoreMimeParameters: boolean; - allowedMdComponents: Dict; + allowedMdComponents: Record; expandDefaultServerVariables: boolean; diff --git a/src/services/models/Field.ts b/src/services/models/Field.ts index f22a86ae..c8412071 100644 --- a/src/services/models/Field.ts +++ b/src/services/models/Field.ts @@ -40,7 +40,7 @@ export class FieldModel { deprecated: boolean; in?: OpenAPIParameterLocation; kind: string; - extensions?: Dict; + extensions?: Record; explode: boolean; style?: OpenAPIParameterStyle; diff --git a/src/services/models/MediaContent.ts b/src/services/models/MediaContent.ts index c709f42a..ff2c4950 100644 --- a/src/services/models/MediaContent.ts +++ b/src/services/models/MediaContent.ts @@ -22,7 +22,7 @@ export class MediaContentModel { */ constructor( parser: OpenAPIParser, - info: Dict, + info: Record, public isRequestType: boolean, options: RedocNormalizedOptions, ) { diff --git a/src/services/models/Operation.ts b/src/services/models/Operation.ts index 0e688ddb..2bb63a01 100644 --- a/src/services/models/Operation.ts +++ b/src/services/models/Operation.ts @@ -73,7 +73,7 @@ export class OperationModel implements IMenuItem { path: string; servers: OpenAPIServer[]; security: SecurityRequirementModel[]; - extensions: Dict; + extensions: Record; isCallback: boolean; constructor( diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index 49e89f12..e393614e 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -59,7 +59,7 @@ export class SchemaModel { rawSchema: OpenAPISchema; schema: MergedOpenAPISchema; - extensions?: Dict; + extensions?: Record; /** * @param isChild if schema discriminator Child diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 8103c2ef..c02a721c 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1,8 +1,3 @@ export * from './open-api'; export type Omit = Pick>; -declare global { - type Dict = { - [key: string]: T; - }; -} diff --git a/src/types/open-api.d.ts b/src/types/open-api.d.ts index 1f4d848a..bb050b6e 100644 --- a/src/types/open-api.d.ts +++ b/src/types/open-api.d.ts @@ -226,22 +226,22 @@ export interface OpenAPISecurityScheme { flows: { implicit?: { refreshUrl?: string; - scopes: Dict; + scopes: Record; authorizationUrl: string; }; password?: { refreshUrl?: string; - scopes: Dict; + scopes: Record; tokenUrl: string; }; clientCredentials?: { refreshUrl?: string; - scopes: Dict; + scopes: Record; tokenUrl: string; }; authorizationCode?: { refreshUrl?: string; - scopes: Dict; + scopes: Record; tokenUrl: string; }; }; diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 257d0eb7..d84217a9 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -24,9 +24,9 @@ export function mapWithLast(array: T[], iteratee: (item: T, isLast: boolea * @param iteratee the function invoked per iteration. */ export function mapValues( - object: Dict, - iteratee: (val: T, key: string, obj: Dict) => P, -): Dict

{ + object: Record, + iteratee: (val: T, key: string, obj: Record) => P, +): Record { const res: { [key: string]: P } = {}; for (const key in object) { if (object.hasOwnProperty(key)) { diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index 8e210dfc..3dba3d22 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -492,7 +492,9 @@ export function mergeParams( return pathParams.concat(operationParams); } -export function mergeSimilarMediaTypes(types: Dict): Dict { +export function mergeSimilarMediaTypes( + types: Record, +): Record { const mergedTypes = {}; Object.keys(types).forEach(name => { const mime = types[name]; @@ -586,7 +588,10 @@ export function isRedocExtension(key: string): boolean { return key in redocExtensions; } -export function extractExtensions(obj: object, showExtensions: string[] | true): Dict { +export function extractExtensions( + obj: object, + showExtensions: string[] | true, +): Record { return Object.keys(obj) .filter(key => { if (showExtensions === true) {