cli icon indicating copy to clipboard operation
cli copied to clipboard

Generate and store a combined config schema

Open shauns opened this issue 10 months ago β€’ 8 comments

Add JSON schema support for app configuration validation

WHY are these changes introduced?

This PR generates a JSON schema for the app configuration file, which will enable better editor integration and validation for developers working with Shopify app configurations.

WHAT is this pull request doing?

Schema is a combination of locally specified schemas -- i.e. because the input format !== the submission format -- and JSON schema contracts.

  • Adds a hardcodedInputJsonSchema property to extension specifications to support schema validation
  • Implements schema bank generation that creates pretty-printed JSON schema files in the .shopify/schemas directory
  • Generates a combined app configuration schema that merges properties from all config modules
  • Prioritizes hardcoded schemas over validation schemas when both are present
  • Ensures schemas are properly formatted with consistent indentation for better readability
  • Cleans up old schema files that are no longer needed

How to test your changes?

Run at least one CLI command. Add #: schema ./.shopify/schemas/app.schema.json to the top of your app.toml file. See validation and autocomplete magic.

shauns avatar Apr 04 '25 14:04 shauns

[!WARNING] This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite. Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

shauns avatar Apr 04 '25 14:04 shauns

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/fs.d.ts
@@ -103,13 +103,13 @@ export declare function writeFile(path: string, data: string | Buffer, options?:
  */
 export declare function writeFileSync(path: string, data: string): void;
 /**
- * Creates a directory at the given path.
+ * Creates a directory at the given path. Directories are created recursively if needed.
  *
  * @param path - Path to the directory to be created.
  */
 export declare function mkdir(path: string): Promise<void>;
 /**
- * Synchronously creates a directory at the given path.
+ * Synchronously creates a directory at the given path. Directories are created recursively if needed.
  *
  * @param path - Path to the directory to be created.
  */
@@ -263,6 +263,13 @@ interface GenerateRandomDirectoryOptions {
  * @returns It returns the name of the directory.
  */
 export declare function generateRandomNameForSubdirectory(options: GenerateRandomDirectoryOptions): Promise<string>;
+/**
+ * Read the contents of a directory.
+ *
+ * @param path - Path to the directory.
+ * @returns A promise that resolves to an array of the names of the files in the directory.
+ */
+export declare function readdir(path: string): Promise<string[]>;
 /**
  * Traverse the file system and return pathnames that match the given pattern.
  *

github-actions[bot] avatar Apr 04 '25 14:04 github-actions[bot]

We detected some changes at packages/*/src and there are no updates in the .changeset. If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

github-actions[bot] avatar Apr 04 '25 14:04 github-actions[bot]

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟑 Statements
76.63% (+0.03% πŸ”Ό)
9435/12313
🟑 Branches
71.78% (+0.02% πŸ”Ό)
4622/6439
🟑 Functions
76.36% (+0.01% πŸ”Ό)
2448/3206
🟑 Lines
77.15% (+0.02% πŸ”Ό)
8921/11563
Show files with reduced coverage πŸ”»
St.:grey_question:
File Statements Branches Functions Lines
🟒
... / ConcurrentOutput.tsx
98.36% (-1.64% πŸ”»)
88% (-4% πŸ”»)
100%
98.33% (-1.67% πŸ”»)

Test suite run success

2182 tests passing in 954 suites.

Report generated by πŸ§ͺjest coverage report action from c3de307551630ea756e92e51f7392474e6e242e0

github-actions[bot] avatar Apr 04 '25 14:04 github-actions[bot]

I tried to test this but my app.schema.json is missing all the modules schemas πŸ€”

i'm getting this:

{
  "type": "object",
  "properties": {
    "client_id": {
      "type": "string"
    },
    "organization_id": {
      "type": "string"
    },
    "build": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "required": [
    "client_id"
  ],
  "additionalProperties": true
}

isaacroldan avatar Apr 08 '25 10:04 isaacroldan

@isaacroldan you'll need DCDD enabled. I don't think any other of the config modules export a portable schema right now.

shauns avatar Apr 08 '25 12:04 shauns

ah! that makes sense, in the next PRs in the stack i see you add the hardcoded schemas

isaacroldan avatar Apr 08 '25 12:04 isaacroldan

This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. β†’ If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

github-actions[bot] avatar May 09 '25 03:05 github-actions[bot]