Class: SpecForge::Documentation::Document::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/documentation/document/operation.rb

Overview

Represents an API operation (endpoint + HTTP method)

An Operation contains all the information about a specific API endpoint with a specific HTTP method, including parameters, request bodies, and possible responses.

Examples:

Operation for creating a user

operation = Operation.new(
  id: "create_user",
  summary: "Creates a new user",
  parameters: {id: {name: "id", location: "path", type: "integer"}},
  requests: [{name: "example", content_type: "application/json", type: "object", content: {}}],
  responses: [{status: 201, content_type: "application/json", headers: {}, body: {}}]
)

Instance Method Summary collapse

Constructor Details

#initialize(id:, summary:, parameters:, requests:, responses:) ⇒ Operation

Creates a new operation with normalized sub-components

Parameters:

  • id (String)

    Unique identifier for the operation

  • summary (String)

    Human-readable summary

  • parameters (Hash)

    Parameters by name with their details

  • requests (Array<Hash>)

    Request body examples

  • responses (Array<Hash>)

    Possible responses



34
35
36
37
38
39
40
41
42
43
# File 'lib/spec_forge/documentation/document/operation.rb', line 34

def initialize(id:, summary:, parameters:, requests:, responses:)
  parameters = parameters.each_pair.map do |name, value|
    [name, Parameter.new(name: name.to_s, **value)]
  end.to_h

  requests = requests.map { |r| RequestBody.new(**r) }
  responses = responses.map { |r| Response.new(**r) }

  super
end