Command line utility to split OpenAPI documents into smaller, self contained, service oriented documents and prepare StackQL provider interfaces

Related tags

Validation openapi3
Overview

openapi-doc-util

Command line utility to split OpenAPI documents into smaller, self contained, service oriented documents and prepare StackQL provider interfaces Command line utility to help developers prepare and submit StackQL provider specs, see StackQL Readme

Installation

NPM

npm i @stackql/openapi-doc-util

YARN

yarn add @stackql/openapi-doc-util

Setup

from the package directory, run:

npm link

Background

Read this section for background on the StackQL product

The StackQL utility provides a SQL interface to cloud and SaaS providers, mapping a provider to an ORM, transpiling input SQL to provider API requests, and bringing back response data as a SQL based result set. StackQL is capable of DML operations such as `INSERT` and `DELETE` which can be used to provision or de-provision cloud resources, query operations using `SELECT` to collect, analyze, report on asset or configuration data, and lifecycle operations such as starting a VM instance using the `EXEC` command in StackQL.

The StackQL ORM provides a logical model to work with cloud resources similar to the way databases are organized into schemas. This object/resource hierarchy is summarized below:

provider/
├─ service/
│  ├─ resource/
│  │  ├─ fields
│  │  ├─ methods

an example would be:

google/
├─ compute/
│  ├─ instances/
│  │  ├─ id, name, status, ...
│  │  ├─ select, insert, delete, start, stop, ...

Enabling StackQL to interact with the google provider using SQL semantics, for example:

Provider discovery operations such as..

SHOW RESOURCES IN google.compute;
DESCRIBE google.compute.instances;

Query operations such as..

SELECT status, COUNT(*) as num_instances 
FROM google.compute.instances
WHERE project = 'myproject' and zone = 'us-west-1a'
GROUP BY status;

Provisioning operations such as creating a Compute Engine instance using an INSERT statement or deprovisioning an instance using a DELETE statement.

Read this section for background on the StackQL Provider Registry

StackQL provider interfaces (such as GCP, Okta, GitHub, AWS, Azure, etc) are defined using annotations to the provider API (OpenAPI) specification, these annotations or extensions allow StackQL to map the providers resource to the desired ORM and define routes for SQL verbs such as `SELECT`, `INSERT`, `DELETE`, and `EXEC`.

Usage

openapi-doc-util <command> [<arguments(s)>] [<flag(s)>]

Commands

validate

Validates an OpenAPI specification document.

split

Splits an Open API document into smaller, self contained, service scoped documents based upon a specified service discriminator (JSONPath expression relative to each operation). Takes an OpenAPI document as input and outputs the following structure:

{output_dir}/
├─ {provider_name}/
│  ├─ {provider_version}/
│  │  ├─ services/
│  │  │  ├─ {service_name}/
│  │  │  │  ├─ {service_name}.yaml
│  │  │  ├─ .../

The {service_name}.yaml file is a self contained, OpenAPI specification document, containing only operations and components for the specified service.

provider-dev

Iterates through a directory of services (created using the split function), generates an additional document for each service {service_name}-resources.yaml and an index document for all services named provider.yaml, this is useful for developing new StackQL providers. The output structure is as follows:

{api_doc_dir}/
├─ {provider_name}/
│  ├─ {provider_version}/
│  │  ├─ services/
│  │  │  ├─ {service_name}/
│  │  │  │  ├─ {service_name}.yaml
│  │  │  │  ├─ {service_name}-resources.yaml
│  │  │  ├─ .../
│  │  ├─ provider.yaml

The original OpenAPI documents are not modified.

The provider-dev function will infer SQL routes for operations under each resources under the sqlVerbs key, this should be reviewed by the developer, removing any duplicate or erroneous routes.

provider-build

Operates on the dev directory structure generated using the provider-dev command, assembles a complete Open API specification per service including the StackQL resources for each service in each document under components/x-stackQL-resources, and outputs the following structure to a new directory:

{output_dir}/
├─ {provider_name}/
│  ├─ {provider_version}/
│  │  ├─ services/
│  │  │  ├─ {service_name}/
│  │  │  │  ├─ {service_name}.yaml
│  │  │  ├─ .../
│  │  ├─ provider.yaml

The output from the provider-build command can be used to test locally (see Test Using a Local Registry). Once you have tested locally you can raise a pull request to stackql/stackql-provider-registry.

