Skip to content

Commit

Permalink
fix: metadata schema in rust models
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirvolek committed Nov 7, 2023
1 parent a474c4e commit 736e5d4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 82 deletions.
49 changes: 25 additions & 24 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
"cSpell.words": [
"Bdatum",
"Bech",
"blockfrost",
"Bscript",
"Bstake",
"cbor",
"delegators",
"IPFS",
"Lovelaces",
"Milkomeda",
"mirs",
"nutlink",
"Ogmios",
"openapi",
"redoc",
"redocly",
"tbody",
"timelock",
"UTXO",
"utxos",
"xpub"
]
}
"cSpell.words": [
"Bdatum",
"Bech",
"blockfrost",
"Bscript",
"Bstake",
"cbor",
"decentralisation",
"delegators",
"IPFS",
"Lovelaces",
"Milkomeda",
"mirs",
"nutlink",
"Ogmios",
"openapi",
"redoc",
"redocly",
"tbody",
"timelock",
"UTXO",
"utxos",
"xpub"
]
}
15 changes: 15 additions & 0 deletions rust/CHNAGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## [Unreleased]

## [0.0.2] - 2023-07-11

### Fixed

- json_metadata schema

## [0.0.1] - 2023-07-06

### Added

- initial commit
2 changes: 1 addition & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "blockfrost-openapi"
description = "Blockfrost OpenAPI generated models"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
build = "build.rs"
license = "Apache-2.0"
Expand Down
44 changes: 22 additions & 22 deletions rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
use std::env;
use std::fs;
use std::path::Path;
// use std::env;
// use std::fs;
// use std::path::Path;

fn main() {
let out_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
let model_path = Path::new("src/models");
let entries = fs::read_dir(model_path).unwrap();
// let out_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
// let model_path = Path::new("src/models");
// let entries = fs::read_dir(model_path).unwrap();

let mut content = String::new();
// let mut content = String::new();

for entry in entries {
let entry = entry.unwrap();
let path = entry.path();
let file_stem = path.file_stem().unwrap();
// for entry in entries {
// let entry = entry.unwrap();
// let path = entry.path();
// let file_stem = path.file_stem().unwrap();

if let Some(file_name_str) = file_stem.to_str() {
if file_name_str == "mod" {
continue;
}
content.push_str(&format!("pub mod {};\n", file_name_str));
} else {
panic!("File name is not valid Unicode: {:?}", file_stem);
}
}
// if let Some(file_name_str) = file_stem.to_str() {
// if file_name_str == "mod" {
// continue;
// }
// content.push_str(&format!("pub mod {};\n", file_name_str));
// } else {
// panic!("File name is not valid Unicode: {:?}", file_stem);
// }
// }

let dest_path = Path::new(&out_dir).join("./src/models/mod.rs");
// let dest_path = Path::new(&out_dir).join("./src/models/mod.rs");

fs::write(dest_path, content).unwrap();
// fs::write(dest_path, content).unwrap();
}
16 changes: 1 addition & 15 deletions rust/src/models/tx_content_metadata_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,11 @@
* Generated by: https://openapi-generator.tech
*/

use super::tx_content_metadata_inner_json_metadata::TxContentMetadataInnerJsonMetadata;

#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct TxContentMetadataInner {
/// Metadata label
#[serde(rename = "label")]
pub label: String,
#[serde(rename = "json_metadata")]
pub json_metadata: Box<TxContentMetadataInnerJsonMetadata>,
}

impl TxContentMetadataInner {
pub fn new(
label: String,
json_metadata: TxContentMetadataInnerJsonMetadata,
) -> TxContentMetadataInner {
TxContentMetadataInner {
label,
json_metadata: Box::new(json_metadata),
}
}
pub json_metadata: Option<serde_json::Value>,
}
20 changes: 1 addition & 19 deletions rust/src/models/tx_metadata_label_json_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,11 @@
* Generated by: https://openapi-generator.tech
*/

use super::tx_metadata_label_json_inner_json_metadata::TxMetadataLabelJsonInnerJsonMetadata;

#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct TxMetadataLabelJsonInner {
/// Transaction hash that contains the specific metadata
#[serde(rename = "tx_hash")]
pub tx_hash: String,
#[serde(rename = "json_metadata", deserialize_with = "Option::deserialize")]
pub json_metadata: Option<Box<TxMetadataLabelJsonInnerJsonMetadata>>,
}

impl TxMetadataLabelJsonInner {
pub fn new(
tx_hash: String,
json_metadata: Option<TxMetadataLabelJsonInnerJsonMetadata>,
) -> TxMetadataLabelJsonInner {
TxMetadataLabelJsonInner {
tx_hash,
json_metadata: if let Some(x) = json_metadata {
Some(Box::new(x))
} else {
None
},
}
}
pub json_metadata: Option<serde_json::Value>,
}

0 comments on commit 736e5d4

Please sign in to comment.