Meshery Schemas
Meshery follows schema-driven development. As a project, Meshery has different types of schemas. Some schemas are external facing, and some internal to Meshery itself. This repository serves as a central location for storing schemas from which all Meshery components can take reference.
Meshery schemas offer a powerful system designed for:
- Model-Driven Management: Meshery uses explicit models for describing infrastructure and applications.
- Dynamic Discovery: The ability to process different kinds of relationships and styles, enables a sophisticated system that can adapt to many configurations.
- Lifecycle Management: The schema properties track status and lifecycle of resources.
- Extensibility: Open-ended metadata and modular schema components enable expansion and customization.
- Visual Representation: The properties for styling of edges and nodes is for creating a user friendly visual representation.
- Automated Operations: The schemas can support validation and automated configuration of infrastructure and applications, and patching.
For an explanation of Meshery's terminology regarding schemas, definitions, declarations, and instances, please see Contributor's Guide to Models.
For identifier-naming rules (wire casing, DB tag separation, URL/path/query-param conventions, operationId form), see docs/identifier-naming-contributor-guide.md — the canonical, reader-friendly directory for the camelCase-on-the-wire contract that this repository and every downstream consumer share.
Contributing
--> For an explanation of the directory structure of this repository and how to contribute changes to Meshery's schemas, see Contributor's Guide to Schema-Driven Development.
Join the Meshery community!
Our projects are community-built and welcome collaboration. 👍 Be sure to see the Contributor Welcome Guide and Community Handbook for a tour of resources available to you. Jump into community Slack or discussion forum to participate.
Find out more on the Meshery community.
Contributing
Please do! We're a warm and welcoming community of open source contributors. All types of contributions are welcome. Please read:
- General Contributor Guide - Overview of contribution processes
- Schema Contributor Guide - Schema-specific development workflows and guidelines
🧬 Schema-Driven Development Guide
Meshery follows a Schema-Driven Development (SDD) approach. This means that the structure of data used throughout the system is centrally defined using schemas. These schemas power consistency, validation, and code generation across the Meshery platform.
🧾 Schema Definition in Meshery
Meshery uses the OpenAPI v3 specification to define and manage schemas. Given the complexity of the platform, Meshery adopts a modular, versioned, and extensible schema strategy:
- ✅ Versioned schemas for backward compatibility.
- 🧩 Modular constructs for maintainability and reuse.
- 🧪 Schemas are used for validation, API documentation, and automatic code generation.
💡 TIP: When referencing models or other constructs in the schema, always add x-go-type and x-go-import-path to avoid generating redundant Go structs. Refer to existing patterns in the codebase.
📁 Schema Directory Structure
All schemas are located in the schemas/ directory at the root of the Meshery repository:
schemas/
constructs/
<schema-version>/ # e.g., v1beta1
<construct>/ # e.g., model, component
api.yml # Index file: references all subschemas + defines API endpoints
<construct>.yaml # Subschema: data model definition for the construct
<other_subschema>.yaml # Additional subschemas (optional)
templates/ # Manually defined templates directory
<construct>_template.json # JSON template from schema
<construct>_template.yaml # YAML template from schema
<variant>_template.json # Additional variant templates (optional)
typescript/ # TypeScript source and generated files
index.ts # Manually maintained - public API surface
generated/ # Auto-generated (do NOT commit)
<schema-version>/
<construct>/
<Construct>.d.ts # TypeScript type definitions
<Construct>Schema.ts # OpenAPI schema as JS object
rtk/ # RTK Query client configurations
cloud.ts
meshery.ts
python/ # Python source and generated files
generated/ # Auto-generated distribution (commit regenerated output when a bundled pilot spec changes)
pyproject.toml # Hand-maintained scaffold (hatchling, meshery-schemas)
src/meshery_schemas/
<construct>/ # Generated client per pilot construct
tests/ # Hand-maintained pytest suites
rust/ # meshery-schemas crate (commit regenerated output when a bundled pilot spec changes)
Cargo.toml, Cargo.lock # Hand-maintained scaffold (crate identity, dependencies, features)
src/lib.rs # Hand-maintained scaffold (declares the construct modules)
src/<construct>/ # Generated models (types/) and async client (mod.rs) per pilot construct
tests/ # Hand-maintained cargo integration tests
dist/ # Built distribution (do NOT commit)
index.js, index.d.ts
cloudApi.js, mesheryApi.js
constructs/ # Built schema exports (renamed from 'generated')
<schema-version>/<construct>/<Construct>Schema.js
models/ # Auto-generated Go code (do NOT commit)
<schema-version>/
<construct>/
<construct>.go
🧠 Explanation
constructs/ – Holds schemas for various versions.
<schema-version>/ – Represents a version (e.g., v1alpha2, v1beta1).
<construct>/ – A directory to contain all files for any given construct like pattern, component, etc.
api.yml – The index file for the construct. This file:
- References all subschemas (via
$ref) to bundle them together
- Defines all API endpoints (REST operations: GET, POST, PUT, DELETE) for the construct
- Serves as the entry point for code generation tools (oapi-codegen, openapi-typescript)
<construct>.yaml – A subschema that defines the data model (noun) for the construct. Contains the schema properties, types, and validation rules.
- Other
.yaml files – Additional subschemas can be defined in separate files (e.g., model_core.yml, component_metadata.yml) and referenced from api.yml.
templates/ – A subdirectory containing manually defined template files. You can add as many different templates here for different variants, use cases, or configurations. Templates are example instances of the schema with default or sample values.
<construct>_template.json / <construct>_template.yaml – Default templates in JSON/YAML format.
- Additional variant templates can be added (e.g.,
<construct>_minimal_template.json, <construct>_full_template.yaml) for different use cases.
Schema Design Principles: The Dual-Schema Pattern
Every persisted entity in Meshery follows a strict two-schema contract. Violating this contract causes generated Go structs and API clients to be incorrect.
Rule 1 — Entity schema = response schema only
The <construct>.yaml file represents the full server-side object as returned in API responses. It must:
- Include all server-generated fields:
id, created_at, updated_at, deleted_at
- List server-generated required fields in
required (they are always present in responses)
- Have
additionalProperties: false at the top level
# keychain.yaml — response schema ✅
type: object
additionalProperties: false
required:
- id
- name
- owner
- created_at
- updated_at
properties:
id:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/uuid
name:
type: string
owner:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/uuid
created_at:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/created_at
updated_at:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/updated_at
deleted_at:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/nullTime
Rule 2 — Write operations use a separate *Payload schema
Every entity that supports POST or PUT must define a dedicated {Entity}Payload schema in api.yml. The payload schema:
- Contains only client-settable fields (no
created_at, updated_at, deleted_at)
- Makes
id optional with omitempty for upsert patterns, or omits it entirely for create-only
- Is referenced by
requestBody in POST/PUT operations
- Is never reused as a response body
# In api.yml — write schema ✅
components:
schemas:
KeychainPayload:
type: object
description: Payload for creating or updating a keychain.
required:
- name
properties:
id:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/uuid
description: Existing keychain ID for updates; omit on create.
x-oapi-codegen-extra-tags:
json: "id,omitempty"
name:
type: string
description: Name of the keychain.
owner:
$ref: ../../v1alpha1/core/api.yml#/components/schemas/uuid
description: Owner UUID; set server-side from auth context if omitted.
x-oapi-codegen-extra-tags:
json: "owner,omitempty"
paths:
/api/auth/keychains:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/KeychainPayload" # ← Payload, not Keychain
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Keychain" # ← Full entity in response
Rule 3 — Never use the entity schema as a POST/PUT request body
Using the full entity schema as a requestBody forces clients to supply server-generated fields (id, created_at, updated_at) and produces incorrect generated client code.
# ❌ Wrong — exposes server-generated required fields to clients
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Keychain"
# ✅ Correct — separate payload type for writes
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/KeychainPayload"
Checklist when adding a new entity
- [ ]
<construct>.yaml has additionalProperties: false
- [ ]
<construct>.yaml lists all server-generated fields in properties and required
- [ ]
api.yml defines a {Construct}Payload schema with only client-settable fields
- [ ] All
POST/PUT requestBody entries reference {Construct}Payload, not {Construct}
- [ ]
GET responses reference the full {Construct} entity schema
Naming Conventions
This section is the inline authority; for the reader-friendly directory (26-row naming table with before/after and do/don't examples), see docs/identifier-naming-contributor-guide.md.
-
Property names
- Use camelCase for property fields (e.g.,
schemaVersion, displayName, componentsCount).
- Identifier fields use lowerCamelCase with "Id" suffix (e.g.,
modelId, registrantId, categoryId).
- Enums use lowercase words (e.g.,
enabled, ignored, duplicate).
- Use singular nouns for object names (e.g.,
model, component, design).
-
OpenAPI schema names
- PascalCase nouns under
components/schemas (e.g., Model, Component).
- Files/folders are lowercase:
api.yml (index), <construct>.yaml (subschemas), templates/<construct>_template.(json|yaml).
-
Endpoints and operations
- Paths are under
/api with kebab-case , plural nouns (e.g., /api/workspaces, /api/environments).
- Path params are camelCase (e.g.,
{subscriptionId}, {connectionId}).
- Non-CRUD actions append a verb segment (e.g.,
.../register, .../export, .../cancel); legacy lowerCamelCase may appear (e.g., .../upgradePreview).
operationId is camelCase VerbNoun (e.g., registerMeshmodels).
-
Versioning
schemaVersion uses group/version (e.g., models.meshery.io/v1beta1, components.meshery.io/v1beta1).
- Version strings follow k8s-style (
v1, v1alpha1, v1beta1); semver fields use standard SemVer.
🔧 Go Helper Files
While Go structs are auto-generated from schemas, you often need to add custom methods to make these structs compatible with databases, implement interfaces, or add utility functions. This is done through manually created helper files.
When to Create Helper Files
Create a helper file (*_helper.go or helpers.go) in the generated package when you need:
- SQL Driver Compatibility - Implement
database/sql/driver.Scanner and driver.Valuer interfaces
- Entity Interface Implementation - Implement the
entity.Entity interface for database operations
- GORM Table Names - Define custom table names via
TableName() method
- Utility Methods - Add helper functions for serialization, validation, or business logic
- Type Conversions - Add methods to convert between related types
Helper File Location
models/
├── core/
│ ├── core.go # Auto-generated (do NOT edit)
│ ├── helpers.go # Manual: utility functions
│ ├── datatype_map.go # Manual: Map type with SQL driver methods
│ └── datatype_null_time.go # Manual: NullTime with SQL driver methods
├── v1beta1/
│ ├── model/
│ │ ├── model.go # Auto-generated (do NOT edit)
│ │ └── model_helper.go # Manual: Entity interface, TableName, etc.
│ ├── component/
│ │ ├── component.go # Auto-generated (do NOT edit)
│ │ └── component_helper.go # Manual: Entity interface, TableName, etc.
│ └── category/
│ ├── category.go # Auto-generated (do NOT edit)
│ └── category_helper.go # Manual: Entity interface, TableName, etc.
SQL Driver Interface Implementation
To store complex types in SQL databases, implement Scan and Value methods:
// helpers.go - This is NOT autogenerated
package mypackage
import (
"database/sql/driver"
"encoding/json"
"github.com/meshery/schemas/models/core"
)
// Scan implements sql.Scanner interface for reading from database
func (m *MyComplexType) Scan(value interface{}) error {
mapVal := core.Map{}
err := mapVal.Scan(value)
if err != nil {
return err
}
return core.MapToStruct(mapVal, m)
}
// Value implements driver.Valuer interface for writing to database
func (m MyComplexType) Value() (driver.Value, error) {
mapVal, err := core.StructToMap(m)
if err != nil {
return nil, err
}
return core.Map(mapVal).Value()
}
Entity Interface Implementation
For structs that need database CRUD operations, implement the entity.Entity interface: