Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Schema
Commits
fc67e09e
Commit
fc67e09e
authored
May 27, 2021
by
devesh bajpai
Browse files
Merge branch 'fix-check-invalid-ref' into 'master'
Check invalid refences in schema See merge request
!106
parents
bc51b1bd
1c200cca
Pipeline
#42868
passed with stages
in 99 minutes and 3 seconds
Changes
15
Pipelines
2
Expand all
Hide whitespace changes
Inline
Side-by-side
NOTICE
View file @
fc67e09e
...
...
@@ -249,6 +249,7 @@ The following software have components provided under the terms of this license:
- AWS Java SDK for Amazon Rekognition (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for Amazon Route 53 Auto Naming (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for Amazon Route 53 Resolver (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for Amazon Route53 (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for Amazon S3 (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for Amazon S3 on Outposts (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for Amazon SES (from https://aws.amazon.com/sdkforjava)
...
...
schema-core/src/main/java/org/opengroup/osdu/schema/util/SchemaResolver.java
View file @
fc67e09e
...
...
@@ -49,23 +49,29 @@ public class SchemaResolver {
JSONObject
originalSchema
=
new
JSONObject
(
schema
);
Map
<
String
,
String
>
refSchemas
=
new
HashMap
<>();
findAndResolveRef
(
originalSchema
,
refSchemas
);
JSONObject
definition
=
fetchObjectFromJSON
(
originalSchema
,
SchemaConstants
.
DEFINITIONS
);
Map
<
String
,
Object
>
definitionMap
=
new
HashMap
<>();
if
(
definition
!=
null
)
{
definitionMap
=
definition
.
toMap
();
}
findAndResolveRef
(
originalSchema
,
refSchemas
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
refSchemas
.
entrySet
())
{
JSONObject
refSchema
=
new
JSONObject
(
entry
.
getValue
());
JSONObject
refSchemaDef
=
fetchObjectFromJSON
(
refSchema
,
SchemaConstants
.
DEFINITIONS
);
if
(
refSchemaDef
!=
null
)
definitionMap
.
putAll
(
refSchemaDef
.
toMap
());
refSchema
.
remove
(
SchemaConstants
.
DEFINITIONS
);
definitionMap
.
put
(
entry
.
getKey
(),
refSchema
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
refSchemas
.
entrySet
())
{
if
(
entry
.
getValue
()
==
null
)
{
if
(!
definitionMap
.
containsKey
(
entry
.
getKey
()))
{
throw
new
BadRequestException
(
String
.
format
(
"Invalid input, no '%s' definition found but provided as a reference"
,
entry
.
getKey
()));
}
}
else
{
JSONObject
refSchema
=
new
JSONObject
(
entry
.
getValue
());
JSONObject
refSchemaDef
=
fetchObjectFromJSON
(
refSchema
,
SchemaConstants
.
DEFINITIONS
);
if
(
refSchemaDef
!=
null
)
definitionMap
.
putAll
(
refSchemaDef
.
toMap
());
refSchema
.
remove
(
SchemaConstants
.
DEFINITIONS
);
definitionMap
.
put
(
entry
.
getKey
(),
refSchema
);
}
}
if
(!
definitionMap
.
isEmpty
())
{
originalSchema
.
put
(
SchemaConstants
.
DEFINITIONS
,
definitionMap
);
...
...
@@ -119,6 +125,7 @@ public class SchemaResolver {
throws
BadRequestException
,
ApplicationException
{
String
value
=
String
.
valueOf
(
object
);
if
(
value
.
startsWith
(
"#"
))
{
refSchemas
.
put
(
value
.
substring
(
value
.
lastIndexOf
(
'/'
)
+
1
),
null
);
return
value
;
}
else
if
(
value
.
startsWith
(
"https"
))
{
String
refSchema
=
getSchemaFromExternal
(
value
);
...
...
schema-core/src/test/java/org/opengroup/osdu/schema/util/SchemaResolverTest.java
View file @
fc67e09e
...
...
@@ -118,4 +118,27 @@ public class SchemaResolverTest {
fail
(
"Should not succeed"
);
}
@Test
public
void
testResolveSchema_noDefinitionForRef
()
throws
JSONException
,
BadRequestException
,
ApplicationException
,
NotFoundException
,
IOException
{
String
originalSchema
=
new
FileUtils
().
read
(
"/test_schema/originalSchemaWithRefButNoDefinition.json"
);
String
referenceSchema
=
new
FileUtils
().
read
(
"/test_schema/referenceSchema.json"
);
Mockito
.
when
(
schemaService
.
getSchema
(
"os:wks:anyCrsFeatureCollection.1.0"
)).
thenReturn
(
referenceSchema
);
expectedException
.
expect
(
BadRequestException
.
class
);
expectedException
.
expectMessage
(
"Invalid input, no 'person' definition found but provided as a reference"
);
schemaResolver
.
resolveSchema
(
originalSchema
);
fail
(
"Should not succeed"
);
}
@Test
public
void
testResolveSchema_withDefinitionForRef
()
throws
JSONException
,
BadRequestException
,
ApplicationException
,
NotFoundException
,
IOException
{
String
resolvedSchema
=
new
FileUtils
().
read
(
"/test_schema/resolvedSchemaWithDefinition.json"
);
String
originalSchema
=
new
FileUtils
().
read
(
"/test_schema/originalSchemaRefWithDefinition.json"
);
String
referenceSchema
=
new
FileUtils
().
read
(
"/test_schema/referenceSchema.json"
);
Mockito
.
when
(
schemaService
.
getSchema
(
"os:wks:anyCrsFeatureCollection.1.0"
)).
thenReturn
(
referenceSchema
);
JSONAssert
.
assertEquals
(
resolvedSchema
,
schemaResolver
.
resolveSchema
(
originalSchema
),
JSONCompareMode
.
NON_EXTENSIBLE
);
}
}
\ No newline at end of file
schema-core/src/test/resources/test_schema/originalSchema.json
View file @
fc67e09e
...
...
@@ -10,9 +10,6 @@
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
},
"allOf"
:
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
...
...
schema-core/src/test/resources/test_schema/originalSchemaRefWithDefinition.json
0 → 100644
View file @
fc67e09e
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"x-os-lifecycle-state"
:
"published"
,
"description"
:
"The entity well."
,
"title"
:
"Well"
,
"type"
:
"object"
,
"definitions"
:
{
"person"
:
{
"type"
:
"object"
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
}
}
}
},
"properties"
:
{
"person"
:
{
"description"
:
"Information for person"
,
"title"
:
"Information for person"
,
"$ref"
:
"#/definitions/person"
},
"locationOriginalCRS"
:
{
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
"title"
:
"WGS84 Location"
,
"$ref"
:
"https://geojson.org/schema/FeatureCollection.json"
,
"example"
:
{
"features"
:
[
{
"geometry"
:
{
"coordinates"
:
[
-92.11569999999999
,
29.8823
,
153.4779442519685
],
"type"
:
"Point"
},
"type"
:
"Feature"
,
"properties"
:
{
"name"
:
"Newton 2-31"
}
}
],
"type"
:
"FeatureCollection"
}
}
}
}
schema-core/src/test/resources/test_schema/originalSchemaWithInvalidExternalPath.json
View file @
fc67e09e
...
...
@@ -10,9 +10,6 @@
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0.json"
},
"allOf"
:
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
...
...
schema-core/src/test/resources/test_schema/originalSchemaWithInvalidExternalPath2.json
View file @
fc67e09e
...
...
@@ -10,9 +10,6 @@
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0.json"
},
"allOf"
:
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
...
...
schema-core/src/test/resources/test_schema/originalSchemaWithInvalidExternalPath3.json
View file @
fc67e09e
...
...
@@ -10,9 +10,6 @@
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0.json"
},
"allOf"
:
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
...
...
schema-core/src/test/resources/test_schema/originalSchemaWithNoDefinitionBlock.json
View file @
fc67e09e
...
...
@@ -9,9 +9,6 @@
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
},
"allOf"
:
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
...
...
schema-core/src/test/resources/test_schema/originalSchemaWithRefButNoDefinition.json
0 → 100644
View file @
fc67e09e
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"x-os-lifecycle-state"
:
"published"
,
"description"
:
"The entity well."
,
"title"
:
"Well"
,
"type"
:
"object"
,
"properties"
:
{
"person"
:
{
"description"
:
"Information for person"
,
"title"
:
"Information for person"
,
"$ref"
:
"#/definitions/person"
},
"locationOriginalCRS"
:
{
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
"title"
:
"WGS84 Location"
,
"$ref"
:
"https://geojson.org/schema/FeatureCollection.json"
,
"example"
:
{
"features"
:
[
{
"geometry"
:
{
"coordinates"
:
[
-92.11569999999999
,
29.8823
,
153.4779442519685
],
"type"
:
"Point"
},
"type"
:
"Feature"
,
"properties"
:
{
"name"
:
"Newton 2-31"
}
}
],
"type"
:
"FeatureCollection"
}
}
}
}
schema-core/src/test/resources/test_schema/originalSchemaWithRef_AttributeInJsonArray.json
View file @
fc67e09e
...
...
@@ -12,9 +12,6 @@
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
},
"allOf"
:
[
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
[
{
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
...
...
schema-core/src/test/resources/test_schema/resolvedSchema.json
View file @
fc67e09e
...
...
@@ -1062,9 +1062,6 @@
"title"
:
"Original CRS Location"
,
"$ref"
:
"#/definitions/os:wks:anyCrsFeatureCollection.1.0"
},
"allOf"
:
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
"title"
:
"WGS84 Location"
,
...
...
schema-core/src/test/resources/test_schema/resolvedSchemaWithDefinition.json
0 → 100644
View file @
fc67e09e
This diff is collapsed.
Click to expand it.
schema-core/src/test/resources/test_schema/resolvedSchema_Ref_AttributeInJsonArray.json
View file @
fc67e09e
...
...
@@ -1063,9 +1063,6 @@
"$ref"
:
"#/definitions/os:wks:anyCrsFeatureCollection.1.0"
},
"allOf"
:
[
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
[
{
"$ref"
:
"#/definitions/os:wks:anyCrsFeatureCollection.1.0"
...
...
testing/schema-test-core/src/test/resources/input_payloads/postSchemaServiceWithRef_positiveScenario.json
View file @
fc67e09e
...
...
@@ -17,9 +17,18 @@
"description"
:
"Theentitywell."
,
"title"
:
"Well"
,
"type"
:
"object"
,
"definitions"
:{
},
"definitions"
:{
"anyCrsFeatureCollection.1.0"
:
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"title"
:
"anyCrsFeatureCollection"
,
"type"
:
"object"
},
"osdu..wks..well.1.0"
:
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"title"
:
"osdu..wks..well"
,
"type"
:
"object"
}
},
"properties"
:{
"locationOriginalCRS"
:{
"description"
:
"Thewell'soriginallocationasAnyCrsFeatureCollection-astructuresimilartobutdistinctfromGeoJSON."
,
...
...
@@ -27,7 +36,7 @@
"$ref"
:
"#/definition/anyCrsFeatureCollection.1.0"
},
"allOf"
:{
"$ref"
:
"#/definition/
slb
..wks..well.1.0"
"$ref"
:
"#/definition/
osdu
..wks..well.1.0"
},
"locationWGS84"
:{
"description"
:
"Thewell'slocationasGeoJSONFeatureCollection."
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment