Skip to content

Commit

Permalink
fix(Rust): Exclude content and parts and add title for simple versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Aug 29, 2021
1 parent df07e95 commit 62ac660
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
37 changes: 20 additions & 17 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ pub struct ClaimSimple {

/// Elements of the collection which can be a variety of different elements, such as Articles, Datatables, Tables and more.
pub parts: Option<Vec<CreativeWorkTypes>>,

/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -1071,6 +1074,9 @@ pub struct CollectionSimple {

/// The identifier for this item.
pub id: Option<Box<String>>,

/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -1575,9 +1581,6 @@ pub struct AudioObjectSimple {
/// The caption for this audio recording.
pub caption: Option<Box<String>>,

/// The structured content of this creative work c.f. property `text`.
pub content: Option<Box<CreativeWorkContent>>,

/// File size in megabits (Mbit, Mb).
pub content_size: Option<Number>,

Expand All @@ -1590,8 +1593,8 @@ pub struct AudioObjectSimple {
/// IANA media type (MIME type).
pub media_type: Option<Box<String>>,

/// Elements of the collection which can be a variety of different elements, such as Articles, Datatables, Tables and more.
pub parts: Option<Vec<CreativeWorkTypes>>,
/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,

/// The transcript of this audio recording.
pub transcript: Option<Box<String>>,
Expand Down Expand Up @@ -1987,6 +1990,9 @@ pub struct FigureSimple {

/// Elements of the collection which can be a variety of different elements, such as Articles, Datatables, Tables and more.
pub parts: Option<Vec<CreativeWorkTypes>>,

/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -2243,9 +2249,6 @@ pub struct ImageObjectSimple {
/// The caption for this image.
pub caption: Option<Box<String>>,

/// The structured content of this creative work c.f. property `text`.
pub content: Option<Box<CreativeWorkContent>>,

/// File size in megabits (Mbit, Mb).
pub content_size: Option<Number>,

Expand All @@ -2258,11 +2261,11 @@ pub struct ImageObjectSimple {
/// IANA media type (MIME type).
pub media_type: Option<Box<String>>,

/// Elements of the collection which can be a variety of different elements, such as Articles, Datatables, Tables and more.
pub parts: Option<Vec<CreativeWorkTypes>>,

/// Thumbnail image of this image.
pub thumbnail: Option<Box<ImageObject>>,

/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -4165,6 +4168,9 @@ pub struct TableSimple {

/// Elements of the collection which can be a variety of different elements, such as Articles, Datatables, Tables and more.
pub parts: Option<Vec<CreativeWorkTypes>>,

/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -4459,9 +4465,6 @@ pub struct VideoObjectSimple {
/// The caption for this video recording.
pub caption: Option<Box<String>>,

/// The structured content of this creative work c.f. property `text`.
pub content: Option<Box<CreativeWorkContent>>,

/// File size in megabits (Mbit, Mb).
pub content_size: Option<Number>,

Expand All @@ -4474,12 +4477,12 @@ pub struct VideoObjectSimple {
/// IANA media type (MIME type).
pub media_type: Option<Box<String>>,

/// Elements of the collection which can be a variety of different elements, such as Articles, Datatables, Tables and more.
pub parts: Option<Vec<CreativeWorkTypes>>,

/// Thumbnail image of this video recording.
pub thumbnail: Option<Box<ImageObject>>,

/// The title of the creative work.
pub title: Option<Box<CreativeWorkTitle>>,

/// The transcript of this video recording.
pub transcript: Option<Box<String>>,
}
Expand Down
13 changes: 12 additions & 1 deletion ts/bindings/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,19 @@ export function interfaceSchemaToSimpleStruct(
const filteredProperties = Object.fromEntries(
Object.entries(properties).reduce(
(prev: [string, JsonSchema][], [name, property]) => {
let keepers: string[]
switch (title) {
case 'MediaObject':
case 'AudioObject':
case 'ImageObject':
case 'VideoObject':
keepers = ['title']
break
default:
keepers = ['title', 'content', 'parts']
}
const keep =
['content', 'parts'].includes(name) ||
keepers.includes(name) ||
!['Thing', 'CreativeWork'].includes(property.from ?? '')
return keep ? [...prev, [name, property]] : prev
},
Expand Down

0 comments on commit 62ac660

Please sign in to comment.