serde_doc/generators/
jsonschema.rs1
2
3use std::io::Write;
4
5use crate::Context;
6
7use super::{Generator, GeneratorConfig};
8use anyhow::{Context as _, Result};
9
10
11pub struct JsonSchemaGenerator {}
12
13impl JsonSchemaGenerator {
14 pub fn new() -> Self {
15 JsonSchemaGenerator {}
16 }
17}
18
19impl Generator for JsonSchemaGenerator {
20 fn generate(&self, ctx: &Context, config:&GeneratorConfig) -> Result<()> {
21 let mut content = String::new();
22
23 match &config.output {
24 Some(output) => {
25
26 let mut file = std::fs::File::create(&output)?;
27
28 file.write(content.as_bytes())
29 .with_context(|| format!("failed to write to file: {:?}", output))?;
30
31 }
32 None => {
33 println!("{}", content);
34 }
35 }
36 Ok(())
37 }
38}