schemautil

package
v1.22.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 1 Imported by: 0

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

func GetPrimaryType(schema *parser.Schema) string

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

func GetSchemaTypes(schema *parser.Schema) []string

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 HasType

func HasType(schema *parser.Schema, targetType string) bool

HasType checks if the schema includes the specified type.

func IsNullable

func IsNullable(schema *parser.Schema) bool

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

func IsSingleType(schema *parser.Schema) bool

IsSingleType returns true if the schema has exactly one type (not counting null).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL