You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn/file-system.md
+91-89Lines changed: 91 additions & 89 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,20 @@ layout: page
3
3
title: Modeling a file system with JSON Schema
4
4
---
5
5
6
-
> Not all constraints to an fstab file can be modeled using JSON Schema alone; however, it can represent a good number of them and the exercise is useful to demonstrate how constraints work.
6
+
*[Introduction](#introduction)
7
+
*[Creating the `fstab` schema](#fstab-schema)
8
+
*[Starting the `entry` schema](#entry-schema)
9
+
*[Constraining an entry](#constraining-entry)
10
+
*[The `diskDevice` definition](#diskdevice)
11
+
*[The `diskUUID` definition](#diskuuid)
12
+
*[The `nfs` definition](#nfs)
13
+
*[The `tmpfs` definition](#tmpfs)
14
+
*[The full entry schema](#full-entry)
15
+
*[Referencing the `entry` schema in the `fstab` schema](#referencing-entry)
16
+
17
+
## <aname="introduction"></a>Introduction
18
+
19
+
> Not all constraints to an fstab file can be modeled using JSON Schema alone; however, it can represent a good number of them and the exercise is useful to demonstrate how constraints work. The examples provided are illustrative of the JSON Schema concepts rather than a real, working schema for an fstab file.
7
20
8
21
This example shows a possible JSON Schema representation of file system mount points as represented in an [`/etc/fstab`](https://en.wikipedia.org/wiki/Fstab) file.
9
22
@@ -43,7 +56,7 @@ An entry in an fstab file can have many different forms; Here is an example:
43
56
}
44
57
```
45
58
46
-
## Creating the schema outline
59
+
## <aname="fstab-schema"></a>Creating the `fstab` schema
47
60
48
61
We will start with a base JSON Schema expressing the following constraints:
49
62
@@ -57,8 +70,11 @@ Building out our JSON Schema from top to bottom:
57
70
* The [`$schema`](http://json-schema.org/latest/json-schema-core.html#rfc.section.7) keyword.
58
71
* The [`type`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.1) validation keyword.
59
72
* The [`required`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.3) validation keyword.
60
-
* The [`properties`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.4) validation keyword with only a `/` entry.
61
-
* The [`patternProperties`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.5) validation keyword to match other property names via a regular expression. Note: it does not match `/`).
73
+
* The [`properties`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.4) validation keyword.
74
+
* The `/` key is empty now; We will fill it out later.
75
+
* The [`patternProperties`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.5) validation keyword.
76
+
* This matches other property names via a regular expression. Note: it does not match `/`.
77
+
* The `^(/[^/]+)+$` key is empty now; We will fill it out later.
62
78
* The [`additionalProperties`](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.6) validation keyword.
63
79
* The value here is `false` to constrain object properties to be either `/` or to match the regular expression.
64
80
@@ -80,7 +96,7 @@ Building out our JSON Schema from top to bottom:
80
96
}
81
97
```
82
98
83
-
## Starting an entry
99
+
## <aname="entry-schema"></a>Starting the `entry` schema
84
100
85
101
We will start with an outline of the JSON schema which adds new concepts to what we've already demonstrated.
This example is much more advanced than the previous example; you will have learned of schema referencing and identification, you will have been introduced to other keywords. There are also a few additional points to consider.
396
-
397
-
### The schema can be improved
398
-
399
-
This is only an example for learning purposes. Some additional constraints could be described. For instance:
400
-
401
-
* it makes no sense for `/` to be mounted on a tmpfs filesystem;
402
-
* it makes no sense to specify the filesystem type if the storage is either NFS or tmpfs.
403
-
404
-
As an exercise, you can always try to add these constraints. It would probably require splitting the schema further.
405
-
406
-
### Not all constraints can be expressed
407
-
408
-
JSON Schema limits itself to describing the structure of JSON data, it cannot express functional constraints.
409
-
410
-
If we take an NFS entry as an example, JSON Schema alone cannot check that the submitted NFS server's hostname, or IP address, is actually correct: this check is left to applications.
411
-
412
-
### Tools have varying JSON Schema support
413
-
414
-
While this is not a concern if you know that the schema you write will be used by you alone, you should keep this in mind if you write a schema which other people can potentially use. The schema we have written here has some features which can be problematic for portability:
415
-
416
-
**format* support is optional, and as such other tools may ignore this keyword: this can lead to a different validation outcome for the same data;
417
-
* it uses regular expressions: care should be taken not to use any advanced features (such as lookarounds), since they may not be supported at the other end;
418
-
* it uses *$schema* to express the need to use draft v6 compliant processing, but not all tools support draft v6.
0 commit comments