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, pathfrom openapi_component_schema;
select name, type, format, deprecated, description, default_value, pathfrom 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.descriptionfrom 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.descriptionfrom 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 schemafrom 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.schemafrom 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.namewhere op.api_path = '/orgs/{org}/members/{username}/delete' and cp.required;
Schema for openapi_component_schema
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
allow_empty_value | boolean | If true, it allows to set a empty value to the property. | |
default_value | text | The default value set for the schema. | |
deprecated | boolean | True, if the schema is deprecated. | |
description | text | A description of the schema. | |
exclusive_max | boolean | Specify the maximum value allowed for a numeric property, where the maximum value is exclusive | |
exclusive_min | boolean | Specify the minimum value allowed for a numeric property, where the minimum value is exclusive. | |
format | text | The format of a specific schema type. | |
items | jsonb | Specify the list of items defined in the property. | |
max | double precision | Specify the maximum number that can be set to the property. | |
max_items | double precision | Specify the maximum number of items that can be added to the property of type array. | |
max_length | double precision | Specify the maximum length of a string type data. | |
min | double precision | Specify the minimum number that can be set to the property. | |
min_items | double precision | Specify the minimum number of items that can be added to the property of type array. | |
min_length | double precision | Specify the minimum length of a string type data. | |
multiple_of | double precision | Specify a numeric property's valid multiplier. | |
name | text | The name of the property. | |
nullable | boolean | If true, null value can be set to a string property. | |
path | text | = | Path to the file. |
pattern | text | Specify the regex pattern for the property value. | |
properties | jsonb | Describes the schema properties. | |
read_only | boolean | If true, the property value cannot be modified. | |
required | jsonb | If true, the property must be defined. | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. | |
title | text | The title of the schema. | |
type | text | The type of the schema. | |
unique_items | boolean | True, if the items in an array are required to be unique. | |
write_only | boolean | If 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