Skip to content

Commit 4d3d4b5

Browse files
committed
nlohmann::json instance and JSON Schema for MemorySourceAccessor
As documented, this for file system objects themselves, since `MemorySourceAccessor` is an implementation detail.
1 parent 90c7d7d commit 4d3d4b5

File tree

20 files changed

+456
-48
lines changed

20 files changed

+456
-48
lines changed

doc/manual/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mkMesonDerivation (finalAttrs: {
3434
(fileset.unions [
3535
../../.version
3636
# For example JSON
37+
../../src/libutil-tests/data/memory-source-accessor
3738
../../src/libutil-tests/data/hash
3839
../../src/libstore-tests/data/content-address
3940
../../src/libstore-tests/data/store-path

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
- [Architecture and Design](architecture/architecture.md)
120120
- [Formats and Protocols](protocols/index.md)
121121
- [JSON Formats](protocols/json/index.md)
122+
- [File System Object](protocols/json/file-system-object.md)
122123
- [Hash](protocols/json/hash.md)
123124
- [Content Address](protocols/json/content-address.md)
124125
- [Store Path](protocols/json/store-path.md)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{#include file-system-object-v1-fixed.md}}
2+
3+
## Examples
4+
5+
### Simple
6+
7+
```json
8+
{{#include schema/file-system-object-v1/simple.json}}
9+
```
10+
11+
### Complex
12+
13+
```json
14+
{{#include schema/file-system-object-v1/complex.json}}
15+
```
16+
17+
<!-- need to convert YAML to JSON first
18+
## Raw Schema
19+
20+
[JSON Schema for File System Object v1](schema/file-system-object-v1.json)
21+
-->

doc/manual/source/protocols/json/fixup-json-schema-generated-doc.sed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ s/\\`/`/g
1111
#
1212
# As we have more such relative links, more replacements of this nature
1313
# should appear below.
14+
s^#/\$defs/\(regular\|symlink\|directory\)^In this schema^g
1415
s^\(./hash-v1.yaml\)\?#/$defs/algorithm^[JSON format for `Hash`](./hash.html#algorithm)^g
1516
s^\(./hash-v1.yaml\)^[JSON format for `Hash`](./hash.html)^g
1617
s^\(./content-address-v1.yaml\)\?#/$defs/method^[JSON format for `ContentAddress`](./content-address.html#method)^g

doc/manual/source/protocols/json/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ json_schema_for_humans = find_program('generate-schema-doc', required : false)
99
json_schema_config = files('json-schema-for-humans-config.yaml')
1010

1111
schemas = [
12+
'file-system-object-v1',
1213
'hash-v1',
1314
'content-address-v1',
1415
'store-path-v1',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libutil-tests/data/memory-source-accessor
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"$schema": http://json-schema.org/draft-04/schema#
2+
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/file-system-object-v1.json
3+
title: File System Object
4+
description: |
5+
This schema describes the JSON representation of Nix's [File System Object](@docroot@/store/file-system-object.md).
6+
7+
The schema is recursive because file system objects contain other file system objects.
8+
type: object
9+
required: ["type"]
10+
properties:
11+
type:
12+
type: string
13+
enum: ["regular", "symlink", "directory"]
14+
15+
# Enforce conditional structure based on `type`
16+
anyOf:
17+
- $ref: "#/$defs/regular"
18+
required: ["type", "contents"]
19+
20+
- $ref: "#/$defs/symlink"
21+
required: ["type", "target"]
22+
23+
- $ref: "#/$defs/directory"
24+
required: ["type", "contents"]
25+
26+
"$defs":
27+
regular:
28+
title: Regular File
29+
required: ["contents"]
30+
properties:
31+
type:
32+
const: "regular"
33+
contents:
34+
type: string
35+
description: Base64-encoded file contents
36+
executable:
37+
type: boolean
38+
description: Whether the file is executable.
39+
default: false
40+
additionalProperties: false
41+
42+
symlink:
43+
title: Symbolic Link
44+
required: ["target"]
45+
properties:
46+
type:
47+
const: "symlink"
48+
target:
49+
type: string
50+
description: Target path of the symlink.
51+
additionalProperties: false
52+
53+
directory:
54+
title: Directory
55+
required: ["contents"]
56+
properties:
57+
type:
58+
const: "directory"
59+
contents:
60+
type: object
61+
description: |
62+
Map of names to nested file system objects (for type=directory)
63+
additionalProperties:
64+
$ref: "#"
65+
additionalProperties: false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../src/libutil-tests/data/memory-source-accessor

src/json-schema-checks/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ schema_dir = meson.current_source_dir() / 'schema'
2020

2121
# Get all example files
2222
schemas = [
23+
{
24+
'stem' : 'file-system-object',
25+
'schema' : schema_dir / 'file-system-object-v1.yaml',
26+
'files' : [
27+
'simple.json',
28+
'complex.json',
29+
],
30+
},
2331
{
2432
'stem' : 'hash',
2533
'schema' : schema_dir / 'hash-v1.yaml',

src/json-schema-checks/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mkMesonDerivation (finalAttrs: {
2020
fileset = lib.fileset.unions [
2121
../../.version
2222
../../doc/manual/source/protocols/json/schema
23+
../../src/libutil-tests/data/memory-source-accessor
2324
../../src/libutil-tests/data/hash
2425
../../src/libstore-tests/data/content-address
2526
../../src/libstore-tests/data/store-path

0 commit comments

Comments
 (0)