Skip to content

Commit

Permalink
fix(platform): event registry only support draft 4 of JSON schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalenic committed Oct 17, 2024
1 parent 1540b3c commit f45ed2e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/stacks/schema/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const getEventSchemaStackProps = (): SchemaStackProps => {
),
},
{
schemaType: 'JSONSchemaDraft7',
...defaultProps,
schemaName: 'orcabus.filemanager@FileStateChange',
schemaDescription: 'Change of state for an object in the file manager',
schemaLocation: path.join(__dirname, docBase + '/filemanager/FileStateChange.schema.json'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "FileStateChange",
"description": "A filemanager object state change event.",
"type": "object",
Expand Down
4 changes: 2 additions & 2 deletions docs/schemas/events/filemanager/example/FSC__example1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"detail-type": "FileStateChange",
"source": "orcabus.filemanager",
"version": "0",
"id": "019297c6-0547-7391-a24c-207a529aa1a2",
"id": "01929850-275f-7511-9fe2-3825cd786a76",
"account": "123456789012",
"time": "2024-10-16T23:59:50.087257150Z",
"time": "2024-10-17T02:30:42.783745070Z",
"region": "ap-southeast-2",
"resources": [],
"detail": {
Expand Down
4 changes: 2 additions & 2 deletions docs/schemas/events/filemanager/example/FSC__example2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"detail-type": "FileStateChange",
"source": "orcabus.filemanager",
"version": "0",
"id": "019297c6-0547-7391-a24c-2084299a77f1",
"id": "01929850-275f-7511-9fe2-383de94eca70",
"account": "123456789012",
"time": "2024-10-16T23:59:50.087370946Z",
"time": "2024-10-17T02:30:42.783850460Z",
"region": "ap-southeast-2",
"resources": [],
"detail": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ uuid = { version = "1", features = ["v7", "serde"] }
chrono = { version = "0.4", features = ["serde"] }

[dev-dependencies]
jsonschema = "0.23"
jsonschema = "0.23"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::error::Result;
use crate::types::FileStateChange;
use crate::types::{Detail, FileStateChangeType, StorageClass, Transition};
use chrono::Utc;
use schemars::schema_for;
use schemars::gen::{SchemaGenerator, SchemaSettings};
use serde::Serialize;
use serde_json::to_string_pretty;
use std::fs::File;
Expand All @@ -33,7 +33,11 @@ pub async fn write_schemas(out_dir: &Path) -> Result<()> {

/// Generate the JSON schemas.
pub async fn generate_file_schema() -> Result<String> {
to_json_string(&schema_for!(FileStateChange)).await
let mut settings = SchemaSettings::default();
settings.meta_schema = Some("http://json-schema.org/draft-04/schema#".to_string());
let schema = SchemaGenerator::new(settings).into_root_schema_for::<FileStateChange>();

to_json_string(&schema).await
}

/// Generate an example schema for an expiration rule.
Expand Down Expand Up @@ -100,7 +104,7 @@ async fn to_json_string<T: ?Sized + Serialize>(value: &T) -> Result<String> {
#[cfg(test)]
mod tests {
use super::*;
use jsonschema::is_valid;
use jsonschema::draft4::is_valid;
use serde_json::from_str;

#[tokio::test]
Expand Down

0 comments on commit f45ed2e

Please sign in to comment.