Enhancement: Option to directly reference a JSON Schema for data #319

Open
opened 2026-10-05 02:39:57 +02:00 by adam · 4 comments
Owner

Is your feature request related to a problem? Please describe.

I took some time over the weekend to write JSON schemas for my data types so I could use those schemas in multiple places. Unfortunately, to use Front Matter for updating the data locally, I have to redefine my schema in frontmatter.json.

For example, instead of defining a data file like this:

"frontMatter.data.files": [
  {
    "file": "[[workspace]]/data/factions/ambitions.yaml",
    "fileType": "yaml",
    "id": "Factions.Ambitions",
    "labelField": "name",
    "title": "FF Ambitions",
    "schema": "https://flagrant.garden/schemas/factions/ambition.schema.json"
  }
]

I need to define the schema itself in frontmatter.js, either as a reusable type or directly in the data file item, like this:

{
  "frontMatter.data.files": [
    {
      "file": "[[workspace]]/data/factions/ambitions.yaml",
      "fileType": "yaml",
      "id": "Factions.Ambitions",
      "labelField": "name",
      "title": "FF Ambitions",
      "schema": {
        "title": "Ambition",
        "description": "A Flagrant Factions Ambition.",
        "type": "object",
        "required": [
          "name",
          "points",
          "condition"
        ],
        "properties": {
          "name": {
            "title": "Name",
            "description": "Specify the name of the Ambition. This is how it's referenced in play.",
            "type": "string"
          },
          "points": {
            "title": "Victory Points",
            "description": "Specify how many VP the Ambition is worth if fulfilled in a Skirmish.",
            "type": "integer",
            "minimum": 1
          },
          "condition": {
            "title": "Fulfillment Condition",
            "description": "Specify the fullfillment conditions for the Ambition.",
            "type": "string",
            "contentMediaType": "text/markdown"
          },
          "source": {
            "title": "Source",
            "description": "Specify the text the Ambition belongs to, such as the name of the supplement.",
            "type": "string"
          }
        }
      }
    }
  ]
}

This gets quickly out of hand for multiple data types, especially if your schemas are ever going to change. Additionally, if my data uses a well-known schema published by someone else, I don't want to have to redefine the schema in my configuration file and keep it up to date manually.

Describe the solution you'd like

I would like the option to specify an existing JSON schema, either local or remote. I'm not sure if it makes sense to do this by updating the schema key to take string values or by adding new keys like schema_path and/or schema_url.

Describe alternatives you've considered

I'm confident I can figure out a local workflow for myself that inserts my schemas via running a script, but that still makes the configuration file very long.

Additional context

N/A

**Is your feature request related to a problem? Please describe.** I took some time over the weekend to write JSON schemas for my data types so I could use those schemas in multiple places. Unfortunately, to use Front Matter for updating the data locally, I have to redefine my schema in `frontmatter.json`. For example, instead of defining a data file like this: ```json "frontMatter.data.files": [ { "file": "[[workspace]]/data/factions/ambitions.yaml", "fileType": "yaml", "id": "Factions.Ambitions", "labelField": "name", "title": "FF Ambitions", "schema": "https://flagrant.garden/schemas/factions/ambition.schema.json" } ] ``` I need to define the schema itself in `frontmatter.js`, either as a reusable type or directly in the data file item, like this: ```json { "frontMatter.data.files": [ { "file": "[[workspace]]/data/factions/ambitions.yaml", "fileType": "yaml", "id": "Factions.Ambitions", "labelField": "name", "title": "FF Ambitions", "schema": { "title": "Ambition", "description": "A Flagrant Factions Ambition.", "type": "object", "required": [ "name", "points", "condition" ], "properties": { "name": { "title": "Name", "description": "Specify the name of the Ambition. This is how it's referenced in play.", "type": "string" }, "points": { "title": "Victory Points", "description": "Specify how many VP the Ambition is worth if fulfilled in a Skirmish.", "type": "integer", "minimum": 1 }, "condition": { "title": "Fulfillment Condition", "description": "Specify the fullfillment conditions for the Ambition.", "type": "string", "contentMediaType": "text/markdown" }, "source": { "title": "Source", "description": "Specify the text the Ambition belongs to, such as the name of the supplement.", "type": "string" } } } } ] } ``` This gets quickly out of hand for multiple data types, especially if your schemas are ever going to change. Additionally, if my data uses a well-known schema published by someone else, I don't want to have to redefine the schema in my configuration file and keep it up to date manually. **Describe the solution you'd like** I would like the option to specify an existing JSON schema, either local or remote. I'm not sure if it makes sense to do this by updating the `schema` key to take string values or by adding new keys like `schema_path` and/or `schema_url`. **Describe alternatives you've considered** I'm confident I can figure out a local workflow for myself that inserts my schemas via running a script, but that still makes the configuration file very long. **Additional context** N/A <!-- github-sync-id:1365442173 -->
Author
Owner

Another use case for this, now that #406 and #412 have landed in beta, is for using the defined schemas for the configuration file(s) to define and edit them directly in the UI. I think this would be an even more delightful UX than we already have (and the schemas absolutely make editing the JSON configurations by hand a pretty good experience, certainly better than continually cross-referencing the docs while filling things out).

Another use case for this, now that #406 and #412 have landed in beta, is for using the defined schemas for the configuration file(s) to define and edit them directly in the UI. I think this would be an even more delightful UX than we already have (and the schemas _absolutely_ make editing the JSON configurations by hand a pretty good experience, certainly better than continually cross-referencing the docs while filling things out). <!-- github-comment-id:1272227821 -->
Author
Owner

@michaeltlombardi that is why the frontMatter.data.types setting was introduced. To allow you to define and reference a schema for the data files. An example is given here: https://frontmatter.codes/docs/dashboard#re-using-a-data-type-for-files-or-folders

Having the option to link an external schema makes sense. A new property would be the best fit for this, as it is easier to check in the code on what is used and for the user to define it.

@michaeltlombardi that is why the **frontMatter.data.types** setting was introduced. To allow you to define and reference a schema for the data files. An example is given here: https://frontmatter.codes/docs/dashboard#re-using-a-data-type-for-files-or-folders Having the option to link an external schema makes sense. A new property would be the best fit for this, as it is easier to check in the code on what is used and for the user to define it. <!-- github-comment-id:1274229640 -->
Author
Owner

I've been making extensive use of frontMatter.data.types - maybe frontMatter.data.externalTypes would be good for the new property? or did you mean a property on an entry in frontmatter.data.types, like externalSchema instead of schema?

I've been making [extensive use][01] of `frontMatter.data.types` - maybe `frontMatter.data.externalTypes` would be good for the new property? or did you mean a property on an entry in `frontmatter.data.types`, like `externalSchema` instead of `schema`? [01]: https://github.com/FlagrantGarden/site/tree/main/.frontmatter/config/data/types <!-- github-comment-id:1275078431 -->
Author
Owner

I just tried this definition to see if it would work, now that I have my JSON schemas sorted (and working via the VS Code YAML extension):

"frontMatter.data.files": [
  {
    "file": "[[workspace]]/data/platen/config/repository.yaml",
    "fileType": "yaml",
    "id": "repository",
    "schema": {
      "type": "object",
      "properties": {},
      "$ref": "https://platen.io/modules/platen/config/site/repository/settings/schema.json"
    },
    "singleEntry": true,
    "title": "Platen Repository Settings"
  }
]

But unfortunately, when I go to access the file in my Front Matter dashboard, it errors:

["INFO" - 09:01:36]  Sending message to webview: dataFileEntries
["INFO" - 09:01:36]  Receiving message from webview: logError
["ERROR" - 09:01:36]  Event ID: 68e3429bf3be48f79f1d3a48ebc1269f
Message: can't resolve reference https://platen.io/modules/platen/config/site/repository/settings/schema.json#/properties/commit_path from id #

Stack: 
    at DataForm (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:121980:21)
    at div
    at section
    at div
    at div
    at DataView (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:122076:66)
    at Routes (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:103341:5)
    at main
    at ErrorBoundary (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:24693:47)
    at App (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:121519:16)
    at Router (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:103275:15)
    at MemoryRouter (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:103188:5)
    at RecoilRoot_INTERNAL (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:112722:3)
    at RecoilRoot (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:112878:5)

I also tried:

"frontMatter.data.files": [
  {
    "file": "[[workspace]]/data/platen/config/repository.yaml",
    "fileType": "yaml",
    "id": "repository",
    "schema": "https://platen.io/modules/platen/config/site/repository/settings/schema.json",
    "singleEntry": true,
    "title": "Platen Repository Settings"
  }
]

But of course, schema expects an object and not a URL string.

I just tried this definition to see if it would work, now that I have my JSON schemas sorted (and working via the VS Code YAML extension): ```jsonc "frontMatter.data.files": [ { "file": "[[workspace]]/data/platen/config/repository.yaml", "fileType": "yaml", "id": "repository", "schema": { "type": "object", "properties": {}, "$ref": "https://platen.io/modules/platen/config/site/repository/settings/schema.json" }, "singleEntry": true, "title": "Platen Repository Settings" } ] ``` But unfortunately, when I go to access the file in my Front Matter dashboard, it errors: ``` ["INFO" - 09:01:36] Sending message to webview: dataFileEntries ["INFO" - 09:01:36] Receiving message from webview: logError ["ERROR" - 09:01:36] Event ID: 68e3429bf3be48f79f1d3a48ebc1269f Message: can't resolve reference https://platen.io/modules/platen/config/site/repository/settings/schema.json#/properties/commit_path from id # Stack: at DataForm (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:121980:21) at div at section at div at div at DataView (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:122076:66) at Routes (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:103341:5) at main at ErrorBoundary (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:24693:47) at App (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:121519:16) at Router (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:103275:15) at MemoryRouter (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:103188:5) at RecoilRoot_INTERNAL (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:112722:3) at RecoilRoot (https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/mikey/.vscode/extensions/eliostruyf.vscode-front-matter-beta-8.3.3863558/dist/dashboardWebView.js:112878:5) ``` I also tried: ```json "frontMatter.data.files": [ { "file": "[[workspace]]/data/platen/config/repository.yaml", "fileType": "yaml", "id": "repository", "schema": "https://platen.io/modules/platen/config/site/repository/settings/schema.json", "singleEntry": true, "title": "Platen Repository Settings" } ] ``` But of course, `schema` expects an object and not a URL string. <!-- github-comment-id:1375862236 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#319