Openapi-generator: [ruby-on-rails] Bug generating ruby-on-rails controller

Created on 24 Jul 2018  路  6Comments  路  Source: OpenAPITools/openapi-generator

Description

ruby-on-rails generator uses different names for controller class file and controller name in routes.rb.
I suppose it is related to the usage of tags.

openapi-generator version

3.1.2-SNAPSHOT via docker

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: asdf 
paths:
  /foo_bar:
    get:
      summary: list all foobars
      operationId: listFooBar
      tags:
        - foo_bar
      responses:
        '200':
          description: OK
Command line used for generation

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/codegen_debug.yaml -g "ruby-on-rails" -o /local/out

Steps to reproduce

generate ruby-on-rails stub with the yaml file above.

The command generates route

[...]
  add_openapi_route 'GET', '//foo_bar', controller_name: 'fooBar', action_name: 'list_foo_bar'
[...]

but the generated controller file is named foo_bar_controller.rb

Related issues/PRs

unknown

Suggest a fix/enhancement

Use common name for controller in routes.rb and the actual controller class file

Bug Ruby

All 6 comments

@and0x000 thanks for reporting the issue and suggesting a fix. May I know if you've time to contribute the fix? I can show you some good starting points.

@wing328 I can try. But beware, I am pretty new to both, rails as well as contributing on github.

https://github.com/OpenAPITools/openapi-generator/wiki/faq#how-can-i-submit-a-pr-to-fix-bugs-or-make-enhancements is a good starting point for contributing to this project

What does the correct route or controller file name look like in the example you provided above?

wrong:

  add_openapi_route 'GET', '//foo_bar', controller_name: 'fooBar', action_name: 'list_foo_bar'

Message whent trying to start the server with it:

Exiting
/var/lib/gems/2.3.0/gems/actionpack-5.0.7/lib/action_dispatch/routing/mapper.rb:314:in `block (2 levels) in check_controller_and_action': 'fooBar' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use (ArgumentError)

correct:

  add_openapi_route 'GET', '//foo_bar', controller_name: 'foo_bar', action_name: 'list_foo_bar'

@and0x000 thanks for the info, which is very useful in fixing the issue.

I've filed https://github.com/OpenAPITools/openapi-generator/pull/706 and my test result (tag: pet_foo_bar) looks good.

@and0x000 the PR has been merged into master. Please pull the latest master to give it a try to use the SNAPSHOT version.

Was this page helpful?
0 / 5 - 0 ratings