Generates OpenAPI 3.1.0 discovery documents for MPP-enabled HTTP operations.
The input is a keyword list or map containing :info, :routes, and optional
:service_info. Routes with payment metadata emit x-payment-info and a 402
response; routes with payment: nil or no :payment key are unpaid and omit
both. Payment metadata may use either discovery form, but generated documents
always contain the recommended multi-offer offers array on payable operations.
Routes may declare OpenAPI Parameter Objects via :parameters (in of
query, path, header, or cookie) and an optional success-response
schema via :response_schema (media type :response_media_type, default
application/json). A path template with a {placeholder} and no matching
in: path parameter is rejected at generation time.
MPP.Discovery.OpenApi.generate(
info: %{title: "Example API", version: "1.0.0"},
service_info: %{
"categories" => ["compute"],
"docs" => %{"homepage" => "https://example.com"}
},
routes: [
[method: :get, path: "/health"],
[
method: :get,
path: "/v1/items/{id}",
summary: "Get item",
parameters: [
[name: "id", in: :path, required: true, schema: %{"type" => "string"}],
[name: "lang", in: :query, schema: %{"type" => "string"}, description: "Locale"]
],
response_schema: %{"type" => "object", "properties" => %{"id" => %{"type" => "string"}}},
payment: %{
"intent" => "charge",
"method" => "tempo",
"amount" => "100",
"currency" => "usd"
}
]
]
)Invalid generation config raises ArgumentError so malformed discovery
documents fail at build time rather than being published.
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
generate | 1 | Generate an OpenAPI 3.1.0 document with MPP discovery extensions. | config: value |
Summary
Functions
Generate an OpenAPI 3.1.0 document with MPP discovery extensions.
Functions
Generate an OpenAPI 3.1.0 document with MPP discovery extensions.
Parameters
config- Keyword list or map withinfo, non-emptyroutes, and optionalservice_info(value)
Returns
JSON-compatible OpenAPI 3.1.0 document (map)
# descripex:contract
%{
params: %{
config: %{
description: "Keyword list or map with `info`, non-empty `routes`, and optional `service_info`",
kind: :value
}
},
returns: %{type: :map, description: "JSON-compatible OpenAPI 3.1.0 document"}
}