Skip to content

Commit

Permalink
Added support for application/octet-stream (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwadams authored Dec 19, 2024
1 parent 10c005c commit a2878c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public bool TryGetFormat(TypeDeclaration typeDeclaration, [NotNullWhen(true)] ou
return true;
}
}
else if (
contentMediaType == "application/octet-stream" &&
typeDeclaration.ExplicitContentEncoding() is string contentEncoding &&
contentEncoding == "base64")
{
format = "corvus-base64-content";
return true;
}
}

format = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public bool TryGetFormat(TypeDeclaration typeDeclaration, [NotNullWhen(true)] ou
return true;
}
}
else if (
contentMediaType == "application/octet-stream" &&
typeDeclaration.ExplicitContentEncoding() is string contentEncoding &&
contentEncoding == "base64")
{
format = "corvus-base64-content";
return true;
}
}

format = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@draft202012

Feature: Repro 526 draft202012

Scenario Outline: Base64 encoded application/octet-stream.
Given a schema file
"""
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"file": {
"type": "object",
"properties": {
"content": {
"type": "string",
"contentEncoding": "base64",
"contentMediaType": "application/octet-stream"
}
}
}
}
}
"""
And the input data value <inputData>
And I assert format
And I generate a type for the schema
And I construct an instance of the schema type from the data
When I validate the instance
Then the result will be <valid>

Examples:
| inputData | valid |
| { "file": { "content": "eyJmb28iOiAiYmFyIn0K" } } | true |
# Invalid items validate successfully even when asserted, and fail during content decoding checks.
| { "file": { "content": "eyJib28iOiAyMH0=" } } | true |

0 comments on commit a2878c8

Please sign in to comment.