Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
e520a420
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e520a420
编写于
6月 16, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes #7730: [json] Referencing **local** JSON schema from another local schema
上级
28ffb39e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
28 deletion
+87
-28
extensions/json/server/src/jsonSchemaService.ts
extensions/json/server/src/jsonSchemaService.ts
+15
-8
extensions/json/server/src/jsonServerMain.ts
extensions/json/server/src/jsonServerMain.ts
+2
-5
extensions/json/server/src/test/schema.test.ts
extensions/json/server/src/test/schema.test.ts
+70
-15
未找到文件。
extensions/json/server/src/jsonSchemaService.ts
浏览文件 @
e520a420
...
...
@@ -128,7 +128,7 @@ class SchemaHandle implements ISchemaHandle {
public
getResolvedSchema
():
Thenable
<
ResolvedSchema
>
{
if
(
!
this
.
resolvedSchema
)
{
this
.
resolvedSchema
=
this
.
getUnresolvedSchema
().
then
(
unresolved
=>
{
return
this
.
service
.
resolveSchemaContent
(
unresolved
);
return
this
.
service
.
resolveSchemaContent
(
unresolved
,
this
.
url
);
});
}
return
this
.
resolvedSchema
;
...
...
@@ -357,17 +357,21 @@ export class JSONSchemaService implements IJSONSchemaService {
);
}
public
resolveSchemaContent
(
schemaToResolve
:
UnresolvedSchema
):
Thenable
<
ResolvedSchema
>
{
public
resolveSchemaContent
(
schemaToResolve
:
UnresolvedSchema
,
schemaURL
:
string
):
Thenable
<
ResolvedSchema
>
{
let
resolveErrors
:
string
[]
=
schemaToResolve
.
errors
.
slice
(
0
);
let
schema
=
schemaToResolve
.
schema
;
let
contextService
=
this
.
contextService
;
let
findSection
=
(
schema
:
IJSONSchema
,
path
:
string
):
any
=>
{
if
(
!
path
)
{
return
schema
;
}
let
current
:
any
=
schema
;
path
.
substr
(
1
).
split
(
'
/
'
).
some
((
part
)
=>
{
if
(
path
[
0
]
===
'
/
'
)
{
path
=
path
.
substr
(
1
);
}
path
.
split
(
'
/
'
).
some
((
part
)
=>
{
current
=
current
[
part
];
return
!
current
;
});
...
...
@@ -388,18 +392,21 @@ export class JSONSchemaService implements IJSONSchemaService {
delete
node
.
$ref
;
};
let
resolveExternalLink
=
(
node
:
any
,
uri
:
string
,
linkPath
:
string
):
Thenable
<
any
>
=>
{
let
resolveExternalLink
=
(
node
:
any
,
uri
:
string
,
linkPath
:
string
,
parentSchemaURL
:
string
):
Thenable
<
any
>
=>
{
if
(
contextService
&&
!
/^
\w
+:
\/\/
.*/
.
test
(
uri
))
{
uri
=
contextService
.
resolveRelativePath
(
uri
,
parentSchemaURL
);
}
return
this
.
getOrAddSchemaHandle
(
uri
).
getUnresolvedSchema
().
then
(
unresolvedSchema
=>
{
if
(
unresolvedSchema
.
errors
.
length
)
{
let
loc
=
linkPath
?
uri
+
'
#
'
+
linkPath
:
uri
;
resolveErrors
.
push
(
localize
(
'
json.schema.problemloadingref
'
,
'
Problems loading reference
\'
{0}
\'
: {1}
'
,
loc
,
unresolvedSchema
.
errors
[
0
]));
}
resolveLink
(
node
,
unresolvedSchema
.
schema
,
linkPath
);
return
resolveRefs
(
node
,
unresolvedSchema
.
schema
);
return
resolveRefs
(
node
,
unresolvedSchema
.
schema
,
uri
);
});
};
let
resolveRefs
=
(
node
:
IJSONSchema
,
parentSchema
:
IJSONSchema
):
Thenable
<
any
>
=>
{
let
resolveRefs
=
(
node
:
IJSONSchema
,
parentSchema
:
IJSONSchema
,
parentSchemaURL
:
string
):
Thenable
<
any
>
=>
{
let
toWalk
:
IJSONSchema
[]
=
[
node
];
let
seen
:
IJSONSchema
[]
=
[];
...
...
@@ -438,7 +445,7 @@ export class JSONSchemaService implements IJSONSchemaService {
if
(
next
.
$ref
)
{
let
segments
=
next
.
$ref
.
split
(
'
#
'
,
2
);
if
(
segments
[
0
].
length
>
0
)
{
openPromises
.
push
(
resolveExternalLink
(
next
,
segments
[
0
],
segments
[
1
]));
openPromises
.
push
(
resolveExternalLink
(
next
,
segments
[
0
],
segments
[
1
]
,
parentSchemaURL
));
continue
;
}
else
{
resolveLink
(
next
,
parentSchema
,
segments
[
1
]);
...
...
@@ -451,7 +458,7 @@ export class JSONSchemaService implements IJSONSchemaService {
return
Promise
.
all
(
openPromises
);
};
return
resolveRefs
(
schema
,
schema
).
then
(
_
=>
new
ResolvedSchema
(
schema
,
resolveErrors
));
return
resolveRefs
(
schema
,
schema
,
schemaURL
).
then
(
_
=>
new
ResolvedSchema
(
schema
,
resolveErrors
));
}
public
getSchemaForResource
(
resource
:
string
,
document
:
Parser
.
JSONDocument
):
Thenable
<
ResolvedSchema
>
{
...
...
extensions/json/server/src/jsonServerMain.ts
浏览文件 @
e520a420
...
...
@@ -13,6 +13,7 @@ import {xhr, XHROptions, XHRResponse, configure as configureHttpRequests} from '
import
path
=
require
(
'
path
'
);
import
fs
=
require
(
'
fs
'
);
import
URI
from
'
./utils/uri
'
;
import
*
as
URL
from
'
url
'
;
import
Strings
=
require
(
'
./utils/strings
'
);
import
{
ISchemaAssociations
}
from
'
./jsonSchemaService
'
;
import
{
JSONDocument
}
from
'
./jsonParser
'
;
...
...
@@ -71,11 +72,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
let
workspaceContext
=
{
resolveRelativePath
:
(
relativePath
:
string
,
resource
:
string
)
=>
{
if
(
typeof
relativePath
===
'
string
'
&&
resource
)
{
let
resourceURI
=
URI
.
parse
(
resource
);
return
URI
.
file
(
path
.
normalize
(
path
.
join
(
path
.
dirname
(
resourceURI
.
fsPath
),
relativePath
))).
toString
();
}
return
void
0
;
return
URL
.
resolve
(
resource
,
relativePath
);
}
};
...
...
extensions/json/server/src/test/schema.test.ts
浏览文件 @
e520a420
...
...
@@ -10,6 +10,7 @@ import JsonSchema = require('../jsonSchema');
import
Json
=
require
(
'
jsonc-parser
'
);
import
Parser
=
require
(
'
../jsonParser
'
);
import
fs
=
require
(
'
fs
'
);
import
url
=
require
(
'
url
'
);
import
path
=
require
(
'
path
'
);
import
{
XHROptions
,
XHRResponse
}
from
'
request-light
'
;
...
...
@@ -43,8 +44,14 @@ suite('JSON Schema', () => {
return
Promise
.
reject
<
XHRResponse
>
({
responseText
:
''
,
status
:
404
});
}
let
workspaceContext
=
{
resolveRelativePath
:
(
relativePath
:
string
,
resource
:
string
)
=>
{
return
url
.
resolve
(
resource
,
relativePath
);
}
};
test
(
'
Resolving $refs
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
https://myschemastore/main
"
:
{
id
:
'
https://myschemastore/main
'
,
...
...
@@ -73,9 +80,9 @@ suite('JSON Schema', () => {
});
});
test
(
'
Resolving $refs 2
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
http://json.schemastore.org/swagger-2.0
"
:
{
id
:
'
http://json.schemastore.org/swagger-2.0
'
,
...
...
@@ -112,8 +119,56 @@ suite('JSON Schema', () => {
});
test
(
'
Resolving $refs 3
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
https://myschemastore/main/schema1.json
"
:
{
id
:
'
https://myschemastore/schema1.json
'
,
type
:
'
object
'
,
properties
:
{
p1
:
{
'
$ref
'
:
'
schema2.json#/definitions/hello
'
},
p2
:
{
'
$ref
'
:
'
./schema2.json#/definitions/hello
'
},
p3
:
{
'
$ref
'
:
'
/main/schema2.json#/definitions/hello
'
}
}
},
"
https://myschemastore/main/schema2.json
"
:{
id
:
'
https://myschemastore/main/schema2.json
'
,
definitions
:
{
"
hello
"
:
{
"
type
"
:
"
string
"
,
"
enum
"
:
[
"
object
"
],
}
}
}
}});
service
.
getResolvedSchema
(
'
https://myschemastore/main/schema1.json
'
).
then
(
fs
=>
{
assert
.
deepEqual
(
fs
.
schema
.
properties
[
'
p1
'
],
{
type
:
'
string
'
,
enum
:
[
"
object
"
]
});
assert
.
deepEqual
(
fs
.
schema
.
properties
[
'
p2
'
],
{
type
:
'
string
'
,
enum
:
[
"
object
"
]
});
assert
.
deepEqual
(
fs
.
schema
.
properties
[
'
p3
'
],
{
type
:
'
string
'
,
enum
:
[
"
object
"
]
});
}).
then
(()
=>
testDone
(),
(
error
)
=>
{
testDone
(
error
);
});
});
test
(
'
FileSchema
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
main
"
:
{
...
...
@@ -142,7 +197,7 @@ suite('JSON Schema', () => {
});
test
(
'
Array FileSchema
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
main
"
:
{
...
...
@@ -174,7 +229,7 @@ suite('JSON Schema', () => {
});
test
(
'
Missing subschema
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
main
"
:
{
...
...
@@ -197,7 +252,7 @@ suite('JSON Schema', () => {
});
test
(
'
Preloaded Schema
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
id
=
'
https://myschemastore/test1
'
;
var
schema
:
JsonSchema
.
IJSONSchema
=
{
type
:
'
object
'
,
...
...
@@ -225,7 +280,7 @@ suite('JSON Schema', () => {
});
test
(
'
External Schema
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
id
=
'
https://myschemastore/test1
'
;
var
schema
:
JsonSchema
.
IJSONSchema
=
{
type
:
'
object
'
,
...
...
@@ -254,7 +309,7 @@ suite('JSON Schema', () => {
test
(
'
Resolving in-line $refs
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
id
=
'
https://myschemastore/test1
'
;
var
schema
:
JsonSchema
.
IJSONSchema
=
{
...
...
@@ -292,7 +347,7 @@ suite('JSON Schema', () => {
});
test
(
'
Resolving in-line $refs automatically for external schemas
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
id
=
'
https://myschemastore/test1
'
;
var
schema
:
JsonSchema
.
IJSONSchema
=
{
id
:
'
main
'
,
...
...
@@ -329,7 +384,7 @@ suite('JSON Schema', () => {
test
(
'
Clearing External Schemas
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
id1
=
'
http://myschemastore/test1
'
;
var
schema1
:
JsonSchema
.
IJSONSchema
=
{
type
:
'
object
'
,
...
...
@@ -370,7 +425,7 @@ suite('JSON Schema', () => {
});
test
(
'
Schema contributions
'
,
function
(
testDone
)
{
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
service
.
setSchemaContributions
({
schemas
:
{
"
http://myschemastore/myschemabar
"
:
{
...
...
@@ -420,7 +475,7 @@ suite('JSON Schema', () => {
test
(
'
Resolving circular $refs
'
,
function
(
testDone
)
{
var
service
:
SchemaService
.
IJSONSchemaService
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
:
SchemaService
.
IJSONSchemaService
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
input
=
{
"
$schema
"
:
"
http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
"
,
...
...
@@ -463,7 +518,7 @@ suite('JSON Schema', () => {
test
(
'
Resolving circular $refs, invalid document
'
,
function
(
testDone
)
{
var
service
:
SchemaService
.
IJSONSchemaService
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
:
SchemaService
.
IJSONSchemaService
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
input
=
{
"
$schema
"
:
"
http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
"
,
...
...
@@ -498,7 +553,7 @@ suite('JSON Schema', () => {
test
(
'
Validate Azure Resource Dfinition
'
,
function
(
testDone
)
{
var
service
:
SchemaService
.
IJSONSchemaService
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
);
var
service
:
SchemaService
.
IJSONSchemaService
=
new
SchemaService
.
JSONSchemaService
(
requestServiceMock
,
workspaceContext
);
var
input
=
{
"
$schema
"
:
"
http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录