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.
The schemas follow a versioned approach to maintain backward compatibility while allowing for evolution of the definitions.
To better understand how schemas fit into Meshery's architecture, read about Meshery's core concepts in the Meshery documentation.`
- oapi-codegen: This tool is essential for generating Go code from OpenAPI specifications. Install it using:
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
- make: The repository uses Makefiles to automate various tasks. Ensure you have make installed on your system.
When you work with the schemas, you'll frequently use this essential command:
make resolve-ref path="./schemas/constructs/[version]"
Key functions:
- Resolves
$ref
references between schema files - Adds code generation metadata tags
- Creates complete, self-contained schemas
- Validates reference consistency
Example: Consider this schema snippet with an external reference:
"capabilities": {
"type": "array",
"description": "Meshery manages components...",
"items": {
"$ref": "../v1alpha1/capability.json" // reference here
}
}
After running the command, it becomes a complete, self-contained schema:
"capabilities": {
"type": "array",
"description": "Meshery manages components...",
"items": {
"$id": "https://schemas.meshery.io/capability.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Meshery manages entities...",
"additionalProperties": false,
"type": "object",
"required": [
"schemaVersion",
"version",
"displayName",
"kind",
"type",
"entityState",
"status"
],
"x-oapi-codegen-extra-tags": { // additional metadata tag
"gorm": "type:bytes;serializer:json"
}
}
}
When to run this command? Whenever you:
- Modify schema files
- Add new schema references
- Before generating Go code
- When troubleshooting code generation issues
The code generation process uses two key configuration files:
- scripts/config.yml: Controls oapi-codegen behavior
package: organization # Set your desired package name
generate:
models: true # Generate model structs
import-mapping: # Map schema references to Go imports
"../v1beta1/model.json": "github.com/meshery/schemas/models/v1beta1/model"
"../v1alpha1/capability.json": "github.com/meshery/schemas/models/v1alpha1/capability"
output: models/v1beta1/organization.go # Specify output file
output-options:
skip-prune: true
include-tags: # Filter generated code by tags
- organizations
- schemas/constructs/openapi/models.yml: Defines OpenAPI schema references
openapi: 3.0.0
components:
schemas:
component_definition:
$ref: ../[version]/component.json
- Update schema references in models.yml:
- Uncomment/add needed schema references
- Each reference generates corresponding Go structs
- Modify config.yml:
- Set appropriate package name
- Update output file path
- Add required import mappings
- Configure include-tags if needed
- Generate code:
oapi-codegen -config scripts/config.yml schemas/constructs/openapi/models.yml
Key Points:
- Run
make resolve-ref
before code generation - Keep import mappings synchronized with schema references
- Generated code inherits package name from config
- Use tags to filter generated structs
When modifying schema structs or their fields, there are two common scenarios:
-
Revert Logic: If you add a new field, the entire file may change due to automated code generation. What to do:
-
Identify the new field or struct you have added.
-
Copy this new addition.
-
Revert the rest of the file to its original state.
-
Re-insert the new field or struct into its appropriate location.
-
Note: We are working on streamlining this process, any contributions to improve automation are welcome! 🚀
-
x-order Tag Usage: If you only add an
x-order
tag, it ensures fields remain in a specific order. Steps:-
Run the usual commands to resolve references and generate the code.
-
If the field order changes unexpectedly, manually rearrange them.
-
Commit the changes, ensuring the
x-order
tag is included to maintain order in future generations.
-
Let's walk through a practical example, you made some changes in the component.json
- First, ensure your schema references are resolved:
make resolve-ref path="./schemas/constructs/v1beta1"
- Update
schemas/constructs/openapi/models.yml
to reference component.json:
openapi: 3.0.0
components:
schemas:
component_definition:
$ref: ../v1beta1/component.json
- Configure config.yml:
package: component
generate:
models: true
import-mapping:
"../v1beta1/model.json": "github.com/meshery/schemas/models/v1beta1/model"
"../v1alpha1/capability.json": "github.com/meshery/schemas/models/v1alpha1/capability"
output: models/v1beta1/component/component.go
output-options:
skip-prune: true
include-tags:
- components
- Generate code
oapi-codegen -config scripts/config.yml schemas/constructs/openapi/models.yml
- Schema Documentation
- Add detailed descriptions in schema fields
- Include example values where helpful
- Document validation rules and constraints
{
"displayName": {
"type": "string",
"description": "Human-readable name for the component.", // <-- description here
"minLength": 1,
"maxLength": 100,
"examples": ["nginx-deployment"] // <-- examples
}
}
- GitHub Issues - Report bugs or request features
- Community Slack - Real-time discussions with maintainers
- Weekly Meetings - Join our community calls
Community Resources
For more contribution guidelines, see the Meshery Contributing Guide.