Skip to content

Commit cdb643a

Browse files
committed
$defs to definitions
Signed-off-by: Clemens Vasters <clemens@vasters.com>
1 parent c329f12 commit cdb643a

6 files changed

+77
-77
lines changed

json-structure-primer.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object-oriented programming.
3535
- [3.1. Example: Declaring a simple object type](#31-example-declaring-a-simple-object-type)
3636
- [3.2. Example: Declaring Primitive and Extended Types](#32-example-declaring-primitive-and-extended-types)
3737
- [4. Example: Declaring inline compound types](#4-example-declaring-inline-compound-types)
38-
- [4.1. Example: Declaring reusable types in `$defs`](#41-example-declaring-reusable-types-in-defs)
38+
- [4.1. Example: Declaring reusable types in `definitions`](#41-example-declaring-reusable-types-in-defs)
3939
- [4.2. Example: Structuring types with namespaces](#42-example-structuring-types-with-namespaces)
4040
- [4.3. Example: Using an Array Type](#43-example-using-an-array-type)
4141
- [4.4. Example: Declaring Maps](#44-example-declaring-maps)
@@ -234,7 +234,7 @@ Example:
234234
```json
235235
{
236236
"$schema": "https://json-structure.github.io/meta/core/v0/#",
237-
"$defs" : {
237+
"definitions" : {
238238
"AddressBase": {
239239
"abstract": true,
240240
"type": "object",
@@ -246,21 +246,21 @@ Example:
246246
},
247247
"StreetAddress": {
248248
"type": "object",
249-
"$extends": "#/$defs/AddressBase",
249+
"$extends": "#/definitions/AddressBase",
250250
"properties": {
251251
"street": { "type": "string" }
252252
}
253253
},
254254
"PostOfficeBoxAddress": {
255255
"type": "object",
256-
"$extends": "#/$defs/AddressBase",
256+
"$extends": "#/definitions/AddressBase",
257257
"properties": {
258258
"poBox": { "type": "string" }
259259
}
260260
},
261261
"Address": {
262262
"type": "object",
263-
"$extends": "#/$defs/AddressBase"
263+
"$extends": "#/definitions/AddressBase"
264264
}
265265
}
266266
}
@@ -287,11 +287,11 @@ applied to any _StreetAddress_ types in a document:
287287
{
288288
"$schema": "https://json-structure.github.io/meta/core/v0/#",
289289
"$id": "https://schemas.vasters.com/Addresses",
290-
"$root": "#/$defs/StreetAddress",
290+
"$root": "#/definitions/StreetAddress",
291291
"$offers": {
292-
"DeliveryInstructions": "#/$defs/DeliveryInstructions"
292+
"DeliveryInstructions": "#/definitions/DeliveryInstructions"
293293
},
294-
"$defs" : {
294+
"definitions" : {
295295
"StreetAddress": {
296296
"type": "object",
297297
"properties": {
@@ -304,7 +304,7 @@ applied to any _StreetAddress_ types in a document:
304304
"DeliveryInstructions": {
305305
"abstract": true,
306306
"type": "object",
307-
"$extends": "#/$defs/StreetAddress",
307+
"$extends": "#/definitions/StreetAddress",
308308
"properties": {
309309
"instructions": { "type": "string" }
310310
}
@@ -501,9 +501,9 @@ type cannot be referenced from other types in the schema.
501501
}
502502
```
503503

504-
### 4.1. Example: Declaring reusable types in `$defs`
504+
### 4.1. Example: Declaring reusable types in `definitions`
505505

506-
To define reusable types, you can use the `$defs` keyword to define types that
506+
To define reusable types, you can use the `definitions` keyword to define types that
507507
can be referenced by other types in the same document. Here is an example:
508508

509509
```json
@@ -518,10 +518,10 @@ can be referenced by other types in the same document. Here is an example:
518518
"score": { "type": "int64" },
519519
"balance": { "type": "decimal", "precision": 20, "scale": 2 },
520520
"isActive": { "type": "boolean" },
521-
"address": { "type" : { "$ref": "#/$defs/Address" } }
521+
"address": { "type" : { "$ref": "#/definitions/Address" } }
522522
},
523523
"required": ["username", "birthdate"],
524-
"$defs": {
524+
"definitions": {
525525
"Address": {
526526
"type": "object",
527527
"properties": {
@@ -536,9 +536,9 @@ can be referenced by other types in the same document. Here is an example:
536536
}
537537
```
538538

539-
In this example, the `Address` type is declared in the `$defs` section and can be
539+
In this example, the `Address` type is declared in the `definitions` section and can be
540540
referenced by other types in the same document using the `$ref` keyword. Mind
541-
that the `$ref` keyword can now only reference types declared in the `$defs`
541+
that the `$ref` keyword can now only reference types declared in the `definitions`
542542
section of the same document. The keyword can only be used where a type is
543543
expected.
544544

@@ -555,11 +555,11 @@ namespaces to structure your types, with two differing `Address` types:
555555
"properties": {
556556
"username": { "type": "string" },
557557
"dateOfBirth": { "type": "date" },
558-
"networkAddress": { "type" : { "$ref": "#/$defs/Network/Address" } },
559-
"physicalAddress": { "type": { "$ref": "#/$defs/Physical/Address" } }
558+
"networkAddress": { "type" : { "$ref": "#/definitions/Network/Address" } },
559+
"physicalAddress": { "type": { "$ref": "#/definitions/Physical/Address" } }
560560
},
561561
"required": ["username", "birthdate"],
562-
"$defs": {
562+
"definitions": {
563563
"Network": {
564564
"Address": {
565565
"type": "object",
@@ -623,8 +623,8 @@ To declare an array of a reusable type, you can use the `$ref` keyword:
623623
{
624624
"$schema": "https://json-structure.github.io/meta/core/v0/#",
625625
"type": "array",
626-
"items": { "type" : { "$ref": "#/$defs/Person" } },
627-
"$defs": {
626+
"items": { "type" : { "$ref": "#/definitions/Person" } },
627+
"definitions": {
628628
"Person": {
629629
"type": "object",
630630
"name": "Person",
@@ -647,8 +647,8 @@ This example shows how to declare a map of strings to `Color` objects:
647647
{
648648
"$schema": "https://json-structure.github.io/meta/core/v0/#",
649649
"type": "map",
650-
"values": { "type": { "$ref": "#/$defs/Color" } },
651-
"$defs": {
650+
"values": { "type": { "$ref": "#/definitions/Color" } },
651+
"definitions": {
652652
"Color": {
653653
"type": "object",
654654
"name": "Color",

samples/py/json_structure_instance_validator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,11 @@ def _process_imports(self, obj, path):
634634
imported_defs = {}
635635
if "type" in external and "name" in external:
636636
imported_defs[external["name"]] = external
637-
if "$defs" in external and isinstance(external["$defs"], dict):
638-
imported_defs.update(external["$defs"])
637+
if "definitions" in external and isinstance(external["definitions"], dict):
638+
imported_defs.update(external["definitions"])
639639
else: # $importdefs
640-
if "$defs" in external and isinstance(external["$defs"], dict):
641-
imported_defs = external["$defs"]
640+
if "definitions" in external and isinstance(external["definitions"], dict):
641+
imported_defs = external["definitions"]
642642
else:
643643
imported_defs = {}
644644
for k, v in imported_defs.items():
@@ -676,7 +676,7 @@ def _fetch_external_schema(self, uri):
676676
"lastName": {"type": "string"},
677677
"address": {"$ref": "#/Address"}
678678
},
679-
"$defs": {
679+
"definitions": {
680680
"Address": {
681681
"name": "Address",
682682
"type": "object",
@@ -690,7 +690,7 @@ def _fetch_external_schema(self, uri):
690690
"https://example.com/importdefs.json": {
691691
"$schema": "https://json-structure.github.io/meta/core/v0/#",
692692
"$id": "https://example.com/importdefs.json",
693-
"$defs": {
693+
"definitions": {
694694
"LibraryType": {
695695
"name": "LibraryType",
696696
"type": "string"

samples/py/json_structure_schema_validator.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class JSONStructureSchemaCoreValidator:
3232
ABSOLUTE_URI_REGEX = re.compile(r'^[a-zA-Z][a-zA-Z0-9+\-.]*://')
3333
MAP_KEY_REGEX = re.compile(r'^[A-Za-z0-9._-]+$')
3434
RESERVED_KEYWORDS = {
35-
"$defs", "$extends", "$id", "$ref", "$root", "$schema", "$uses",
35+
"definitions", "$extends", "$id", "$ref", "$root", "$schema", "$uses",
3636
"$offers", "abstract", "additionalProperties", "const", "default",
3737
"description", "enum", "examples", "format", "items", "maxLength",
3838
"name", "precision", "properties", "required", "scale", "type",
@@ -92,11 +92,11 @@ def validate(self, doc, source_text=None):
9292
self._validate_schema(doc, is_root=True, path="#", name_in_namespace=None)
9393
if "$root" in doc:
9494
self._check_json_pointer(doc["$root"], self.doc, "$root")
95-
if "$defs" in doc:
96-
if not isinstance(doc["$defs"], dict):
97-
self._err("$defs must be an object.", "#/$defs")
95+
if "definitions" in doc:
96+
if not isinstance(doc["definitions"], dict):
97+
self._err("definitions must be an object.", "#/definitions")
9898
else:
99-
self._validate_namespace(doc["$defs"], "#/$defs")
99+
self._validate_namespace(doc["definitions"], "#/definitions")
100100
if "$offers" in doc:
101101
self._check_offers(doc["$offers"], "#/$offers")
102102
return self.errors
@@ -150,12 +150,12 @@ def _process_imports(self, obj, path):
150150
# JSONStructureImport root type if available.
151151
if "type" in external and "name" in external:
152152
imported_defs[external["name"]] = external
153-
# Also import definitions from $defs if available.
154-
if "$defs" in external and isinstance(external["$defs"], dict):
155-
imported_defs.update(external["$defs"])
153+
# Also import definitions from definitions if available.
154+
if "definitions" in external and isinstance(external["definitions"], dict):
155+
imported_defs.update(external["definitions"])
156156
else: # $importdefs
157-
if "$defs" in external and isinstance(external["$defs"], dict):
158-
imported_defs = external["$defs"]
157+
if "definitions" in external and isinstance(external["definitions"], dict):
158+
imported_defs = external["definitions"]
159159
else:
160160
imported_defs = {}
161161
# Merge imported definitions directly into the current object.
@@ -203,9 +203,9 @@ def _fetch_external_schema(self, uri):
203203
"properties": {
204204
"firstName": {"type": "string"},
205205
"lastName": {"type": "string"},
206-
"address": {"$ref": "#/$defs/Address"}
206+
"address": {"$ref": "#/definitions/Address"}
207207
},
208-
"$defs": {
208+
"definitions": {
209209
"Address": {
210210
"name": "Address",
211211
"type": "object",
@@ -231,7 +231,7 @@ def _fetch_external_schema(self, uri):
231231

232232
def _validate_namespace(self, obj, path):
233233
"""
234-
Recursively validates objects in $defs as either a namespace or a schema.
234+
Recursively validates objects in definitions as either a namespace or a schema.
235235
"""
236236
if not isinstance(obj, dict):
237237
self._err(f"{path} must be an object.", path)

samples/py/test_import.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def test_import_with_temp_files(tmp_path):
2727
external_schema_address = {
2828
"$schema": "https://json-structure.github.io/meta/core/v0/#",
2929
"$id": "https://example.com/schema/address",
30-
"$root": "#/$defs/Address",
31-
"$defs": {
30+
"$root": "#/definitions/Address",
31+
"definitions": {
3232
"Address": {
3333
"name": "Address",
3434
"type": "object",
@@ -53,13 +53,13 @@ def test_import_with_temp_files(tmp_path):
5353
"type": "object",
5454
"properties": {
5555
"person": {
56-
"type": { "$ref": "#/$defs/People/Person" }
56+
"type": { "$ref": "#/definitions/People/Person" }
5757
},
5858
"address": {
59-
"type": { "$ref": "#/$defs/Addresses/Address" }
59+
"type": { "$ref": "#/definitions/Addresses/Address" }
6060
}
6161
},
62-
"$defs": {
62+
"definitions": {
6363
"People": {
6464
"$import": "https://example.com/schema/person"
6565
},

samples/py/test_json_structure_instance_validator.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"$id": "https://example.com/schemas/derived",
4242
"name": "DerivedObject",
4343
"type": "object",
44-
"$extends": "#/$defs/BaseObject",
44+
"$extends": "#/definitions/BaseObject",
4545
"properties": {} # Derived does not redefine inherited properties.
4646
}
4747

@@ -645,7 +645,7 @@ def test_enum_invalid():
645645
assert any("not in enum" in err for err in errors)
646646

647647
# -------------------------------------------------------------------
648-
# $ref Resolution Tests (using $defs)
648+
# $ref Resolution Tests (using definitions)
649649
# -------------------------------------------------------------------
650650

651651

@@ -656,9 +656,9 @@ def test_ref_resolution_valid():
656656
"name": "refSchema",
657657
"type": "object",
658658
"properties": {
659-
"value": {"type": {"$ref": "#/$defs/RefType"}}
659+
"value": {"type": {"$ref": "#/definitions/RefType"}}
660660
},
661-
"$defs": {
661+
"definitions": {
662662
"RefType": {"name": "RefType", "type": "string"}
663663
}
664664
}
@@ -674,9 +674,9 @@ def test_ref_resolution_invalid():
674674
"$id": "dummy",
675675
"name": "refSchema",
676676
"properties": {
677-
"value": {"type": {"$ref": "#/$defs/NonExistent"}}
677+
"value": {"type": {"$ref": "#/definitions/NonExistent"}}
678678
},
679-
"$defs": {}
679+
"definitions": {}
680680
}
681681
validator = JSONStructureInstanceValidator(schema)
682682
errors = validator.validate_instance({"value": "test"})
@@ -694,7 +694,7 @@ def test_extends_valid():
694694
"$id": "dummy",
695695
"name": "Root",
696696
"properties": {"child": DERIVED_SCHEMA_VALID},
697-
"$defs": {"BaseObject": BASE_OBJECT_SCHEMA}
697+
"definitions": {"BaseObject": BASE_OBJECT_SCHEMA}
698698
}
699699
instance = {"child": {"baseProp": "hello"}}
700700
validator = JSONStructureInstanceValidator(root_schema)
@@ -708,7 +708,7 @@ def test_extends_conflict():
708708
"$id": "dummy",
709709
"name": "DerivedConflict",
710710
"type": "object",
711-
"$extends": "#/$defs/BaseObject",
711+
"$extends": "#/definitions/BaseObject",
712712
"properties": {"baseProp": {"type": "number"}}
713713
}
714714
root_schema = {
@@ -717,7 +717,7 @@ def test_extends_conflict():
717717
"$id": "dummy",
718718
"name": "Root",
719719
"properties": {"child": derived_conflict},
720-
"$defs": {"BaseObject": BASE_OBJECT_SCHEMA}
720+
"definitions": {"BaseObject": BASE_OBJECT_SCHEMA}
721721
}
722722
instance = {"child": {"baseProp": "should be string"}}
723723
validator = JSONStructureInstanceValidator(root_schema)
@@ -784,7 +784,7 @@ def test_import_and_importdefs(tmp_path):
784784
external_importdefs = {
785785
"$schema": "https://json-structure.github.io/meta/core/v0/#",
786786
"$id": "https://example.com/importdefs.json",
787-
"$defs": {
787+
"definitions": {
788788
"LibraryType": {"name": "LibraryType", "type": "string"}
789789
}
790790
}

0 commit comments

Comments
 (0)