Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FIT-Connect-SDK - .NET
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FIT-Connect
FIT-Connect-SDK - .NET
Commits
94a7b714
Commit
94a7b714
authored
2 years ago
by
Klaus Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Added simple json schema for data verification
parent
1053a96d
No related branches found
No related tags found
1 merge request
!24
AutoReject planning#594
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
FitConnect/Services/Models/v1/Api/Problems.cs
+12
-3
12 additions, 3 deletions
FitConnect/Services/Models/v1/Api/Problems.cs
FitConnect/Subscriber.cs
+32
-7
32 additions, 7 deletions
FitConnect/Subscriber.cs
simple_schema.json
+21
-0
21 additions, 0 deletions
simple_schema.json
with
65 additions
and
10 deletions
FitConnect/Services/Models/v1/Api/Problems.cs
+
12
−
3
View file @
94a7b714
...
@@ -38,6 +38,9 @@ public class Problems {
...
@@ -38,6 +38,9 @@ public class Problems {
public
const
string
TitleUnsupportedSchema
=
"Metadatenschema nicht unterstützt"
;
public
const
string
TitleUnsupportedSchema
=
"Metadatenschema nicht unterstützt"
;
public
const
string
DetailUnsupportedSchema
=
"Die angegebene Metadatenschema-URI ('$schema') ist keines der unterstützten Metadatenschemas."
;
public
const
string
DetailUnsupportedSchema
=
"Die angegebene Metadatenschema-URI ('$schema') ist keines der unterstützten Metadatenschemas."
;
public
const
string
TitleUnsupportedDataSchema
=
"Fachdatenschema nicht unterstützt"
;
public
const
string
DetailUnsupportedDataSchema
=
"Das angegebene Fachdatenschema wird nicht unterstützt."
;
// @formatter:on
// @formatter:on
public
enum
ProblemTypeEnum
{
public
enum
ProblemTypeEnum
{
...
@@ -53,7 +56,8 @@ public class Problems {
...
@@ -53,7 +56,8 @@ public class Problems {
ServiceMismatch
,
ServiceMismatch
,
SchemaViolation
,
SchemaViolation
,
SyntaxViolation
,
SyntaxViolation
,
UnsupportedSchema
,
UnsupportedDataSchema
,
UnsupportedMetaSchema
,
UnsupportedService
UnsupportedService
}
}
...
@@ -128,7 +132,12 @@ public class Problems {
...
@@ -128,7 +132,12 @@ public class Problems {
title
=
TitleSyntaxViolation
;
title
=
TitleSyntaxViolation
;
instance
=
"metadata"
;
instance
=
"metadata"
;
break
;
break
;
case
ProblemTypeEnum
.
UnsupportedSchema
:
case
ProblemTypeEnum
.
UnsupportedDataSchema
:
type
+=
"unsupported-schema"
;
title
=
TitleUnsupportedDataSchema
;
instance
=
"metadata"
;
break
;
case
ProblemTypeEnum
.
UnsupportedMetaSchema
:
type
+=
"unsupported-schema"
;
type
+=
"unsupported-schema"
;
title
=
TitleUnsupportedSchema
;
title
=
TitleUnsupportedSchema
;
instance
=
"metadata"
;
instance
=
"metadata"
;
...
@@ -221,7 +230,7 @@ public class Problems {
...
@@ -221,7 +230,7 @@ public class Problems {
);
);
public
static
readonly
Problems
UnsupportedSchema
=
new
Problems
(
public
static
readonly
Problems
UnsupportedSchema
=
new
Problems
(
ProblemTypeEnum
.
UnsupportedSchema
,
ProblemTypeEnum
.
Unsupported
Meta
Schema
,
"Metadatenschema nicht unterstützt"
,
"Metadatenschema nicht unterstützt"
,
"Die angegebene Metadatenschema-URI ('$schema') ist keines der unterstützten Metadatenschemas."
,
"Die angegebene Metadatenschema-URI ('$schema') ist keines der unterstützten Metadatenschemas."
,
ProblemInstanceEnum
.
Metadata
ProblemInstanceEnum
.
Metadata
...
...
This diff is collapsed.
Click to expand it.
FitConnect/Subscriber.cs
+
32
−
7
View file @
94a7b714
...
@@ -10,7 +10,9 @@ using IdentityModel;
...
@@ -10,7 +10,9 @@ using IdentityModel;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
using
NJsonSchema
;
using
Newtonsoft.Json.Linq
;
using
Newtonsoft.Json.Schema
;
using
JsonSchema
=
NJsonSchema
.
JsonSchema
;
using
Metadata
=
FitConnect
.
Models
.
Api
.
Metadata
.
Metadata
;
using
Metadata
=
FitConnect
.
Models
.
Api
.
Metadata
.
Metadata
;
using
SecurityEventToken
=
FitConnect
.
Models
.
SecurityEventToken
;
using
SecurityEventToken
=
FitConnect
.
Models
.
SecurityEventToken
;
...
@@ -121,7 +123,7 @@ public class Subscriber : FitConnectClient,
...
@@ -121,7 +123,7 @@ public class Subscriber : FitConnectClient,
}
}
catch
(
Exception
e
)
{
catch
(
Exception
e
)
{
// SuccessCriteria:3.5
// SuccessCriteria:3.5
var
problem
=
new
Problems
(
Problems
.
ProblemTypeEnum
.
UnsupportedSchema
,
var
problem
=
new
Problems
(
Problems
.
ProblemTypeEnum
.
Unsupported
Meta
Schema
,
Problems
.
DetailUnsupportedSchema
);
Problems
.
DetailUnsupportedSchema
);
RejectSubmission
(
problem
);
RejectSubmission
(
problem
);
throw
new
SecurityEventException
(
problem
,
e
);
throw
new
SecurityEventException
(
problem
,
e
);
...
@@ -177,11 +179,16 @@ public class Subscriber : FitConnectClient,
...
@@ -177,11 +179,16 @@ public class Subscriber : FitConnectClient,
// SuccessCriteria:3.11
// SuccessCriteria:3.11
// TODO get data schema for data
// TODO No test for data schema implemented, missing schema url
string
?
dataSchema
=
null
;
var
dataSchema
=
GetSchemaUrlFromJson
(
submission
.
Data
);
if
(
dataSchema
!=
null
)
{
if
(
dataSchema
==
null
)
{
if
(
destinationService
.
SubmissionSchemas
!=
null
&&
destinationService
.
SubmissionSchemas
.
Select
(
s
=>
s
.
SchemaUri
)
Logger
?.
LogWarning
(
"No data schema found for submission {SubmissionId}"
,
submissionId
);
}
else
{
if
(
destinationService
.
SubmissionSchemas
!=
null
&&
destinationService
.
SubmissionSchemas
.
Select
(
s
=>
s
.
SchemaUri
)
.
Contains
(
dataSchema
))
{
.
Contains
(
dataSchema
))
{
CheckDataSchema
(
dataSchema
,
submission
);
}
}
}
}
...
@@ -198,6 +205,24 @@ public class Subscriber : FitConnectClient,
...
@@ -198,6 +205,24 @@ public class Subscriber : FitConnectClient,
return
this
;
return
this
;
}
}
private
string
?
GetSchemaUrlFromJson
(
string
?
jsonString
)
=>
jsonString
==
null
?
null
:
(
JsonConvert
.
DeserializeObject
(
jsonString
)
as
JObject
)?[
"$schema"
]?.
ToString
();
private
void
CheckDataSchema
(
string
dataSchema
,
Submission
submission
)
{
var
dataSchemaObject
=
JsonSchema
.
FromUrlAsync
(
dataSchema
).
Result
;
var
jSchema
=
JSchema
.
Parse
(
dataSchemaObject
.
ToJson
());
var
isValidSchemaData
=
JObject
.
Parse
(
submission
.
Data
!).
IsValid
(
jSchema
);
if
(!
isValidSchemaData
)
{
var
problem
=
new
Problems
(
Problems
.
ProblemTypeEnum
.
UnsupportedDataSchema
,
Problems
.
DetailUnsupportedDataSchema
);
RejectSubmission
(
submission
,
problem
);
throw
new
SecurityEventException
(
problem
);
}
}
#
region
Check
Submission
and
Reject
if
needed
#
region
Check
Submission
and
Reject
if
needed
private
void
VerifyDataHash
(
Submission
submission
,
string
dataString
)
{
private
void
VerifyDataHash
(
Submission
submission
,
string
dataString
)
{
...
@@ -223,7 +248,7 @@ public class Subscriber : FitConnectClient,
...
@@ -223,7 +248,7 @@ public class Subscriber : FitConnectClient,
// SuccessCriteria:3.6
// SuccessCriteria:3.6
RejectSubmission
(
submission
,
RejectSubmission
(
submission
,
new
Problems
(
Problems
.
ProblemTypeEnum
.
UnsupportedSchema
,
new
Problems
(
Problems
.
ProblemTypeEnum
.
Unsupported
Meta
Schema
,
Problems
.
DetailUnsupportedSchema
));
Problems
.
DetailUnsupportedSchema
));
throw
new
Exception
(
"Metadata validation failed"
);
throw
new
Exception
(
"Metadata validation failed"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
simple_schema.json
0 → 100644
+
21
−
0
View file @
94a7b714
{
"$id"
:
"https://example.com/person.schema.json"
,
"$schema"
:
"https://json-schema.org/draft/2020-12/schema"
,
"title"
:
"Person"
,
"type"
:
"object"
,
"properties"
:
{
"firstName"
:
{
"type"
:
"string"
,
"description"
:
"The person's first name."
},
"lastName"
:
{
"type"
:
"string"
,
"description"
:
"The person's last name."
},
"age"
:
{
"description"
:
"Age in years which must be equal to or greater than zero."
,
"type"
:
"integer"
,
"minimum"
:
0
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment