chore: remove global Dict<T> and replace it with Record<string, T>

This commit is contained in:
Roman Hotsiy 2020-05-25 16:37:38 +03:00
parent 9dd129d90b
commit c69f6de4c9
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
12 changed files with 24 additions and 24 deletions

View File

@ -26,7 +26,7 @@ export interface ParametersProps {
const PARAM_PLACES = ['path', 'query', 'cookie', 'header']; const PARAM_PLACES = ['path', 'query', 'cookie', 'header'];
export class Parameters extends React.PureComponent<ParametersProps> { export class Parameters extends React.PureComponent<ParametersProps> {
orderParams(params: FieldModel[]): Dict<FieldModel[]> { orderParams(params: FieldModel[]): Record<string, FieldModel[]> {
const res = {}; const res = {};
params.forEach(param => { params.forEach(param => {
safePush(res, param.in, param); safePush(res, param.in, param);

View File

@ -30,7 +30,7 @@ export type ExtendedOpenAPIOperation = {
pathServers: Array<OpenAPIServer> | undefined; pathServers: Array<OpenAPIServer> | undefined;
} & OpenAPIOperation; } & OpenAPIOperation;
export type TagsInfoMap = Dict<TagInfo>; export type TagsInfoMap = Record<string, TagInfo>;
export interface TagGroup { export interface TagGroup {
name: string; name: string;

View File

@ -298,8 +298,8 @@ export class OpenAPIParser {
* returns map of definition pointer to definition name * returns map of definition pointer to definition name
* @param $refs array of references to find derived from * @param $refs array of references to find derived from
*/ */
findDerived($refs: string[]): Dict<string[] | string> { findDerived($refs: string[]): Record<string, string[] | string> {
const res: Dict<string[]> = {}; const res: Record<string, string[]> = {};
const schemas = (this.spec.components && this.spec.components.schemas) || {}; const schemas = (this.spec.components && this.spec.components.schemas) || {};
for (const defName in schemas) { for (const defName in schemas) {
const def = this.deref(schemas[defName]); const def = this.deref(schemas[defName]);

View File

@ -30,7 +30,7 @@ export interface RedocRawOptions {
unstable_ignoreMimeParameters?: boolean; unstable_ignoreMimeParameters?: boolean;
allowedMdComponents?: Dict<MDXComponentMeta>; allowedMdComponents?: Record<string, MDXComponentMeta>;
labels?: LabelsConfigRaw; labels?: LabelsConfigRaw;
@ -172,7 +172,7 @@ export class RedocNormalizedOptions {
/* tslint:disable-next-line */ /* tslint:disable-next-line */
unstable_ignoreMimeParameters: boolean; unstable_ignoreMimeParameters: boolean;
allowedMdComponents: Dict<MDXComponentMeta>; allowedMdComponents: Record<string, MDXComponentMeta>;
expandDefaultServerVariables: boolean; expandDefaultServerVariables: boolean;

View File

@ -40,7 +40,7 @@ export class FieldModel {
deprecated: boolean; deprecated: boolean;
in?: OpenAPIParameterLocation; in?: OpenAPIParameterLocation;
kind: string; kind: string;
extensions?: Dict<any>; extensions?: Record<string, any>;
explode: boolean; explode: boolean;
style?: OpenAPIParameterStyle; style?: OpenAPIParameterStyle;

View File

@ -22,7 +22,7 @@ export class MediaContentModel {
*/ */
constructor( constructor(
parser: OpenAPIParser, parser: OpenAPIParser,
info: Dict<OpenAPIMediaType>, info: Record<string, OpenAPIMediaType>,
public isRequestType: boolean, public isRequestType: boolean,
options: RedocNormalizedOptions, options: RedocNormalizedOptions,
) { ) {

View File

@ -73,7 +73,7 @@ export class OperationModel implements IMenuItem {
path: string; path: string;
servers: OpenAPIServer[]; servers: OpenAPIServer[];
security: SecurityRequirementModel[]; security: SecurityRequirementModel[];
extensions: Dict<any>; extensions: Record<string, any>;
isCallback: boolean; isCallback: boolean;
constructor( constructor(

View File

@ -59,7 +59,7 @@ export class SchemaModel {
rawSchema: OpenAPISchema; rawSchema: OpenAPISchema;
schema: MergedOpenAPISchema; schema: MergedOpenAPISchema;
extensions?: Dict<any>; extensions?: Record<string, any>;
/** /**
* @param isChild if schema discriminator Child * @param isChild if schema discriminator Child

View File

@ -1,8 +1,3 @@
export * from './open-api'; export * from './open-api';
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
declare global {
type Dict<T> = {
[key: string]: T;
};
}

View File

@ -226,22 +226,22 @@ export interface OpenAPISecurityScheme {
flows: { flows: {
implicit?: { implicit?: {
refreshUrl?: string; refreshUrl?: string;
scopes: Dict<string>; scopes: Record<string, string>;
authorizationUrl: string; authorizationUrl: string;
}; };
password?: { password?: {
refreshUrl?: string; refreshUrl?: string;
scopes: Dict<string>; scopes: Record<string, string>;
tokenUrl: string; tokenUrl: string;
}; };
clientCredentials?: { clientCredentials?: {
refreshUrl?: string; refreshUrl?: string;
scopes: Dict<string>; scopes: Record<string, string>;
tokenUrl: string; tokenUrl: string;
}; };
authorizationCode?: { authorizationCode?: {
refreshUrl?: string; refreshUrl?: string;
scopes: Dict<string>; scopes: Record<string, string>;
tokenUrl: string; tokenUrl: string;
}; };
}; };

View File

@ -24,9 +24,9 @@ export function mapWithLast<T, P>(array: T[], iteratee: (item: T, isLast: boolea
* @param iteratee the function invoked per iteration. * @param iteratee the function invoked per iteration.
*/ */
export function mapValues<T, P>( export function mapValues<T, P>(
object: Dict<T>, object: Record<string, T>,
iteratee: (val: T, key: string, obj: Dict<T>) => P, iteratee: (val: T, key: string, obj: Record<string, T>) => P,
): Dict<P> { ): Record<string, P> {
const res: { [key: string]: P } = {}; const res: { [key: string]: P } = {};
for (const key in object) { for (const key in object) {
if (object.hasOwnProperty(key)) { if (object.hasOwnProperty(key)) {

View File

@ -492,7 +492,9 @@ export function mergeParams(
return pathParams.concat(operationParams); return pathParams.concat(operationParams);
} }
export function mergeSimilarMediaTypes(types: Dict<OpenAPIMediaType>): Dict<OpenAPIMediaType> { export function mergeSimilarMediaTypes(
types: Record<string, OpenAPIMediaType>,
): Record<string, OpenAPIMediaType> {
const mergedTypes = {}; const mergedTypes = {};
Object.keys(types).forEach(name => { Object.keys(types).forEach(name => {
const mime = types[name]; const mime = types[name];
@ -586,7 +588,10 @@ export function isRedocExtension(key: string): boolean {
return key in redocExtensions; return key in redocExtensions;
} }
export function extractExtensions(obj: object, showExtensions: string[] | true): Dict<any> { export function extractExtensions(
obj: object,
showExtensions: string[] | true,
): Record<string, any> {
return Object.keys(obj) return Object.keys(obj)
.filter(key => { .filter(key => {
if (showExtensions === true) { if (showExtensions === true) {