CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-openapi3-parser

OpenAPI v3 parser that transforms specification documents into structured Python objects for programmatic access and manipulation

Pending
Overview
Eval results
Files

type-system-and-enums.mddocs/

Type System and Enums

The type system provides enumeration classes that define allowed values for various OpenAPI specification fields. These enums ensure type safety and provide validation constraints for data types, formats, HTTP methods, parameter locations, content types, and security configurations.

Capabilities

Schema Data Types

Defines the fundamental data types available for OpenAPI schemas.

class DataType(Enum):
    NULL = "null"
    INTEGER = "integer"
    NUMBER = "number"
    STRING = "string"
    BOOLEAN = "boolean"
    ARRAY = "array"
    OBJECT = "object"
    ONE_OF = "oneOf"
    ANY_OF = "anyOf"

Values:

  • NULL: Null/none type
  • INTEGER: Whole numbers
  • NUMBER: Floating-point numbers
  • STRING: Text values
  • BOOLEAN: True/false values
  • ARRAY: Ordered collections
  • OBJECT: Key-value structures
  • ONE_OF: Exactly one schema must match
  • ANY_OF: One or more schemas must match

Format Types

Integer Formats

Standard format specifications for integer values.

class IntegerFormat(Enum):
    INT32 = "int32"
    INT64 = "int64"

Values:

  • INT32: Signed 32-bit integer (-2³¹ to 2³¹-1)
  • INT64: Signed 64-bit integer (-2⁶³ to 2⁶³-1)

Number Formats

Standard format specifications for floating-point numbers.

class NumberFormat(Enum):
    FLOAT = "float"
    DOUBLE = "double"

Values:

  • FLOAT: Single-precision floating-point
  • DOUBLE: Double-precision floating-point

String Formats

Format specifications for string validation and interpretation.

class StringFormat(Enum):
    BYTE = "byte"
    BINARY = "binary"
    DATE = "date"
    DATETIME = "date-time"
    PASSWORD = "password"
    UUID = "uuid"
    UUID4 = "uuid4"
    EMAIL = "email"
    URI = "uri"
    HOSTNAME = "hostname"
    IPV4 = "ipv4"
    IPV6 = "ipv6"
    URL = "url"

Values:

  • BYTE: Base64-encoded binary data
  • BINARY: Binary data
  • DATE: Full-date (RFC 3339, e.g., "2023-12-25")
  • DATETIME: Date-time (RFC 3339, e.g., "2023-12-25T10:30:00Z")
  • PASSWORD: Password input (UI hint)
  • UUID: Universally unique identifier
  • UUID4: UUID version 4 specifically
  • EMAIL: Email address
  • URI: Universal resource identifier
  • HOSTNAME: Internet hostname
  • IPV4: IPv4 address
  • IPV6: IPv6 address
  • URL: Universal resource locator

HTTP Operations

Defines the supported HTTP methods for API operations.

class OperationMethod(Enum):
    GET = "get"
    PUT = "put"
    POST = "post"
    DELETE = "delete"
    OPTIONS = "options"
    HEAD = "head"
    PATCH = "patch"
    TRACE = "trace"

Values:

  • GET: Retrieve resource
  • PUT: Update/replace resource
  • POST: Create resource or submit data
  • DELETE: Remove resource
  • OPTIONS: Get allowed methods
  • HEAD: Get headers only
  • PATCH: Partial update
  • TRACE: Diagnostic trace

Parameter Locations

Base Location

Base locations for security parameters.

class BaseLocation(Enum):
    HEADER = "header"
    QUERY = "query"
    COOKIE = "cookie"

Parameter Location

All supported parameter locations including path parameters.

class ParameterLocation(Enum):
    HEADER = "header"
    QUERY = "query"
    COOKIE = "cookie"
    PATH = "path"

Values:

  • HEADER: HTTP header parameter
  • QUERY: URL query string parameter
  • COOKIE: HTTP cookie parameter
  • PATH: URL path parameter

Parameter Styles

Path Parameter Styles

Serialization styles for path parameters.

class PathParameterStyle(Enum):
    SIMPLE = "simple"
    LABEL = "label"
    MATRIX = "matrix"

Values:

  • SIMPLE: Simple comma-separated values
  • LABEL: Dot-prefixed values
  • MATRIX: Semicolon-prefixed key-value pairs

Query Parameter Styles

Serialization styles for query parameters.

class QueryParameterStyle(Enum):
    FORM = "form"
    SPACE_DELIMITED = "spaceDelimited"
    PIPE_DELIMITED = "pipeDelimited"
    DEEP_OBJECT = "deepObject"

Values:

  • FORM: Form-style serialization
  • SPACE_DELIMITED: Space-separated values
  • PIPE_DELIMITED: Pipe-separated values
  • DEEP_OBJECT: Deep object serialization

Header Parameter Styles

Serialization styles for header parameters.

class HeaderParameterStyle(Enum):
    SIMPLE = "simple"

Cookie Parameter Styles

Serialization styles for cookie parameters.

class CookieParameterStyle(Enum):
    FORM = "form"

Content Types

Standard MIME content types for request and response bodies.

class ContentType(Enum):
    JSON = "application/json"
    JSON_TEXT = "text/json"
    JSON_ANY = "application/*+json"
    JSON_PROBLEM = "application/problem+json"
    XML = "application/xml"
    FORM = "application/x-www-form-urlencoded"
    MULTIPART_FORM = "multipart/form-data"
    PLAIN_TEXT = "text/plain"
    HTML = "text/html"
    PDF = "application/pdf"
    PNG = "image/png"
    JPEG = "image/jpeg"
    GIF = "image/gif"
    SVG = "image/svg+xml"
    AVIF = "image/avif"
    BMP = "image/bmp"
    WEBP = "image/webp"
    Image = "image/*"
    BINARY = "application/octet-stream"

Security Types

Security scheme types for API authentication.

class SecurityType(Enum):
    API_KEY = "apiKey"
    HTTP = "http"
    OAUTH2 = "oauth2"
    OPEN_ID_CONNECT = "openIdConnect"

Values:

  • API_KEY: API key authentication
  • HTTP: HTTP authentication schemes
  • OAUTH2: OAuth 2.0 authentication
  • OPEN_ID_CONNECT: OpenID Connect authentication

Authentication Schemes

HTTP authentication schemes for security configurations.

class AuthenticationScheme(Enum):
    BASIC = "basic"
    BEARER = "bearer"
    DIGEST = "digest"
    HOBA = "hoba"
    MUTUAL = "mutual"
    NEGOTIATE = "negotiate"
    OAUTH = "oauth"
    SCRAM_SHA1 = "scram-sha-1"
    SCRAM_SHA256 = "scram-sha-256"
    VAPID = "vapid"

OAuth Flow Types

OAuth 2.0 flow types for authentication configuration.

class OAuthFlowType(Enum):
    IMPLICIT = "implicit"
    PASSWORD = "password"
    CLIENT_CREDENTIALS = "clientCredentials"
    AUTHORIZATION_CODE = "authorizationCode"

Values:

  • IMPLICIT: Implicit grant flow
  • PASSWORD: Resource owner password credentials flow
  • CLIENT_CREDENTIALS: Client credentials grant flow
  • AUTHORIZATION_CODE: Authorization code grant flow

Loose Types

For compatibility with non-standard specifications, the library provides loose type definitions that allow custom values beyond the standard enums:

@dataclass
class LooseEnum:
    """Container for non-standard enum values"""
    value: str

# Type aliases for loose validation (all are aliases to LooseEnum)
LooseContentType = LooseEnum
LooseIntegerFormat = LooseEnum
LooseNumberFormat = LooseEnum  
LooseStringFormat = LooseEnum

Usage Examples

Working with enums:

from openapi_parser import parse
from openapi_parser.enumeration import DataType, OperationMethod, ContentType

spec = parse('api-spec.yml')

# Check data types in schemas
for name, schema in (spec.schemas or {}).items():
    print(f"Schema {name}: {schema.type.value}")
    
    # Type-specific handling
    if schema.type == DataType.STRING:
        print(f"  String schema with format: {getattr(schema, 'format', 'none')}")
    elif schema.type == DataType.ARRAY:
        print(f"  Array with item type: {schema.items.type.value}")

# List HTTP methods used
methods_used = set()
for path in spec.paths:
    for operation in path.operations:
        methods_used.add(operation.method)

print("HTTP methods used:")
for method in sorted(methods_used, key=lambda m: m.value):
    print(f"  {method.value.upper()}")

# Find content types
content_types_used = set()
for path in spec.paths:
    for operation in path.operations:
        if operation.request_body:
            for content in operation.request_body.content:
                if isinstance(content.type, ContentType):
                    content_types_used.add(content.type.value)

print("Content types used:")
for ct in sorted(content_types_used):
    print(f"  {ct}")

Enum validation and loose types:

# With strict enum validation (default)
spec_strict = parse('api-spec.yml', strict_enum=True)

# With loose enum validation (allows custom values)
spec_loose = parse('api-spec.yml', strict_enum=False)

# Check for loose types
for path in spec_loose.paths:
    for operation in path.operations:
        if operation.request_body:
            for content in operation.request_body.content:
                if isinstance(content.type, str):
                    print(f"Custom content type: {content.type}")

Install with Tessl CLI

npx tessl i tessl/pypi-openapi3-parser

docs

core-parsing.md

index.md

operations-and-paths.md

schema-system.md

security-system.md

specification-structure.md

type-system-and-enums.md

tile.json