Class: DocsUI::OpenApiOperation

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
app/components/docs_ui/open_api_operation.rb

Overview

Renders one OpenAPI operation as a full endpoint reference, composed entirely from the existing kit — zero hand-restatement. Given a DocsKit::OpenApi::Operation it emits:

* a DocsUI::Section titled with the operation summary (id: the operationId,
so deep links + the auto-TOC resolve), described by a DocsUI::Endpoint badge;
* the operation description as Markdown prose (when present);
* a parameters DocsUI::FieldTable and a request-body DocsUI::FieldTable (each
labelled only when BOTH are present, so a single table reads clean);
* a DocsUI::ErrorTable from the 4xx/5xx responses (when any);
* the request block — the operation's x-codeSamples (a DocsUI::Example when
≥2, a plain DocsUI::Code when exactly one), else a generated
DocsUI::RequestExample (respecting a passed clients: filter);
* a DocsUI::JsonResponse from the first 2xx example (when derivable);
* finally the caller's block, so a page can append hand-authored prose.

render DocsUI::OpenApiOperation.new(doc.operation("createInvoice"))

The operation page helper is the friction-free front door; use this directly for bespoke composition. It reads config only through the components it composes (RequestExample pulls api_base_url/auth), never hardcodes a site value.

Instance Method Summary collapse

Constructor Details

#initialize(operation, clients: nil) ⇒ OpenApiOperation

Returns a new instance of OpenApiOperation.



26
27
28
29
# File 'app/components/docs_ui/open_api_operation.rb', line 26

def initialize(operation, clients: nil)
  @operation = operation
  @clients = clients
end

Instance Method Details

#view_template(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'app/components/docs_ui/open_api_operation.rb', line 31

def view_template(&block)
  render DocsUI::Section.new(@operation.title, id: @operation.operation_id, description: endpoint_badge) do
    operation_description
    field_tables
    error_table
    request_block
    success_response
    yield_content(&block)
  end
end