Handle body parameters for OpenAPI

What does this MR do and why?

This code change enhances an OpenAPI documentation generator for REST APIs by adding support for request body parameters. Previously, the system only handled URL parameters and query parameters, but now it can properly document the data that gets sent in the body of POST, PUT, and PATCH requests (like form data or JSON payloads).

The main improvements include:

  • A new converter that specifically handles request body parameters, separating them from URL/query parameters
  • Better organization of API documentation by distinguishing between summary and detailed descriptions
  • Support for complex nested data structures (like objects within objects) that can be sent in request bodies
  • Enhanced handling of different data types including dates, arrays, and validation rules
  • Updated parameter processing to only include path and query parameters for GET/DELETE requests, while POST/PUT/PATCH requests now properly document their body parameters separately

This makes the generated API documentation more accurate and complete, helping developers understand exactly what data needs to be sent where when calling different API endpoints.

References

Screenshots or screen recordings

Before After

How to set up and validate locally

  • In a Rails console, run the following:
Rails.application.eager_load!
api_classes = API::Base.descendants
entity_classes = Grape::Entity.descendants
generator = Gitlab::GrapeOpenapi::Generator.new(api_classes: api_classes, entity_classes: entity_classes)
File.write(Rails.root.join('tmp', 'myfile.json'), generator.generate.to_json)
  • Using the redocly CLI, generate the docs: redocly build-docs ~/gdk/gitlab/tmp/myfile.json
  • Check that the body parameters are accurate on non GET or DELETE endpoints.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Max Woolf

Merge request reports

Loading