Skip to content

Commit e5cac4a

Browse files
authored
✨ JSON validation for amp-story-shopping config (ampproject#37474)
* added camelcase to shopping config files * added attribute validators for validate config * added upper limit for max string length * added validate number and optional attributes * optimzied arrays * spruced up required and optional attribute blaidtor * added in proper valdiation checks using reduce funcitons * Added in required attributes * added correct unit tests * added correct attribtues to the visual diff tests * fixed JSON formatting of remote config * finished writing unit tests for config * added camelCase * fixed merge conflicts * fixed unit test * changed producttagid to prodcutId * Fixed a few find and replace bugs * added tempalte literals * fix reduce array * removed unused fiedls * changed test string * udpated test to remove unusd fields * added better vladiation logic * fixed unit test * updated unit tests * removed unued variable * refactored unit tests and typedefs * test, do not merge * added in test that throw errors * fixed a few validation PR things * Added alt attribute for product images * udpated visual diff tests * added better string test * added update to config * Added in aggregate enhancement for validation * removed page attachment as it's lazy lodaded * added in logic to skip optional attributes * updated unit tests * updated unit test * updated unit tests * updated unit tests * updated unit test * added reducer logic for config valdiation * added essetial fields method * dupated code path to the correc texecution path * removed bad console log * removed unnnescessary exports * rmeoved unnened exports * removed extra config valdiation * fixed unit test for shopping config * amp story shopping lang de * added in vlaidation unit tests * Addd unit tests to work * added alt attribute * removed alt code * relsolved merge conflicts * added remove shopping tag by index logic * added validation config checks for Arraay, obejcts, added stoppping conditiosn for array, objects, and eve nthe field names * added validation config checks for Arraay, obejcts, added stoppping conditiosn for array, objects, and eve nthe field names * addex splice index to add correct index offset * added seprate array function * unit test cleanup * changed name * made aggregate rating optional * made aggregate rating optional * Added some nit fixes to shoppingtagvalidation * updated logic, added case where optional fields with no validaterequired function does not blokc rndering * added blocking rendering for optional attributes (revert this commit if you do not want optional attributes to block rendering, see the shopping validation i2i for more info) * added validateCurrency and validate currency unit test * optimized currency by using international number format's built-in error check ing to reduce bundle size * optimized currency by using international number format's built-in error check ing to reduce bundle size * updated it to return functions * updated warning mesage * updated error and warning message with nullish coalescing operator * updated error and warning message with nullish coalescing operator * updated and simplified reducer into a filter function * updated and simplified reducer into a filter function * added test for validate HTML id * cleaned up validation conifg * fixed up vlaidtion config * got validation unit tests to pass, added several validation config enhancements * added product vendor id * resolved merge conflict * fixed some validation test files * added shopping config fixes * thrwo away invalid remote config URL * fixed validtion test errors * updated unit tests with length checks * added validation * udpated validation unit tests * added test dependencies * removed unneesc dependencies * integrated ajv json schema validator initial commit * added validate prodcut to configuration * add back in some code, per function or per block validation? * updated json schema to a working schema * added valid config * added First working validation for ajv json schema * updated unit tests yet again * cleaned up json schema code * added passing unit tests, updated regex, updated .html files to pass validation * added realtive url validation * updated test regex * added support for relative URLs * added better url checks * added udpated export functions relativeToSourceUrl * fixed test * fixed prettier formatting * fixed json formatting * fixed json formatting * added additoinal items * added item name prefix * added newline test * refactored code, page id, etc * added comment to pass circleci tests * pass circleCI
1 parent cb67fc9 commit e5cac4a

File tree

8 files changed

+524
-125
lines changed

8 files changed

+524
-125
lines changed

Diff for: examples/amp-story/amp-story-shopping.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@
147147
"productPrice": 799.00,
148148
"productPriceCurrency": "USD",
149149
"productImages": [
150-
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 1"},
151-
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 2"},
152-
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 3"},
153-
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 4"},
154-
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 5"},
155-
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 6"}
150+
{"url": "https://source.unsplash.com/Ry9WBo3qmoc/500x500", "alt": "lamp 1"},
151+
{"url": "https://source.unsplash.com/KP7p0-DRGbg", "alt": "lamp 2"},
152+
{"url": "https://source.unsplash.com/mFnbFaCIu1I", "alt": "lamp 3"},
153+
{"url": "https://source.unsplash.com/py9sH2rThWs", "alt": "lamp 4"},
154+
{"url": "https://source.unsplash.com/VDPauwJ_sHo", "alt": "lamp 5"},
155+
{"url": "https://source.unsplash.com/3LTht2nxd34", "alt": "lamp 6"}
156156
],
157157
"aggregateRating": {
158158
"ratingValue": 4.4,

Diff for: examples/amp-story/shopping/product.schema.json

+281
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
{
2+
"title": "Product",
3+
"description": "A product from an amp-story-shopping configuration.",
4+
"type": "object",
5+
"additionalProperties": false,
6+
"properties": {
7+
"productId": {
8+
"description": "Keys for amp-story-shopping-tag nodes, sent out in analytics events.",
9+
"type": "string"
10+
},
11+
"productUrl": {
12+
"description": "Links to the product's website, whne the buy now button is clicked.",
13+
"type": "string",
14+
"$ref": "#/$defs/https"
15+
},
16+
"productTitle": {
17+
"description": "The name of the product, displayed on the tag.",
18+
"type": "string"
19+
},
20+
"productPrice": {
21+
"description": "The price of the product, displayed on the tag.",
22+
"type": "number"
23+
},
24+
"productPriceCurrency": {
25+
"description": "The ISO 4217 currency code of the product price.",
26+
"type": "string",
27+
"enum": [
28+
"AED",
29+
"AFN",
30+
"ALL",
31+
"AMD",
32+
"ANG",
33+
"AOA",
34+
"ARS",
35+
"AUD",
36+
"AWG",
37+
"AZN",
38+
"BAM",
39+
"BBD",
40+
"BDT",
41+
"BGN",
42+
"BHD",
43+
"BIF",
44+
"BMD",
45+
"BND",
46+
"BOB",
47+
"BOV",
48+
"BRL",
49+
"BSD",
50+
"BTN",
51+
"BWP",
52+
"BYN",
53+
"BZD",
54+
"CAD",
55+
"CDF",
56+
"CHE",
57+
"CHF",
58+
"CHW",
59+
"CLF",
60+
"CLP",
61+
"CNY",
62+
"COP",
63+
"COU",
64+
"CRC",
65+
"CUC",
66+
"CUP",
67+
"CVE",
68+
"CZK",
69+
"DJF",
70+
"DKK",
71+
"DOP",
72+
"DZD",
73+
"EGP",
74+
"ERN",
75+
"ETB",
76+
"EUR",
77+
"FJD",
78+
"FKP",
79+
"GBP",
80+
"GEL",
81+
"GHS",
82+
"GIP",
83+
"GMD",
84+
"GNF",
85+
"GTQ",
86+
"GYD",
87+
"HKD",
88+
"HNL",
89+
"HRK",
90+
"HTG",
91+
"HUF",
92+
"IDR",
93+
"ILS",
94+
"INR",
95+
"IQD",
96+
"IRR",
97+
"ISK",
98+
"JMD",
99+
"JOD",
100+
"JPY",
101+
"KES",
102+
"KGS",
103+
"KHR",
104+
"KMF",
105+
"KPW",
106+
"KRW",
107+
"KWD",
108+
"KYD",
109+
"KZT",
110+
"LAK",
111+
"LBP",
112+
"LKR",
113+
"LRD",
114+
"LSL",
115+
"LYD",
116+
"MAD",
117+
"MDL",
118+
"MGA",
119+
"MKD",
120+
"MMK",
121+
"MNT",
122+
"MOP",
123+
"MRU",
124+
"MUR",
125+
"MVR",
126+
"MWK",
127+
"MXN",
128+
"MXV",
129+
"MYR",
130+
"MZN",
131+
"NAD",
132+
"NGN",
133+
"NIO",
134+
"NOK",
135+
"NPR",
136+
"NZD",
137+
"OMR",
138+
"PAB",
139+
"PEN",
140+
"PGK",
141+
"PHP",
142+
"PKR",
143+
"PLN",
144+
"PYG",
145+
"QAR",
146+
"RON",
147+
"RSD",
148+
"RUB",
149+
"RWF",
150+
"SAR",
151+
"SBD",
152+
"SCR",
153+
"SDG",
154+
"SEK",
155+
"SGD",
156+
"SHP",
157+
"SLL",
158+
"SOS",
159+
"SRD",
160+
"SSP",
161+
"STN",
162+
"SVC",
163+
"SYP",
164+
"SZL",
165+
"THB",
166+
"TJS",
167+
"TMT",
168+
"TND",
169+
"TOP",
170+
"TRY",
171+
"TTD",
172+
"TWD",
173+
"TZS",
174+
"UAH",
175+
"UGX",
176+
"USD",
177+
"USN",
178+
"UYI",
179+
"UYU",
180+
"UYW",
181+
"UZS",
182+
"VED",
183+
"VES",
184+
"VND",
185+
"VUV",
186+
"WST",
187+
"XAF",
188+
"XAG",
189+
"XAU",
190+
"XBA",
191+
"XBB",
192+
"XBC",
193+
"XBD",
194+
"XCD",
195+
"XDR",
196+
"XOF",
197+
"XPD",
198+
"XPF",
199+
"XPT",
200+
"XSU",
201+
"XTS",
202+
"XUA",
203+
"XXX",
204+
"YER",
205+
"ZAR",
206+
"ZMW",
207+
"ZWL"
208+
]
209+
},
210+
"productImages": {
211+
"description": "A list of images for the product used in the carousel of the product page",
212+
"type": "array",
213+
"items": {
214+
"required": ["url", "alt"],
215+
"additionalProperties": false,
216+
"type": "object",
217+
"properties": {
218+
"url": {
219+
"$ref": "#/$defs/https"
220+
},
221+
"alt": {
222+
"type": "string"
223+
}
224+
}
225+
}
226+
},
227+
"productDetails": {
228+
"description": "Details about the product used in the product details page",
229+
"type": "string"
230+
},
231+
"productBrand": {
232+
"description": "Brand name of the product used in the tag.",
233+
"type": "string"
234+
},
235+
"productIcon": {
236+
"description": "Links the icon image for the product in the tag. Defaults to a shopping bag icon.",
237+
"type": "string"
238+
},
239+
"productTagText": {
240+
"description": "Text for the Prodcut tag. Supersedes productPrice",
241+
"type": "string"
242+
},
243+
"aggregateRating": {
244+
"description": "Ratings and review data for the product displayed on the product page.",
245+
"type": "object",
246+
"required": ["ratingValue", "reviewCount", "reviewUrl"],
247+
"additionalProperties": false,
248+
"properties": {
249+
"ratingValue": {
250+
"description": "The aggregate rating value of the product.",
251+
"type": "number"
252+
},
253+
"reviewCount": {
254+
"description": "The number of reviews for the product.",
255+
"type": "number"
256+
},
257+
"reviewUrl": {
258+
"description": "The Url for the product reviews.",
259+
"type": "string",
260+
"$ref": "#/$defs/https"
261+
}
262+
}
263+
}
264+
},
265+
"required": [
266+
"productId",
267+
"productUrl",
268+
"productTitle",
269+
"productPrice",
270+
"productPriceCurrency",
271+
"productImages",
272+
"productDetails"
273+
],
274+
"$defs": {
275+
"https": {
276+
"type": "string",
277+
"format": "uri-reference",
278+
"pattern": "^(/|https://|https?://(127.0.0.1|([^/]+\\.)?localhost)(:[0-9]+)?/)"
279+
}
280+
}
281+
}

Diff for: examples/visual-tests/amp-story/amp-story-shopping-landscape.html

+16-16
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 6"}
7272
],
7373
"aggregateRating": {
74-
"ratingValue": "4.4",
75-
"reviewCount": "89",
74+
"ratingValue": 4.4,
75+
"reviewCount": 89,
7676
"reviewUrl": "https://www.google.com"
7777
},
7878
"productDetails": "One newline after this. \n Two newlines after this. \n\n Five consecutive newlines after this, should become 2 newlines. \n\n\n\n\n Many consecutive newlines with different spacing and tabs after this, should become 2 newlines. \n \n\n \n \n \n \n \n I hope it works!"
@@ -86,8 +86,8 @@
8686
"productPriceCurrency": "INR",
8787
"productImages": [{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "art"}],
8888
"aggregateRating": {
89-
"ratingValue": "4.4",
90-
"reviewCount": "89",
89+
"ratingValue": 4.4,
90+
"reviewCount": 89,
9191
"reviewUrl": "https://www.google.com"
9292
},
9393
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. \n Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
@@ -101,8 +101,8 @@
101101
"productTagText": "The perfectly imperfect yellow chair",
102102
"productImages": [{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "chair"}],
103103
"aggregateRating": {
104-
"ratingValue": "4.4",
105-
"reviewCount": "89",
104+
"ratingValue": 4.4,
105+
"reviewCount": 89,
106106
"reviewUrl": "https://www.google.com"
107107
},
108108
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
@@ -117,8 +117,8 @@
117117
"productIcon": "/examples/visual-tests/amp-story/img/shopping/icon.png",
118118
"productImages": [{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "flowers"}],
119119
"aggregateRating": {
120-
"ratingValue": "4.4",
121-
"reviewCount": "89",
120+
"ratingValue": 4.4,
121+
"reviewCount": 89,
122122
"reviewUrl": "https://www.google.com"
123123
},
124124
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
@@ -161,8 +161,8 @@
161161
{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "lamp 6"}
162162
],
163163
"aggregateRating": {
164-
"ratingValue": "4.4",
165-
"reviewCount": "89",
164+
"ratingValue": 4.4,
165+
"reviewCount": 89,
166166
"reviewUrl": "https://www.google.com"
167167
},
168168
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. \n Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
@@ -176,8 +176,8 @@
176176
"productPriceCurrency": "INR",
177177
"productImages": [{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "art"}],
178178
"aggregateRating": {
179-
"ratingValue": "4.4",
180-
"reviewCount": "89",
179+
"ratingValue": 4.4,
180+
"reviewCount": 89,
181181
"reviewUrl": "https://www.google.com"
182182
},
183183
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. \n Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
@@ -191,8 +191,8 @@
191191
"productTagText": "The perfectly imperfect yellow chair",
192192
"productImages": [{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "chair"}],
193193
"aggregateRating": {
194-
"ratingValue": "4.4",
195-
"reviewCount": "89",
194+
"ratingValue": 4.4,
195+
"reviewCount": 89,
196196
"reviewUrl": "https://www.google.com"
197197
},
198198
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. \n Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
@@ -207,8 +207,8 @@
207207
"productIcon": "/examples/visual-tests/amp-story/img/shopping/icon.png",
208208
"productImages": [{"url": "/examples/visual-tests/amp-story/img/cat1.jpg", "alt": "flowers"}],
209209
"aggregateRating": {
210-
"ratingValue": "4.4",
211-
"reviewCount": "89",
210+
"ratingValue": 4.4,
211+
"reviewCount": 89,
212212
"reviewUrl": "https://www.google.com"
213213
},
214214
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. \n Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."

Diff for: examples/visual-tests/amp-story/amp-story-shopping-rtl.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"reviewCount": 89,
7575
"reviewUrl": "https://www.google.com"
7676
},
77-
"productDetails": "One newline after this. \n Two newlines after this. \n\n Five consecutive newlines after this, should become 2 newlines. \n\n\n\n\n Many consecutive newlines with different spacing and tabs after this, should become 2 newlines. \n \n\n \n \n \n \n \n I hope it works!"
77+
"productDetails": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere error deserunt dignissimos in laborum ea molestias veritatis sint laudantium iusto expedita atque provident doloremque, ad voluptatem culpa adipisci."
7878
},
7979
{
8080
"productUrl": "https://www.google.com",

0 commit comments

Comments
 (0)