Skip to content

Commit 379215b

Browse files
committed
add json schema & validator for config
Signed-off-by: caozhuozi <[email protected]>
1 parent b4b9a24 commit 379215b

File tree

9 files changed

+800
-2
lines changed

9 files changed

+800
-2
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.PHONY: validate-examples
2+
validate-examples: ## validate examples in the specification markdown files
3+
go test ./schema/example_test.go
4+
5+
.PHONY: test
6+
test:
7+
go test ./...

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ The following terms are used in this section:
107107

108108
Here is an example model artifact configuration JSON document:
109109

110-
```json
110+
```json,title=Model%20Config%20JSON&mediatype=application/vnd.cnai.model.config.v1%2Bjson
111111
{
112112
"descriptor": {
113113
"createdAt": "2025-01-01T00:00:00Z",

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ module github.com/CloudNativeAI/model-spec
22

33
go 1.23.1
44

5-
require github.com/opencontainers/go-digest v1.0.0
5+
require (
6+
github.com/opencontainers/go-digest v1.0.0
7+
github.com/russross/blackfriday v1.6.0
8+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
9+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
22
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
3+
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
4+
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
5+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
6+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=

schema/config-schema.json

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"description": "Model Artifact Configuration Schema",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
4+
"$id": "https://github.com/CloudNativeAI/model-spec/config",
5+
"type": "object",
6+
"properties": {
7+
"descriptor": {
8+
"$ref": "#/$defs/ModelDescriptor"
9+
},
10+
"modelfs": {
11+
"$ref": "#/$defs/ModelFS"
12+
},
13+
"config": {
14+
"$ref": "#/$defs/ModelConfig"
15+
}
16+
},
17+
"additionalProperties": false,
18+
"required": [
19+
"descriptor",
20+
"modelfs"
21+
],
22+
"$defs": {
23+
"ModelConfig": {
24+
"type": "object",
25+
"properties": {
26+
"architecture": {
27+
"type": "string"
28+
},
29+
"format": {
30+
"type": "string"
31+
},
32+
"paramSize": {
33+
"type": "string"
34+
},
35+
"precision": {
36+
"type": "string"
37+
},
38+
"quantization": {
39+
"type": "string"
40+
}
41+
},
42+
"additionalProperties": false
43+
},
44+
"ModelDescriptor": {
45+
"type": "object",
46+
"properties": {
47+
"createdAt": {
48+
"type": "string",
49+
"format": "date-time"
50+
},
51+
"authors": {
52+
"type": "array",
53+
"items": {
54+
"type": "string"
55+
}
56+
},
57+
"family": {
58+
"type": "string"
59+
},
60+
"name": {
61+
"type": "string",
62+
"minLength": 1
63+
},
64+
"docURL": {
65+
"type": "string"
66+
},
67+
"sourceURL": {
68+
"type": "string"
69+
},
70+
"version": {
71+
"type": "string"
72+
},
73+
"revision": {
74+
"type": "string"
75+
},
76+
"vendor": {
77+
"type": "string"
78+
},
79+
"licenses": {
80+
"type": "array",
81+
"items": {
82+
"type": "string"
83+
}
84+
},
85+
"title": {
86+
"type": "string"
87+
},
88+
"description": {
89+
"type": "string"
90+
}
91+
},
92+
"additionalProperties": false,
93+
"required": [
94+
"name",
95+
"version"
96+
]
97+
},
98+
"ModelFS": {
99+
"type": "object",
100+
"properties": {
101+
"type": {
102+
"type": "string",
103+
"enum": ["layers"]
104+
},
105+
"diff_ids": {
106+
"type": "array",
107+
"items": {
108+
"type": "string"
109+
},
110+
"minItems": 1
111+
}
112+
},
113+
"additionalProperties": false,
114+
"required": [
115+
"type",
116+
"diff_ids"
117+
]
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)