Documentation
/ Reference
hive-apispec
API specifications to records. Package hiveapispec, CLI hiveapispec. It calls no model and no
network.
A concept card cannot hold thousands of operations, parameters and schemas. hive-apispec keeps
them whole as records of the database-object tier, beside the records of
hive-dbparse.
Run it
pip install vf-hive-apispec
hiveapispec build --src /path/to/specs --out /path/to/corpus/concepts/widgets-api --product widgets-api --id-prefix widgets-api
hiveapispec check --src /path/to/specs --out /path/to/corpus/concepts/widgets-api
| Command | What it does |
|---|---|
build |
reads the specifications, writes the records, runs the gate and publishes only on a pass |
check |
runs the round-trip check again on published records |
| Option | Meaning |
|---|---|
--version |
print the installed vf-hive-apispec version and exit (before the command) |
--src DIR |
folder of specification files |
--out DIR |
folder that receives the db/ directory |
--product NAME |
product that the specifications belong to (build only) |
--id-prefix ID |
record id of --out below concepts/ (build only, default <product>/api) |
--plugin FILE |
the rules of one corpus |
A command that refuses prints the reason and exits with a nonzero status. It refuses an empty or
missing --src, an empty --out, and folders that lie inside each other. It replaces the whole
<out>/db directory. It refuses to replace a db directory that it did not write.
You can also start it from a hive-ingest job. It then reads
only the files that the api handler claimed.
Input
| Format | How the content shows it | What becomes a record |
|---|---|---|
| OpenAPI 3.x, JSON or YAML | top-level openapi |
operations by module, component schemas, callbacks and webhooks |
| JSON Schema | $schema names json-schema.org |
the root schema and each definition |
| XSD | root element schema of the XML Schema namespace |
each global component |
| WSDL 1.1 and 2.0 | root element definitions or description |
operations by port type or interface, embedded schemas |
| Postman collection | info.schema names the Postman schema |
requests by folder |
| Postman environment or globals | top-level _postman_variable_scope |
a specification record of the variables |
A file can be compressed as .gz. Each other file of the folder gets a row in gaps.jsonl with
the reason.
The tool does not read these, and the run fails:
- Swagger 2.0 or non-3.x OpenAPI. Convert the file to OpenAPI 3 first.
- An XML file that declares a DOCTYPE.
- A
$ref, aninclude, animport, aredefineor anoverridethat leaves the input, or a localxs:redefine/xs:overridethat redeclares components. Nothing is fetched. Animportof the XML Schema, XML or SOAP encoding namespace needs no file. - A relative
$refinside a subschema that declares its own$id. An absolute URI there is read. - A file over 256 MiB decompressed, a YAML file exceeding 5,000,000 expanded values or containing circular references, duplicate object keys in JSON or YAML, a multi-document YAML stream holding a specification, or a file with a specification extension that cannot be parsed.
The folder walk lists a symbolic link and never follows it.
Output
<out>/db/
modules/<group>/<module>.md
schemas/<group or shared>/<name>.md
callouts/<group or shared>/<id>.md
specs/<group>.md
manifest.jsonl
gaps.jsonl
.hive-api.run.json
.hive-api.failed.json only after a failed run
A group is one specification file, named after the file. Each record is an OKF card of type
dbobject.
| Record | Holds |
|---|---|
| module | one tag, folder, port type or interface, with a section for each operation |
| schema | the field table, links to other schemas and the source |
| callout | one callback or webhook, or one extension point that a plug-in hands over |
| spec | what a document says outside its operations and schemas, or the variables of a Postman environment |
Each section and each schema record ends with the source of the item. XML source is the exact text of the file. JSON and YAML source is the parsed value, written as JSON. Neither holds the possible credentials. Schemas that are identical, with all that they refer to, share one record.
manifest.jsonl has one row for each record and one row of kind endpoint for each operation. An
endpoint row names the record and the anchor that hold the operation. gaps.jsonl has one row for
each operation with its documentation gaps, one for each skipped file and one for each value that
was left out.
| Gap | Meaning |
|---|---|
no-description |
the operation has no summary and no description |
request-body-without-fields |
a request body is declared, and no field of it |
response-without-schema |
no response of the operation has a schema that describes anything |
no-example |
the operation has no example |
A record over 58 KB is split into parts named <id>~part-NNN. The parts hold the whole body in
order, and the parent record lists them. If that list does not fit, one row covers several parts in
a row and links the first and the last of them.
The front matter of a record names at most 20 source files and 20 groups. The body names them all.
Where to put the records
hive-serve keeps every db directory out of the concept index. Its find_db_objects tool reads
concepts/<product>/db/manifest.jsonl and no deeper path. For this reason:
- For a product that is only an API, use
--out concepts/<name>and--id-prefix <name>. The tool then finds the records. - With the default prefix
<product>/api, the records sit beside the other cards of a product.find_db_objectsdoes not read their manifest. An API lookup inhive-serveis follow-up work.
The gate
A run publishes its records only when all of these are true. If one is false, the run fails and the previous records stay as they were.
- No item is unparsed. This covers each path item key, operation, schema, component and reference.
- The input holds at least one operation, schema or callout. (A folder holding only a Postman
environment produces only a
specrecord and fails this check.) - The record counts equal the parsed counts.
- The round-trip check finds no difference.
.hive-api.run.json records the job, the input, the number of records and the outcome of the run that
published the records. check reads its input from there. A failed run leaves that file as it was
and writes .hive-api.failed.json, which records counts by reason and no text of a specification.
The next run that publishes removes it.
The round-trip check
The check does not use the readers or the renderer. It reads the specifications again, parses the records from disk and compares the two:
- each operation and each schema has exactly one record, and no record lacks a source;
- each source block equals its source;
- parameter tables, response codes and field tables name what the source names;
- the manifest, the parts and the files agree, no record is over 60 KB, and each link resolves;
- no key or token of a known format stands anywhere in the output.
Possible credentials
Records go into git and are served to a model. A record must also hold all that the API documentation says. So the tool removes a value only if it really is a secret. It works in two steps. The first step removes credentials from the places that hold them. The second step masks secrets inside text, and copies of the removed values.
Removed from their places
The tool writes <left out: possible credential> in place of such a value.
A key or token of a known format is a secret wherever it stands in a JSON or YAML value. In an XSD
or WSDL file, the first step finds it in each documentation element and in each default, fixed
and enumeration value. It also finds it in the text of a plug-in: the title, description, body
and tags of its records, and the lines that it adds to an operation. These are the known formats:
- a private key block that holds key material;
- a JSON Web Token;
- an AWS access key id (
AKIA...); - a Google API key (
AIza...); - a GitHub token (
ghp_...,github_pat_...and the othergh?_forms); - a GitLab token (
glpat-...); - a Slack token (
xox?-...); - a Stripe secret or restricted key (
sk_live_...,rk_test_...).
So is the value of an Authorization, cookie or API key header. An API key header has apikey,
api_key or api-key in its name, or an apiKey security scheme declares it. The tool also finds
such a value where text writes it out, for example Authorization: ..., Cookie: name=value,
"cookie": "name=value", Bearer ... or Basic ....
| Input | What else is removed | What stays |
|---|---|---|
| OpenAPI and JSON Schema | for such a header parameter, a cookie parameter or such a response header: its example, examples (including OpenAPI 3.2 dataValue and serializedValue), default, const, x-*example* keys, and what they refer to. In an example, such an entry of a headers map |
every other example, default and description, whatever the name of its field; types and enum lists |
| Postman collection | the credentials of auth blocks, and saved cookies |
URLs, paths, query parameters, body fields, collection variables, the auth settings that only describe the method, and each {{variable}} |
| Postman environment or globals | the value of a variable that has the type secret or a secret key, such as password, token, secret, apiKey, client_secret or auth |
every other value, such as base URLs, hosts, tenant names, paths and ports |
Masked inside text
The tool writes [masked] in place of such a value. The label, the user name and the host stay.
The rules are in hiveapispec/mask.py. hive-ingest
uses the same rules. Where a string stands decides which
forms the tool reads:
| Where | What the tool masks |
|---|---|
free text: a description, a summary, an x- extension (except x-*example* keys), a Postman script, XSD or WSDL documentation, the text of a plug-in |
a labelled password or token, also as set("password", "<value>") or <add key="password" value="<value>"/> writes it, a login note, a connection string, a password in a URL, an auth header, a known key format, and a long random string near a secret word. A value after a label or in a login note goes only if it is plainly a secret |
| each other field | a known key format, an auth header, a password in a URL, and a long random string near a secret word. The name of a field alone decides nothing |
a documentation value: example, examples, x-*example*, default, const, enum, a saved response of a Postman collection, a default, fixed or enumeration value of XSD |
no form of its own. Only the first step and copies change it |
A value is plainly a secret if it is a long random string. It is also one if it has 8 or more
characters with letters, digits and a mix of cases or symbols, and holds no word that an example
uses, such as Password, test or example.
A reference only points at a value, so it stays: ${NAME}, <name>, {{name}} and {name}. A
bare $NAME counts as a value.
Copies
The tool also looks for each removed or masked value in all other strings of the input,
documentation values included. It looks only for a value that reads like a token, and only where
the value stands alone. A plain word stays, because that word can be part of any sentence. A user
name of an auth block is not looked for.
The list of what went
gaps.jsonl has one row for each value that went, and never the value:
| Field | Holds |
|---|---|
file, location |
the input file and the place in it. For XML the location is a line |
state, actor |
left out, code |
label |
what marked the value: a secret word such as password, a key format, or the name of a header or variable. A label inside a text or a table never holds the words around the secret word |
detector |
known key format, auth header, auth block, secret variable, URL credential, connection string, labelled secret, login note, random string near a secret word or copy of a secret value |
The run summary counts the values as values_left_out, and by detector as
left_out_by_detector.
Limits
The tool does not clean names and pointers, such as an object key, an XML name, $ref or $id. It
also does not clean other XML text, such as a comment, appinfo or a service address. If a known
key or token from there reaches the output, the run fails. The message names the input file and the
place in it, as a line of XML or a path of JSON or YAML, and never the value. If no input file holds
the key, the message names the record. A person must look at the source, correct it and run again.
A password that looks like an example stays in API text. No filter is complete, so review records
from client files before you commit them.
The plug-in seam
Rules for one vendor stay in the corpus. A corpus writes a Python file that defines plugin, an
instance of a subclass of hiveapispec.plugins.Plugin, and names it with --plugin.
| Setting or method | Use |
|---|---|
example_bodies = True |
add to each schema record, where possible, an example body that the engine generates from the schema. Its placeholder values are in no specification. The default is False |
documents(source) |
hand over specifications from a layout that is not a folder of specification files |
operation(operation, parsed) |
add lines, gap flags, a request body label or links to one operation |
records(parsed, ids) |
add records of the corpus's own kind, for example how-to pages |
A plug-in can hand over a document of format callouts for extension points that no standard
describes: {"callouts": [{"id", "type", "description", "input", "output"}]}. A record keeps the
whole entry, and only entries that are equal share one record. Leave out what differs from copy to
copy, such as a registration time.
A plug-in is code, so the tool loads only the file that you name. The hive-ingest MCP server loads
no plug-in.
What it does not do
- It does not crawl or download specifications.
- It does not guess a request body that a specification does not document.
Modules
| Module | Purpose |
|---|---|
load.py |
read files and name their format from the content |
readers/ |
one reader for each format, all producing the model of model.py |
redact.py |
remove credentials from their places, and find known keys that remain |
mask.py, sweep.py |
the rules that find secrets inside text, and their use on API sources |
render.py, parts.py |
write records, manifest rows and gap rows, and split large records |
check.py |
the round-trip check |
plugins.py |
the plug-in seam |
run.py, cli.py |
the gate and the command line |
Tests
The tests build synthetic specifications. They use no client file and no network. Run
uv sync --extra dev && uv run pytest -q in tooling/hive-apispec/.