openapi

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 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 SchemaProcessor

type SchemaProcessor struct{}

SchemaProcessor handles OpenAPI schema generation with flexible multipart form support

Supported tags for multipart form control:

Field-level tags:

  • `upload:"file|binary"` - Force field to be treated as binary file upload
  • `upload:"text"` - Force field to be treated as text input in multipart form
  • `format:"binary"` - Mark field as binary (same as upload:"file")
  • `mime:"type"` - Specify MIME type (binary if not text/json/xml)
  • `required:"true"` - Mark field as required
  • `optional:"true"` - Mark field as optional (overrides auto-detection)
  • `doc:"description"` - Field description for OpenAPI

Body-level tags:

  • `contentType:"multipart/form-data"` - Force multipart form (overrides auto-detection)
  • `contentType:"application/json"` - Force JSON (disables auto-detection)

Auto-detection rules (when no explicit contentType is set):

  1. Explicit upload/format tags take precedence
  2. MIME type tags indicating non-text content
  3. Common file field names (file, upload, attachment, image, etc.) with string/[]byte types
  4. []byte fields are always treated as binary in multipart forms

Examples:

type FileUpload struct {
  Body struct {
    File        string `json:"file" format:"binary"`           // Binary file
    Document    string `json:"doc" upload:"file"`              // Binary file
    Description string `json:"desc" upload:"text"`             // Text field
    Avatar      string `json:"avatar" mime:"image/png"`        // Binary by MIME
    Resume      []byte `json:"resume"`                         // Auto-detected binary
    Optional    string `json:"tags" optional:"true"`           // Optional field
  } `contentType:"multipart/form-data"`                        // Explicit multipart
}

func NewSchemaProcessor

func NewSchemaProcessor() *SchemaProcessor

NewSchemaProcessor creates a new schema processor

func (*SchemaProcessor) ProcessOperation

func (p *SchemaProcessor) ProcessOperation(operation *huma.Operation, api huma.API, inputType, outputType reflect.Type, deps []*core.DependencyCore) error

ProcessOperation processes an operation like huma.Register does

Jump to

Keyboard shortcuts

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