schema

package
v2.1.93 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body struct {
	Value  json.RawMessage
	Schema *Schema
}

Body is a struct that represents a request body.

type Discriminator

type Discriminator struct {
	// PropertyName is the JSON property name that holds the discriminator value
	PropertyName string

	// Mapping maps discriminator values to property names in the schema
	// For example: {"simple": "nodeType", "compound": "nodeType"}
	// The keys are the valid discriminator values
	Mapping map[string]string
}

Discriminator describes a discriminator for oneOf/anyOf schemas. It maps discriminator values to the property names that should be used.

type GeneratedRequest

type GeneratedRequest struct {
	Path        string          `json:"path"`
	ContentType string          `json:"contentType,omitempty"`
	Headers     any             `json:"headers,omitempty"`
	Body        json.RawMessage `json:"body,omitempty"`
}

GeneratedRequest is a struct that represents a generated mock request.

type Headers

type Headers struct {
	Value  http.Header
	Schema *Schema
}

Headers is a struct that represents a header parameter.

type Operation

type Operation struct {
	ID string `json:"id,omitempty"`

	// Content-Type of the request body (e.g., "application/json")
	ContentType string          `json:"contentType,omitempty"`
	Method      string          `json:"method,omitempty"`
	Path        string          `json:"path,omitempty"`
	PathParams  *Schema         `json:"pathParams,omitempty"`
	Query       QueryParameters `json:"query,omitempty"`
	Headers     *Schema         `json:"headers,omitempty"`
	Body        *Schema         `json:"body,omitempty"`

	// Encoding metadata for form fields
	BodyEncoding map[string]codegen.RequestBodyEncoding `json:"bodyEncoding,omitempty"`
	Response     *Response                              `json:"response,omitempty"`
}

Operation represents an OpenAPI operation (endpoint).

type Parameter

type Parameter struct {
	Type  ParameterType
	Value any
}

Parameter represents a single parameter with its type and value.

type ParameterType

type ParameterType string

ParameterType represents the type/location of a parameter.

const (
	ParameterTypePath   ParameterType = "path"
	ParameterTypeQuery  ParameterType = "query"
	ParameterTypeHeader ParameterType = "header"
)

type Path

type Path struct {
	Value   string
	Schema  *Schema
	Pattern string
}

Path is a struct that represents a path parameter.

type Query

type Query struct {
	Value  string
	Schema *Schema
}

Query is a struct that represents a query parameter.

type QueryParameter

type QueryParameter struct {
	Schema   *Schema                    `json:"schema,omitempty"`
	Required bool                       `json:"required,omitempty"`
	Encoding *codegen.ParameterEncoding `json:"encoding,omitempty"`
}

QueryParameter represents a single query parameter.

type QueryParameters

type QueryParameters map[string]*QueryParameter

QueryParameters is a map of parameter name to parameter info.

type RequestData

type RequestData struct {
	Method     string                // HTTP method (GET, POST, PUT, etc.)
	ResourceID string                // The operation path pattern with placeholders (e.g., /users/{id})
	Params     map[string]*Parameter // All parameters (path, query, header) with their types
	Body       any                   // Parsed request body (can be map[string]any for objects, []any for arrays, or primitives)
}

RequestData represents the actual parsed request data from an HTTP request.

type RequestSchema

type RequestSchema struct {
	URL     string
	Method  string
	Path    *Path
	Body    *Body
	Query   *Query
	Headers *Headers
}

RequestSchema is a struct that represents an OpenAPI request needed to generate a response.

type Response

type Response struct {
	All         map[int]*ResponseItem `json:"all.omitempty"`
	SuccessCode int                   `json:"successCode,omitempty"`
}

Response is a struct that represents an OpenAPI Response.

func NewResponse

func NewResponse(all map[int]*ResponseItem, successCode int) *Response

NewResponse creates a new Response instance.

func (*Response) GetResponse

func (r *Response) GetResponse(code int) *ResponseItem

GetResponse returns the response for the given status code.

func (*Response) GetSuccess

