Generated Go Structs

How Structs Are Generated

Go structs are produced by oapi-codegen from the bundled OpenAPI specification. For each construct, the generator creates a .go file in models/<version>/<construct>/:

models/v1beta1/connection/
├── connection.go          # Auto-generated — DO NOT edit
└── connection_helper.go   # Manual helpers (SQL, interfaces, etc.)
Never edit generated files Files without the // This is not autogenerated. header are regenerated on every build. Changes will be overwritten.

Generated Struct Pattern

A typical generated struct looks like:

// Connection defines the response schema for a managed connection.
type Connection struct {
    Id          core.Uuid     `json:"id" yaml:"id" db:"id"`
    Name        string        `json:"name" yaml:"name" db:"name"`
    SubType     string        `json:"sub_type" yaml:"sub_type" db:"sub_type"`
    Kind        string        `json:"kind" yaml:"kind" db:"kind"`
    Status      string        `json:"status" yaml:"status" db:"status"`
    Metadata    core.Map      `json:"metadata" yaml:"metadata" db:"metadata"`
    CreatedAt   core.Time     `json:"created_at" yaml:"created_at" db:"created_at"`
    UpdatedAt   core.Time     `json:"updated_at" yaml:"updated_at" db:"updated_at"`
    DeletedAt   core.NullTime `json:"deleted_at" yaml:"deleted_at" db:"deleted_at"`
}

Tag Mapping

Tag Source Purpose
json Schema property name JSON serialization — matches the wire format
yaml Schema property name YAML serialization
db x-oapi-codegen-extra-tags.db Database column mapping for GORM/Pop

The json tag always matches the schema property name exactly. If the property is DB-backed and snake_case, the JSON tag is also snake_case.

Core Types Reference

All core types live in github.com/meshery/schemas/models/core:

Go Type Schema Source Purpose
core.Uuid uuid component UUID string with SQL driver support
core.Id id component Alias for UUID used as primary key
core.Time time / created_at / updated_at Time with custom JSON marshaling
core.NullTime nullTime / deleted_at Nullable time for soft deletes
core.SqlNullTime Legacy deleted_at Backward-compatible nullable time (v1beta1)
core.Map Amorphous JSON objects map[string]interface{} with SQL JSON driver
core.MapObject Typed JSON objects Structured JSON blob with SQL driver

Finding a Struct

To find the Go struct for a specific construct:

  1. Check the API version (usually v1beta1 or v1beta2)
  2. Look in models/<version>/<construct>/<construct>.go
  3. The struct name matches the PascalCase schema component name
# Example: find the Connection struct
cat models/v1beta1/connection/connection.go

Schema-to-Struct Field Mapping

Schema Property Go Field JSON Tag Notes
id (uuid ref) Id core.Uuid json:"id" Primary key
name (string) Name string json:"name"  
created_at (time ref) CreatedAt core.Time json:"created_at" Server-generated
deleted_at (nullTime ref) DeletedAt core.NullTime json:"deleted_at" Soft delete
metadata (Map type) Metadata core.Map json:"metadata" JSON blob
schemaVersion (string) SchemaVersion string json:"schemaVersion" camelCase, non-DB
sub_type (string, DB) SubType string json:"sub_type" snake_case, DB-backed

Payload Structs

For writable entities, a separate *Payload struct is also generated:

// ConnectionPayload is the request body for creating/updating a connection.
type ConnectionPayload struct {
    Id       *core.Uuid `json:"id,omitempty"`
    Name     string     `json:"name"`
    SubType  string     `json:"sub_type"`
    Kind     string     `json:"kind"`
    Metadata core.Map   `json:"metadata,omitempty"`
}

Key differences from the entity struct:

  • No created_at, updated_at, deleted_at
  • Id has omitempty for upsert patterns
  • Only client-settable fields