Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ScalarSchema = {
export type NormalizedScalarSchema = {
name?: never;
type?: 'string' | 'boolean' | 'number' | 'integer' | 'object' | 'array';
items?: ScalarSchema;
items?: NormalizedScalarSchema;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check with snapshot on monorepo.

enum?: string[];
directResolveAs?: NormalizedNodeType;
resolvable: boolean;
Expand Down Expand Up @@ -46,7 +46,7 @@ export type NormalizedNodeType = {
requiredOneOf?: string[];
allowed?: (value: any) => string[] | undefined;
extensionsPrefix?: string;
directResolveAs?: NormalizedPropType;
directResolveAs?: NormalizedNodeType;
description?: string;
documentationLink?: string;
};
Expand Down Expand Up @@ -122,7 +122,7 @@ export function normalizeTypes(

if (options.doNotResolveExamples && prop && (prop as ScalarSchema).isExample) {
mappedProps[propName] = {
...(prop as object),
...prop,
resolvable: false,
};
}
Expand All @@ -132,24 +132,25 @@ export function normalizeTypes(
}

// typings are painful here...
function resolveType(type?: any): any {
function resolveType(
type: NormalizedPropType | NormalizedResolveTypeFn | string
): NormalizedPropType | NormalizedResolveTypeFn {
if (typeof type === 'string') {
if (!normalizedTypes[type]) {
throw new Error(`Unknown type name found: ${type}`);
}
return normalizedTypes[type];
} else if (typeof type === 'function') {
return (value: any, key: string) => {
return resolveType(type(value, key));
};
} else if (type && type.name) {
return (value: unknown, key: string) =>
resolveType((type as NormalizedResolveTypeFn)(value, key)) as NormalizedPropType;
} else if (isNamedType(type)) {
type = { ...type };
normalizeType(type);
return type;
} else if (type && type.directResolveAs) {
} else if (type?.directResolveAs !== undefined) {
return {
...type,
directResolveAs: resolveType(type.directResolveAs),
directResolveAs: (resolveType(type.directResolveAs) ?? undefined) as NormalizedNodeType,
};
} else {
return type;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/redocly-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const configGovernanceProperties: Record<
return {
...ConfigGovernance,
directResolveAs: { name: 'ConfigGovernance', ...ConfigGovernance },
} as PropType;
};
},
description: 'Use extends to inherit rules and their configurations from other rulesets.',
documentationLink: 'https://redocly.com/docs/cli/configuration/reference/extends#extends',
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/typings/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ export interface Oas3Discriminator {
export interface Oas3MediaType<T extends Oas3Schema | Oas3_1Schema = Oas3Schema | Oas3_1Schema> {
schema?: Referenced<T>;
example?: unknown;
examples?: { [name: string]: Referenced<Oas3Example> };
encoding?: { [field: string]: Oas3Encoding<T> };
examples?: Record<string, Referenced<Oas3Example>>;
encoding?: Record<string, Oas3Encoding<T>>;
itemSchema?: Referenced<T>; // added in OAS 3.2
prefixEncoding?: Oas3Encoding<T>[]; // added in OAS 3.2
itemEncoding?: Referenced<Oas3Encoding<T>>; // added in OAS 3.2
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/typings/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export type Oas2Header = Oas2Items & { description?: 'string' };
export interface Oas2Response {
description?: string;
schema: Referenced<Schema>;
examples?: Record<string, any>;
examples?: Record<string, unknown>;
headers?: Record<string, Oas2Header>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/is-not-empty-array.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isNotEmptyArray<T>(args?: T[]): args is [T, ...T[]] {
return Array.isArray(args) && !!args.length;
return Array.isArray(args) && args.length > 0;
}
8 changes: 4 additions & 4 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const configExtension: { [key: string]: ViteUserConfig } = {
'packages/cli/src/utils/assert-node-version.ts',
],
thresholds: {
lines: 79,
functions: 82,
statements: 78,
branches: 70,
lines: 80,
functions: 83,
statements: 79,
branches: 71,
},
},
},
Expand Down
Loading