Skip to content

Commit 1817ef1

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

File tree

2 files changed

+82
-86
lines changed

2 files changed

+82
-86
lines changed
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from 'vitest';
22
import { createEntityTypes } from '../types/entity-yaml.js';
3-
import { normalizeTypes, ResolveTypeFn } from '../types/index.js';
3+
import { NormalizedNodeType, normalizeTypes, ResolveTypeFn } from '../types/index.js';
44
import { entityFileSchema, entityFileDefaultSchema } from '@redocly/config';
55
describe('entity-yaml', () => {
66
it('should create entity types with discriminator', () => {
@@ -24,12 +24,13 @@ describe('entity-yaml', () => {
2424
const entityFileArrayNode = normalizedTypes['EntityFileArray'];
2525

2626
const unknownEntity = { key: 'unknown', title: 'Unknown' };
27-
const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(unknownEntity, 'root');
27+
const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(
28+
unknownEntity,
29+
'root'
30+
) as NormalizedNodeType;
2831

2932
expect(resolvedType).toBeTruthy();
30-
if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
31-
expect(resolvedType.name).toBe('EntityFileDefault');
32-
}
33+
expect(resolvedType.name).toBe('EntityFileDefault');
3334
});
3435

3536
it('should resolve entity type based on discriminator for array items', () => {
@@ -43,33 +44,28 @@ describe('entity-yaml', () => {
4344
title: 'John Doe',
4445
metadata: { email: '[email protected]' },
4546
};
46-
const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(userEntity, 'root');
47+
const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(
48+
userEntity,
49+
'root'
50+
) as NormalizedNodeType;
4751

4852
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');
53-
}
54-
}
53+
expect(resolvedType.name).toBe('user');
54+
expect(resolvedType.properties).toHaveProperty('metadata');
5555
});
5656

5757
it('should have correct required fields for entity types', () => {
5858
const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
5959
const normalizedTypes = normalizeTypes(entityTypes);
6060

6161
const userNode = normalizedTypes['user'];
62-
if (userNode && Array.isArray(userNode.required)) {
63-
expect(userNode.required).toContain('key');
64-
expect(userNode.required).toContain('title');
65-
expect(userNode.required).toContain('type');
66-
}
62+
expect(userNode.required).toContain('key');
63+
expect(userNode.required).toContain('title');
64+
expect(userNode.required).toContain('type');
6765

6866
const defaultNode = normalizedTypes['EntityFileDefault'];
69-
if (defaultNode && Array.isArray(defaultNode.required)) {
70-
expect(defaultNode.required).toContain('type');
71-
expect(defaultNode.required).toContain('key');
72-
expect(defaultNode.required).toContain('title');
73-
}
67+
expect(defaultNode.required).toContain('type');
68+
expect(defaultNode.required).toContain('key');
69+
expect(defaultNode.required).toContain('title');
7470
});
7571
});

packages/core/src/__tests__/lint.test.ts

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,25 +2015,25 @@ describe('lint', () => {
20152015
});
20162016

20172017
it('should lint array of entities', async () => {
2018-
const entitiesYaml = `
2019-
- type: user
2020-
key: john-doe
2021-
title: John Doe
2022-
metadata:
2023-
2024-
2025-
- type: service
2026-
key: api-service
2027-
title: API Service
2028-
summary: Core API service
2029-
2030-
- type: api-description
2031-
key: users-api
2032-
title: Users API
2033-
metadata:
2034-
specType: openapi
2035-
descriptionFile: users-api.yaml
2036-
`;
2018+
const entitiesYaml = outdent`
2019+
- type: user
2020+
key: john-doe
2021+
title: John Doe
2022+
metadata:
2023+
2024+
2025+
- type: service
2026+
key: api-service
2027+
title: API Service
2028+
summary: Core API service
2029+
2030+
- type: api-description
2031+
key: users-api
2032+
title: Users API
2033+
metadata:
2034+
specType: openapi
2035+
descriptionFile: users-api.yaml
2036+
`;
20372037

20382038
const document = makeDocumentFromString(entitiesYaml, '/entities.yaml');
20392039

@@ -2220,13 +2220,13 @@ describe('lint', () => {
22202220
});
22212221

22222222
it('should validate type-specific metadata fields correctly', async () => {
2223-
const apiOperationYaml = `
2224-
type: api-operation
2225-
key: test-operation
2226-
title: Test Operation
2227-
metadata:
2228-
wrongField: value
2229-
`;
2223+
const apiOperationYaml = outdent`
2224+
type: api-operation
2225+
key: test-operation
2226+
title: Test Operation
2227+
metadata:
2228+
wrongField: value
2229+
`;
22302230

22312231
const document = makeDocumentFromString(apiOperationYaml, '/entity.yaml');
22322232

@@ -2247,28 +2247,28 @@ describe('lint', () => {
22472247
});
22482248

22492249
it('should validate different metadata schemas in array of mixed entity types', async () => {
2250-
const mixedEntitiesYaml = `
2251-
- type: api-description
2252-
key: my-api
2253-
title: My API
2254-
metadata:
2255-
specType: openapi
2256-
# Missing descriptionFile
2257-
2258-
- type: api-operation
2259-
key: my-operation
2260-
title: My Operation
2261-
metadata:
2262-
wrongField: value
2263-
# Missing method and path
2264-
2265-
- type: data-schema
2266-
key: my-schema
2267-
title: My Schema
2268-
metadata:
2269-
wrongField: value
2270-
# Missing specType
2271-
`;
2250+
const mixedEntitiesYaml = outdent`
2251+
- type: api-description
2252+
key: my-api
2253+
title: My API
2254+
metadata:
2255+
specType: openapi
2256+
# Missing descriptionFile
2257+
2258+
- type: api-operation
2259+
key: my-operation
2260+
title: My Operation
2261+
metadata:
2262+
wrongField: value
2263+
# Missing method and path
2264+
2265+
- type: data-schema
2266+
key: my-schema
2267+
title: My Schema
2268+
metadata:
2269+
wrongField: value
2270+
# Missing specType
2271+
`;
22722272

22732273
const document = makeDocumentFromString(mixedEntitiesYaml, '/entities.yaml');
22742274

@@ -2298,22 +2298,22 @@ describe('lint', () => {
22982298
});
22992299

23002300
it('should handle entity without type in array using default schema', async () => {
2301-
const mixedEntitiesYaml = `
2302-
- type: user
2303-
key: valid-user
2304-
title: Valid User
2305-
metadata:
2306-
2307-
2308-
- key: no-type-entity
2309-
title: Entity Without Type
2310-
summary: This entity is missing the type field
2311-
# Missing type - should use EntityFileDefault schema
2312-
2313-
- type: service
2314-
key: valid-service
2315-
title: Valid Service
2316-
`;
2301+
const mixedEntitiesYaml = outdent`
2302+
- type: user
2303+
key: valid-user
2304+
title: Valid User
2305+
metadata:
2306+
2307+
2308+
- key: no-type-entity
2309+
title: Entity Without Type
2310+
summary: This entity is missing the type field
2311+
# Missing type - should use EntityFileDefault schema
2312+
2313+
- type: service
2314+
key: valid-service
2315+
title: Valid Service
2316+
`;
23172317

23182318
const document = makeDocumentFromString(mixedEntitiesYaml, '/entities.yaml');
23192319

0 commit comments

Comments
 (0)