func (r *Response) GetSuccess() *ResponseItem

GetSuccess returns the success response.

type ResponseData

type ResponseData struct {
	Body    json.RawMessage `json:"body,omitempty"`
	Headers http.Header     `json:"headers,omitempty"`
	IsError bool            `json:"isError,omitempty"`
}

ResponseData is a struct that represents a generated response.

type ResponseItem

type ResponseItem struct {
	Headers     map[string]*Schema `json:"headers,omitempty"`
	Content     *Schema            `json:"content,omitempty"`
	ContentType string             `json:"contentType,omitempty"`
	StatusCode  int                `json:"statusCode,omitempty"`
}

ResponseItem represents a single response for a specific status code.

type ResponseSchema

type ResponseSchema struct {
	ContentType string
	Body        *Schema
	Headers     map[string]*Schema
	Error       *Schema
}

ResponseSchema is a struct that represents a schema needed to generate a response.

type Schema

type Schema struct {
	Type string `yaml:"type,omitempty"`

	// in 3.1 examples can be an array (which is recommended)
	Examples []any `yaml:"examples,omitempty"`

	// items can be a schema in 2.0, 3.0 and 3.1 or a bool in 3.1
	Items *Schema `yaml:"items,omitempty"`

	// Compatible with all versions
	MultipleOf           *float64           `yaml:"multipleOf,omitempty"`
	Maximum              *float64           `yaml:"maximum,omitempty"`
	ExclusiveMaximum     *float64           `yaml:"exclusiveMaximum,omitempty"`
	Minimum              *float64           `yaml:"minimum,omitempty"`
	ExclusiveMinimum     *float64           `yaml:"exclusiveMinimum,omitempty"`
	MaxLength            *int64             `yaml:"maxLength,omitempty"`
	MinLength            *int64             `yaml:"minLength,omitempty"`
	Pattern              string             `yaml:"pattern,omitempty"`
	Format               string             `yaml:"format,omitempty"`
	MaxItems             *int64             `yaml:"maxItems,omitempty"`
	MinItems             *int64             `yaml:"minItems,omitempty"`
	MaxProperties        *int64             `yaml:"maxProperties,omitempty"`
	MinProperties        *int64             `yaml:"minProperties,omitempty"`
	Required             []string           `yaml:"required,omitempty"`
	Enum                 []any              `yaml:"enum,omitempty"`
	Properties           map[string]*Schema `yaml:"properties,omitempty"`
	Default              any                `yaml:"default,omitempty"`
	Nullable             bool               `yaml:"nullable,omitempty"`
	ReadOnly             bool               `yaml:"readOnly,omitempty"`
	WriteOnly            bool               `yaml:"writeOnly,omitempty"`
	Example              any                `yaml:"example,omitempty"`
	Deprecated           bool               `yaml:"deprecated,omitempty"`
	AdditionalProperties *Schema            `yaml:"additionalProperties,omitempty"`

	// Discriminator describes the discriminator for oneOf/anyOf schemas.
	// When set, the generator should use one of the valid discriminator values
	// for the discriminator property instead of generating a random value.
	Discriminator *Discriminator `yaml:"-" json:"-"`

	// Recursive indicates this schema was truncated due to circular reference.
	// The content generator should return nil for such schemas.
	Recursive bool `yaml:"-" json:"-"`

	// StaticContent holds pre-rendered content for static responses.
	// When set, the generator should return this content directly instead of generating.
	// This is used for static services where responses are pre-defined files.
	StaticContent string `yaml:"-" json:"-"`
}

Schema is a struct that represents an OpenAPI schema. It is compatible with all versions of OpenAPI. All schema provider should implement the Document and KinOperation interfaces. This provides a unified way to work with different OpenAPI parsers.

func BuildSchemaFromContent

func BuildSchemaFromContent(content []byte, contentType string) (*Schema, error)

BuildSchemaFromContent creates a Schema from static content. It infers the schema structure from the content based on the content type. The original content is stored in StaticContent for direct return.

Jump to

Keyboard shortcuts

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