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

Non-column attributes #3

Open
zernie opened this issue Jul 22, 2019 · 4 comments · May be fixed by #4
Open

Non-column attributes #3

zernie opened this issue Jul 22, 2019 · 4 comments · May be fixed by #4

Comments

@zernie
Copy link

zernie commented Jul 22, 2019

Having a resource like this:

class Api::V1::TripResource < Api::V1::BaseResource
  attribute :test

  def test
    123
  end
end

$ rails g jsonapi:swagger Api::V1::Trip fails with jsonapi-swagger-0.7.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:80:in block (2 levels) in properties': undefined method []' for nil:NilClass (NoMethodError)

@zernie
Copy link
Author

zernie commented Jul 22, 2019

It's not easy to guess what type will the given method return, so I suppose a string will do for now

@superiorlu
Copy link
Owner

At present, the attribute type in resource comes from the type of the field in the database, so you need to associate wth active record.

@zernie
Copy link
Author

zernie commented Jul 25, 2019

@superiorlu I understand that, but this restriction greatly limits the usefulness of this lib.
I'd suggest that when it is not possible to identify the type of the attribute using the DB, use string type as a default and emit a warning. Maybe add a treat_unknown_attribute_type_as = :string config option?

Thanks.

@superiorlu
Copy link
Owner

yes, that's good idea. we can support this config option.

@zernie zernie linked a pull request Jul 31, 2019 that will close this issue
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 a pull request may close this issue.

2 participants