Skip to content

Conversation

alishah730
Copy link

@alishah730 alishah730 commented Oct 1, 2025

Add ApiService Export to Generated Index File

Fix issue #380

Summary

This pull request adds the ApiService class export to the main index file template, making it available for direct import from the generated API package root.

Problem Statement

Previously, the ApiService class was not exported from the main index file (index.ts), which meant developers had to import it from a specific nested path within the generated API package. This made the API less convenient to use and inconsistent with other core classes that were already being exported.

Solution

Added an export statement for the {{apiServiceClass}} in the templates/index.handlebars template file:

export { {{apiServiceClass}} } from './{{{apiServiceFile}}}';

This change ensures that when code is generated, the ApiService class will be available as a direct export from the package root, allowing for simpler imports like:

import { ApiService } from 'my-generated-api';

Instead of having to use nested imports like:

import { ApiService } from 'my-generated-api/services/api.service';

Changes Made

Core Changes

  • templates/index.handlebars: Added export line for {{apiServiceClass}} from {{apiServiceFile}}

Test Updates

  • test/all-types.spec.ts: Updated test to expect 6 exports instead of 5 in the generated index file
  • test/noModule.spec.ts: Updated test to expect 4 exports instead of 3 for the no-module scenario

Testing

✅ All existing tests pass successfully
✅ Build process completes without errors
✅ Linting passes
✅ No breaking changes to existing functionality

The changes are backward compatible and only add new functionality without modifying existing behavior.

Impact

  • Positive: Improves developer experience by making ApiService directly importable from package root
  • Risk: None - this is an additive change that doesn't modify existing exports
  • Breaking Changes: None

Generated Code Example

After this change, the generated index.ts file will include:

export { ApiConfiguration } from './api-configuration';
export { RequestBuilder } from './request-builder';
export { ApiService } from './api';  // ← NEW: This line is added
export { ApiModule } from './api.module';
export type { StrictHttpResponse } from './strict-http-response';
// ... other exports

This makes the API more intuitive and consistent with Angular conventions where service classes are typically exported from the main module index.

Added export apiService class so that import will available from index
@alishah730 alishah730 changed the title Add ApiService Export to Generated Index File : fix #380 Add ApiService Export to Generated Index File #380 Oct 1, 2025
@alishah730 alishah730 changed the title Add ApiService Export to Generated Index File #380 Add ApiService Export to Generated Index File Oct 1, 2025
@alishah730
Copy link
Author

Hi Team,
request your help and review on this PR

@luisfpg/Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant