diff options
author | Cyborus <cyborus@cyborus.xyz> | 2024-07-09 04:22:39 +0200 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2024-07-09 04:22:39 +0200 |
commit | 03c2ff9a172b99dafed809e6e687caac46b9bbfa (patch) | |
tree | 55e59bddc6121cb0799800dc1e50d6088f8e6cf0 /generator | |
parent | Merge pull request 'bump version to 0.3.1' (#60) from v0.3.1 into main (diff) | |
download | forgejo-api-03c2ff9a172b99dafed809e6e687caac46b9bbfa.tar.xz forgejo-api-03c2ff9a172b99dafed809e6e687caac46b9bbfa.zip |
fix: null team reviews
Diffstat (limited to 'generator')
-rw-r--r-- | generator/src/openapi.rs | 3 | ||||
-rw-r--r-- | generator/src/structs.rs | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/generator/src/openapi.rs b/generator/src/openapi.rs index 35dd9ba..0678b59 100644 --- a/generator/src/openapi.rs +++ b/generator/src/openapi.rs @@ -1079,6 +1079,9 @@ pub struct Schema { pub xml: Option<Xml>, pub external_docs: Option<ExternalDocs>, pub example: Option<serde_json::Value>, + + #[serde(flatten)] + pub extensions: BTreeMap<String, serde_json::Value>, } impl JsonDeref for Schema { diff --git a/generator/src/structs.rs b/generator/src/structs.rs index 4c78fac..6a74dc1 100644 --- a/generator/src/structs.rs +++ b/generator/src/structs.rs @@ -1,7 +1,7 @@ use crate::openapi::*; use eyre::WrapErr; use heck::ToPascalCase; -use std::fmt::Write; +use std::{collections::BTreeMap, fmt::Write}; pub fn create_structs(spec: &OpenApiV2) -> eyre::Result<String> { let mut s = String::new(); @@ -51,6 +51,13 @@ pub fn create_struct_for_definition( let mut subtypes = Vec::new(); + let parse_with = schema + .extensions + .get("x-parse-with") + .map(|ex| serde_json::from_value::<BTreeMap<String, String>>(ex.clone())) + .transpose()? + .unwrap_or_default(); + let docs = create_struct_docs(schema)?; let mut fields = String::new(); let required = schema.required.as_deref().unwrap_or_default(); @@ -90,6 +97,11 @@ pub fn create_struct_for_definition( if field_ty == "Option<time::OffsetDateTime>" { fields.push_str("#[serde(with = \"time::serde::rfc3339::option\")]\n"); } + if let Some(parse_method) = parse_with.get(prop_name) { + fields.push_str("#[serde(deserialize_with = \"crate::"); + fields.push_str(parse_method); + fields.push_str("\")]\n"); + } if let MaybeRef::Value { value } = &prop_schema { if let Some(desc) = &value.description { for line in desc.lines() { |