Skip to content

feature: update schemas $id structure: model, component, connection and all which they reference #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

n2h9
Copy link
Contributor

@n2h9 n2h9 commented Apr 27, 2025

Notes for Reviewers

This PR introduces an update to the $id field values.

What do we want?

  • use json schema according to the RFC specification;
  • be able to use backend libraries for validation documents against the schema;
  • keep the same structure of schema folders, because they are already used somewhere, f.e. on frontend;

Why do we need this update?

Based on the draft-07 RFC schemas and subschemas does not operate with the entity like folder. There is a concept of an URI
According to the schema section 8.2:

The "$id" keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against.

hence when there is an $id field with a absolute URI the resolution of $ref within this schema is done based on the $id property.
What does it mean in our case. F.e. for v1beta1 model.json, it has $id = "https://schemas.meshery.io/model.json" and references to core.json as ../../core.json and so this is resolved to "https://schemas.meshery.io/core.json" according to rules defined in RFC. And both go libraries which I tried resolve it like this.

For proper use with backend validation libraries within a filesystem, we could set up a custom loader to say that all URIs starting from this domains https://schemas.meshery.io take fron this directory, how I did it here: #306 f.e.
For this we need update in $id structure like in this pr.
I assume it will be also useful / necessary when we expose all schemas to be available online under https://schemas.meshery.io


For now I am only updating model, component, relationship and sub schemas that they refer.

Signed commits

  • Yes, I signed my commits.

n2h9 added 2 commits April 27, 2025 14:33
…d all which they reference: run make generate-types

Signed-off-by: Nikita B <[email protected]>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @n2h9, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on updating the $id structure within the Meshery schemas to align with RFC specifications for JSON schema. The primary goal is to ensure that the schemas can be effectively used with backend validation libraries and to prepare for potential online exposure of the schemas under https://schemas.meshery.io. The changes involve modifying the $id fields in several JSON schema files, including core.json, capability.json, relationship.json, category.json, component.json, connection.json, model.json, and subcategory.json. Additionally, corresponding updates are made in the TypeScript definition files to reflect the new $id structure.

Highlights

  • Schema ID Updates: The $id fields in multiple JSON schema files have been updated to use absolute URIs, following RFC specifications. This change affects model, component, connection, relationship, and related sub-schemas.
  • TypeScript Definition Updates: TypeScript definition files, specifically core.d.ts, have been modified to reflect the updated $id structure in the JSON schemas. This includes renaming interfaces to match the new URI-based naming convention.
  • OpenAPI Schema Updates: OpenAPI schema files, such as ComponentOpenApiSchema.ts and ModelOpenApiSchema.ts, have been updated to use the new $id values for the JSON schemas. This ensures consistency across the codebase.

Changelog

