Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions schemas/theme/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand All @@ -221,7 +222,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand All @@ -237,7 +239,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand Down Expand Up @@ -273,7 +276,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand All @@ -293,7 +297,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand Down Expand Up @@ -368,7 +373,8 @@
"additionalProperties": { "type": "string" },
"description": "A map of palette color names to color values. Each key is an arbitrary name and each value is a CSS color.",
"markdownDescription": "A map of palette color names to color values.\n\nEach **key** is an arbitrary name. Each **value** is a CSS color, typically a hex code.\n\n**Example:**\n```json\n\"default\": {\n \"background\": \"#ffffff\",\n \"foreground\": \"#000000\"\n}\n```\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/settings/input-settings#color_palette)"
}
},
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand Down Expand Up @@ -495,7 +501,8 @@
]
},
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"required": ["definition", "role"],
"additionalProperties": false
Expand Down Expand Up @@ -647,7 +654,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"required": ["metaobject_type"],
"additionalProperties": false
Expand All @@ -672,7 +680,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"required": ["metaobject_type"],
"additionalProperties": false
Expand Down Expand Up @@ -726,7 +735,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand All @@ -742,7 +752,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand All @@ -762,7 +773,8 @@
"default": true,
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": { "$ref": "#/definitions/ignoredConditionalSetting" }
},
"additionalProperties": false
},
Expand Down Expand Up @@ -1113,6 +1125,13 @@
}
},

"ignoredConditionalSetting": {
"$comment": "visible_if on setting types that don't support it. Accepted so the file saves, but ignored by the theme editor.",
"type": "string",
"description": "visible_if isn't supported on this setting type. It's ignored and the setting is always visible in the theme editor.",
"markdownDescription": "`visible_if` isn't supported on this setting type. It's ignored and the setting is always visible in the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/storefronts/themes/architecture/settings#conditional-settings)"
},

"inputSettingsStandardAttributes": {
"required": ["type", "id", "label"],
"properties": {
Expand Down
28 changes: 25 additions & 3 deletions tests/section.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('JSON Schema validation of Liquid theme section schema tags', () => {
);

it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)(
'should not allow visible_if on %s setting type',
'should accept (and ignore) visible_if on %s setting type',
async (settingType) => {
const schema = {
settings: [
Expand All @@ -265,10 +265,32 @@ describe('JSON Schema validation of Liquid theme section schema tags', () => {
};

const diagnostics = await validate('sections/section.liquid', schema);
expect(diagnostics).toContainEqual(
expect(diagnostics).not.toContainEqual(
expect.objectContaining({
message: 'Property visible_if is not allowed.',
severity: 1,
}),
);
},
);

it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)(
'should still require visible_if to be a string on %s setting type',
async (settingType) => {
const schema = {
settings: [
{
type: settingType,
id: 'test_setting',
label: 'Test Setting',
visible_if: 42,
},
],
};

const diagnostics = await validate('sections/section.liquid', schema);
expect(diagnostics).toContainEqual(
expect.objectContaining({
message: 'Incorrect type. Expected "string".',
}),
);
},
Expand Down
1 change: 1 addition & 0 deletions tests/test-constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// visible_if is accepted on these types so files still save, but the theme editor ignores it.
export const SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF = [
'article',
'article_list',
Expand Down
8 changes: 2 additions & 6 deletions tests/theme-settings/color_palette.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,12 @@ describe('Module: theme settings validation (config/settings_schema.json)', () =
]);
});

it('refuses the visible_if property', async () => {
it('accepts (and ignores) the visible_if property', async () => {
const diagnostics = await validate(
'config/settings_schema.json',
settings({ visible_if: '{{ section.settings.show_palette }}' }),
);
expect(diagnostics).toStrictEqual([
expect.objectContaining({
message: 'Property visible_if is not allowed.',
}),
]);
expect(diagnostics).toStrictEqual([]);
});

it('requires the default property', async () => {
Expand Down
9 changes: 4 additions & 5 deletions tests/theme_block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('JSON Schema validation of Liquid theme block schema tags', () => {
expect(diagnostics).toStrictEqual([]);
});

it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)('should not allow visible_if on %s setting type', async (settingType) => {
it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)('should accept (and ignore) visible_if on %s setting type', async (settingType) => {
const schema = {
settings: [
{
Expand All @@ -254,12 +254,11 @@ describe('JSON Schema validation of Liquid theme block schema tags', () => {
}
]
};

const diagnostics = await validate('blocks/block.liquid', schema);
expect(diagnostics).toContainEqual(
expect(diagnostics).not.toContainEqual(
expect.objectContaining({
message: 'Property visible_if is not allowed.',
severity: 1
message: 'Property visible_if is not allowed.'
})
);
});
Expand Down
Loading