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

Can't find a way to follow jsonapi spec for the 'included' field #129

Open
pldavid2 opened this issue Dec 29, 2019 · 1 comment
Open

Can't find a way to follow jsonapi spec for the 'included' field #129

pldavid2 opened this issue Dec 29, 2019 · 1 comment

Comments

@pldavid2
Copy link

Hello thanks for this awesome gem!

I'm having an issue when trying to define the schema following jsonapi spec, particularly with the "included" array where someone can specify objects related to the primary data, an array that can have different model/schema types.

I currently have a schema defined for an Article and then a schema for the Author and the Comments. If i try to relate this two last schemas (Author and Comments) on the 'included' array of the Article block it doesn't work. I tried with bot these two forms

      property :included, type: :array do
        items do
          key :'$ref', :Comment
        end          
        items do
          key :'$ref', :Author
        end          
      end

And with

      property :included, type: :array do
        items do
          key :'$ref', :Comment
          key :'$ref', :Author
        end          
      end

The full Article, Comment and Author schemas are something like these

module Swagger::ArticleSchema
  extend ActiveSupport::Concern
  include Swagger::Blocks

  included do
    swagger_schema :Article do
      property :id do
        key :type, :integer
      end
      property :type do
        key :type, :string
      end
      property :attributes, type: :object do
        property :text do
          key :type, :string
        end
      end

      property :included, type: :array do
        items do
          key :'$ref', :Comment
        end          
        items do
          key :'$ref', :Author
        end          
      end #end included
    end
  end
end

module Swagger::CommentSchema
  extend ActiveSupport::Concern
  include Swagger::Blocks

  included do
    swagger_schema :Article do
      property :id do
        key :type, :integer
      end
      property :type do
        key :type, :string
      end
      property :attributes, type: :object do
        property :text do
          key :type, :string
        end
      end
    end
  end
end

module Swagger::AuthorSchema
  extend ActiveSupport::Concern
  include Swagger::Blocks

  included do
    swagger_schema :Article do
      property :id do
        key :type, :integer
      end
      property :type do
        key :type, :string
      end
      property :attributes, type: :object do
        property :full_name do
          key :type, :string
        end
      end
    end
  end
end

Is there any way to get them working with $ref? Or i need to manually specify all the 'included' relations manually?

Thanks!

@faizaankhan
Copy link

Same issue here: #122

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

No branches or pull requests

2 participants