Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow customizing the namespace for path helpers #50

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

ElMassimo
Copy link
Owner

@ElMassimo ElMassimo commented Sep 25, 2024

Description 📖

This pull request is an attempt to address some of the shortcomings of grouping routes by controllers in apps that have more complex routing:

It adds support for a namespace option in export:

resources :video_clips, export: {namespace: :videos} do
  get :download, on: :member
end

which would then generate a VideosApi.ts file instead of VideoClipsApi.ts.

As a result it's now possible to create custom groupings of path helpers, providing a flexible and intuitive escape hatch for routes that have complex nesting or where the usage in the frontend benefits from a different grouping.

Background 📜

In setups like the following, users can now define a separate file for helpers:

resources :sections, path: "s", param: :slug do
  resources :discussions
end

resources :custom_sections, path: "cs", param: :slug, export: {namespace: "custom_section_discussions"} do
  resources :discussions
end

which will generate another file (CustomSectionDiscussionsApi.ts), containing the second set of paths.

In addition, this pull request also prevents different routes that target the same action from being omitted, in which case it will try to disambiguate additional routes by using their fully qualified name or verb.

FYI @reinvanimschoot @Shaglock

@ElMassimo ElMassimo added the enhancement New feature or request label Sep 25, 2024
@ElMassimo ElMassimo changed the title feat: allow exporting more than one helper per action feat: allow customizing the namespace for path helpers Sep 25, 2024
@ElMassimo ElMassimo merged commit 9d38c83 into main Oct 11, 2024
9 checks passed
@ElMassimo ElMassimo deleted the feat/different-paths-for-same-action branch October 11, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant