Skip to main content

JsonSchemaRenderer

Struct JsonSchemaRenderer 

Source
pub struct JsonSchemaRenderer {
    pub fragment_mode: bool,
}
Expand description

Generator for JSON Schema (Draft 2020-12)

This generator produces a JSON Schema compatible with OpenAI’s response_format and other AI tools that require structured output validation.

§Example

use unistructgen_codegen::JsonSchemaRenderer;
use unistructgen_core::CodeGenerator;

let generator = JsonSchemaRenderer::default();
let schema_json = generator.generate(&ir_module)?;

Fields§

§fragment_mode: bool

If true, the generated schema will not include the $schema keyword, making it suitable for embedding in other schemas.

Implementations§

Source§

impl JsonSchemaRenderer

Source

pub fn new() -> Self

Source

pub fn fragment(self) -> Self

Enable fragment mode (no $schema, no generic wrapper if possible)

Trait Implementations§

Source§

impl CodeGenerator for JsonSchemaRenderer

Source§

type Error = JsonSchemaError

The error type this generator produces
Source§

fn generate(&self, module: &IRModule) -> Result<String, Self::Error>

Generate code from an IR module Read more
Source§

fn language(&self) -> &'static str

Get the target language name Read more
Source§

fn file_extension(&self) -> &str

Get the file extension for generated code Read more
Source§

fn metadata(&self) -> GeneratorMetadata

Get metadata about the generator (optional) Read more
Source§

fn validate(&self, _module: &IRModule) -> Result<(), Self::Error>

Validate IR before generation (optional) Read more
Source§

fn format(&self, code: String) -> Result<String, Self::Error>

Format generated code (optional) Read more
Source§

impl Debug for JsonSchemaRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JsonSchemaRenderer

Source§

fn default() -> JsonSchemaRenderer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<G> CodeGeneratorExt for G
where G: CodeGenerator,

Source§

fn generate_formatted(&self, module: &IRModule) -> Result<String, Self::Error>

Generate and format code in one step
Source§

fn generate_validated(&self, module: &IRModule) -> Result<String, Self::Error>

Generate code with validation first
Source§

fn generate_complete(&self, module: &IRModule) -> Result<String, Self::Error>

Generate, validate, and format code
Source§

fn generate_or<E>(&self, module: &IRModule) -> Result<String, E>
where E: From<Self::Error>,

Generate code and convert to a specific error type
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.