any2tosca
any2tosca turns the schemas you already have into TOSCA 2.0 types. API definitions, hardware models and network data models already describe the resources a system is built from; any2tosca converts them into TOSCA data types and node types, so the types a TOSCA profile needs are generated from the source of truth rather than written by hand. The generated types can then be checked with tosca-core, the open-source TOSCA parser and validator.
| Command | Input format |
|---|---|
any2tosca |
JSON Schema |
oas2tosca |
OpenAPI 2.0 / 3.x |
redfish2tosca |
Redfish JSON Schema |
yang2tosca |
YANG modules |
A quick example
Given server.json:
{
"title": "Server",
"type": "object",
"properties": {
"name": {"type": "string"},
"cpus": {"type": "integer", "minimum": 1, "maximum": 64},
"disk": {"type": "string", "enum": ["ssd", "hdd"]}
},
"required": ["name", "cpus"]
}
any2tosca server.json writes tosca/server.yaml:
tosca_definitions_version: tosca_2_0
description: >-
Types generated from JSON Schema by any2tosca
data_types:
Server:
description: >-
Server
properties:
name:
type: string
required: true
cpus:
type: integer
required: true
validation:
$and:
- $greater_or_equal:
- $value
- 1
- $less_or_equal:
- $value
- 64
disk:
type: string
required: false
validation:
$valid_values:
- $value
- - ssd
- hdd
Installation
any2tosca needs Python 3.10 or later and is installed from a checkout:
git clone https://github.com/ubicity-corp/any2tosca
cd any2tosca
pip install .
For development, with the test tools, use pip install -e ".[dev]" instead.
Usage
Each command takes input files or directories and writes one TOSCA file per input file, with the same base name, into the output directory:
any2tosca my_schema.json # writes tosca/my_schema.yaml
any2tosca schemas/ -o tosca/ # every schema in a directory
oas2tosca openapi.yaml -o tosca/
redfish2tosca ComputerSystem.v1_20_0.json -I /path/to/DMTF/json-schema -o tosca/
yang2tosca server.yang -o tosca/
| Option | |
|---|---|
-o DIR, --output DIR |
the output directory (default: tosca/) |
-I DIR, --include-dir DIR |
another directory to search for referenced schema files; repeatable |
-v, --verbose |
list the types as they are converted |
A schema that references another file becomes a TOSCA file that imports the
other one's output, by url and with a namespace. Referenced files are
looked for beside the input file first, then in each -I directory. TOSCA does
not allow circular imports, so reference cycles between files are broken
during conversion (docs/circular-import-algorithm.md).
What it generates
- Data types for objects, enumerations and constrained scalars. Object
types are derived from a parent only where the schema names one (a single
$refinallOf,anyOforoneOf); scalars derive from their TOSCA primitive type. - Node types for the schemas that describe resources, as each format
identifies them: OpenAPI request bodies of
POSToperations, the Redfish resource a schema file defines, and top-level YANG containers and lists. Plain JSON Schema produces data types only. - Capabilities and requirements that let node types be connected. Every
node type gets a
featureand acontainablecapability, whose types are written to a companion file,<name>_caps.yaml, so that other files can target the node type without importing it. A property whose value is another node type becomes a requirement, with aContainsorDependsOnrelationship.
For example, an OpenAPI document whose POST /servers takes a Server produces:
imports:
- url: Core.yaml
namespace: core
- url: servers_caps.yaml
namespace: srvrscps
node_types:
Server:
properties:
name:
type: string
required: true
cpus:
type: integer
required: false
validation:
$greater_or_equal:
- $value
- 1
capabilities:
feature:
type: srvrscps:ServerFeature
containable:
type: srvrscps:ServerContainable
The base types: Core.yaml
Node types build on four base types that any2tosca does not generate: the
Feature and Containable capability types and the Contains and
DependsOn relationship types. Output with node types imports them from a
Core.yaml beside it, which you provide:
tosca_definitions_version: tosca_2_0
relationship_types:
Contains: {}
DependsOn: {}
capability_types:
Containable: {}
Feature: {}
Importing these types from a named profile instead, with an option to choose the profile, is planned.
Using the output
The generated files are TOSCA type definitions. They declare no profile:
name, so they are used in one of two ways:
- Imported by a profile or service template of your own, through an
importsentry with the file'surl. - As a profile of their own: add a
profile:line naming it (for exampleprofile: com.example.servers:1.0) to the main file, and it can be validated and onboarded as a profile.
tosca-core checks the result
against TOSCA's rules. A single file with a profile: line is validated
directly:
pip install tosca-core
tosca-validate tosca/server.yaml
Output of several files (node types, their _caps.yaml and Core.yaml) is
validated as a directory holding them, with a TOSCA.meta that names the main
file:
TOSCA-Meta-File-Version: 1.1
CSAR-Version: 2.0
Created-By: any2tosca
Entry-Definitions: servers.yaml
An option that writes the profile: line, and packages the output as a CSAR,
is planned.
Conversion reference
JSON Schema → TOSCA
| JSON Schema | TOSCA |
|---|---|
type: string |
type: string |
type: integer |
type: integer |
type: number |
type: float |
type: boolean |
type: boolean |
type: object |
data_type with properties |
type: array |
type: list with entry_schema |
properties |
properties |
required |
required: true/false per property |
default |
default |
description / title |
description (folded block style) |
minimum / maximum |
$greater_or_equal / $less_or_equal |
exclusiveMinimum/Maximum |
$greater_than / $less_than |
minLength / maxLength |
$min_length / $max_length |
enum |
$valid_values |
pattern |
$pattern |
items |
entry_schema |
additionalProperties |
entry_schema |
$ref (local) |
resolved inline |
$ref (external file) |
namespace:TypeName + imports entry |
allOf with single $ref |
derived_from |
allOf with mixed schemas |
merged properties |
anyOf / oneOf with null alternative |
flattened to non-null member |
anyOf / oneOf with single $ref |
derived_from |
anyOf / oneOf with versioned $refs (same base name) |
highest version → derived_from |
anyOf / oneOf with versioned + unversioned $refs |
highest versioned → derived_from, unversioned properties merged |
anyOf / oneOf with multiple unversioned $refs |
first $ref → derived_from, rest merged |
definitions / $defs |
top-level data_types entries |
docs/jsonschema.md is a reference to the JSON Schema keywords themselves.
OpenAPI → TOSCA
oas2tosca converts the schemas of an OpenAPI 2.0 (definitions) or 3.x
(components.schemas) document with the JSON Schema rules above. A schema
used as the request body of a POST operation, the thing the API creates,
becomes a node type; the rest become data types.
Redfish → TOSCA
redfish2tosca first normalizes a Redfish schema into plain JSON Schema,
dropping OData annotations and flattening nullable alternatives, then converts
it. The resource a schema file defines becomes a node type; a family of
versioned schemas (Drive.v1_13_0.json, Drive.v1_14_0.json, ...) becomes a
chain of derived_from types; Links become DependsOn requirements; and
Actions become an interface type.
docs/redfish-conversion.md describes every step.
YANG → TOSCA
| YANG | TOSCA |
|---|---|
typedef |
data_type |
container (top-level) |
node_type |
list (top-level) |
node_type |
container (nested) |
inline data_type |
list (nested) |
list property with entry_schema |
leaf |
scalar property |
leaf-list |
list property |
grouping / uses |
inlined by pyang before conversion |
enumeration |
$valid_values constraint |
range |
$greater_or_equal / $less_or_equal |
length |
$min_length / $max_length |
pattern |
$pattern |
mandatory true |
required: true |
| Named typedef ref | $ref → resolved data_type |
YANG integer types (int8–int64, uint8–uint64) map to TOSCA integer;
decimal64 maps to float; all string-like types map to string.
Limitations
- JSON Schema keywords left out of the conversion:
const,format,multipleOf,minItems/maxItems,uniqueItems,patternProperties,if/then/else,not,readOnly/writeOnly, and OpenAPI'sdiscriminator. The values they constrain are converted; the constraints they add are not. - Kubernetes: the Kubernetes OpenAPI definitions convert like any other OpenAPI document, into one set of types. Splitting them into one profile per API group, as oas2tosca does for the Kubernetes profiles, is not yet supported.
Python API
Each command is also available from Python. These functions and classes are not yet a stable API: they may change in any release before 1.0.
JSON Schema
import json
from pathlib import Path
from any2tosca import convert_schema, build_tosca_document
from any2tosca.yaml_utils import dump_tosca_yaml
with open("my_schema.json") as f:
root_schema = json.load(f)
result = convert_schema(root_schema, top_name="MyType",
base_path=Path("my_schema.json").parent)
tosca_doc = build_tosca_document(result.data_types, result.node_types,
result.imports or None)
print(dump_tosca_yaml(tosca_doc))
OpenAPI
import json
from any2tosca.openapi import OpenAPIExtractor
from any2tosca import convert_schema, build_tosca_document
from any2tosca.yaml_utils import dump_tosca_yaml
with open("openapi.json") as f:
doc = json.load(f)
root_schema, node_type_names = OpenAPIExtractor().extract(doc)
result = convert_schema(root_schema, "api", node_type_names)
print(dump_tosca_yaml(build_tosca_document(result.data_types, result.node_types)))
Redfish
import json
from pathlib import Path
from any2tosca.redfish import RedfishNormalizer
from any2tosca import convert_schema, build_tosca_document
from any2tosca.yaml_utils import dump_tosca_yaml
with open("SimpleServer.v1_0_1.json") as f:
schema = json.load(f)
root_schema, node_type_names = RedfishNormalizer().normalize(schema)
result = convert_schema(root_schema, "SimpleServer", node_type_names,
base_path=Path("SimpleServer.v1_0_1.json").parent)
print(dump_tosca_yaml(build_tosca_document(result.data_types, result.node_types,
result.imports or None)))
YANG
from pathlib import Path
from any2tosca.yang import YANGNormalizer
from any2tosca import convert_schema, build_tosca_document
from any2tosca.yaml_utils import dump_tosca_yaml
yang_path = Path("server.yang")
normalizer = YANGNormalizer()
root_schema, node_type_names = normalizer.normalize(yang_path)
result = convert_schema(root_schema, normalizer.module_name, node_type_names,
base_path=yang_path.parent)
print(dump_tosca_yaml(build_tosca_document(result.data_types, result.node_types)))
Running tests
pip install -e ".[dev]"
pytest
Contributing
Report a problem or ask a question by opening an issue. Changes come as pull
requests, with a test that pins what they fix and pytest passing. Report a
security vulnerability privately, through the repository's Security tab,
rather than in an issue.
License
Apache License 2.0; see LICENSE.
Metadata
Release files for any2tosca 0.1.0
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 |
|---|---|---|---|---|
| any2tosca-0.1.0.tar.gz | 56.9 kB | With provenance | Details for any2tosca-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| any2tosca-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for any2tosca-0.1.0-py3-none-any.whl |
Total release size: 101.4 kB
Release files / any2tosca-0.1.0.tar.gz
| Download URL | any2tosca-0.1.0.tar.gz |
|---|---|
| Size | 56.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
866ab12df113bb348a8360a0604fbd7af68d0240d7914a4f08bbcea7542d3611
|
|
BLAKE2b-256 checksum How to use checksums |
7bb8d0397c33deaad56a07c5947486a102e45390558e20d3af8ed07826786cdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / any2tosca-0.1.0-py3-none-any.whl
| Download URL | any2tosca-0.1.0-py3-none-any.whl |
|---|---|
| Size | 44.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8622b8a2c5d01c94b6b00a6efc406ce4164f1052c399fb52df12e4b26b8cb6c
|
|
BLAKE2b-256 checksum How to use checksums |
f1e56c409a168bc037e2a7da5568fee7f830ce6ced2a1cb320e96e6d8d27f0a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for any2tosca 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for any2tosca-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA 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.