Skip to content

Commit dfe771f

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

File tree

9 files changed

+781
-2
lines changed

9 files changed

+781
-2
lines changed

Makefile

+7
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

+1-1
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

+5-1
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

+4
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

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
"config",
21+
"modelfs"
22+
],
23+
"$defs": {
24+
"ModelConfig": {
25+
"type": "object",
26+
"properties": {
27+
"architecture": {
28+
"type": "string"
29+
},
30+
"format": {
31+
"type": "string"
32+
},
33+
"paramSize": {
34+
"type": "string"
35+
},
36+
"precision": {
37+
"type": "string"
38+
},
39+
"quantization": {
40+
"type": "string"
41+
}
42+
},
43+
"additionalProperties": false
44+
},
45+
"ModelDescriptor": {
46+
"type": "object",
47+
"properties": {
48+
"createdAt": {
49+
"type": "string",
50+
"format": "date-time"
51+
},
52+
"authors": {
53+
"type": "array",
54+
"items": {
55+
"type": "string"
56+
}
57+
},
58+
"family": {
59+
"type": "string"
60+
},
61+
"name": {
62+
"type": "string",
63+
"minLength": 1
64+
},
65+
"docURL": {
66+
"type": "string"
67+
},
68+
"sourceURL": {
69+
"type": "string"
70+
},
71+
"version": {
72+
"type": "string"
73+
},
74+
"revision": {
75+
"type": "string"
76+
},
77+
"vendor": {
78+
"type": "string"
79+
},
80+
"licenses": {
81+
"type": "array",
82+
"items": {
83+
"type": "string"
84+
}
85+
},
86+
"title": {
87+
"type": "string"
88+
},
89+
"description": {
90+
"type": "string"
91+
}
92+
},
93+
"additionalProperties": false
94+
},
95+
"ModelFS": {
96+
"type": "object",
97+
"properties": {
98+
"type": {
99+
"type": "string",
100+
"enum": ["layers"]
101+
},
102+
"diff_ids": {
103+
"type": "array",
104+
"items": {
105+
"type": "string"
106+
},
107+
"minItems": 1
108+
}
109+
},
110+
"additionalProperties": false,
111+
"required": [
112+
"type",
113+
"diff_ids"
114+
]
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)