Options

--svcDiscriminator, -s JSONPath expression OR svcName:servicename

The service discriminator option is used to determine how to split a large provider document into smaller, service scoped documents. The option is required for the split command and ignored otherwise. If you do not wish to spilt the provider API spec, specify svcName:<servicename> for this option which will define one service in the StackQL provider with the name provided in servicename.

Example: -s "$['x-github'].category" would split the given provider API spec into service documents by matching the x-github.category value in each unique operation (combination of a path and an HTTP method) in API doc.

--resDiscriminator, -r JSONPath expression OR path_tokens

The resource discriminator option is used to determine how to identify StackQL resources in a given provider API spec. This option is used for the provider-dev command and ignored otherwise.

Example: -r "$['x-github'].subcategory" would identify resources in the given provider API spec by matching the x-github.subcategory value in each unique operation (combination of a path and an HTTP method) in API doc.

if path_tokens is specified for the --resDiscriminator option, the resource name will be derived by joining the 'meaningful' path tokens (not equivalent to the service name) with an '_'. For instance a path of /sites/{site_id}/service-instances would result in a resource name of sites_service_instances assuming the service name was not sites.

--methodkey, -m JSONPath expression

The method key option determines uniquely named operations which are mapped to SQL methods in the StackQL ORM. These methods are then mapped to default routes (SQL query and DML methods) in StackQL, the developer can override or update these mappings in the development docs which are outputted from the provider-dev command. This option is used for the provider-dev command and ignored otherwise.

If supplied it must be a JSONPath expression relative to the operation (http path and verb), if not supplied it will default to operationId in the OpenAPI specification for each operation.

--output, -o directory

The output directory option specifies the root directory to output files from the split, or the root directory to output assembled provider specs from the provider-build command. The default is the current working directory. If the directory exists in either case the program will exit with an error unless the --overwrite option is set.

If not supplied it will default to the current working directory

--overwrite

The overwrite option specifies whether to overwrite files in the output directory. The default is false.

--debug, -d

debug flag which can be set for additional print statements.

Example

This example demonstrates creating a StackQL provider for github and testing this provider locally using stackql

Example Project Structure

The following directory structure represents the target after an API dev workspace is set up and the StackQL provider for github is built.

local-registry/
├─ ref/
│  ├─ github/
│  │  ├─ api.github.com.yaml
├─ dev/
│  ├─ github/
│  │  ├─ v0.1.0/
│  │  │  ├─ provider.yaml
│  │  │  ├─ services/
│  │  │  │  ├─ repos/
│  │  │  │  │  ├─ repos.yaml
│  │  │  │  │  ├─ repos-resources.yaml
│  │  │  │  ├─ .../
├─ src/
│  ├─ github/
│  │  ├─ v0.1.0/
│  │  │  ├─ provider.json
│  │  │  ├─ services/
│  │  │  │  ├─ repos/
│  │  │  │  │  ├─ repos-v0.1.0.json

local-registry/ref/github/api.github.com.yaml is the source OpenAPI 3 specification for the github api, this was sourced from GitHub.

The dev directory contains the output of the dev docs generated by the openapi-doc-util split command, which will then serve as input to the openapi-doc-util provider-dev command.

The src directory contains the output of the StackQL provider interface generated from the dev docs using openapi-doc-util provider-build.

1. Split large spec into service specs

PowerShell:

