Skip to content

Commit 7244ff0

Browse files
committed
chore: apply review suggestions
1 parent ddd8adb commit 7244ff0

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

packages/core/src/__tests__/entity-yaml.test.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { describe, it, expect } from 'vitest';
22
import { createEntityTypes } from '../types/entity-yaml.js';
3-
import { normalizeTypes } from '../types/index.js';
3+
import { normalizeTypes, ResolveTypeFn } from '../types/index.js';
44
import { entityFileSchema, entityFileDefaultSchema } from '@redocly/config';
5-
65
describe('entity-yaml', () => {
76
it('should create entity types with discriminator', () => {
87
const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
@@ -18,36 +17,39 @@ describe('entity-yaml', () => {
1817
expect(entityTypes).toHaveProperty('EntityFileArray');
1918
});
2019

21-
it('should resolve entity type based on discriminator for array items', () => {
20+
it('should resolve entity type to default for array items', () => {
2221
const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
2322
const normalizedTypes = normalizeTypes(entityTypes);
2423

2524
const entityFileArrayNode = normalizedTypes['EntityFileArray'];
26-
if (typeof entityFileArrayNode.items === 'function') {
27-
const userEntity = {
28-
type: 'user',
29-
key: 'john-doe',
30-
title: 'John Doe',
31-
metadata: { email: 'john@example.com' },
32-
};
33-
const resolvedType = entityFileArrayNode.items(userEntity, 'root');
3425

35-
expect(resolvedType).toBeTruthy();
36-
if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
37-
expect(resolvedType.name).toBe('user');
38-
if ('properties' in resolvedType) {
39-
expect(resolvedType.properties).toHaveProperty('metadata');
40-
}
41-
}
26+
const unknownEntity = { key: 'unknown', title: 'Unknown' };
27+
const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(unknownEntity, 'root');
28+
29+
expect(resolvedType).toBeTruthy();
30+
if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
31+
expect(resolvedType.name).toBe('EntityFileDefault');
4232
}
33+
});
4334

44-
if (typeof entityFileArrayNode.items === 'function') {
45-
const unknownEntity = { key: 'unknown', title: 'Unknown' };
46-
const resolvedType = entityFileArrayNode.items(unknownEntity, 'root');
35+
it('should resolve entity type based on discriminator for array items', () => {
36+
const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
37+
const normalizedTypes = normalizeTypes(entityTypes);
38+
39+
const entityFileArrayNode = normalizedTypes['EntityFileArray'];
40+
const userEntity = {
41+
type: 'user',
42+
key: 'john-doe',
43+
title: 'John Doe',
44+
metadata: { email: 'john@example.com' },
45+
};
46+
const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(userEntity, 'root');
4747

48-
expect(resolvedType).toBeTruthy();
49-
if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
50-
expect(resolvedType.name).toBe('EntityFileDefault');
48+
expect(resolvedType).toBeTruthy();
49+
if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
50+
expect(resolvedType.name).toBe('user');
51+
if ('properties' in resolvedType) {
52+
expect(resolvedType.properties).toHaveProperty('metadata');
5153
}
5254
}
5355
});

packages/core/src/lint.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ export async function lintEntityFile(opts: {
232232
if (Array.isArray(config.document.parsed)) {
233233
rootType = types.EntityFileArray;
234234
} else if (isPlainObject(config.document.parsed)) {
235-
const typeValue = (config.document.parsed as Record<string, unknown>)[
236-
ENTITY_DISCRIMINATOR_NAME
237-
];
235+
const typeValue = config.document.parsed[ENTITY_DISCRIMINATOR_NAME];
238236
if (typeof typeValue === 'string' && types[typeValue]) {
239237
rootType = types[typeValue];
240238
}

0 commit comments

Comments
 (0)