@meshery/schemas 0.0.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2019, 2020 Layer5, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,472 @@
1
+
2
+ <p style="text-align:center;" align="center"><a href="https://meshery.io"><picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/meshery/meshery/master/.github/assets/images/readme/meshery-logo-light-text-side.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/meshery/meshery/master/.github/assets/images/readme/meshery-logo-dark-text-side.svg">
5
+ <img src="https://raw.githubusercontent.com/meshery/meshery/master/.github/assets/images/readme/meshery-logo-dark-text-side.svg"
6
+ alt="Meshery Logo" width="70%" /></picture></a><br /><br /></p>
7
+ <p align="center">
8
+ <a href="https://hub.docker.com/r/layer5/meshery" alt="Docker pulls">
9
+ <img src="https://img.shields.io/docker/pulls/layer5/meshery.svg" /></a>
10
+ <a href="https://github.com/issues?q=is%3Aopen+is%3Aissue+archived%3Afalse+org%3Alayer5io+org%3Ameshery+org%3Aservice-mesh-performance+org%3Aservice-mesh-patterns+org%3A+label%3A%22help+wanted%22+" alt="GitHub issues by-label">
11
+ <img src="https://img.shields.io/github/issues/layer5io/meshery/help%20wanted.svg?color=informational" /></a>
12
+ <a href="https://github.com/meshery/meshery/blob/master/LICENSE" alt="LICENSE">
13
+ <img src="https://img.shields.io/github/license/meshery/meshery?color=brightgreen" /></a>
14
+ <a href="https://artifacthub.io/packages/helm/meshery/meshery" alt="Artifact Hub Meshery">
15
+ <img src="https://img.shields.io/endpoint?color=brightgreen&label=Helm%20Chart&style=plastic&url=https%3A%2F%2Fartifacthub.io%2Fbadge%2Frepository%2Fartifact-hub" /></a>
16
+ <a href="https://goreportcard.com/report/github.com/meshery/meshery" alt="Go Report Card">
17
+ <img src="https://goreportcard.com/badge/github.com/meshery/meshery" /></a>
18
+ <a href="https://github.com/meshery/meshery/actions" alt="Build Status">
19
+ <img src="https://img.shields.io/github/actions/workflow/status/meshery/meshery/release-drafter.yml" /></a>
20
+ <a href="https://bestpractices.coreinfrastructure.org/projects/3564" alt="CLI Best Practices">
21
+ <img src="https://bestpractices.coreinfrastructure.org/projects/3564/badge" /></a>
22
+ <a href="http://discuss.meshery.io" alt="Discuss Users">
23
+ <img src="https://img.shields.io/discourse/users?label=discuss&logo=discourse&server=https%3A%2F%2Fdiscuss.layer5.io" /></a>
24
+ <a href="https://slack.meshery.io" alt="Join Slack">
25
+ <img src="https://img.shields.io/badge/Slack-@layer5.svg?logo=slack" /></a>
26
+ <a href="https://twitter.com/intent/follow?screen_name=mesheryio" alt="Twitter Follow">
27
+ <img src="https://img.shields.io/twitter/follow/mesheryio.svg?label=Follow+Meshery&style=social" /></a>
28
+ <a href="https://github.com/meshery/meshery/releases" alt="Meshery Downloads">
29
+ <img src="https://img.shields.io/github/downloads/meshery/meshery/total" /></a>
30
+ <!-- <a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fmeshery%2Fmeshery?ref=badge_shield" alt="License Scan Report">
31
+ <img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmeshery%2Fmeshery.svg?type=shield"/></a>
32
+ -->
33
+ </p>
34
+
35
+ <h5><p align="center"><i>If you’re using Meshery or if you like the project, please <a href="https://github.com/meshery/meshery/stargazers">★</a> this repository to show your support! 🤩</i></p></h5>
36
+
37
+ # Meshery Schemas
38
+
39
+ 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.
40
+
41
+ Meshery schemas offer a powerful system designed for:
42
+
43
+ - **Model-Driven Management:** Meshery uses explicit models for describing infrastructure and applications.
44
+ - **Dynamic Discovery:** The ability to process different kinds of relationships and styles, enables a sophisticated system that can adapt to many configurations.
45
+ - **Lifecycle Management:** The schema properties track status and lifecycle of resources.
46
+ - **Extensibility:** Open-ended metadata and modular schema components enable expansion and customization.
47
+ - **Visual Representation:** The properties for styling of edges and nodes is for creating a user friendly visual representation.
48
+ - **Automated Operations:** The schemas can support validation and automated configuration of infrastructure and applications, and patching.
49
+
50
+ For an explanation of Meshery's terminology regarding schemas, definitions, declarations, and instances, please see [Contributor's Guide to Models](https://docs.meshery.io/project/contributing/contributing-models).
51
+
52
+ ## Contributing
53
+ --> **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](https://docs.meshery.io/project/contributing/contributing-schemas).**
54
+
55
+ <p style="clear:both;">&nbsp;</p>
56
+
57
+ ## Join the Meshery community!
58
+
59
+ <a name="contributing"></a><a name="community"></a>
60
+ Our projects are community-built and welcome collaboration. 👍 Be sure to see the <a href="https://docs.meshery.io/project/contributing#not-sure-where-to-start">Contributor Welcome Guide</a> and <a href="https://meshery.io/community#handbook">Community Handbook</a> for a tour of resources available to you and the <a href="https://layer5.io/community/handbook/repository-overview">Repository Overview</a> for a cursory description of repository by technology and programming language. Jump into community <a href="https://slack.meshery.io">Slack</a> or <a href="https://meshery.io/community#discussion-forums">discussion forum</a> to participate.
61
+
62
+ <p style="clear:both;">
63
+ <a href ="https://meshery.io/community"><img alt="MeshMates" src=".github/assets/images/readme/layer5-community-sign.png" style="margin-right:36px; margin-bottom:7px;" width="140px" align="left" /></a>
64
+ <h3>Find your MeshMate</h3>
65
+
66
+ <p>MeshMates are experienced community members, who will help you learn your way around, discover live projects, and expand your community network. Connect with a Meshmate today!</p>
67
+
68
+ Find out more on the <a href="https://meshery.io/community#meshmates">Meshery community</a>. <br />
69
+
70
+ </p>
71
+ <br /><br />
72
+ <div style="display: flex; justify-content: center; align-items:center;">
73
+ <div>
74
+ <a href="https://meshery.io/community"><img alt="Meshery Cloud Native Community" src="https://docs.meshery.io/assets/img/readme/community.png" width="140px" style="margin-right:36px; margin-bottom:7px;" width="140px" align="left"/></a>
75
+ </div>
76
+ <div style="width:60%; padding-left: 16px; padding-right: 16px">
77
+ <p>
78
+ ✔️ <em><strong>Join</strong></em> any or all of the weekly meetings on <a href="https://meshery.io/calendar">community calendar</a>.<br />
79
+ ✔️ <em><strong>Watch</strong></em> community <a href="https://www.youtube.com/@mesheryio?sub_confirmation=1">meeting recordings</a>.<br />
80
+ ✔️ <em><strong>Fill-in</strong></em> a <a href="https://layer5.io/newcomers">community member form</a> to gain access to community resources.
81
+ <br />
82
+ ✔️ <em><strong>Discuss</strong></em> in the <a href="https://meshery.io/community#discussion-forums">Community Forum</a>.<br />
83
+ ✔️ <em><strong>Explore more</strong></em> in the <a href="https://meshery.io/community#handbook">Community Handbook</a>.<br />
84
+ </p>
85
+ <p align="center">
86
+ <i>Not sure where to start?</i> Grab an open issue with the <a href="https://github.com/issues?q=is%3Aopen+is%3Aissue+archived%3Afalse+org%3Alayer5io+org%3Ameshery+org%3Ameshery-extensions+org%3Aservice-mesh-performance+org%3Aservice-mesh-patterns+label%3A%22help+wanted%22">help-wanted label</a>.
87
+ </p>
88
+ </div>
89
+ <div>&nbsp;</div>
90
+
91
+ ## Contributing
92
+
93
+ Please do! We're a warm and welcoming community of open source contributors. All types of contributions are welcome. Please read:
94
+
95
+ - [General Contributor Guide](https://docs.meshery.io/project/contributing) - Overview of contribution processes
96
+ - [Schema Contributor Guide](./CONTRIBUTING.md) - Schema-specific development workflows and guidelines
97
+
98
+ <div>&nbsp;</div>
99
+
100
+
101
+ # 🧬 Schema-Driven Development Guide
102
+
103
+ 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.
104
+
105
+ ---
106
+
107
+ ## 🧾 Schema Definition in Meshery
108
+
109
+ 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:
110
+
111
+ * ✅ **Versioned schemas** for backward compatibility.
112
+ * 🧩 **Modular constructs** for maintainability and reuse.
113
+ * 🧪 **Schemas are used** for validation, API documentation, and automatic code generation.
114
+
115
+ > 💡 **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.
116
+
117
+ ---
118
+
119
+ ## 📁 Schema Directory Structure
120
+
121
+ All schemas are located in the `schemas/` directory at the root of the Meshery repository:
122
+
123
+ ```
124
+ schemas/
125
+ constructs/
126
+ <schema-version>/ # e.g., v1beta1
127
+ <construct>/ # e.g., model, component
128
+ <construct>.json # Schema definition for the construct (noun)
129
+ subschemas/ # Reusable modular pieces
130
+ openapi.yml # API operations (verbs: create, update, delete)
131
+ <construct>_template.json # Generated JSON template from schema
132
+ <construct>_template.yaml # Generated YAML template from schema
133
+ ```
134
+
135
+ ### 🧠 Explanation
136
+
137
+ * **`constructs/`** – Holds schemas for various versions.
138
+ * **`<schema-version>/`** – Represents a version (e.g., `v1alpha2`, `v1beta1`).
139
+ * **`<construct>/`** – A specific construct like `pattern`, `component`, etc.
140
+ * **`<construct>.json`** – Defines the **data model (noun)** for the construct.
141
+ * **`subschemas/`** – Contains shared schema components for reuse.
142
+ * **`openapi.yml`** – Defines **API operations** (verbs).
143
+ * **Templates** – `*_template.json` and `*_template.yaml` are auto-generated examples with resolved references and defaults.
144
+
145
+ ---
146
+
147
+ ## ⚙️ Code Generation
148
+
149
+ Meshery supports **automated code generation** from schemas for:
150
+
151
+ * **Go**: Strongly-typed models for backend.
152
+ * **TypeScript**: Interfaces and types for frontend use.
153
+ * **RTK Query**: Clients generated from OpenAPI for use with Redux.
154
+ * **JSON/YAML**: Templates with defaults and resolved references.
155
+
156
+ ---
157
+
158
+ ## 🚀 Unified Build: One Command for Everything
159
+
160
+ Use the following command to perform the **entire schema-driven generation workflow**:
161
+
162
+ ```bash
163
+ make build
164
+ ```
165
+
166
+ ### 🔧 What `make build` does:
167
+
168
+ 1. **Bundles OpenAPI schemas** for:
169
+
170
+ * Meshery
171
+ * Remote Providers (e.g. Layer5 Cloud)
172
+ * Combined (all constructs)
173
+
174
+ 2. **Generates:**
175
+
176
+ * Golang structs
177
+ * TypeScript types
178
+ * JSON & YAML templates
179
+ * RTK Query clients
180
+
181
+ > ⚠️ This is the recommended way to stay in sync with schema changes.
182
+
183
+ ---
184
+
185
+ ## 🧱 Bundled Schema Outputs
186
+
187
+ After running `make build`, three bundled schema files are created:
188
+
189
+ | File | Purpose |
190
+ | -------------------- | ---------------------------------------------- |
191
+ | `merged_schema.yml` | All schemas combined (used by Meshery clients) |
192
+ | `cloud_schema.yml` | Cloud-specific APIs for Remote Providers (e.g. Layer5 Cloud) |
193
+ | `meshery_schema.yml` | Meshery-specific APIs |
194
+
195
+ ---
196
+
197
+ ## ✍️ Annotating OpenAPI Paths
198
+
199
+ To control which schema paths are included in each bundled output, use the `x-internal` annotation inside the OpenAPI operations (`get`, `post`, etc.).
200
+
201
+ ### Example:
202
+
203
+ ```yaml
204
+ paths:
205
+ /api/entitlement/plans:
206
+ get:
207
+ x-internal: ["cloud"]
208
+ operationId: getPlans
209
+ tags:
210
+ - Plans
211
+ summary: Get all plans supported by the system
212
+ responses:
213
+ "200":
214
+ description: Plans fetched successfully
215
+ content:
216
+ application/json:
217
+ schema:
218
+ type: array
219
+ items:
220
+ $ref: "#/components/schemas/Plan"
221
+ ```
222
+
223
+ * **With `x-internal`**: Included only in the respective client (e.g., `cloud`).
224
+ * **Without `x-internal`**: Included in **all** clients.
225
+
226
+ ---
227
+
228
+ ## 🛠️ Advanced Usage (Optional)
229
+
230
+ ### 📌 Custom Generation in `generate.sh`
231
+
232
+ Meshery uses a helper script (`generate.sh`) to map schema constructs to generated output:
233
+
234
+ ```bash
235
+ generate_schema_models <construct> <schema-version> [<openapi-file>]
236
+
237
+ generate_schema_models "capability" "v1alpha1"
238
+ generate_schema_models "category" "v1beta1"
239
+ generate_schema_models "pattern" "v1beta1" "schemas/constructs/v1beta1/design/openapi.yml"
240
+ ```
241
+
242
+ This maps to Go packages like:
243
+
244
+ ```
245
+ models/v1alpha1/capability/capability.go
246
+ ```
247
+
248
+ ### 🧩 RTK Query Client Generation
249
+
250
+ The OpenAPI bundle is passed to a codegen tool to generate RTK Query clients. Include relevant paths using `x-internal` annotations and define request/response schemas appropriately.
251
+
252
+ You can control this in `generate.sh` like:
253
+
254
+ ```bash
255
+ # Merge relevant constructs for RTK generation
256
+ npx @redocly/cli join schemas/base_cloud.yml \
257
+ "${v1beta1}/pattern/${merged_construct}" \
258
+ "${v1beta1}/component/${merged_construct}" \
259
+ "${v1beta1}/model/${merged_construct}" \
260
+ ... \
261
+ -o schemas/merged_openapi.yml \
262
+ --prefix-tags-with-info-prop title \
263
+ --prefix-components-with-info-prop title
264
+ ```
265
+
266
+ # Using Generated RTK Query Clients
267
+
268
+
269
+ ## Prerequisites
270
+
271
+ Before using the generated RTK clients, ensure you have:
272
+
273
+ 1. Installed the required dependencies:
274
+ - `@reduxjs/toolkit`
275
+ - `@layer5/schemas`
276
+
277
+ 2. Set up environment variables:
278
+ - `RTK_CLOUD_ENDPOINT_PREFIX`: Base URL for Cloud API endpoints
279
+ - `RTK_MESHERY_ENDPOINT_PREFIX`: Base URL for Meshery API endpoints
280
+
281
+ ## Store Configuration
282
+
283
+ ### Import API Slices Correctly
284
+
285
+ To avoid cyclical imports that can break your application, import API slices from their specific exports:
286
+
287
+ ```javascript
288
+ // ✅ Correct: Import from specific API exports
289
+ import { cloudApi as cloudBaseApi } from "@layer5/schemas/dist/cloudApi";
290
+ import { mesheryApi } from "@layer5/schemas/dist/mesheryApi";
291
+
292
+ // ❌ Incorrect: Do not import directly from generic API file
293
+ // import { api } from "@layer5/schemas/dist/api"; // Can cause cyclical imports
294
+ ```
295
+
296
+ ### Configure Redux Store
297
+
298
+ Add the API reducers and middleware to your Redux store configuration:
299
+
300
+ ```javascript
301
+ import { combineReducers, configureStore } from "@reduxjs/toolkit";
302
+ import { cloudApi as cloudBaseApi } from "@layer5/schemas/dist/cloudApi";
303
+ import catalogReducer from "./slices/catalog";
304
+ import connectionReducer from "./slices/connection";
305
+ import organizationReducer from "./slices/organization";
306
+ import chartReducer from "./slices/charts";
307
+ import themeReducer from "./slices/theme";
308
+ // Optional: If you have locally defined APIs
309
+ import { cloudApi } from "../api";
310
+
311
+ // Combine reducers
312
+ const rootReducer = combineReducers({
313
+ catalog: catalogReducer,
314
+ charts: chartReducer,
315
+ organization: organizationReducer,
316
+ connection: connectionReducer,
317
+ theme: themeReducer,
318
+ // Add generated API reducers
319
+ [cloudBaseApi.reducerPath]: cloudBaseApi.reducer,
320
+ // Optional: Add locally defined API reducers
321
+ [cloudApi.reducerPath]: cloudApi.reducer
322
+ });
323
+
324
+ // Configure store with middleware
325
+ export const store = configureStore({
326
+ reducer: reduxPersist.createPersistEnhancedReducer(rootReducer),
327
+ middleware: getDefaultMiddleware =>
328
+ getDefaultMiddleware()
329
+ // Add generated API middleware
330
+ .concat(cloudBaseApi.middleware)
331
+ // Optional: Add locally defined API middleware
332
+ .concat(cloudApi.middleware)
333
+ // Add persistence middleware if needed
334
+ .concat(reduxPersist.persistMiddleware)
335
+ });
336
+
337
+ // Set up listeners for RTK Query cache behaviors like refetchOnFocus/refetchOnReconnect
338
+ setupListeners(store.dispatch);
339
+ ```
340
+
341
+ ## Using API Hooks
342
+
343
+ After configuring your store, you can import and use the generated hooks:
344
+
345
+ ### Cloud API Hooks
346
+
347
+ ```javascript
348
+ import {
349
+ useGetPlansQuery,
350
+ useCreateDesignMutation,
351
+ useGetDesignsQuery,
352
+ // Other cloud API hooks...
353
+ } from "@layer5/schemas/dist/cloudApi";
354
+
355
+ function MyComponent() {
356
+ // Use hooks directly in your components
357
+ const { data: plans, isLoading, error } = useGetPlansQuery();
358
+
359
+ // Handle loading states
360
+ if (isLoading) return <div>Loading plans...</div>;
361
+
362
+ // Handle errors
363
+ if (error) return <div>Error loading plans</div>;
364
+
365
+ // Use data
366
+ return (
367
+ <div>
368
+ {plans.map(plan => (
369
+ <div key={plan.id}>{plan.name}</div>
370
+ ))}
371
+ </div>
372
+ );
373
+ }
374
+ ```
375
+
376
+ ### Meshery API Hooks
377
+
378
+ ```javascript
379
+ import {
380
+ useGetMeshModelsQuery,
381
+ useSubmitMeshConfigMutation,
382
+ // Other Meshery API hooks...
383
+ } from "@layer5/schemas/dist/mesheryApi";
384
+
385
+ function MesheryComponent() {
386
+ const { data: meshModels } = useGetMeshModelsQuery();
387
+ // ...
388
+ }
389
+ ```
390
+
391
+ ## Troubleshooting
392
+
393
+ ### Common Issues
394
+
395
+ 1. **Stuck Loading States**:
396
+ - Verify environment variables are correctly set
397
+ - Check for CORS issues
398
+ - Ensure proper authentication headers are included
399
+
400
+ 2. **Cyclical Imports**:
401
+ - Always import from specific API files (`cloudApi.ts`, `mesheryApi.ts`)
402
+ - Avoid importing from generic `api.ts` files
403
+
404
+ 3. **Multiple RTK Instances**:
405
+ - Ensure proper reducer and middleware registration
406
+ - Check for naming conflicts in reducerPaths
407
+
408
+ ### Redux DevTools
409
+
410
+ For better debugging, use Redux DevTools to monitor:
411
+ - API request lifecycles
412
+ - State changes
413
+ - Caching behavior
414
+
415
+ ## Best Practices
416
+
417
+ 1. **Handle Loading States**:
418
+ ```javascript
419
+ const { data, isLoading, isFetching, error } = useGetDataQuery();
420
+ ```
421
+
422
+ 2. **Leverage Cache Options**:
423
+ ```javascript
424
+ const { data } = useGetDataQuery(null, {
425
+ pollingInterval: 30000, // Re-fetch every 30 seconds
426
+ refetchOnMountOrArgChange: true,
427
+ skip: !isReady // Skip query when not ready
428
+ });
429
+ ```
430
+
431
+ 3. **Use Transformations When Needed**:
432
+ ```javascript
433
+ const transformedData = data?.map(item => ({
434
+ ...item,
435
+ formattedValue: formatValue(item.value)
436
+ }));
437
+ ```
438
+
439
+ ## 🧪 Testing & Validating Schemas
440
+
441
+ Validate your schema updates before committing by running:
442
+
443
+ ```bash
444
+ make build
445
+ ```
446
+
447
+ Or validate a single file:
448
+
449
+ ```bash
450
+ npx @redocly/cli lint schemas/constructs/v1beta1/pattern/openapi.yml
451
+ ```
452
+
453
+ ---
454
+
455
+ ## ✅ Summary
456
+
457
+ | Task | Command |
458
+ | ----------------------- | ----------------------- |
459
+ | Generate everything | `make build` |
460
+ | Generate Go code only | `make golang-generate` |
461
+ | Generate TS + templates | `make generate-types` |
462
+ | Lint OpenAPI | `npx @redocly/cli lint` |
463
+
464
+ ---
465
+
466
+ ### License
467
+
468
+ This repository and site are available as open-source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
469
+
470
+ <p align="center" >
471
+ MESHERY IS A CLOUD NATIVE COMPUTING FOUNDATION PROJECT
472
+ </p>