Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template generator fails with a single nested field #139

Open
annaghi opened this issue Oct 7, 2024 · 0 comments
Open

Template generator fails with a single nested field #139

annaghi opened this issue Oct 7, 2024 · 0 comments
Assignees

Comments

@annaghi
Copy link

annaghi commented Oct 7, 2024

If there is a single nested field without comment in a config, the template generator fails:

Output is invalid YAML:

nested:   one: true

Minimal example:

#[derive(Debug, Clone, Config, Serialize, Deserialize)]
pub struct ProjectConfig {
    #[setting(nested)]
    pub nested: NestedConfig,
}

#[derive(Debug, Clone, Config, Serialize, Deserialize)]
pub struct NestedConfig {
    #[setting(default = true)]
    pub one: bool,
}
fn generate_project_template(out_dir: &Path) -> Result<()> {
    let mut generator = SchemaGenerator::default();
    generator.add::<ProjectConfig>();

    generator
        .generate(out_dir.join("project.yml"), create_yaml_template_renderer())
        .map_err(|e| anyhow!("Template generation failed: {}", e))
        .with_context(|| "Failed to generate project template")?;

    Ok(())
}

fn create_yaml_template_renderer() -> YamlTemplateRenderer {
    YamlTemplateRenderer::new(TemplateOptions {
        ..TemplateOptions::default()
    })
}
@milesj milesj self-assigned this Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants