Documentation
¶
Overview ¶
Package schemautil provides utilities for working with OpenAPI schema types.
This package centralizes type assertion patterns for OAS version-specific fields, particularly handling the differences between OAS 2.0/3.0 (string types) and OAS 3.1+ (array types for nullable support).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPrimaryType ¶
GetPrimaryType returns the first non-null type from a schema. This is useful for OAS 3.1+ where type arrays may include "null".
Returns an empty string if the schema is nil or has no types.
func GetSchemaTypes ¶
GetSchemaTypes returns the type(s) from a schema, handling both string (OAS 2.0/3.0) and []any (OAS 3.1+) representations.
Examples:
- OAS 3.0: {"type": "string"} returns ["string"]
- OAS 3.1: {"type": ["string", "null"]} returns ["string", "null"]
func IsNullable ¶
IsNullable checks if the schema allows null values. In OAS 3.1+, this is indicated by "null" in the type array. In OAS 3.0, this is indicated by the nullable field (not checked here).
func IsSingleType ¶
IsSingleType returns true if the schema has exactly one type (not counting null).
Types ¶
This section is empty.