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

Output routes definition in JSON format by `rails routes -o json` #37136

Closed
wants to merge 1 commit into from

Conversation

@unasuke
Copy link
Contributor

commented Sep 5, 2019

Summary

The code outputs routing definition by JSON format to stdout in
"rails routes --format=json" command.

Result of "rails routes" command is easy to read for human but it's hard
to parse and we have no way to use public API to get an easily parsable
routing format of the application.

schema

      { routes: [
        { path: "/users(.:format)",  verb: "GET", prefix: "users",  controller_and_action: "users#index" },
      #...
      ]
}

I think it's debatable...

Other Information

It's one of the use cases of JSON format routing, my gem https://github.com/unasuke/openapi3_definition_generator-rails generates OpenAPI3 specification YAML by rails routing.
It was a more easy job if rails outputs JSON format routings in a built-in feature.

Output routes definition in json format by `rails routes -o json`
The code outputs routing definition by JSON format to stdout in
"rails routes --format=json" command.

Result of "rails routes" command is easy to read for human but it's hard
to parse and we have no way to use public API to get an easily parsable
routing format of the application.
@@ -8,6 +8,7 @@ class RoutesCommand < Base # :nodoc:
class_option :controller, aliases: "-c", desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController."
class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern."
class_option :expanded, type: :boolean, aliases: "-E", desc: "Print routes expanded vertically with parts explained."
class_option :format, aliases: "-o", desc: "Print routes with specified format (currentry, json only)."

This comment has been minimized.

Copy link
@unasuke

unasuke Sep 5, 2019

Author Contributor

I think to move "expanded" option to argument of "--format" option is better but it's breaking changes...

@kaspth

This comment has been minimized.

Copy link
Member

commented Sep 6, 2019

We don't want to support parsing routes from somewhere else via JSON. The routes command is for local development. Thanks!

@kaspth kaspth closed this Sep 6, 2019

@unasuke unasuke deleted the unasuke:rails_routes_json branch Sep 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.