Home > Software design >  Nested resources in grape / swagger
Nested resources in grape / swagger

Time:09-30

In the project I'm using

gem 'grape'
gem 'grape-swagger'

I have a namespace in the API that is responsible for the users END-points

namespace :users do
  mount V1::Users::AuthAPI
  mount V1::Users::MaterialsAPI
  ...
end

Each of the mounted files has its own namespace, for example app/api/v1/users/materials_api.rb

namespace :materials do
  ...
end

In the swagger documentation, this is displayed in such a way that all paths belong to the users namespace

enter image description here

How can I break these paths into sections?

CodePudding user response:

Though I haven't used grape-swagger, you can achieve that by using tags and assigning to each endpoint a tag.

openapi: 3.0.0
....
tags:
  - name: users
   description: something about users
  - name: materials
   description: something about materials
paths:
  /api/v1/users/auth:
    post:
     tags:
       - users
     ...
  /api/v1/users/materials:
    get:
      tags:
        - materials
     ....
      

That config should render something like this:

enter image description here

I see grape-swagger has this https://github.com/ruby-grape/grape-swagger#tags-

  • Related