Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@raphael
Copy link
Member

@raphael raphael commented Jun 7, 2025

refactor(codegen): eliminate global dependencies and improve code generation architecture

This PR refactors the code generation architecture to remove global dependencies and improve maintainability across the codebase. The changes span three main areas that were causing confusion and making the code harder to maintain.

Changes

Remove Global Root Expression Dependencies

This commit modifies the code generation logic to consistently utilize non-global root expressions across various files. Changes include updating function signatures and internal calls to pass the root expression as a parameter, ensuring that the generated code correctly references the API structure. This refactor removes the need for code generation algorithms to refer to the global root expression variable.

Restructure ServicesData Architecture

The most significant change eliminates the confusing ServicesData global dependencies in both transport and non-transport code generation algorithms. Previously, we had a confusing pattern where ServicesData contained a ServiceData field, making it unclear which layer you were working with.

Key improvements:

  • Embed service.ServicesData directly in transport packages to eliminate confusing field names
  • Rename transport service maps to GRPCServices/HTTPServices for clarity
  • Add constructor functions to reduce boilerplate initialization
  • Update variable names from serviceData to services for semantic accuracy
  • Establish consistent patterns across service, HTTP, and gRPC codegen packages

This creates clear separation between service layer and transport layer data structures.

Streamline Service File Generation

  • Consolidate file appending in Service function for improved readability
  • Simplify section template creation in EndpointFile and ViewsFile functions
  • Introduce IsAliased and ServiceTypeRef fields in ServiceData for better type resolution
  • Update request initialization template to utilize new fields for aliased types

Impact

These changes enhance the clarity and efficiency of the code generation process while ensuring better maintainability and consistency across service files. The refactor maintains full backward compatibility for generated code - no changes are required for existing Goa applications.

The elimination of global state dependencies makes the codebase more testable and modular, while the improved naming conventions make it much clearer which layer of the system you're working with at any given time.

raphael added 3 commits June 6, 2025 22:00
…essions

This commit modifies the code generation logic to consistently utilize a non-global root expressions across various files. Changes include updating function signatures and internal calls to pass the root expression, ensuring that the generated code correctly references the API structure. This refactor removes the need for code generation algorithms to refer to the global root expression variable.
- Embed service.ServicesData in transport packages to eliminate confusing field names
- Rename transport service maps to GRPCServices/HTTPServices for clarity
- Add constructor functions to reduce boilerplate initialization
- Update variable names from serviceData to services for semantic accuracy
- Establish consistent patterns across service, HTTP, and gRPC codegen packages

This eliminates the confusing naming where ServicesData contained a ServiceData field,
and creates clear separation between service layer and transport layer data structures.
…plate handling

- Consolidate file appending in Service function for improved readability.
- Simplify section template creation in EndpointFile and ViewsFile functions.
- Introduce IsAliased and ServiceTypeRef fields in ServiceData for better type resolution.
- Update request initialization template to utilize new fields for aliased types.

These changes enhance the clarity and efficiency of the code generation process, ensuring better maintainability and consistency across service files.
@raphael raphael merged commit c0023b3 into v3 Jun 7, 2025
9 checks passed
@raphael raphael deleted the chore/remove_global_root branch June 7, 2025 22:38
@nitinmohan87 nitinmohan87 mentioned this pull request Jul 18, 2025
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