Click here to see the changelog
  • schemas/constructs/core.json
    • Updated $id from relative path to absolute URI: ../core.json to https://schemas.meshery.io/core.json.
  • schemas/constructs/v1alpha1/capability/capability.json
    • Updated $id to include version and entity path: https://schemas.meshery.io/capability.json to https://schemas.meshery.io/v1alpha1/capability/capability.json.
  • schemas/constructs/v1alpha3/relationship.json
    • Updated $id to include version: https://schemas.meshery.io/relationship.json to https://schemas.meshery.io/v1alpha3/relationship.json.
  • schemas/constructs/v1beta1/category/category.json
    • Updated $id to include version and entity path: https://schemas.meshery.io/category.json to https://schemas.meshery.io/v1beta1/category/category.json.
  • schemas/constructs/v1beta1/component/component.json
    • Updated $id to include version and entity path: https://schemas.meshery.io/component.json to https://schemas.meshery.io/v1beta1/component/component.json.
  • schemas/constructs/v1beta1/connection.json
    • Updated $id to include version: https://schemas.meshery.io/component.json to https://schemas.meshery.io/v1beta1/connection.json.
  • schemas/constructs/v1beta1/model/model.json
    • Updated $id to include version and entity path: https://schemas.meshery.io/model.json to https://schemas.meshery.io/v1beta1/model/model.json.
  • schemas/constructs/v1beta1/subcategory/subcategory.json
    • Updated $id to include version and entity path: https://schemas.meshery.io/category.json to https://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
  • typescript/constructs/core.d.ts
    • Renamed interfaces referencing CoreJson to HttpsSchemasMesheryIoCoreJson.
  • typescript/constructs/v1alpha1/capability/CapabilityOpenApiSchema.ts
    • Updated $id in Capability schema to https://schemas.meshery.io/v1alpha1/capability/capability.json.
  • typescript/constructs/v1alpha1/capability/capability.d.ts
    • Renamed interface HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
  • typescript/constructs/v1alpha2/relationship.d.ts
    • Updated references to HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
    • Updated references to HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
  • typescript/constructs/v1alpha3/relationship.d.ts
    • Renamed interface HttpsSchemasMesheryIoRelationshipJson to HttpsSchemasMesheryIoV1Alpha3RelationshipJson.
  • typescript/constructs/v1alpha3/selector.d.ts
    • Updated references to HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
    • Updated references to HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
  • typescript/constructs/v1beta1/category/CategoryOpenApiSchema.ts
    • Updated $id in CategoryDefinition schema to https://schemas.meshery.io/v1beta1/category/category.json.
  • typescript/constructs/v1beta1/category/category.d.ts
    • Renamed interface HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
  • typescript/constructs/v1beta1/component/ComponentOpenApiSchema.ts
    • Updated $id in ComponentDefinition schema to https://schemas.meshery.io/v1beta1/component/component.json.
    • Updated $id in Model schema to https://schemas.meshery.io/v1beta1/model/model.json.
    • Updated $id in Connection schema to https://schemas.meshery.io/v1beta1/connection.json.
    • Updated $id in CategoryDefinition schema to https://schemas.meshery.io/v1beta1/category/category.json.
    • Updated $id in SubCategory schema to https://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
    • Updated $id in Capability schema to https://schemas.meshery.io/v1alpha1/capability/capability.json.
  • typescript/constructs/v1beta1/component/component.d.ts
    • Renamed interface HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ComponentComponentJson.
    • Updated references to HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson1 to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson1.
    • Updated references to HttpsSchemasMesheryIoComponentJson1 to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
    • Updated references to HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
  • typescript/constructs/v1beta1/connection.d.ts
    • Renamed interface HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
  • typescript/constructs/v1beta1/design/DesignOpenApiSchema.ts
    • Updated $id in Component schema to https://schemas.meshery.io/v1beta1/component/component.json.
    • Updated $id in Model schema to https://schemas.meshery.io/v1beta1/model/model.json.
    • Updated $id in Connection schema to https://schemas.meshery.io/v1beta1/connection.json.
    • Updated $id in CategoryDefinition schema to https://schemas.meshery.io/v1beta1/category/category.json.
    • Updated $id in SubCategory schema to https://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
    • Updated $id in Capability schema to https://schemas.meshery.io/v1alpha1/capability/capability.json.
    • Updated $id in Relationship schema to https://schemas.meshery.io/v1alpha3/relationship.json.
  • typescript/constructs/v1beta1/design/design.d.ts
    • Updated references to HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ComponentComponentJson.
    • Updated references to HttpsSchemasMesheryIoRelationshipJson to HttpsSchemasMesheryIoV1Alpha3RelationshipJson.
    • Updated references to HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoComponentJson1 to HttpsSchemasMesheryIoComponentJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson1 to HttpsSchemasMesheryIoCapabilityJson.
    • Updated references to HttpsSchemasMesheryIoModelJson2 to HttpsSchemasMesheryIoModelJson1.
    • Updated references to HttpsSchemasMesheryIoComponentJson3 to HttpsSchemasMesheryIoComponentJson1.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson4 to HttpsSchemasMesheryIoCapabilityJson2.
    • Updated references to HttpsSchemasMesheryIoModelJson3 to HttpsSchemasMesheryIoModelJson2.
    • Updated references to HttpsSchemasMesheryIoComponentJson4 to HttpsSchemasMesheryIoComponentJson2.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson5 to HttpsSchemasMesheryIoCapabilityJson3.
    • Updated references to HttpsSchemasMesheryIoModelJson4 to HttpsSchemasMesheryIoModelJson3.
    • Updated references to HttpsSchemasMesheryIoComponentJson5 to HttpsSchemasMesheryIoComponentJson3.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson6 to HttpsSchemasMesheryIoCapabilityJson4.
    • Updated references to HttpsSchemasMesheryIoModelJson5 to HttpsSchemasMesheryIoModelJson4.
    • Updated references to HttpsSchemasMesheryIoComponentJson6 to HttpsSchemasMesheryIoComponentJson4.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson7 to HttpsSchemasMesheryIoCapabilityJson5.
  • typescript/constructs/v1beta1/evaluation/EvaluationOpenApiSchema.ts
    • Updated $id in Component schema to https://schemas.meshery.io/v1beta1/component/component.json.
    • Updated $id in Model schema to https://schemas.meshery.io/v1beta1/model/model.json.
    • Updated $id in Connection schema to https://schemas.meshery.io/v1beta1/connection.json.
    • Updated $id in CategoryDefinition schema to https://schemas.meshery.io/v1beta1/category/category.json.
    • Updated $id in SubCategory schema to https://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
    • Updated $id in Capability schema to https://schemas.meshery.io/v1alpha1/capability/capability.json.
    • Updated $id in Relationship schema to https://schemas.meshery.io/v1alpha3/relationship.json.
  • typescript/constructs/v1beta1/model/ModelOpenApiSchema.ts
    • Updated $id in ModelDefinition schema to https://schemas.meshery.io/v1beta1/model/model.json.
    • Updated $id in Connection schema to https://schemas.meshery.io/v1beta1/connection.json.
    • Updated $id in CategoryDefinition schema to https://schemas.meshery.io/v1beta1/category/category.json.
    • Updated $id in SubCategory schema to https://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
    • Updated $id in Capability schema to https://schemas.meshery.io/v1alpha1/capability/capability.json.
  • typescript/constructs/v1beta1/model/model.d.ts
    • Renamed interface HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
    • Updated references to HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
  • typescript/constructs/v1beta1/subcategory/SubcategoryOpenApiSchema.ts
    • Updated $id in SubCategoryDefinition schema to https://schemas.meshery.io/v1beta1/subcategory/subcategory.json.
  • typescript/constructs/v1beta2-draft/catalog_data.d.ts
    • Updated references to HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoComponentJson to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
    • Updated references to HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
  • typescript/constructs/v1beta2-draft/draft-v1beta2.d.ts
    • Updated references to HttpsSchemasMesheryIoModelJson to HttpsSchemasMesheryIoV1Beta1ModelModelJson.
    • Updated references to HttpsSchemasMesheryIoComponentJson1 to HttpsSchemasMesheryIoV1Beta1ConnectionJson.
    • Updated references to HttpsSchemasMesheryIoCategoryJson to HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson.
    • Updated references to HttpsSchemasMesheryIoCapabilityJson to HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A schema's ID,
