Table: openapi_component_request_body - Query OpenAPI Component Request Bodies using SQL
OpenAPI is a specification for building APIs that offer a high level of interoperability. A key part of this specification is the Component Request Body, which defines the structure and data requirements for the body of a request when making API calls. This provides a standardized way for APIs to communicate what data they expect, helping to ensure consistency and reliability in API interactions.
Table Usage Guide
The openapi_component_request_body
table provides insights into the structure and data requirements of API endpoints within an OpenAPI Specification. As an API designer or developer, explore request body component details through this table, including data types, required fields, and associated metadata. Utilize it to uncover information about the request body components, such as their structure, the types of data they expect, and the constraints on that data.
Examples
Basic info
Explore the essential components of an OpenAPI request body. This query is particularly useful for understanding the key elements that are required for a successful API request, along with their descriptions and content.
select key, description, required, jsonb_pretty(content)from openapi_component_request_body;
select key, description, required, contentfrom openapi_component_request_body;
List unused request body definitions
Determine the areas in which request body definitions are unused in your OpenAPI paths. This is beneficial in identifying redundant components, helping to streamline your API documentation and maintain efficiency.
with list_used_request_bodies as ( select path, array_agg(distinct split_part(request_body_ref, '/', 4)) as req_bodies from openapi_path_request_body where request_body_ref is not null group by path),-- List all available request body definitionsall_request_body_definition as ( select path, array_agg(key) as req_body_defs from openapi_component_request_body group by path),-- List all unused request body definitonsunused_request_body_definitions as ( select path, unnest(req_body_defs) as data from all_request_body_definition except select path, unnest(req_bodies) as data from list_used_request_bodies)select path, concat('components.requestBodies.', data) as request_body_reffrom unused_request_body_definitions;
Error: SQLite does not support array_agg,split_part,unnestand concat functions.
List request body definitions without schema
Explore instances where request body definitions lack a schema. This can help identify potential areas in your API where data validation might be missing, thus improving overall data quality and consistency.
select path, concat( 'components.requestBodies.', key, '.content.', c ->> 'contentType' ) as request_body_reffrom openapi_component_request_body, jsonb_array_elements(content) as cwhere c ->> 'schema' is null;
select path, 'components.requestBodies.' || key || '.content.' || json_extract(c.value, '$.contentType') as request_body_reffrom openapi_component_request_body, json_each(content) as cwhere json_extract(c.value, '$.schema') is null;
Schema for openapi_component_request_body
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
content | jsonb | The content of the request body. | |
description | text | A brief description of the request body. | |
key | text | The key used to refer or search the request body. | |
path | text | = | Path to the file. |
required | boolean | True, if the request body is required. | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- openapi
You can pass the configuration to the command with the --config
argument:
steampipe_export_openapi --config '<your_config>' openapi_component_request_body