-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pollux): add Json VC schema meta validation #892
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f10775
chore(prism-agent): bump 'json-schema-validator' dep to latest version
bvoiturier 68d9729
feat(pollux): add JSON credential schema serdes
bvoiturier 4b2facf
feat(pollux): perform vc json schema meta validation
bvoiturier dd26d61
test(prism-agent): fix existing unit-tests
bvoiturier e9f0583
feat(pollux): add 'enum' support for string/integer/number types in J…
bvoiturier 54c84f0
test(pollux): add unit tests for Json VC schema meta validation
bvoiturier 311b6ef
test(pollux): check on new error messages returned by latest json-sch…
bvoiturier be767d6
chore(pollux): rename 'oneOf' meta schema definition to avoid confusion
bvoiturier 499fe61
test(prism-agent): fix e2e tests
bvoiturier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 234 additions & 0 deletions
234
...main/scala/io/iohk/atala/pollux/core/model/schema/type/CredentialJsonSchemaSerDesV1.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
package io.iohk.atala.pollux.core.model.schema.`type` | ||
|
||
import io.iohk.atala.pollux.core.model.schema.validator.SchemaSerDes | ||
import zio.* | ||
import zio.json.* | ||
import zio.json.ast.Json | ||
|
||
case class CredentialJsonSchemaSerDesV1( | ||
$schema: String, | ||
$id: Option[String], | ||
description: Option[String], | ||
properties: Json, | ||
required: Set[String], | ||
additionalProperties: Option[Boolean] | ||
) | ||
|
||
object CredentialJsonSchemaSerDesV1 { | ||
val version: String = "CredentialSchemaSchemaV1" | ||
|
||
private val schema: String = """ | ||
|{ | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "$id": "https://example.com/custom-meta-schema", | ||
| "type": "object", | ||
| "properties": { | ||
| "$id": { | ||
| "type": "string", | ||
| "format": "uri-reference" | ||
| }, | ||
| "$schema": { | ||
| "type": "string", | ||
| "format": "uri", | ||
| "enum": ["https://json-schema.org/draft/2020-12/schema"] | ||
| }, | ||
| "description": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "maxLength": 2000 | ||
| }, | ||
| "type": { | ||
| "enum": ["object"] | ||
| }, | ||
| "properties": { | ||
| "type": "object", | ||
| "patternProperties": { | ||
| ".*": { | ||
| "$ref": "#/$defs/oneOf" | ||
| } | ||
| } | ||
| }, | ||
| "required": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string", | ||
| "minLength": 1 | ||
| }, | ||
| "minItems": 0, | ||
| "maxItems": 125, | ||
| "uniqueItems": true | ||
| }, | ||
| "additionalProperties": { | ||
| "type": "boolean" | ||
| } | ||
| }, | ||
| "required": ["$schema","type","properties"], | ||
| "additionalProperties": false, | ||
| "$defs": { | ||
| "oneOf": { | ||
| "oneOf": [ | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["string"] | ||
| }, | ||
| "minLength": { | ||
| "type": "integer", | ||
| "minimum": 0 | ||
| }, | ||
| "maxLength": { | ||
| "type": "integer", | ||
| "minimum": 0 | ||
| }, | ||
| "format": { | ||
| "type": "string", | ||
| "enum": ["date-time","date","time","duration","ipv4","ipv6","email","uri","uuid"] | ||
| }, | ||
| "pattern": { | ||
| "type": "string", | ||
| "format": "regex" | ||
| }, | ||
| "enum": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string", | ||
| "minItems": 1 | ||
| } | ||
| } | ||
| }, | ||
| "required": ["type"], | ||
| "additionalProperties": false | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["integer"] | ||
| }, | ||
| "minimum": { | ||
| "type": "integer" | ||
| }, | ||
| "exclusiveMinimum": { | ||
| "type": "integer" | ||
| }, | ||
| "maximum": { | ||
| "type": "integer" | ||
| }, | ||
| "exclusiveMaximum": { | ||
| "type": "integer" | ||
| }, | ||
| "enum": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "integer", | ||
| "minItems": 1 | ||
| } | ||
| } | ||
| }, | ||
| "required": ["type"], | ||
| "additionalProperties": false | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["number"] | ||
| }, | ||
| "minimum": { | ||
| "type": "number" | ||
| }, | ||
| "exclusiveMinimum": { | ||
| "type": "number" | ||
| }, | ||
| "maximum": { | ||
| "type": "number" | ||
| }, | ||
| "exclusiveMaximum": { | ||
| "type": "number" | ||
| }, | ||
| "enum": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "number", | ||
| "minItems": 1 | ||
| } | ||
| } | ||
| }, | ||
| "required": ["type"], | ||
| "additionalProperties": false | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["boolean"] | ||
| } | ||
| }, | ||
| "required": ["type"], | ||
| "additionalProperties": false | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["array"] | ||
| }, | ||
| "items": { | ||
| "$ref": "#/$defs/oneOf" | ||
| }, | ||
| "minItems": { | ||
| "type": "integer" | ||
| }, | ||
| "maxItems": { | ||
| "type": "integer" | ||
| }, | ||
| "uniqueItems": { | ||
| "type": "boolean" | ||
| } | ||
| }, | ||
| "required": ["type","items"], | ||
| "additionalProperties": false | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["object"] | ||
| }, | ||
| "properties": { | ||
| "type": "object", | ||
| "patternProperties": { | ||
| ".*": { | ||
| "$ref": "#/$defs/oneOf" | ||
| } | ||
| } | ||
| }, | ||
| "minProperties": { | ||
| "type": "integer" | ||
| }, | ||
| "maxProperties": { | ||
| "type": "integer" | ||
| } | ||
| }, | ||
| "required": ["type","properties"], | ||
| "additionalProperties": false | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|} | ||
""".stripMargin | ||
|
||
val schemaSerDes: SchemaSerDes[CredentialJsonSchemaSerDesV1] = SchemaSerDes(schema) | ||
|
||
given JsonEncoder[CredentialJsonSchemaSerDesV1] = DeriveJsonEncoder.gen[CredentialJsonSchemaSerDesV1] | ||
|
||
given JsonDecoder[CredentialJsonSchemaSerDesV1] = DeriveJsonDecoder.gen[CredentialJsonSchemaSerDesV1] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need two
oneOf
terms?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well pointed out @yshyn-iohk. The top-level one is actually just the name/id for the inner
oneOf
def declaration. I will indeed give it another name (i.e.oneOfDef
) to avoid any confusion 👍