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

a setting for disabling documentation to internal APIs #2233

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

dnesteryuk
Copy link
Member

@dnesteryuk dnesteryuk commented Jan 8, 2022

Our application has 3 APIs, 2 of them are internal and don't require documentation. However, there has not been any option to prevent Grape from documenting parameters for internal APIs.

This change adds a do_not_document! setting which instructs Grape to not document parameters, thus needless objects allocation is avoided.

class Api < Grape::API
  do_not_document!
end

The logic for documenting parameters was moved to a separate class, the Grape::Validations::ParamsScope class has to many responsibilities, it would be better to split it.

Our API has lots of endpoints like this:

resource :addresses do
  params do
    requires :address, type: Hash do
    requires :street, type: String
    requires :postal_code, type: Integer
    optional :city, type: String
  end
  post '/' do
    declared(params, include_missing: false)
    'Done'
  end
end

With documentation:

Total allocated: 342247 bytes (3186 objects)
Total retained:  70915 bytes (594 objects)

Without documentation:

Total allocated: 341183 bytes (3178 objects)
Total retained:  69091 bytes (580 objects)

1,78 Kb is saved.

@dnesteryuk dnesteryuk force-pushed the feature/endpoints-without-docs branch 4 times, most recently from 80702a3 to bd387e3 Compare January 8, 2022 11:57
Our application has 3 APIs, 2 of them are internal and don't require
documentations. However, there has not been any option to prevent
Grape from documenting parameters for internal APIs.

This change adds a `do_not_document!` setting which instructs Grape
to not document parameters, thus needless objects allocation is avoided.

    class Api < Grape::API
      do_not_document!
    end

The logic for documenting parameters was moved to a separate class,
the `Grape::Validations::ParamsScope` class has to many responsibilities,
it would be better to split it.
@dnesteryuk dnesteryuk force-pushed the feature/endpoints-without-docs branch from bd387e3 to 1c65d8b Compare January 9, 2022 14:08
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this, @dmitry care to CR too?

Copy link
Member

@dm1try dm1try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
though, some of those changes are refactoring not related to documentation, I would prefer to have separate commits for that next time.

@dblock dblock merged commit 8cc362b into ruby-grape:master Jan 11, 2022
@dnesteryuk dnesteryuk deleted the feature/endpoints-without-docs branch January 11, 2022 17:35
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 this pull request may close these issues.

None yet

3 participants