grape-jsonapi icon indicating copy to clipboard operation
grape-jsonapi copied to clipboard

Improvement suggestions: Support UUID in swagger parser

Open code-bunny opened this issue 7 months ago • 1 comments

The Swagger parser inherently believes all ID fields to be integers and doesn't support when we set a UUID instead. Our current solution is to monkey patch the parser. It would be ideal if we can set some magic comment that lets the parser know this id is gonna be a UUID.

Something of a proposal for the interface.

class TransactionSerializer < BaseSerializer
  # id: :uuid
  belongs_to :user

  has_one :item

  attribute :created_at do |object|
    object.created_at.iso8601
  end

  attribute :updated_at do |object|
    object.updated_at.iso8601
  end
end

# or 

desc "Transactions" do
  success code: 200, model: TransactionSerializer, is_collection: true, id: :uuid
  produces [ "application/vnd.api+json" ]
  consumes [ "application/vnd.api+json" ]
  headers Authorization: {
    description: "Authorization token for the current user(JWT).",
    required: true
  }
end

code-bunny avatar May 20 '25 15:05 code-bunny

@code-bunny I'd keep the default parser simple, but if you really need this feel free to create a pull request with what you would like to see changed 🙏

EmCousin avatar May 21 '25 11:05 EmCousin