Jentic OpenAPI Data Models
Project description
from semantic_release.cli.commands.version import build_distributions
jentic-openapi-datamodels
Low-level and high-level data models for OpenAPI specifications.
This package provides data model classes for representing OpenAPI specification objects in Python.
Features
Low-Level Architecture
- Preserve Everything: All data from source documents preserved exactly as-is, including invalid values
- Zero Validation: No validation or coercion during parsing - deferred to higher layers
- Separation of Concerns: Low-level model focuses on faithful representation; validation belongs elsewhere
Source Tracking
- Complete Source Fidelity: Every field tracks its exact YAML node location
- Precise Error Reporting: Line and column numbers via
start_markandend_mark - Metadata Preservation: Full position tracking for accurate diagnostics
Python Integration
- Python-Idiomatic Naming: snake_case field names (e.g.,
bearer_format,property_name) - Spec-Aligned Mapping: Automatic YAML name mapping (e.g.,
bearerFormat↔bearer_format) - Type Safety: Full type hints with Generic types (
FieldSource[T],KeySource[T],ValueSource[T])
Extensibility
- Extension Support: Automatic extraction of OpenAPI
x-*specification extensions - Unknown Field Tracking: Capture typos and invalid fields for validation tools
- Generic Builder Pattern: Core
build_model()function with object-specific builders for complex cases
Performance
- Memory Efficient: Immutable frozen dataclasses with
__slots__for optimal memory usage - Shared Context: All instances share a single YAML constructor for efficiency
Version Support
- OpenAPI 2.0: Planned for future release
- OpenAPI 3.0.x: Currently implemented
- OpenAPI 3.1.x: Planned for future release
- OpenAPI 3.2.x: Planned for future release
Installation
pip install jentic-openapi-datamodels
Prerequisites:
- Python 3.11+
Quick Start
Basic Usage
from ruamel.yaml import YAML
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build
# Parse YAML
yaml = YAML()
root = yaml.compose("""
type: http
scheme: bearer
bearerFormat: JWT
""")
# Build low-level model
security_scheme = build(root)
# Access via Python field names (snake_case)
print(security_scheme.bearer_format.value) # "JWT"
# Access source location information
print(security_scheme.bearer_format.key_node.value) # "bearerFormat"
print(security_scheme.bearer_format.key_node.start_mark.line) # Line number
Field Name Mapping
YAML camelCase fields automatically map to Python snake_case:
bearerFormat→bearer_formatauthorizationUrl→authorization_urlopenIdConnectUrl→openid_connect_url
Special cases for Python reserved keywords/special characters:
$ref→refin→in_
Source Tracking
The package provides three immutable wrapper types for preserving source information:
FieldSource[T] - For OpenAPI fields with key-value pairs
- Used for: Fixed fields (
name,bearer_format) and patterned fields (status codes, path items, schema properties) - Tracks: Both key and value nodes
- Example:
SecurityScheme.bearer_formatisFieldSource[str], response status codes areFieldSource[Response]
KeySource[T] - For dictionary keys
- Used for: keys in OpenAPI fields,
x-*extensions and mapping dictionaries - Tracks: Only key node
- Example: Keys in
Discriminator.mappingareKeySource[str]
ValueSource[T] - For dictionary values and array items
- Used for: values in OpenAPI fields, in
x-*extensions, mapping dictionaries and array items - Tracks: Only value node
- Example: Values in
Discriminator.mappingareValueSource[str]
from ruamel.yaml import YAML
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
from jentic.apitools.openapi.datamodels.low.v30.discriminator import build as build_discriminator
# FieldSource: Fixed specification fields
yaml = YAML()
root = yaml.compose("type: http\nscheme: bearer\nbearerFormat: JWT")
security_scheme = build_security_scheme(root)
field = security_scheme.bearer_format # FieldSource[str]
print(field.value) # "JWT" - The actual value
print(field.key_node) # YAML node for "bearerFormat"
print(field.value_node) # YAML node for "JWT"
# KeySource/ValueSource: Dictionary fields (mapping, extensions)
root = yaml.compose("propertyName: petType\nmapping:\n dog: Dog\n cat: Cat")
discriminator = build_discriminator(root)
for key, value in discriminator.mapping.value.items():
print(key.value) # KeySource[str]: "dog" or "cat"
print(key.key_node) # YAML node for the key
print(value.value) # ValueSource[str]: "Dog" or "Cat"
print(value.value_node) # YAML node for the value
Location Ranges
Access precise location ranges within the source document using start_mark and end_mark:
from ruamel.yaml import YAML
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
yaml_content = """
type: http
scheme: bearer
bearerFormat: JWT
description: Bearer token authentication
"""
yaml = YAML()
root = yaml.compose(yaml_content)
security_scheme = build_security_scheme(root)
# Access location information for any field
field = security_scheme.bearer_format
# Key location (e.g., "bearerFormat")
print(f"Key start: line {field.key_node.start_mark.line}, col {field.key_node.start_mark.column}")
print(f"Key end: line {field.key_node.end_mark.line}, col {field.key_node.end_mark.column}")
# Value location (e.g., "JWT")
print(f"Value start: line {field.value_node.start_mark.line}, col {field.value_node.start_mark.column}")
print(f"Value end: line {field.value_node.end_mark.line}, col {field.value_node.end_mark.column}")
# Full field range (from key start to value end)
start = field.key_node.start_mark
end = field.value_node.end_mark
print(f"Field range: ({start.line}:{start.column}) to ({end.line}:{end.column})")
Invalid Data Handling
Low-level models preserve invalid data:
from ruamel.yaml import YAML
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
yaml = YAML()
root = yaml.compose("bearerFormat: 123") # Wrong type (should be string)
security_scheme = build_security_scheme(root)
print(security_scheme.bearer_format.value) # 123 (preserved as-is)
print(type(security_scheme.bearer_format.value)) # <class 'int'>
Error Reporting
This architecture—where the low-level model preserves data without validation and validation tools consume that data—allows the low-level model to remain simple while enabling sophisticated validation tools to provide user-friendly error messages with exact source locations.
Testing
Run the test suite:
uv run --package jentic-openapi-datamodels pytest packages/jentic-openapi-datamodels -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jentic_openapi_datamodels-1.0.0a16.tar.gz.
File metadata
- Download URL: jentic_openapi_datamodels-1.0.0a16.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec85628f6ba124921a6e67869da9351648286248c4343833468e5641fd03476
|
|
| MD5 |
700032044f39776f1435c50548f2004d
|
|
| BLAKE2b-256 |
a4d9b5f6fe7944d1a01fd454cebd0fa453a696abd1d6f15da29e6dc290c5df2b
|
Provenance
The following attestation bundles were made for jentic_openapi_datamodels-1.0.0a16.tar.gz:
Publisher:
release.yml on jentic/jentic-openapi-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jentic_openapi_datamodels-1.0.0a16.tar.gz -
Subject digest:
eec85628f6ba124921a6e67869da9351648286248c4343833468e5641fd03476 - Sigstore transparency entry: 686356900
- Sigstore integration time:
-
Permalink:
jentic/jentic-openapi-tools@a66b638b1e0bf5cb38e57a604bd0374d3a98b32e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jentic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a66b638b1e0bf5cb38e57a604bd0374d3a98b32e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file jentic_openapi_datamodels-1.0.0a16-py3-none-any.whl.
File metadata
- Download URL: jentic_openapi_datamodels-1.0.0a16-py3-none-any.whl
- Upload date:
- Size: 38.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3844fdc2bdf7d0140a0966771f2e01c901f1f0bdb945b05ba6e1458bd8926e6
|
|
| MD5 |
ca3ad550d2c8f2258d45c4a04c8a91e9
|
|
| BLAKE2b-256 |
b2e0b21e68217f2327da12003f3c3128091fde9cc5e8207668e6a9a6591aaf82
|
Provenance
The following attestation bundles were made for jentic_openapi_datamodels-1.0.0a16-py3-none-any.whl:
Publisher:
release.yml on jentic/jentic-openapi-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jentic_openapi_datamodels-1.0.0a16-py3-none-any.whl -
Subject digest:
c3844fdc2bdf7d0140a0966771f2e01c901f1f0bdb945b05ba6e1458bd8926e6 - Sigstore transparency entry: 686356943
- Sigstore integration time:
-
Permalink:
jentic/jentic-openapi-tools@a66b638b1e0bf5cb38e57a604bd0374d3a98b32e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jentic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a66b638b1e0bf5cb38e57a604bd0374d3a98b32e -
Trigger Event:
workflow_dispatch
-
Statement type: