steampipe plugin install openapi

Table: openapi_component_schema - Query OpenAPI Components using SQL

OpenAPI Components are reusable entities within the OpenAPI definition. They provide a way to reuse definitions and parameters across multiple endpoints, reducing duplication and promoting consistency. Components can include schemas, which describe the structure of an API's data model.

Table Usage Guide

The openapi_component_schema table provides insights into the OpenAPI Components within an API specification. As an API developer or architect, explore schema-specific details through this table, including data types, properties, and associated metadata. Utilize it to understand the structure of your API's data models, such as complex object definitions, data validation rules, and the relationships between different schemas.

Examples

Basic info

Explore the basic elements of an OpenAPI component schema to understand its structure and contents. This can help determine which components might be deprecated or have default values, aiding in the maintenance and updating of the schema.

select
name,
type,
format,
deprecated,
description,
default_value,
path
from
openapi_component_schema;
select
name,
type,
format,
deprecated,
description,
default_value,
path
from
openapi_component_schema;

Get the properties returned by a specific API on success

Determine the details and structure of successful responses from a specific API endpoint. This can be useful for understanding what data is returned upon successful API calls, which can aid in further API integration and data management.

with get_schema_ref as (
select
api_path,
r.key as response_status,
r.value -> 'content' -> 'application/json' -> 'schema' ->> '$ref' as schema_ref
from
openapi_path,
jsonb_each(responses) as r
where
api_path = '/repos/{owner}/{repo}/issues/post'
and r.key :: integer >= '201'
and r.key :: integer < 300
)
select
r.api_path,
s.name,
jsonb_pretty(s.properties) as schema_property,
jsonb_pretty(s.required) as required,
s.description
from
get_schema_ref as r
join openapi_component_schema as s on r.schema_ref = concat('#/components/schemas/', s.name);
with get_schema_ref as (
select
api_path,
r.key as response_status,
json_extract(r.value, '$.content.application/json.schema.$ref') as schema_ref
from
openapi_path,
json_each(responses) as r
where
api_path = '/repos/{owner}/{repo}/issues/post'
and r.key >= '201'
and r.key < 300
)
select
r.api_path,
s.name,
s.properties as schema_property,
s.required,
s.description
from
get_schema_ref as r
join openapi_component_schema as s on r.schema_ref = '#/components/schemas/' || s.name;

Get the schema of a required parameter of a specific API

This example helps you understand the structure of a specific API's required parameter. It's useful when you need to know what information is necessary to successfully use or interact with a particular API.

select
op.api_path,
cp.required,
jsonb_pretty(cp.schema) as schema
from
openapi_path as op,
jsonb_array_elements(op.parameters) as p
join openapi_component_parameter as cp on (p ->> '$ref') = concat('#/components/parameters/', cp.name)
where
op.api_path = '/orgs/{org}/members/{username}/delete'
and cp.required;
select
op.api_path,
cp.required,
cp.schema
from
openapi_path as op,
json_each(op.parameters) as p
join openapi_component_parameter as cp on json_extract(p.value, '$.$ref') = '#/components/parameters/' || cp.name
where
op.api_path = '/orgs/{org}/members/{username}/delete'
and cp.required;

Schema for openapi_component_schema

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form, e.g. connection_name.
allow_empty_valuebooleanIf true, it allows to set a empty value to the property.
default_valuetextThe default value set for the schema.
deprecatedbooleanTrue, if the schema is deprecated.
descriptiontextA description of the schema.
exclusive_maxbooleanSpecify the maximum value allowed for a numeric property, where the maximum value is exclusive
exclusive_minbooleanSpecify the minimum value allowed for a numeric property, where the minimum value is exclusive.
formattextThe format of a specific schema type.
itemsjsonbSpecify the list of items defined in the property.
maxdouble precisionSpecify the maximum number that can be set to the property.
max_itemsdouble precisionSpecify the maximum number of items that can be added to the property of type array.
max_lengthdouble precisionSpecify the maximum length of a string type data.
mindouble precisionSpecify the minimum number that can be set to the property.
min_itemsdouble precisionSpecify the minimum number of items that can be added to the property of type array.
min_lengthdouble precisionSpecify the minimum length of a string type data.
multiple_ofdouble precisionSpecify a numeric property's valid multiplier.
nametextThe name of the property.
nullablebooleanIf true, null value can be set to a string property.
pathtext=Path to the file.
patterntextSpecify the regex pattern for the property value.
propertiesjsonbDescribes the schema properties.
read_onlybooleanIf true, the property value cannot be modified.
requiredjsonbIf true, the property must be defined.
titletextThe title of the schema.
typetextThe type of the schema.
unique_itemsbooleanTrue, if the items in an array are required to be unique.
write_onlybooleanIf true, the property value can be modified.

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_schema