Skip to content

Commit 2c7e780

Browse files
fix: update types to the methods
1 parent 990df4e commit 2c7e780

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

packages/elements-core/src/utils/exampleGeneration/exampleGeneration.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isPlainObject, safeStringify } from '@stoplight/json';
22
import * as Sampler from '@stoplight/json-schema-sampler';
33
import { IMediaTypeContent, INodeExample, INodeExternalExample } from '@stoplight/types';
4-
import { JSONSchema7 } from 'json-schema';
4+
import { JSONSchema7, JSONSchema7Object, JSONSchema7Type } from 'json-schema';
55
import React from 'react';
66

77
import { useDocument } from '../../context/InlineRefResolver';
@@ -60,7 +60,7 @@ export const generateExampleFromMediaTypeContent = (
6060
return '';
6161
};
6262

63-
export const generateExamplesFromJsonSchema = (schema: JSONSchema7 & { 'x-examples'?: unknown }): Example[] => {
63+
export const generateExamplesFromJsonSchema = (schema: JSONSchema7 & { 'x-examples'?: JSONSchema7Type }): Example[] => {
6464
const examples: Example[] = [];
6565
const hasResolvedProperties = (schemaToCheck: JSONSchema7): boolean => {
6666
// Case 1: Direct object with properties
@@ -152,9 +152,9 @@ export const exceedsSize = (example: string, size: number = 500) => {
152152
* @returns New array of filtered objects matching the schema structure
153153
*/
154154
export const filterExamplesBySchema = (
155-
schema: JSONSchema7 & { 'x-examples'?: unknown },
156-
examples: unknown[],
157-
): unknown[] => {
155+
schema: JSONSchema7 & { 'x-examples'?: JSONSchema7Type },
156+
examples: JSONSchema7Type[],
157+
): JSONSchema7Type[] => {
158158
return examples.map(example => {
159159
try {
160160
return filterValueBySchema(example, schema);
@@ -212,7 +212,7 @@ const findPropertySchema = (schema: JSONSchema7, propertyName: string): JSONSche
212212
return undefined;
213213
};
214214

215-
const filterValueBySchema = (value: unknown, schema: JSONSchema7): unknown => {
215+
const filterValueBySchema = (value: JSONSchema7Type, schema: JSONSchema7): JSONSchema7Type => {
216216
if (value === null || value === undefined) return value;
217217

218218
// Handle arrays
@@ -231,14 +231,14 @@ const filterValueBySchema = (value: unknown, schema: JSONSchema7): unknown => {
231231
const hasStructure = allowedKeys.size > 0;
232232
const hasAdditionalProperties = schema.additionalProperties;
233233

234-
if (!hasStructure && !hasAdditionalProperties) return value;
234+
if (!hasStructure && !hasAdditionalProperties) return value as JSONSchema7Object;
235235

236-
const result: Record<string, unknown> = {};
236+
const result: JSONSchema7Object = {};
237237

238-
for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
238+
for (const [key, val] of Object.entries(value as JSONSchema7Object)) {
239239
if (allowedKeys.has(key)) {
240240
const propSchema = findPropertySchema(schema, key);
241-
result[key] = propSchema ? filterValueBySchema(val, propSchema) : val;
241+
result[key] = propSchema ? filterValueBySchema(val as JSONSchema7Type, propSchema) : val;
242242
} else if (hasAdditionalProperties) {
243243
result[key] = val;
244244
}

0 commit comments

Comments
 (0)