Skip to content

Commit c8ce059

Browse files
committed
chore: export config constants and refactor exports
1 parent 049cbdd commit c8ce059

File tree

5 files changed

+68
-84
lines changed

5 files changed

+68
-84
lines changed

packages/cli/src/__tests__/commands/bundle.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
bundle,
33
getTotals,
44
logger,
5-
Config,
5+
createConfig,
66
type ResolvedApiConfig,
77
type ResolvedConfig,
88
} from '@redocly/openapi-core';
@@ -160,7 +160,7 @@ describe('bundle', () => {
160160
} as ResolvedApiConfig,
161161
},
162162
};
163-
const config = new Config(resolvedConfigMock);
163+
const config = await createConfig(resolvedConfigMock);
164164

165165
vi.mocked(getFallbackApisOrExit).mockResolvedValueOnce(
166166
Object.entries(resolvedConfigMock.apis!).map(([alias, { root, ...api }]) => ({
@@ -198,7 +198,7 @@ describe('bundle', () => {
198198
} as ResolvedApiConfig,
199199
},
200200
};
201-
const config = new Config(resolvedConfigMock);
201+
const config = await createConfig(resolvedConfigMock);
202202

203203
vi.mocked(getFallbackApisOrExit).mockResolvedValueOnce(
204204
Object.entries(resolvedConfigMock.apis!).map(([alias, { root, ...api }]) => ({
@@ -233,7 +233,7 @@ describe('bundle', () => {
233233
} as ResolvedApiConfig,
234234
},
235235
};
236-
const config = new Config(resolvedConfigMock);
236+
const config = await createConfig(resolvedConfigMock);
237237

238238
vi.mocked(getFallbackApisOrExit).mockResolvedValueOnce([{ path: 'openapi.yaml' }]);
239239
vi.mocked(getTotals).mockReturnValue({
@@ -266,7 +266,7 @@ describe('bundle', () => {
266266
},
267267
};
268268

269-
const config = new Config(resolvedConfigMock);
269+
const config = await createConfig(resolvedConfigMock);
270270

271271
vi.mocked(getFallbackApisOrExit).mockResolvedValueOnce(
272272
Object.entries(resolvedConfigMock.apis!).map(([alias, { root, ...api }]) => ({

packages/cli/src/__tests__/commands/generate-arazzo.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { GenerateArazzoCommandArgv, handleGenerateArazzo } from '../../commands/generate-arazzo.js';
22
import { generate } from '@redocly/respect-core';
33
import { vi, describe, it, expect, beforeEach } from 'vitest';
4-
import { Config } from '@redocly/openapi-core';
4+
import * as openapiCore from '@redocly/openapi-core';
55

66
vi.mock('@redocly/respect-core', async () => {
77
const actual = await vi.importActual<typeof import('@redocly/respect-core')>(
@@ -13,14 +13,6 @@ vi.mock('@redocly/respect-core', async () => {
1313
};
1414
});
1515

16-
vi.mock('node:fs', async () => {
17-
return {
18-
writeFileSync: vi.fn(),
19-
existsSync: vi.fn(() => true),
20-
readFileSync: vi.fn(() => ''),
21-
};
22-
});
23-
2416
vi.mock('@redocly/openapi-core', async () => {
2517
const actual = await vi.importActual('@redocly/openapi-core');
2618
return {
@@ -39,7 +31,7 @@ describe('handleGenerateArazzo', () => {
3931
});
4032

4133
it('should call generate with the correct arguments', async () => {
42-
const mockConfig = new Config({});
34+
const mockConfig = await openapiCore.createConfig({});
4335
const commandArgs = {
4436
argv: {
4537
descriptionPath: 'openapi.yaml',
@@ -61,7 +53,7 @@ describe('handleGenerateArazzo', () => {
6153
});
6254

6355
it('should use custom output file when provided', async () => {
64-
const mockConfig = new Config({});
56+
const mockConfig = await openapiCore.createConfig({});
6557
const commandArgs = {
6658
argv: {
6759
descriptionPath: 'openapi.yaml',
@@ -84,7 +76,7 @@ describe('handleGenerateArazzo', () => {
8476
});
8577

8678
it('should throw an error if the openapi file is not valid', async () => {
87-
const mockConfig = new Config({});
79+
const mockConfig = await openapiCore.createConfig({});
8880
const commandArgs = {
8981
argv: {
9082
descriptionPath: 'openapi.yaml',

packages/cli/src/__tests__/commands/respect/respect.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { handleRespect, type RespectArgv } from '../../../commands/respect/index.js';
22
import { run } from '@redocly/respect-core';
3-
import { Config } from '@redocly/openapi-core';
3+
import * as openapiCore from '@redocly/openapi-core';
44

55
// Mock node:fs
66
vi.mock('node:fs', async () => {
@@ -52,7 +52,7 @@ describe('handleRespect', () => {
5252
vi.clearAllMocks();
5353
});
5454
it('should call run with the correct arguments', async () => {
55-
const mockConfig = new Config({});
55+
const mockConfig = await openapiCore.createConfig({});
5656
const commandArgs = {
5757
argv: {
5858
files: ['test.arazzo.yaml'],

packages/core/src/config/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ export * from './builtIn.js';
55
export * from './load.js';
66
export * from './utils.js';
77
export * from './config-resolvers.js';
8-
export * from './constants.js';

packages/core/src/index.ts

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export {
2-
type CollectFn,
3-
type Exact,
42
keysOf,
53
readFileFromUrl,
64
slash,
@@ -13,6 +11,8 @@ export {
1311
isEmptyObject,
1412
isNotEmptyArray,
1513
isNotEmptyObject,
14+
type CollectFn,
15+
type Exact,
1616
} from './utils.js';
1717
export { dequal } from './utils/dequal.js';
1818
export { Oas3_1Types } from './types/oas3_1.js';
@@ -22,75 +22,33 @@ export { Oas2Types } from './types/oas2.js';
2222
export { AsyncApi2Types } from './types/asyncapi2.js';
2323
export { AsyncApi3Types } from './types/asyncapi3.js';
2424
export { ConfigTypes, createConfigTypes } from './types/redocly-yaml.js';
25-
26-
export type {
27-
Oas3Definition,
28-
Oas3_1Definition,
29-
Oas3Components,
30-
Oas3_1Components,
31-
Oas3PathItem,
32-
Oas3Paths,
33-
Oas3ComponentName,
34-
Oas3Schema,
35-
Oas3_1Schema,
36-
Oas3Tag,
37-
Referenced,
38-
OasRef,
39-
Oas3Parameter,
40-
Oas3Server,
41-
Oas3Operation,
42-
Oas3Responses,
43-
ApiKeyAuth,
44-
HttpAuth,
45-
BasicAuth,
46-
BearerAuth,
47-
DigestAuth,
48-
MutualTLSAuth,
49-
OAuth2Auth,
50-
OpenIDAuth,
51-
Oas3SecurityScheme,
52-
Oas3SecurityRequirement,
53-
} from './typings/openapi.js';
54-
export type { Oas2Definition } from './typings/swagger.js';
55-
export type { Async3Definition } from './typings/asyncapi3.js';
56-
export type { Async2Definition } from './typings/asyncapi.js';
57-
export type {
58-
ArazzoDefinition,
59-
ExtendedOperation,
60-
ExtendedSecurity,
61-
ResolvedSecurity,
62-
} from './typings/arazzo.js';
63-
export type { StatsAccumulator, StatsName } from './typings/common.js';
64-
export { type NormalizedNodeType, type NodeType, normalizeTypes } from './types/index.js';
25+
export { normalizeTypes, type NormalizedNodeType, type NodeType } from './types/index.js';
6526
export { Stats } from './rules/other/stats.js';
66-
6727
export {
28+
loadConfig,
29+
createConfig,
30+
findConfig,
31+
resolvePlugins,
32+
ConfigValidationError,
33+
Config, // FIXME: export it as a type
6834
type RawUniversalConfig,
6935
type RawUniversalApiConfig,
7036
type ResolvedConfig,
7137
type ResolvedApiConfig,
7238
type Plugin,
7339
type RuleConfig,
74-
Config, // FIXME: export it as a type
75-
IGNORE_FILE,
76-
loadConfig,
77-
findConfig,
78-
CONFIG_FILE_NAME,
7940
type RuleSeverity,
80-
createConfig,
81-
ConfigValidationError,
82-
resolvePlugins,
8341
} from './config/index.js';
84-
42+
export * from './config/constants.js';
8543
export {
86-
type ResolvedRefMap,
8744
Source,
8845
BaseResolver,
8946
Document,
90-
resolveDocument,
9147
ResolveError,
9248
YamlParseError,
49+
resolveDocument,
9350
makeDocumentFromString,
51+
type ResolvedRefMap,
9452
} from './resolve.js';
9553
export { parseYaml, stringifyYaml } from './js-yaml/index.js';
9654
export {
@@ -101,11 +59,11 @@ export {
10159
type Location,
10260
} from './ref-utils.js';
10361
export {
104-
type SpecMajorVersion,
105-
getMajorSpecVersion,
106-
type SpecVersion,
10762
detectSpec,
63+
getMajorSpecVersion,
10864
getTypes,
65+
type SpecVersion,
66+
type SpecMajorVersion,
10967
} from './oas-types.js';
11068
export {
11169
normalizeVisitors,
@@ -134,31 +92,66 @@ export {
13492
type Arazzo1Preprocessor,
13593
type Overlay1Preprocessor,
13694
} from './visitors.js';
137-
13895
export {
13996
WalkContext,
140-
walkDocument,
14197
NormalizedProblem,
14298
ProblemSeverity,
14399
LineColLocationObject,
144100
LocationObject,
145101
Loc,
102+
walkDocument,
146103
type UserContext,
147104
} from './walk.js';
148-
149105
export { getAstNodeByPointer, getLineColLocation, getCodeframe } from './format/codeframes.js';
150-
export { formatProblems, OutputFormat, getTotals, Totals } from './format/format.js';
106+
export { formatProblems, getTotals, type OutputFormat, type Totals } from './format/format.js';
151107
export { lint, lint as validate, lintDocument, lintFromString, lintConfig } from './lint.js';
152108
export {
153-
type BundleResult,
154109
bundle,
155110
bundleDocument,
156111
mapTypeToComponent,
157112
bundleFromString,
113+
type BundleResult,
158114
} from './bundle.js';
159-
160115
export { type Assertions, type Assertion } from './rules/common/assertions/index.js';
161-
162116
export { logger, type LoggerInterface } from './logger.js';
163117
export { HandledError } from './utils/error.js';
164118
export { isBrowser } from './env.js';
119+
120+
export type {
121+
Oas3Definition,
122+
Oas3_1Definition,
123+
Oas3Components,
124+
Oas3_1Components,
125+
Oas3PathItem,
126+
Oas3Paths,
127+
Oas3ComponentName,
128+
Oas3Schema,
129+
Oas3_1Schema,
130+
Oas3Tag,
131+
Referenced,
132+
OasRef,
133+
Oas3Parameter,
134+
Oas3Server,
135+
Oas3Operation,
136+
Oas3Responses,
137+
ApiKeyAuth,
138+
HttpAuth,
139+
BasicAuth,
140+
BearerAuth,
141+
DigestAuth,
142+
MutualTLSAuth,
143+
OAuth2Auth,
144+
OpenIDAuth,
145+
Oas3SecurityScheme,
146+
Oas3SecurityRequirement,
147+
} from './typings/openapi.js';
148+
export type { Oas2Definition } from './typings/swagger.js';
149+
export type { Async3Definition } from './typings/asyncapi3.js';
150+
export type { Async2Definition } from './typings/asyncapi.js';
151+
export type {
152+
ArazzoDefinition,
153+
ExtendedOperation,
154+
ExtendedSecurity,
155+
ResolvedSecurity,
156+
} from './typings/arazzo.js';
157+
export type { StatsAccumulator, StatsName } from './typings/common.js';

0 commit comments

Comments
 (0)