Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"generate-api-with-core": {
"executor": "@nx-plugin-openapi/core:generate-api",
"options": {
"generator": "hey-openapi",
"generator": "hey-api",
"inputSpec": "apps/demo/swagger.json",
"outputPath": "apps/demo/src/app/api-core",
"generatorOptions": {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/plugin-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ describe('plugin-loader', () => {

it('should use built-in mapping for auto-installation', async () => {
const mockPlugin = {
name: 'hey-openapi',
name: 'hey-api',
generate: jest.fn(),
};

// The module mock will throw on first import, then succeed after "installation"
let isInstalled = false;
jest.doMock(
'@nx-plugin-openapi/plugin-hey-openapi',
'@nx-plugin-openapi/plugin-hey-api',
() => {
if (!isInstalled) {
const error = new Error('Cannot find module');
Expand All @@ -430,10 +430,10 @@ describe('plugin-loader', () => {
isInstalled = true;
});

const result = await loadPlugin('hey-openapi');
const result = await loadPlugin('hey-api');

expect(autoInstaller.installPackages).toHaveBeenCalledWith(
['@nx-plugin-openapi/plugin-hey-openapi'],
['@nx-plugin-openapi/plugin-hey-api'],
{ dev: true }
);
expect(result).toBe(mockPlugin);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isLocalDev } from './utils/is-local-dev';

const BUILTIN_PLUGIN_MAP: Record<string, string> = {
'openapi-tools': '@nx-plugin-openapi/plugin-openapi',
'hey-openapi': '@nx-plugin-openapi/plugin-hey-openapi',
'hey-api': '@nx-plugin-openapi/plugin-hey-api',
};

const cache = new Map<string, GeneratorPlugin>();
Expand Down Expand Up @@ -143,7 +143,7 @@ export async function loadPlugin(
if (
isLocal &&
(pkg === '@nx-plugin-openapi/plugin-openapi' ||
pkg === '@nx-plugin-openapi/plugin-hey-openapi')
pkg === '@nx-plugin-openapi/plugin-hey-api')
) {
const pkgName = pkg.split('/').pop() ?? '';
const fallbackPaths = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# plugin-hey-openapi
# plugin-hey-api

This library provides a generator plugin that uses `@hey-api/openapi-ts` to generate TypeScript clients from OpenAPI specs.

## Building

Run `nx build plugin-hey-openapi` to build the library.
Run `nx build plugin-hey-api` to build the library.

## Running unit tests

Run `nx test plugin-hey-openapi` to execute the unit tests via Jest.
Run `nx test plugin-hey-api` to execute the unit tests via Jest.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
displayName: 'plugin-hey-openapi',
displayName: 'plugin-hey-api',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/plugin-hey-openapi',
coverageDirectory: '../../coverage/packages/plugin-hey-api',
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@nx-plugin-openapi/plugin-hey-openapi",
"name": "@nx-plugin-openapi/plugin-hey-api",
"version": "0.0.1",
"dependencies": {
"@nx-plugin-openapi/core": "0.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plugin-hey-openapi",
"name": "plugin-hey-api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/plugin-hey-openapi/src",
"sourceRoot": "packages/plugin-hey-api/src",
"projectType": "library",
"release": {
"version": {
Expand All @@ -17,10 +17,10 @@
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/plugin-hey-openapi",
"main": "packages/plugin-hey-openapi/src/index.ts",
"tsConfig": "packages/plugin-hey-openapi/tsconfig.lib.json",
"assets": ["packages/plugin-hey-openapi/*.md"]
"outputPath": "dist/packages/plugin-hey-api",
"main": "packages/plugin-hey-api/src/index.ts",
"tsConfig": "packages/plugin-hey-api/tsconfig.lib.json",
"assets": ["packages/plugin-hey-api/*.md"]
}
},
"nx-release-publish": {
Expand All @@ -35,7 +35,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/plugin-hey-openapi/jest.config.ts"
"jestConfig": "packages/plugin-hey-api/jest.config.ts"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-hey-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as HeyApiPlugin } from './lib/hey-api-generator';
export { default } from './lib/hey-api-generator';
export { HeyApiGenerator } from './lib/hey-api-generator';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HeyOpenApiGenerator } from './hey-openapi-generator';
import { HeyApiGenerator } from './hey-api-generator';
import { GeneratorContext } from '@nx-plugin-openapi/core';

jest.mock(
Expand All @@ -9,14 +9,14 @@ jest.mock(
{ virtual: true }
);

describe('HeyOpenApiGenerator', () => {
let generator: HeyOpenApiGenerator;
describe('HeyApiGenerator', () => {
let generator: HeyApiGenerator;
let mockContext: GeneratorContext;
let cleanOutputSpy: jest.SpyInstance;

beforeEach(() => {
jest.clearAllMocks();
generator = new HeyOpenApiGenerator();
generator = new HeyApiGenerator();
mockContext = { root: '/workspace', workspaceName: 'test' };
// Spy on cleanOutput inherited from BaseGenerator
cleanOutputSpy = jest
Expand All @@ -28,7 +28,7 @@ describe('HeyOpenApiGenerator', () => {
});

it('should have correct plugin name', () => {
expect(generator.name).toBe('hey-openapi');
expect(generator.name).toBe('hey-api');
});

it('should call openapi-ts generate for single spec', async () => {
Expand All @@ -41,7 +41,7 @@ describe('HeyOpenApiGenerator', () => {
inputSpec: 'api.yaml',
outputPath: 'src/generated',
generatorOptions: { client: 'fetch' },
} as unknown as Parameters<HeyOpenApiGenerator['generate']>[0],
} as unknown as Parameters<HeyApiGenerator['generate']>[0],
mockContext
);

Expand All @@ -64,7 +64,7 @@ describe('HeyOpenApiGenerator', () => {
{
inputSpec: { users: 'users.yaml', products: 'products.yaml' },
outputPath: 'src/api',
} as unknown as Parameters<HeyOpenApiGenerator['generate']>[0],
} as unknown as Parameters<HeyApiGenerator['generate']>[0],
mockContext
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import {
GenerateOptionsBase,
} from '@nx-plugin-openapi/core';

export interface HeyOpenApiOptions {
export interface HeyApiOptions {
[key: string]: unknown;
}

export class HeyOpenApiGenerator
export class HeyApiGenerator
extends BaseGenerator
implements GeneratorPlugin<HeyOpenApiOptions>
implements GeneratorPlugin<HeyApiOptions>
{
readonly name = 'hey-openapi';
readonly name = 'hey-api';

async generate(
options: HeyOpenApiOptions & GenerateOptionsBase,
options: HeyApiOptions & GenerateOptionsBase,
ctx: GeneratorContext
): Promise<void> {
const { inputSpec, outputPath } = options;
const generatorOptions = (options.generatorOptions ||
{}) as Partial<HeyOpenApiOptions>;
{}) as Partial<HeyApiOptions>;

logger.info(`Starting hey-openapi code generation`);
logger.info(`Starting hey-api code generation`);
logger.debug(`Input spec: ${JSON.stringify(inputSpec)}`);
logger.debug(`Output path: ${outputPath}`);

Expand Down Expand Up @@ -56,7 +56,7 @@ export class HeyOpenApiGenerator
}
}

logger.info(`hey-openapi code generation completed successfully`);
logger.info(`hey-api code generation completed successfully`);
}

private async invokeOpenApiTs(
Expand Down Expand Up @@ -97,4 +97,4 @@ export class HeyOpenApiGenerator
}
}

export default new HeyOpenApiGenerator();
export default new HeyApiGenerator();
3 changes: 0 additions & 3 deletions packages/plugin-hey-openapi/src/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"@nx-plugin-openapi/core": ["packages/core/src/index.ts"],
"@nx-plugin-openapi/plugin-openapi": [
"packages/plugin-openapi/src/index.ts"
],
"@nx-plugin-openapi/plugin-hey-api": [
"packages/plugin-hey-api/src/index.ts"
]
}
},
Expand Down