Now clear for all to see,
Validation sings.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR updates the $id fields in the JSON schemas to use absolute URIs, which is a good practice for interoperability and validation. The changes seem well-considered, and the provided explanation is clear. However, there are a few minor issues that should be addressed before merging.

Summary of Findings

  • Typos in descriptions: There are a few typos in the descriptions of the schemas. While not critical, correcting them would improve the overall quality of the documentation.
  • Inconsistent $id structure: The $id in schemas/constructs/core.json does not follow the same pattern as the other $id values. It should be updated to https://schemas.meshery.io/core.json to maintain consistency.
  • Interface naming in typescript/constructs/core.d.ts: The interfaces in typescript/constructs/core.d.ts are being renamed to include the full URL. While technically correct, this results in very long and unwieldy names. Consider if there's a better way to represent this, perhaps by aliasing or using a different naming convention.
  • Inconsistent interface naming in typescript/constructs/v1alpha1/capability/capability.d.ts: The interface in typescript/constructs/v1alpha1/capability/capability.d.ts is being renamed to include the full URL. While technically correct, this results in very long and unwieldy names. Consider if there's a better way to represent this, perhaps by aliasing or using a different naming convention.

Merge Readiness

The pull request is almost ready for merging. Addressing the typos and considering the interface naming in the TypeScript definitions would be beneficial. I am unable to directly approve this pull request, and strongly recommend that others review and approve this code before merging. Given the presence of medium severity comments, I recommend that the pull request not be merged until those are addressed (at a minimum).

