Skip to content

Commit 913af24

Browse files
committed
Merge pull request #55 from fge/gh-pages
Some minor updates to the example page
2 parents 3ffdffa + 7675580 commit 913af24

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

examples.html

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,58 @@ <h3>Example JSON data for a product API</h3>
3636

3737
<p>When you're talking about a data format, you want to have metadata about what fields mean, and what valid inputs for those fields are. JSON schema is a specification for standardizing how to answer those questions for JSON data.</p>
3838
<h3>Example schema for the product API</h3>
39-
<p>To start a schema definition, let's begin with a basic to JSON schema.</p>
39+
<p>To start a schema definition, let's begin with a basic JSON schema:</p>
4040

41-
<script src="https://gist.github.com/4460744.js"></script>
41+
<script src="https://gist.github.com/4461646.js"></script>
4242

43-
<p>The above schema has a <em>description</em> saying we are going to describe a product, a <em>type</em> saying our product is a JSON object (versus a simple datapoint like a string/number), and a <em>properties</em>section for describing the data in that object.</p>
43+
<p>The above schema has four properties called <em>keywords</em>.
44+
45+
The <em>title</em> and <em>description</em> keywords are descriptive only, in that they do not add
46+
constraints to the data being validated. The intent of the schema is stated with these two keywords
47+
(that is, this schema describes a product).</p>
48+
49+
<p>The <em>type</em> keyword defines the first constraint on our JSON data: it has to be a JSON
50+
Object.</p>
51+
52+
<p>Finally, the <em>$schema</em> keyword states that this schema is written according to the draft
53+
v4 specification.</p>
4454

4555
<p>Next let's answer our previous questions about this API, starting with id.</p>
4656

4757
<h4>What is id?</h4>
4858
<p><em>id</em> is a numeric value that uniquely identifies a product. Since this is the canonical identifier for a product, it doesn't make sense to have a product without one, so it is required.</p>
4959

5060
<p>In JSON Schema terms, we can update our schema to:</p>
51-
<script src="https://gist.github.com/4460750.js"></script>
61+
<script src="https://gist.github.com/4461657.js"></script>
5262

5363
<h4>Is name required?</h4>
54-
<p><em>name</em> is a string value that describes a product. Since there isn't much to a product, it also is required. Adding this gives us the schema:</p>
64+
<p><em>name</em> is a string value that describes a product. Since there isn't
65+
much to a product without a name, it also is required. Adding this gives us the schema:</p>
5566

56-
<script src="https://gist.github.com/4460756.js"></script>
67+
<script src="https://gist.github.com/4461659.js"></script>
5768

5869
<h4>Can price be 0?</h4>
59-
<p>According to Acme's docs, there are no free products. In JSON schema a number can have a minimum. By default this minimum is inclusive, so we need to specify <em>exclusiveMinimum</em>. Therefore we can update our schema with <em>price</em>:</p>
70+
<p>According to Acme's docs, there are no free products. In JSON schema a number can have a minimum. By default this minimum is inclusive, so we need to specify <em>exclusiveMinimum</em>. Therefore we can update our schema with <em>price</em>:</p>
6071

61-
<script src="https://gist.github.com/4460762.js"></script>
72+
<script src="https://gist.github.com/4461668.js"></script>
6273

6374
<h4>Are all tags strings?</h4>
64-
<p>Finally, we come to the tags property. Unlike the previous properties, tags have many values, and is represented as a JSON array. According to Acme's docs, all tags must be strings, but you aren't required to specify tags. We simply leave <em>tags</em> out of the list of required properties, giving us:</p>
75+
<p>Finally, we come to the <em>tags</em> property. Unlike the previous
76+
properties, tags have many values, and is represented as a JSON array. According
77+
to Acme's docs, all tags must be strings, but you aren't required to specify
78+
tags. We simply leave <em>tags</em> out of the list of required properties.</p>
79+
80+
<p>However, Acme's docs add two constraints:</p>
81+
82+
<ul>
83+
<li>there must be at least one tag,</li>
84+
<li>all tags must be unique.</li>
85+
</ul>
86+
87+
<p>The first constraint can be added with <em>minItems</em>, and the second one by
88+
specifying <em>uniqueItems</em> as being true:</p>
6589

66-
<script src="https://gist.github.com/4460767.js"></script>
90+
<script src="https://gist.github.com/4461739.js"></script>
6791

6892
<h3>Example summary</h3>
6993
<p>The above example is by no means definitive of all the types of data JSON schema can define. For more definitive information see the <a href="#definitions">full standard draft</a>.</p>
@@ -77,7 +101,7 @@ <h4>Set of products:</h4>
77101

78102
<h4>Set of products schema:</h4>
79103

80-
<script src="https://gist.github.com/4460778.js"></script>
104+
<script src="https://gist.github.com/4461781.js"></script>
81105

82106
</div>
83107
</div>

0 commit comments

Comments
 (0)