From 1337f7ae5c27983c732dd86bf1f11c04918eee62 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 14 May 2019 13:30:59 -0700 Subject: rust codegen and impl --- rust/fatcat-api-spec/README.md | 2 +- rust/fatcat-api-spec/api.yaml | 274 ++++++++++++----------- rust/fatcat-api-spec/api/swagger.yaml | 399 ++++++++++++++++++---------------- rust/fatcat-api-spec/src/models.rs | 217 +++++++++--------- rust/src/entity_crud.rs | 40 ++-- rust/src/identifiers.rs | 3 +- rust/tests/test_refs.rs | 2 +- 7 files changed, 494 insertions(+), 443 deletions(-) (limited to 'rust') diff --git a/rust/fatcat-api-spec/README.md b/rust/fatcat-api-spec/README.md index e597d8d1..479be91a 100644 --- a/rust/fatcat-api-spec/README.md +++ b/rust/fatcat-api-spec/README.md @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.2.0 -- Build date: 2019-05-14T01:07:41.344Z +- Build date: 2019-05-14T20:29:45.170Z This autogenerated project defines an API crate `fatcat` which contains: * An `Api` trait defining the API in Rust. diff --git a/rust/fatcat-api-spec/api.yaml b/rust/fatcat-api-spec/api.yaml index 02d4fda1..4c2bf20f 100644 --- a/rust/fatcat-api-spec/api.yaml +++ b/rust/fatcat-api-spec/api.yaml @@ -180,18 +180,7 @@ definitions: urls: type: array items: - type: object - required: - - url - - rel - properties: - url: - type: string - format: url - example: "https://example.edu/~frau/prcding.pdf" - rel: - type: string - example: "webarchive" + $ref: "#/definitions/file_url" mimetype: type: string example: "application/pdf" @@ -199,6 +188,19 @@ definitions: type: array items: <<: *FATCATIDENT + file_url: + type: object + required: + - url + - rel + properties: + url: + type: string + format: url + example: "https://example.edu/~frau/prcding.pdf" + rel: + type: string + example: "webarchive" fileset_entity: type: object properties: @@ -207,46 +209,50 @@ definitions: # limit of 200 files, at least to start type: array items: - type: object - required: - - path - - size - properties: - path: - type: string - example: "img/cat.png" - size: - type: integer - example: 1048576 - format: int64 - md5: - <<: *FATCATMD5 - sha1: - <<: *FATCATSHA1 - sha256: - <<: *FATCATSHA256 - extra: - type: object - additionalProperties: {} + $ref: "#/definitions/fileset_file" urls: type: array items: - type: object - required: - - url - - rel - properties: - url: - type: string - format: url - example: "https://example.edu/~frau/prcding.pdf" - rel: - type: string - example: "webarchive" + $ref: "#/definitions/fileset_url" release_ids: type: array items: <<: *FATCATIDENT + fileset_url: + type: object + required: + - url + - rel + properties: + url: + type: string + format: url + example: "https://example.edu/~frau/prcding.pdf" + rel: + type: string + example: "webarchive" + fileset_file: + type: object + required: + - path + - size + properties: + path: + type: string + example: "img/cat.png" + size: + type: integer + example: 1048576 + format: int64 + md5: + <<: *FATCATMD5 + sha1: + <<: *FATCATSHA1 + sha256: + <<: *FATCATSHA256 + extra: + type: object + additionalProperties: {} webcapture_entity: type: object properties: @@ -255,55 +261,11 @@ definitions: # limit of 200 CDX lines, at least to start? type: array items: - type: object - required: - - surt - - timestamp - - url - - sha1 - properties: - surt: - type: string - example: "org,asheesh)/apus/ch1/node15.html" - timestamp: - type: string - format: date-time - example: "2016-09-19T17:20:24Z" - description: "UTC, 'Z'-terminated, second (or better) precision" - url: - type: string - # NOTE: not format:url to allow alternatives - example: "http://www.asheesh.org:80/APUS/ch1/node15.html" - mimetype: - type: string - example: "text/html" - status_code: - type: integer - example: 200 - format: int64 - size: - type: integer - example: 1048576 - format: int64 - sha1: - <<: *FATCATSHA1 - sha256: - <<: *FATCATSHA256 + $ref: "#/definitions/webcapture_cdx_line" archive_urls: type: array items: - type: object - required: - - url - - rel - properties: - url: - type: string - format: url - example: "https://web.archive.org/web/" - rel: - type: string - example: "wayback" + $ref: "#/definitions/webcapture_url" original_url: type: string format: url @@ -316,6 +278,54 @@ definitions: type: array items: <<: *FATCATIDENT + webcapture_cdx_line: + type: object + required: + - surt + - timestamp + - url + - sha1 + properties: + surt: + type: string + example: "org,asheesh)/apus/ch1/node15.html" + timestamp: + type: string + format: date-time + example: "2016-09-19T17:20:24Z" + description: "UTC, 'Z'-terminated, second (or better) precision" + url: + type: string + # NOTE: not format:url to allow alternatives + example: "http://www.asheesh.org:80/APUS/ch1/node15.html" + mimetype: + type: string + example: "text/html" + status_code: + type: integer + example: 200 + format: int64 + size: + type: integer + example: 1048576 + format: int64 + sha1: + <<: *FATCATSHA1 + sha256: + <<: *FATCATSHA256 + webcapture_url: + type: object + required: + - url + - rel + properties: + url: + type: string + format: url + example: "https://web.archive.org/web/" + rel: + type: string + example: "wayback" release_entity: type: object # required for creation: title @@ -379,32 +389,7 @@ definitions: example: 2014 format: int64 ext_ids: - type: object - properties: - doi: - type: string - #format: custom - example: "10.1234/abcde.789" - wikidata_qid: - type: string - isbn13: - type: string - #format: custom - pmid: - type: string - pmcid: - type: string - core: - type: string - #format: custom - arxiv: - type: string - jstor: - type: string - ark: - type: string - mag: - type: string + $ref: "#/definitions/release_ext_ids" volume: type: string issue: @@ -435,19 +420,48 @@ definitions: abstracts: type: array items: - type: object - properties: - sha1: - <<: *FATCATSHA1 - content: - type: string - example: "Some abstract thing goes here" - mimetype: - type: string - example: "application/xml+jats" - lang: - type: string - example: "en" + $ref: "#/definitions/release_abstract" + release_ext_ids: + type: object + properties: + doi: + type: string + #format: custom + example: "10.1234/abcde.789" + wikidata_qid: + type: string + isbn13: + type: string + #format: custom + pmid: + type: string + pmcid: + type: string + core: + type: string + #format: custom + arxiv: + type: string + jstor: + type: string + ark: + type: string + mag: + type: string + release_abstract: + type: object + properties: + sha1: + <<: *FATCATSHA1 + content: + type: string + example: "Some abstract thing goes here" + mimetype: + type: string + example: "application/xml+jats" + lang: + type: string + example: "en" work_entity: type: object properties: diff --git a/rust/fatcat-api-spec/api/swagger.yaml b/rust/fatcat-api-spec/api/swagger.yaml index 4486470b..6730a328 100644 --- a/rust/fatcat-api-spec/api/swagger.yaml +++ b/rust/fatcat-api-spec/api/swagger.yaml @@ -7561,7 +7561,7 @@ definitions: urls: type: "array" items: - $ref: "#/definitions/file_entity_urls" + $ref: "#/definitions/file_url" sha256: type: "string" example: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" @@ -7637,6 +7637,23 @@ definitions: edit_extra: "{}" md5: "1b39813549077b2347c0f370c3864b40" upperCaseName: "FILE_ENTITY" + file_url: + type: "object" + required: + - "rel" + - "url" + properties: + url: + type: "string" + format: "url" + example: "https://example.edu/~frau/prcding.pdf" + rel: + type: "string" + example: "webarchive" + example: + rel: "webarchive" + url: "https://example.edu/~frau/prcding.pdf" + upperCaseName: "FILE_URL" fileset_entity: type: "object" properties: @@ -7652,11 +7669,11 @@ definitions: urls: type: "array" items: - $ref: "#/definitions/file_entity_urls" + $ref: "#/definitions/fileset_url" manifest: type: "array" items: - $ref: "#/definitions/fileset_entity_manifest" + $ref: "#/definitions/fileset_file" state: type: "string" enum: @@ -7718,6 +7735,64 @@ definitions: edit_extra: "{}" revision: "86daea5b-1b6b-432a-bb67-ea97795f80fe" upperCaseName: "FILESET_ENTITY" + fileset_url: + type: "object" + required: + - "rel" + - "url" + properties: + url: + type: "string" + format: "url" + example: "https://example.edu/~frau/prcding.pdf" + rel: + type: "string" + example: "webarchive" + example: + rel: "webarchive" + url: "https://example.edu/~frau/prcding.pdf" + upperCaseName: "FILESET_URL" + fileset_file: + type: "object" + required: + - "path" + - "size" + properties: + path: + type: "string" + example: "img/cat.png" + size: + type: "integer" + format: "int64" + example: 1048576 + md5: + type: "string" + example: "1b39813549077b2347c0f370c3864b40" + minLength: 32 + maxLength: 32 + pattern: "[a-f0-9]{32}" + sha1: + type: "string" + example: "e9dd75237c94b209dc3ccd52722de6931a310ba3" + minLength: 40 + maxLength: 40 + pattern: "[a-f0-9]{40}" + sha256: + type: "string" + example: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" + minLength: 64 + maxLength: 64 + pattern: "[a-f0-9]{64}" + extra: + type: "object" + example: + sha1: "e9dd75237c94b209dc3ccd52722de6931a310ba3" + path: "img/cat.png" + size: 1048576 + sha256: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" + extra: "{}" + md5: "1b39813549077b2347c0f370c3864b40" + upperCaseName: "FILESET_FILE" webcapture_entity: type: "object" properties: @@ -7743,11 +7818,11 @@ definitions: archive_urls: type: "array" items: - $ref: "#/definitions/webcapture_entity_archive_urls" + $ref: "#/definitions/webcapture_url" cdx: type: "array" items: - $ref: "#/definitions/webcapture_entity_cdx" + $ref: "#/definitions/webcapture_cdx_line" edit_extra: type: "object" extra: @@ -7815,6 +7890,75 @@ definitions: timestamp: "2000-01-23T04:56:07.000+00:00" revision: "86daea5b-1b6b-432a-bb67-ea97795f80fe" upperCaseName: "WEBCAPTURE_ENTITY" + webcapture_cdx_line: + type: "object" + required: + - "sha1" + - "surt" + - "timestamp" + - "url" + properties: + surt: + type: "string" + example: "org,asheesh)/apus/ch1/node15.html" + timestamp: + type: "string" + format: "date-time" + example: "2016-09-19T17:20:24Z" + description: "UTC, 'Z'-terminated, second (or better) precision" + url: + type: "string" + example: "http://www.asheesh.org:80/APUS/ch1/node15.html" + mimetype: + type: "string" + example: "text/html" + status_code: + type: "integer" + format: "int64" + example: 200 + size: + type: "integer" + format: "int64" + example: 1048576 + sha1: + type: "string" + example: "e9dd75237c94b209dc3ccd52722de6931a310ba3" + minLength: 40 + maxLength: 40 + pattern: "[a-f0-9]{40}" + sha256: + type: "string" + example: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" + minLength: 64 + maxLength: 64 + pattern: "[a-f0-9]{64}" + example: + sha1: "e9dd75237c94b209dc3ccd52722de6931a310ba3" + surt: "org,asheesh)/apus/ch1/node15.html" + status_code: 200 + size: 1048576 + sha256: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" + mimetype: "text/html" + url: "http://www.asheesh.org:80/APUS/ch1/node15.html" + timestamp: "2016-09-19T17:20:24Z" + upperCaseName: "WEBCAPTURE_CDX_LINE" + webcapture_url: + type: "object" + required: + - "rel" + - "url" + properties: + url: + type: "string" + format: "url" + example: "https://web.archive.org/web/" + rel: + type: "string" + example: "wayback" + example: + rel: "wayback" + url: "https://web.archive.org/web/" + upperCaseName: "WEBCAPTURE_URL" release_entity: type: "object" required: @@ -7823,7 +7967,7 @@ definitions: abstracts: type: "array" items: - $ref: "#/definitions/release_entity_abstracts" + $ref: "#/definitions/release_abstract" refs: type: "array" items: @@ -7852,7 +7996,7 @@ definitions: volume: type: "string" ext_ids: - $ref: "#/definitions/release_entity_ext_ids" + $ref: "#/definitions/release_ext_ids" withdrawn_year: type: "integer" format: "int64" @@ -8222,6 +8366,66 @@ definitions: revision: "86daea5b-1b6b-432a-bb67-ea97795f80fe" container_id: "q3nouwy3nnbsvo3h5klxsx4a7y" upperCaseName: "RELEASE_ENTITY" + release_ext_ids: + type: "object" + properties: + doi: + type: "string" + example: "10.1234/abcde.789" + wikidata_qid: + type: "string" + isbn13: + type: "string" + pmid: + type: "string" + pmcid: + type: "string" + core: + type: "string" + arxiv: + type: "string" + jstor: + type: "string" + ark: + type: "string" + mag: + type: "string" + example: + core: "core" + mag: "mag" + jstor: "jstor" + isbn13: "isbn13" + arxiv: "arxiv" + wikidata_qid: "wikidata_qid" + ark: "ark" + pmid: "pmid" + pmcid: "pmcid" + doi: "10.1234/abcde.789" + upperCaseName: "RELEASE_EXT_IDS" + release_abstract: + type: "object" + properties: + sha1: + type: "string" + example: "e9dd75237c94b209dc3ccd52722de6931a310ba3" + minLength: 40 + maxLength: 40 + pattern: "[a-f0-9]{40}" + content: + type: "string" + example: "Some abstract thing goes here" + mimetype: + type: "string" + example: "application/xml+jats" + lang: + type: "string" + example: "en" + example: + sha1: "e9dd75237c94b209dc3ccd52722de6931a310ba3" + mimetype: "application/xml+jats" + lang: "en" + content: "Some abstract thing goes here" + upperCaseName: "RELEASE_ABSTRACT" work_entity: type: "object" properties: @@ -9187,187 +9391,6 @@ definitions: username: "zerocool93" token: "token" upperCaseName: "AUTH_OIDC_RESULT" - file_entity_urls: - required: - - "rel" - - "url" - properties: - url: - type: "string" - format: "url" - example: "https://example.edu/~frau/prcding.pdf" - rel: - type: "string" - example: "webarchive" - example: - rel: "webarchive" - url: "https://example.edu/~frau/prcding.pdf" - upperCaseName: "FILE_ENTITY_URLS" - fileset_entity_manifest: - required: - - "path" - - "size" - properties: - path: - type: "string" - example: "img/cat.png" - size: - type: "integer" - format: "int64" - example: 1048576 - md5: - type: "string" - example: "1b39813549077b2347c0f370c3864b40" - minLength: 32 - maxLength: 32 - pattern: "[a-f0-9]{32}" - sha1: - type: "string" - example: "e9dd75237c94b209dc3ccd52722de6931a310ba3" - minLength: 40 - maxLength: 40 - pattern: "[a-f0-9]{40}" - sha256: - type: "string" - example: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" - minLength: 64 - maxLength: 64 - pattern: "[a-f0-9]{64}" - extra: - type: "object" - example: - sha1: "e9dd75237c94b209dc3ccd52722de6931a310ba3" - path: "img/cat.png" - size: 1048576 - sha256: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" - extra: "{}" - md5: "1b39813549077b2347c0f370c3864b40" - upperCaseName: "FILESET_ENTITY_MANIFEST" - webcapture_entity_archive_urls: - required: - - "rel" - - "url" - properties: - url: - type: "string" - format: "url" - example: "https://web.archive.org/web/" - rel: - type: "string" - example: "wayback" - example: - rel: "wayback" - url: "https://web.archive.org/web/" - upperCaseName: "WEBCAPTURE_ENTITY_ARCHIVE_URLS" - webcapture_entity_cdx: - required: - - "sha1" - - "surt" - - "timestamp" - - "url" - properties: - surt: - type: "string" - example: "org,asheesh)/apus/ch1/node15.html" - timestamp: - type: "string" - format: "date-time" - example: "2016-09-19T17:20:24Z" - description: "UTC, 'Z'-terminated, second (or better) precision" - url: - type: "string" - example: "http://www.asheesh.org:80/APUS/ch1/node15.html" - mimetype: - type: "string" - example: "text/html" - status_code: - type: "integer" - format: "int64" - example: 200 - size: - type: "integer" - format: "int64" - example: 1048576 - sha1: - type: "string" - example: "e9dd75237c94b209dc3ccd52722de6931a310ba3" - minLength: 40 - maxLength: 40 - pattern: "[a-f0-9]{40}" - sha256: - type: "string" - example: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" - minLength: 64 - maxLength: 64 - pattern: "[a-f0-9]{64}" - example: - sha1: "e9dd75237c94b209dc3ccd52722de6931a310ba3" - surt: "org,asheesh)/apus/ch1/node15.html" - status_code: 200 - size: 1048576 - sha256: "cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452" - mimetype: "text/html" - url: "http://www.asheesh.org:80/APUS/ch1/node15.html" - timestamp: "2016-09-19T17:20:24Z" - upperCaseName: "WEBCAPTURE_ENTITY_CDX" - release_entity_abstracts: - properties: - sha1: - type: "string" - example: "e9dd75237c94b209dc3ccd52722de6931a310ba3" - minLength: 40 - maxLength: 40 - pattern: "[a-f0-9]{40}" - content: - type: "string" - example: "Some abstract thing goes here" - mimetype: - type: "string" - example: "application/xml+jats" - lang: - type: "string" - example: "en" - example: - sha1: "e9dd75237c94b209dc3ccd52722de6931a310ba3" - mimetype: "application/xml+jats" - lang: "en" - content: "Some abstract thing goes here" - upperCaseName: "RELEASE_ENTITY_ABSTRACTS" - release_entity_ext_ids: - properties: - doi: - type: "string" - example: "10.1234/abcde.789" - wikidata_qid: - type: "string" - isbn13: - type: "string" - pmid: - type: "string" - pmcid: - type: "string" - core: - type: "string" - arxiv: - type: "string" - jstor: - type: "string" - ark: - type: "string" - mag: - type: "string" - example: - core: "core" - mag: "mag" - jstor: "jstor" - isbn13: "isbn13" - arxiv: "arxiv" - wikidata_qid: "wikidata_qid" - ark: "ark" - pmid: "pmid" - pmcid: "pmcid" - doi: "10.1234/abcde.789" - upperCaseName: "RELEASE_ENTITY_EXT_IDS" editgroup_edits: properties: containers: diff --git a/rust/fatcat-api-spec/src/models.rs b/rust/fatcat-api-spec/src/models.rs index ee0079f5..41b9f95e 100644 --- a/rust/fatcat-api-spec/src/models.rs +++ b/rust/fatcat-api-spec/src/models.rs @@ -507,7 +507,7 @@ pub struct FileEntity { #[serde(rename = "urls")] #[serde(skip_serializing_if = "Option::is_none")] - pub urls: Option>, + pub urls: Option>, #[serde(rename = "sha256")] #[serde(skip_serializing_if = "Option::is_none")] @@ -575,7 +575,7 @@ impl FileEntity { } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct FileEntityUrls { +pub struct FileUrl { #[serde(rename = "url")] pub url: String, @@ -583,9 +583,9 @@ pub struct FileEntityUrls { pub rel: String, } -impl FileEntityUrls { - pub fn new(url: String, rel: String) -> FileEntityUrls { - FileEntityUrls { url: url, rel: rel } +impl FileUrl { + pub fn new(url: String, rel: String) -> FileUrl { + FileUrl { url: url, rel: rel } } } @@ -597,11 +597,11 @@ pub struct FilesetEntity { #[serde(rename = "urls")] #[serde(skip_serializing_if = "Option::is_none")] - pub urls: Option>, + pub urls: Option>, #[serde(rename = "manifest")] #[serde(skip_serializing_if = "Option::is_none")] - pub manifest: Option>, + pub manifest: Option>, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] @@ -649,7 +649,7 @@ impl FilesetEntity { } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct FilesetEntityManifest { +pub struct FilesetFile { #[serde(rename = "path")] pub path: String, @@ -673,9 +673,9 @@ pub struct FilesetEntityManifest { pub extra: Option, } -impl FilesetEntityManifest { - pub fn new(path: String, size: i64) -> FilesetEntityManifest { - FilesetEntityManifest { +impl FilesetFile { + pub fn new(path: String, size: i64) -> FilesetFile { + FilesetFile { path: path, size: size, md5: None, @@ -686,6 +686,51 @@ impl FilesetEntityManifest { } } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct FilesetUrl { + #[serde(rename = "url")] + pub url: String, + + #[serde(rename = "rel")] + pub rel: String, +} + +impl FilesetUrl { + pub fn new(url: String, rel: String) -> FilesetUrl { + FilesetUrl { url: url, rel: rel } + } +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct ReleaseAbstract { + #[serde(rename = "sha1")] + #[serde(skip_serializing_if = "Option::is_none")] + pub sha1: Option, + + #[serde(rename = "content")] + #[serde(skip_serializing_if = "Option::is_none")] + pub content: Option, + + #[serde(rename = "mimetype")] + #[serde(skip_serializing_if = "Option::is_none")] + pub mimetype: Option, + + #[serde(rename = "lang")] + #[serde(skip_serializing_if = "Option::is_none")] + pub lang: Option, +} + +impl ReleaseAbstract { + pub fn new() -> ReleaseAbstract { + ReleaseAbstract { + sha1: None, + content: None, + mimetype: None, + lang: None, + } + } +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReleaseContrib { #[serde(rename = "index")] @@ -748,7 +793,7 @@ impl ReleaseContrib { pub struct ReleaseEntity { #[serde(rename = "abstracts")] #[serde(skip_serializing_if = "Option::is_none")] - pub abstracts: Option>, + pub abstracts: Option>, #[serde(rename = "refs")] #[serde(skip_serializing_if = "Option::is_none")] @@ -793,7 +838,7 @@ pub struct ReleaseEntity { pub volume: Option, #[serde(rename = "ext_ids")] - pub ext_ids: models::ReleaseEntityExtIds, + pub ext_ids: models::ReleaseExtIds, #[serde(rename = "withdrawn_year")] #[serde(skip_serializing_if = "Option::is_none")] @@ -896,7 +941,7 @@ pub struct ReleaseEntity { } impl ReleaseEntity { - pub fn new(ext_ids: models::ReleaseEntityExtIds) -> ReleaseEntity { + pub fn new(ext_ids: models::ReleaseExtIds) -> ReleaseEntity { ReleaseEntity { abstracts: None, refs: None, @@ -937,37 +982,7 @@ impl ReleaseEntity { } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct ReleaseEntityAbstracts { - #[serde(rename = "sha1")] - #[serde(skip_serializing_if = "Option::is_none")] - pub sha1: Option, - - #[serde(rename = "content")] - #[serde(skip_serializing_if = "Option::is_none")] - pub content: Option, - - #[serde(rename = "mimetype")] - #[serde(skip_serializing_if = "Option::is_none")] - pub mimetype: Option, - - #[serde(rename = "lang")] - #[serde(skip_serializing_if = "Option::is_none")] - pub lang: Option, -} - -impl ReleaseEntityAbstracts { - pub fn new() -> ReleaseEntityAbstracts { - ReleaseEntityAbstracts { - sha1: None, - content: None, - mimetype: None, - lang: None, - } - } -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct ReleaseEntityExtIds { +pub struct ReleaseExtIds { #[serde(rename = "doi")] #[serde(skip_serializing_if = "Option::is_none")] pub doi: Option, @@ -1009,9 +1024,9 @@ pub struct ReleaseEntityExtIds { pub mag: Option, } -impl ReleaseEntityExtIds { - pub fn new() -> ReleaseEntityExtIds { - ReleaseEntityExtIds { +impl ReleaseExtIds { + pub fn new() -> ReleaseExtIds { + ReleaseExtIds { doi: None, wikidata_qid: None, isbn13: None, @@ -1092,6 +1107,53 @@ impl Success { } } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct WebcaptureCdxLine { + #[serde(rename = "surt")] + pub surt: String, + + /// UTC, 'Z'-terminated, second (or better) precision + #[serde(rename = "timestamp")] + pub timestamp: chrono::DateTime, + + #[serde(rename = "url")] + pub url: String, + + #[serde(rename = "mimetype")] + #[serde(skip_serializing_if = "Option::is_none")] + pub mimetype: Option, + + #[serde(rename = "status_code")] + #[serde(skip_serializing_if = "Option::is_none")] + pub status_code: Option, + + #[serde(rename = "size")] + #[serde(skip_serializing_if = "Option::is_none")] + pub size: Option, + + #[serde(rename = "sha1")] + pub sha1: String, + + #[serde(rename = "sha256")] + #[serde(skip_serializing_if = "Option::is_none")] + pub sha256: Option, +} + +impl WebcaptureCdxLine { + pub fn new(surt: String, timestamp: chrono::DateTime, url: String, sha1: String) -> WebcaptureCdxLine { + WebcaptureCdxLine { + surt: surt, + timestamp: timestamp, + url: url, + mimetype: None, + status_code: None, + size: None, + sha1: sha1, + sha256: None, + } + } +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct WebcaptureEntity { #[serde(rename = "release_ids")] @@ -1109,11 +1171,11 @@ pub struct WebcaptureEntity { #[serde(rename = "archive_urls")] #[serde(skip_serializing_if = "Option::is_none")] - pub archive_urls: Option>, + pub archive_urls: Option>, #[serde(rename = "cdx")] #[serde(skip_serializing_if = "Option::is_none")] - pub cdx: Option>, + pub cdx: Option>, #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] @@ -1163,7 +1225,7 @@ impl WebcaptureEntity { } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct WebcaptureEntityArchiveUrls { +pub struct WebcaptureUrl { #[serde(rename = "url")] pub url: String, @@ -1171,56 +1233,9 @@ pub struct WebcaptureEntityArchiveUrls { pub rel: String, } -impl WebcaptureEntityArchiveUrls { - pub fn new(url: String, rel: String) -> WebcaptureEntityArchiveUrls { - WebcaptureEntityArchiveUrls { url: url, rel: rel } - } -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct WebcaptureEntityCdx { - #[serde(rename = "surt")] - pub surt: String, - - /// UTC, 'Z'-terminated, second (or better) precision - #[serde(rename = "timestamp")] - pub timestamp: chrono::DateTime, - - #[serde(rename = "url")] - pub url: String, - - #[serde(rename = "mimetype")] - #[serde(skip_serializing_if = "Option::is_none")] - pub mimetype: Option, - - #[serde(rename = "status_code")] - #[serde(skip_serializing_if = "Option::is_none")] - pub status_code: Option, - - #[serde(rename = "size")] - #[serde(skip_serializing_if = "Option::is_none")] - pub size: Option, - - #[serde(rename = "sha1")] - pub sha1: String, - - #[serde(rename = "sha256")] - #[serde(skip_serializing_if = "Option::is_none")] - pub sha256: Option, -} - -impl WebcaptureEntityCdx { - pub fn new(surt: String, timestamp: chrono::DateTime, url: String, sha1: String) -> WebcaptureEntityCdx { - WebcaptureEntityCdx { - surt: surt, - timestamp: timestamp, - url: url, - mimetype: None, - status_code: None, - size: None, - sha1: sha1, - sha256: None, - } +impl WebcaptureUrl { + pub fn new(url: String, rel: String) -> WebcaptureUrl { + WebcaptureUrl { url: url, rel: rel } } } diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs index 3bd19cce..8f4c33a8 100644 --- a/rust/src/entity_crud.rs +++ b/rust/src/entity_crud.rs @@ -1048,11 +1048,11 @@ impl EntityCrud for FileEntity { None => (None, None, None), }; - let urls: Vec = file_rev_url::table + let urls: Vec = file_rev_url::table .filter(file_rev_url::file_rev.eq(rev_row.id)) .get_results(conn)? .into_iter() - .map(|r: FileRevUrlRow| FileEntityUrls { + .map(|r: FileRevUrlRow| FileUrl { rel: r.rel, url: r.url, }) @@ -1221,11 +1221,11 @@ impl EntityCrud for FilesetEntity { None => (None, None, None), }; - let manifest: Vec = fileset_rev_file::table + let manifest: Vec = fileset_rev_file::table .filter(fileset_rev_file::fileset_rev.eq(rev_row.id)) .get_results(conn)? .into_iter() - .map(|r: FilesetRevFileRow| FilesetEntityManifest { + .map(|r: FilesetRevFileRow| FilesetFile { path: r.path_name, size: r.size_bytes, md5: r.md5, @@ -1235,11 +1235,11 @@ impl EntityCrud for FilesetEntity { }) .collect(); - let urls: Vec = fileset_rev_url::table + let urls: Vec = fileset_rev_url::table .filter(fileset_rev_url::fileset_rev.eq(rev_row.id)) .get_results(conn)? .into_iter() - .map(|r: FilesetRevUrlRow| FileEntityUrls { + .map(|r: FilesetRevUrlRow| FilesetUrl { rel: r.rel, url: r.url, }) @@ -1431,11 +1431,11 @@ impl EntityCrud for WebcaptureEntity { None => (None, None, None), }; - let cdx: Vec = webcapture_rev_cdx::table + let cdx: Vec = webcapture_rev_cdx::table .filter(webcapture_rev_cdx::webcapture_rev.eq(rev_row.id)) .get_results(conn)? .into_iter() - .map(|c: WebcaptureRevCdxRow| WebcaptureEntityCdx { + .map(|c: WebcaptureRevCdxRow| WebcaptureCdxLine { surt: c.surt, timestamp: c.timestamp, url: c.url, @@ -1447,11 +1447,11 @@ impl EntityCrud for WebcaptureEntity { }) .collect(); - let archive_urls: Vec = webcapture_rev_url::table + let archive_urls: Vec = webcapture_rev_url::table .filter(webcapture_rev_url::webcapture_rev.eq(rev_row.id)) .get_results(conn)? .into_iter() - .map(|r: WebcaptureRevUrlRow| WebcaptureEntityArchiveUrls { + .map(|r: WebcaptureRevUrlRow| WebcaptureUrl { rel: r.rel, url: r.url, }) @@ -1641,7 +1641,7 @@ impl EntityCrud for ReleaseEntity { language: None, license_slug: None, work_id: None, - ext_ids: ReleaseEntityExtIds { + ext_ids: ReleaseExtIds { doi: None, pmid: None, pmcid: None, @@ -1897,7 +1897,7 @@ impl EntityCrud for ReleaseEntity { ), }; - let abstracts: Option> = if hide.abstracts { + let abstracts: Option> = if hide.abstracts { None } else { Some( @@ -1906,19 +1906,17 @@ impl EntityCrud for ReleaseEntity { .filter(release_rev_abstract::release_rev.eq(rev_row.id)) .get_results(conn)? .into_iter() - .map( - |r: (ReleaseRevAbstractRow, AbstractsRow)| ReleaseEntityAbstracts { - sha1: Some(r.0.abstract_sha1), - mimetype: r.0.mimetype, - lang: r.0.lang, - content: Some(r.1.content), - }, - ) + .map(|r: (ReleaseRevAbstractRow, AbstractsRow)| ReleaseAbstract { + sha1: Some(r.0.abstract_sha1), + mimetype: r.0.mimetype, + lang: r.0.lang, + content: Some(r.1.content), + }) .collect(), ) }; - let mut ext_ids = ReleaseEntityExtIds { + let mut ext_ids = ReleaseExtIds { doi: rev_row.doi, pmid: rev_row.pmid, pmcid: rev_row.pmcid, diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs index ae75c8a7..88e22960 100644 --- a/rust/src/identifiers.rs +++ b/rust/src/identifiers.rs @@ -275,7 +275,8 @@ fn test_check_doi() { pub fn check_arxiv_id(raw: &str) -> Result<()> { lazy_static! { - static ref RE: Regex = Regex::new(r"^(\d{4}.\d{4,5}|[a-z\-]+(\.[A-Z]{2})?/\d{7})v\d+$").unwrap(); + static ref RE: Regex = + Regex::new(r"^(\d{4}.\d{4,5}|[a-z\-]+(\.[A-Z]{2})?/\d{7})v\d+$").unwrap(); } if raw.is_ascii() && RE.is_match(raw) { Ok(()) diff --git a/rust/tests/test_refs.rs b/rust/tests/test_refs.rs index 38d8c71e..20dafe04 100644 --- a/rust/tests/test_refs.rs +++ b/rust/tests/test_refs.rs @@ -21,7 +21,7 @@ fn test_refs_blob() { make_edit_context(&conn, editor_id, Some(editgroup_id), false, None, None).unwrap(); // this release entity should be unchanged after being inserted/fetched - let mut r1 = ReleaseEntity::new(ReleaseEntityExtIds::new()); + let mut r1 = ReleaseEntity::new(ReleaseExtIds::new()); r1.title = Some("release-test hashes".to_string()); r1.refs = Some(vec![ ReleaseRef { -- cgit v1.2.3