@@ -67,7 +67,7 @@ describe('openapi-client generator', () => {
67
67
let tempSpecPath: string;
68
68
69
69
const options = {
70
- client: 'fetch' as const ,
70
+ client: '@hey-api/client- fetch',
71
71
directory: './libs',
72
72
name: 'test-api',
73
73
plugins: [],
@@ -122,10 +122,11 @@ paths:
122
122
const normalized = normalizeOptions(options);
123
123
124
124
expect(normalized).toEqual({
125
- clientType: 'fetch',
126
- projectDirectory: 'test-api',
125
+ clientType: '@hey-api/client-fetch',
126
+ plugins: [],
127
+ projectDirectory: 'libs',
127
128
projectName: 'test-api',
128
- projectRoot: 'test-api',
129
+ projectRoot: 'libs/ test-api',
129
130
projectScope: '@test-api',
130
131
specFile: tempSpecPath,
131
132
tagArray: ['api', 'openapi'],
@@ -142,8 +143,9 @@ paths:
142
143
const normalized = normalizeOptions(customOptions);
143
144
144
145
expect(normalized).toEqual({
145
- clientType: 'fetch',
146
- projectDirectory: 'custom-dir/test-api',
146
+ clientType: '@hey-api/client-fetch',
147
+ plugins: [],
148
+ projectDirectory: 'custom-dir',
147
149
projectName: 'test-api',
148
150
projectRoot: 'custom-dir/test-api',
149
151
projectScope: '@test-api',
@@ -157,7 +159,7 @@ paths:
157
159
it('should generate project configuration', () => {
158
160
const normalizedOptions = normalizeOptions(options);
159
161
160
- generateNxProject({ normalizedOptions, tree });
162
+ generateNxProject({ clientPlugins: {}, normalizedOptions, tree });
161
163
162
164
const config = readJson(
163
165
tree,
@@ -166,14 +168,13 @@ paths:
166
168
expect(config).toBeDefined();
167
169
expect(config.projectType).toBe('library');
168
170
expect(config.targets.build).toBeDefined();
169
- expect(config.targets.lint).toBeDefined();
170
171
expect(config.targets.generateApi).toBeDefined();
171
172
});
172
173
173
174
it('should generate project files', () => {
174
175
const normalizedOptions = normalizeOptions(options);
175
176
176
- generateNxProject({ normalizedOptions, tree });
177
+ generateNxProject({ clientPlugins: {}, normalizedOptions, tree });
177
178
178
179
expect(
179
180
tree.exists(`${normalizedOptions.projectRoot}/tsconfig.json`),
@@ -223,67 +224,137 @@ paths:
223
224
});
224
225
225
226
describe('updatePackageJson', () => {
226
- it('should update package.json with correct dependencies', () => {
227
+ it('should update package.json with correct dependencies', async () => {
227
228
const normalizedOptions = normalizeOptions(options);
228
- const { clientType, projectName, projectRoot, projectScope } =
229
- normalizedOptions;
229
+ const { projectName, projectRoot, projectScope } = normalizedOptions;
230
230
231
231
// Create initial package.json
232
232
tree.write(
233
233
`${projectRoot}/package.json`,
234
234
JSON.stringify({
235
235
dependencies: {},
236
236
devDependencies: {},
237
- name: projectName,
237
+ name: `${projectScope}/${ projectName}` ,
238
238
}),
239
239
);
240
240
241
- updatePackageJson({
242
- clientType,
241
+ // Create tsconfig.base.json
242
+ tree.write(
243
+ 'tsconfig.base.json',
244
+ JSON.stringify({
245
+ compilerOptions: {
246
+ paths: {},
247
+ },
248
+ }),
249
+ );
250
+
251
+ await updatePackageJson({
252
+ clientPlugins: {},
253
+ clientType: '@hey-api/client-fetch',
243
254
projectName,
244
255
projectRoot,
245
256
projectScope,
246
257
tree,
247
258
});
248
259
260
+ // Verify tsconfig.base.json was updated
261
+ const tsconfig = readJson(tree, 'tsconfig.base.json');
262
+ expect(
263
+ tsconfig.compilerOptions.paths[`${projectScope}/${projectName}`],
264
+ ).toBeDefined();
265
+
249
266
const packageJson = readJson(tree, `${projectRoot}/package.json`);
250
- expect(packageJson.dependencies['@hey-api/client-fetch']).toBe('^0.9.0');
251
- expect(packageJson.devDependencies['@hey-api/openapi-ts']).toBe(
252
- '^0.66.0',
267
+ expect(packageJson.dependencies['@hey-api/client-fetch']).toBeDefined();
268
+ });
269
+
270
+ it('should update package.json with correct dependencies', async () => {
271
+ const normalizedOptions = normalizeOptions(options);
272
+ const { projectName, projectRoot, projectScope } = normalizedOptions;
273
+
274
+ // Create initial package.json
275
+ tree.write(
276
+ `${projectRoot}/package.json`,
277
+ JSON.stringify({
278
+ dependencies: {},
279
+ devDependencies: {},
280
+ name: `${projectScope}/${projectName}`,
281
+ }),
282
+ );
283
+
284
+ // Create tsconfig.base.json
285
+ tree.write(
286
+ 'tsconfig.base.json',
287
+ JSON.stringify({
288
+ compilerOptions: {
289
+ paths: {},
290
+ },
291
+ }),
253
292
);
293
+
294
+ await updatePackageJson({
295
+ clientPlugins: {
296
+ '@tanstack/react-query': {
297
+ tsConfigCompilerPaths: {
298
+ 'my-test-path': './src/index.ts',
299
+ },
300
+ },
301
+ },
302
+ clientType: '@hey-api/client-fetch',
303
+ projectName,
304
+ projectRoot,
305
+ projectScope,
306
+ tree,
307
+ });
308
+
309
+ // Verify tsconfig.base.json was updated
310
+ const tsconfig = readJson(tree, 'tsconfig.base.json');
311
+ expect(
312
+ tsconfig.compilerOptions.paths[`${projectScope}/${projectName}`],
313
+ ).toBeDefined();
314
+ expect(tsconfig.compilerOptions.paths['my-test-path']).toBeDefined();
254
315
});
255
316
256
- it('should update package.json with axios dependencies when clientType is axios', () => {
257
- const axiosOptions = {
258
- ...options,
259
- client: 'axios' as const,
260
- } satisfies OpenApiClientGeneratorSchema;
261
- const normalizedOptions = normalizeOptions(axiosOptions);
262
- const { clientType, projectName, projectRoot, projectScope } =
263
- normalizedOptions;
317
+ it('should update package.json with axios dependencies when clientType is axios', async () => {
318
+ const normalizedOptions = normalizeOptions(options);
319
+ const { projectName, projectRoot, projectScope } = normalizedOptions;
264
320
265
321
// Create initial package.json
266
322
tree.write(
267
323
`${projectRoot}/package.json`,
268
324
JSON.stringify({
269
325
dependencies: {},
270
326
devDependencies: {},
271
- name: projectName,
327
+ name: `${projectScope}/${projectName}`,
328
+ }),
329
+ );
330
+
331
+ // Create tsconfig.base.json
332
+ tree.write(
333
+ 'tsconfig.base.json',
334
+ JSON.stringify({
335
+ compilerOptions: {
336
+ paths: {},
337
+ },
272
338
}),
273
339
);
274
340
275
- updatePackageJson({
276
- clientType,
341
+ await updatePackageJson({
342
+ clientPlugins: {},
343
+ clientType: '@hey-api/client-axios',
277
344
projectName,
278
345
projectRoot,
279
346
projectScope,
280
347
tree,
281
348
});
282
349
350
+ // Verify tsconfig.base.json was updated
351
+ const tsconfig = readJson(tree, 'tsconfig.base.json');
352
+ expect(
353
+ tsconfig.compilerOptions.paths[`${projectScope}/${projectName}`],
354
+ ).toBeDefined();
355
+
283
356
const packageJson = readJson(tree, `${projectRoot}/package.json`);
284
- expect(packageJson.dependencies['@hey-api/client-axios']).toBeTruthy();
285
- expect(packageJson.dependencies['axios']).toBeTruthy();
286
- expect(packageJson.devDependencies['@hey-api/openapi-ts']).toBeTruthy();
357
+ expect(packageJson.dependencies.axios).toBeDefined();
287
358
});
288
359
});
289
360
0 commit comments