adp-api-transformer
A CLI tool that transforms OpenAPI specifications (JSON or YAML) for use in the ADP1 APIM repository. It enriches specs with missing attributes, normalizes operation metadata, and can split large specs into smaller per-tag or per-path files — each containing only the relevant paths and schemas.
Table of Contents
Features
- Accepts OpenAPI specs in
.json,.yaml, or.ymlformats. - Adds missing
operationId,summary, andtagsfields to every operation. - Ensures every
operationIdends with the-{{consumerphase}}suffix (appends it if missing). - Sets
info.titleto the template value{{apiTitle}}. - Split by tag — produces one file per tag, with paths starting after the tag segment.
- Split by path — groups endpoints by their first path segment, with an optional prefix to ignore (e.g.
api/v1). - Only includes schemas that are actually referenced by each split file (plus general shared schemas), resolved recursively.
- Outputs all specs as formatted JSON.
Installation
From PyPI
pip install adp-api-transformer
For development
Clone the repository and install in editable mode:
git clone <repo-url>
cd adp-api-converter
pip install -e .
Usage
adp-api-transformer <input_file> [output] [--split-by-tag] [--split-by-path] [--ignore-prefix PREFIX]
| Argument | Description |
|---|---|
input_file |
Path to the input OpenAPI spec (JSON or YAML). Required. |
output |
Output file path (single-file mode) or ignored when splitting. Defaults to openapi.json. |
--split-by-tag |
Split the spec into multiple files based on each operation's first tag. |
--split-by-path |
Split the spec into multiple files based on the first path segment. |
--ignore-prefix PREFIX |
Used with --split-by-path. Strips this prefix before determining the grouping segment (e.g. api/v1). |
When using
--split-by-tagor--split-by-path, output files are written to a directory named after the input file (without the extension).
Basic conversion
Convert a spec and write a single enriched JSON file:
adp-api-transformer api.yaml modified_api.json
Split by tag
Create one file per tag. Each file only contains the operations for that tag, with paths rewritten to start after the tag segment:
adp-api-transformer api.yaml --split-by-tag
Given an input with paths /collection, /collection/{id}, and /user/profile, this produces:
api/
collection.openapi.json # paths: / and /{id}
user.openapi.json # paths: /profile
Split by path
Group endpoints by the first meaningful path segment. Useful when tags are absent or unreliable:
adp-api-transformer api.yaml --split-by-path
If your paths share a common prefix (e.g. /api/v1/studies/..., /api/v1/extractions/...), use --ignore-prefix so grouping happens on the segment after the prefix:
adp-api-transformer api.yaml --split-by-path --ignore-prefix api/v1
This groups /api/v1/studies/{id} under studies (path becomes /{id}) and /api/v1/extractions under extractions (path becomes /).
What the tool does
Attribute enrichment
Every operation in the spec is processed with the following rules:
| Field | Rule |
|---|---|
info.title |
Always set to {{apiTitle}}. |
operationId |
If missing or empty, generated as <method>_<path>-{{consumerphase}} (e.g. get_collection_id-{{consumerphase}}). If present but not ending with -{{consumerphase}}, the suffix is appended. |
summary |
If missing, generated as <METHOD> <path> (e.g. GET /collection/{id}). |
tags |
If missing or empty, set to the first path segment (e.g. /collection/{id} → ["collection"]). |
Schema filtering
When splitting, each output file only includes:
- Directly referenced schemas — any
$refpointing to#/components/schemas/...found in that file's operations. - Transitively referenced schemas — if schema A references schema B, both are included.
- General shared schemas — schemas named
security,error,paginated, ormetadataare always included (if they exist). - Other component types —
securitySchemesare copied to every output file. Other top-level fields (e.g.servers,security) are also preserved.
Path rewriting
| Mode | Input path | Result |
|---|---|---|
Split by tag (tag = collection) |
/collection/{id} |
/{id} |
Split by tag (tag = collection) |
/collection |
/ |
| Split by path | /studies/{id}/results |
Group: studies, path: /{id}/results |
Split by path with --ignore-prefix api/v1 |
/api/v1/studies/{id} |
Group: studies, path: /{id} |
Examples
The example/ directory contains sample output files generated by splitting the included example.openapi.json by tag:
example/
collection.openapi.json
domain.openapi.json
user.openapi.json
workflow.openapi.json
...
To regenerate them:
adp-api-transformer example.openapi.json --split-by-tag
Requirements
- Python 3.9+
- pyyaml
Metadata
Release files for adp-api-transformer 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adp_api_transformer-1.0.6.tar.gz | 9.5 kB | Without provenance | Details for adp_api_transformer-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adp_api_transformer-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for adp_api_transformer-1.0.6-py3-none-any.whl |
Total release size: 17.7 kB
Release files / adp_api_transformer-1.0.6.tar.gz
| Download URL | adp_api_transformer-1.0.6.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c02a0b74cc95c92906afcefb59daaabf87611a8e1c64afb2ff2de87117ad725
|
|
BLAKE2b-256 checksum How to use checksums |
2c68ff8734e8ae6dbaf1a7f0dd897f94904b1cd4d79dc650b9b3397758c7e3ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / adp_api_transformer-1.0.6-py3-none-any.whl
| Download URL | adp_api_transformer-1.0.6-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44379ebc6664461aa293a3e395dfe512ec64bdf450a96bc922753f868deb25f9
|
|
BLAKE2b-256 checksum How to use checksums |
bcc3907e215fc35cf4c83221207fa4e9cead7afb963ec1a77495b66dc8f96acc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for adp-api-transformer 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.