cd local-registry
openapi-doc-util split `
-n github `
-v v0.1.0 `
-s "$['x-github'].category" `
-o .\dev `
./ref/github/api.github.com.yaml

Bash:

cd local-registry
openapi-doc-util split \
-n github \
-v v0.1.0 \
-s '$["x-github"].category' \
-o ./dev \
ref/github/api.github.com.yaml

2. Create dev provider docs

PowerShell:

cd local-registry
openapi-doc-util provider-dev `
-n github `
-v v0.1.0 `
-r "$['x-github'].subcategory" `
.\dev

Bash:

cd local-registry
openapi-doc-util provider-dev \
-n github \
-v v0.1.0 \
-r '$["x-github"].subcategory' \
./dev

Assemble final provider docs

PowerShell:

cd local-registry
openapi-doc-util provider-build `
-n github `
-v v0.1.0 `
-o .\src `
.\dev

Bash:

cd local-registry
openapi-doc-util provider-build \
-n github \
-v v0.1.0 \
-o ./src \
./dev

Test Using a Local Registry

cd local-registry
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)"
REG_STR='{"url": "file://'${PROVIDER_REGISTRY_ROOT_DIR}'", "localDocRoot": "'${PROVIDER_REGISTRY_ROOT_DIR}'", "verifyConfig": {"nopVerify": true}}'
AUTH_STR='{"github": { "type": "null_auth" }}'
./stackql shell --auth="${AUTH_STR}" --registry="${REG_STR}"
You might also like...

jQuery library to validate html forms. compatible with bootstrap v4 and bootstrap v3

jQuery library to validate html forms. compatible with bootstrap v4 and bootstrap v3

jQuery form validation jQuery form validation is a library that helps you to validate your HTML form, it's completable with both Bootstrap 3 and Boots

Jun 10, 2021

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

Ajv JSON schema validator The fastest JSON validator for Node.js and browser. Supports JSON Schema draft-06/07/2019-09/2020-12 (draft-04 is supported

Jan 4, 2023

GUI for editing, visualizing, and manipulating JSON data

GUI for editing, visualizing, and manipulating JSON data

JSON-Splora JSON-Splora is a GUI for editing, visualizing, and manipulating JSON data with jq or JavaScript. Design Built with Electron Editor and out

Dec 25, 2022

ForgJs is a javascript lightweight object validator. Go check the Quick start section and start coding with love

ForgJs is a javascript lightweight object validator. Go check the Quick start section and start coding with love

Hey every one im really happy that this repo reached this many stars 🎉 ,but this repo needs your contibution I started to better document the code th

Dec 21, 2022

Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is a powerful tool to sanitize and validate JS objects. It's designed to work both client-side and server-side and to be scalable wit

Oct 3, 2022

:white_check_mark: Easy property validation for JavaScript, Node and Express.

property-validator ✅ Easy property validation for JavaScript, Node and Express Built on top of validator.js, property-validator makes validating reque

Dec 14, 2022

Receipt parser webapplication written in javascript and python.

Receipt parser webapplication written in javascript and python.

Receipt Manager Webapp You can find pre-compiled releases on the Github release page. All the needed info about how to use the receipt-manager-webapp

Nov 27, 2022

Validate properties and well known annotations in your Backstage catalog-info.yaml files.

Backstage entity validator This package can be used as a GitHub action or a standalone node.js module GitHub action Inputs path Optional Path to the c

Dec 26, 2022
Owner
StackQL Studios
Cloud infrastructure, platform and software asset management and deployment automation software solutions.
StackQL Studios
Reading emails from Gmail provider using Node.js along with Google API

?? Project summary Reading emails from Gmail provider using Node.js along with Google API (study only). ?? Technologies Project was built using Node.j

Jhony Walker 2 Jan 8, 2022
Fallblatt - fallblatt is a lightweight jQuery plugin for animating split flap displays

fallblatt Ever wondered about those big legacy displays in aiport terminals and train stations? They are called split-flap displays (Fallblattanzeige

Julian Pelizäus 11 Oct 11, 2022
A library that generates OpenAPI (Swagger) docs from Zod schemas

Zod to OpenAPI A library that uses zod schemas to generate an Open API Swagger documentation. Purpose and quick example Usage Installation The openapi

Astea Solutions 130 Dec 30, 2022
Validate your forms, frontend, without writing a single line of javascript

Parsley JavaScript form validation, without actually writing a single line of JavaScript! Version 2.9.2 Doc See index.html and doc/ Requirements jQuer

Guillaume Potier 9k Dec 27, 2022
A JavaScript function to convert a number into words

Number to Words by Nicholas C. Zakas If you find this useful, please consider supporting my work with a donation. Description A function that accepts

Human Who Codes 29 Aug 7, 2022
A simple and composable way to validate data in JavaScript (and TypeScript).

A simple and composable way to validate data in JavaScript (and TypeScript). Usage • Why? • Principles • Demo • Examples • Documentation Superstruct m

Ian Storm Taylor 6.3k Jan 9, 2023
Codestamp - Stamp and verify your files and contents

A language-agnostic tool for signing and verifying your (codegen'd) files and contents.

Keyan Zhang 4 Jan 26, 2022
FieldVal - multipurpose validation library. Supports both sync and async validation.

FieldVal-JS The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports. Documentation and Examples D

null 137 Sep 24, 2022