Comment on lines +11 to 12
* This interface was referenced by `HttpsSchemasMesheryIoCoreJson`'s JSON-Schema
* via the `definition` "inputString".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider aliasing HttpsSchemasMesheryIoCoreJson to something shorter, as it's used repeatedly. The same applies to other interfaces in this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist, will you suggest how to create an alias?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of ways to create an alias in TypeScript. One common approach is to use a type alias. Here's how you could apply that to HttpsSchemasMesheryIoCoreJson:

type CoreJson = HttpsSchemasMesheryIoCoreJson;

You would place this line at the top of the core.d.ts file. Then, you can use CoreJson throughout the file as a shorthand for HttpsSchemasMesheryIoCoreJson. This improves readability, especially when the type is used repeatedly.

Another approach, if HttpsSchemasMesheryIoCoreJson is an interface, you could use interface extension:

interface CoreJson extends HttpsSchemasMesheryIoCoreJson {}

However, this approach is less about creating a simple alias and more about creating a new interface that inherits from the original. For the purpose of shortening the name, a type alias is generally more appropriate.

Suggested change
* This interface was referenced by `HttpsSchemasMesheryIoCoreJson`'s JSON-Schema
* via the `definition` "inputString".
type CoreJson = HttpsSchemasMesheryIoCoreJson;

@@ -8,7 +8,7 @@
/**
* Meshery manages entities in accordance with their specific capabilities. This field explicitly identifies those capabilities largely by what actions a given component supports; e.g. metric-scrape, sub-interface, and so on. This field is extensible. Entities may define a broad array of capabilities, which are in-turn dynamically interpretted by Meshery for full lifecycle management.
*/
export interface HttpsSchemasMesheryIoCapabilityJson {
export interface HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider aliasing HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson to something shorter, as it's used repeatedly. The same applies to other interfaces in this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To Gemini's point, is this interface name auto-generated (something out of our direct control) or something that we might easily shorten, e.g. v1Alpha1Capability?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the interface name is auto-generated from the JSON schema file name. Shortening it to V1Alpha1Capability would improve readability without losing clarity. This change would need to be reflected wherever the interface is used.

Suggested change
export interface HttpsSchemasMesheryIoV1Alpha1CapabilityCapabilityJson {
export interface V1Alpha1Capability {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow, it can even respond to the messages 😮

Right all typescript in this pr is auto generated.


To the point that it would be nice to have this autogeneration in ci, so that pr will not have this load.
I do not even know if this typescript is related to current changes in schema, or somebody just forgot to run

make generate-types on their pr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, it is related.

The name is generated from $id
$id was "https://schemas.meshery.io/v1alpha1/capability.json"

and now $id is "https://schemas.meshery.io/v1alpha1/capability/capability.json"

wondering if it means some updates will be required on frontend 🤔 ?
@leecalcote @aabidsofi19

@@ -13,7 +13,7 @@ const schema = {
"components": {
"schemas": {
"CategoryDefinition": {
"$id": "https://schemas.meshery.io/category.json",
"$id": "https://schemas.meshery.io/v1beta1/category/category.json",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider aliasing HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson to something shorter, as it's used repeatedly. The same applies to other interfaces in this file.

@@ -8,7 +8,7 @@
/**
* Category of the model.
*/
export interface HttpsSchemasMesheryIoCategoryJson {
export interface HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider aliasing HttpsSchemasMesheryIoV1Beta1CategoryCategoryJson to something shorter, as it's used repeatedly. The same applies to other interfaces in this file.

Copy link
Member

@leecalcote leecalcote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"$id": "https://schemas.meshery.io/v1alpha1/capability/capability.json",

Perfect. What we previously had (currently have) is without identification of schema version. Other than the core.json schema, to reference a schema without inclusion of it's version is to not reference a schema at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants