roas_codegen/lib.rs
1//! Generate Rust and Go types from OpenAPI descriptions.
2//!
3//! The pipeline is: detect the version, parse the typed model, normalize
4//! everything to OpenAPI 3.2 while recording what that loses, validate,
5//! lower every schema to a representation where the hard decisions are
6//! already made, and render. [`SourceDocument::parse`] and [`validate`]
7//! turn bytes into a [`ValidatedSourceDocument`]; [`generate`] turns that
8//! and a [`Config`] into a [`Generation`]: files in memory, every
9//! diagnostic, and the dependency list the generated code needs, in Rust
10//! or in Go.
11//!
12//! ```no_run
13//! use roas_codegen::{
14//! ConfigFile, Input, SourceDocument, Target, generate, generation_options, validate,
15//! };
16//! use url::Url;
17//!
18//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
19//! let bytes = std::fs::read("openapi.json")?;
20//! let document = SourceDocument::parse(Input::Json(bytes), Url::parse("file:///openapi.json")?)?;
21//! let document = validate(document, generation_options())?;
22//! let mut file = ConfigFile::default();
23//! file.target = Some(Target::Rust);
24//! let config = file.build()?;
25//! let generation = generate(&document, &config)?;
26//! for file in &generation.files {
27//! println!("{}: {} bytes", file.path.display(), file.contents.len());
28//! }
29//! for diagnostic in &generation.diagnostics {
30//! eprintln!("{diagnostic}");
31//! }
32//! # Ok(()) }
33//! ```
34
35mod checks;
36mod config;
37mod diagnostic;
38mod front;
39mod generate;
40mod go;
41mod ir;
42mod lower;
43mod pattern;
44mod report;
45mod rust;
46mod source;
47mod templates;
48mod validate;
49mod write;
50mod yaml_value;
51
52pub use config::{
53 Config, ConfigError, ConfigFile, FieldConfig, GoConfig, GoConfigFile, Layout, RustConfig,
54 RustConfigFile, Substitution, Target, TypeConfig, TypeSpelling, rust_module_name,
55};
56pub use diagnostic::{Diagnostic, DiagnosticKind, SchemaId, Severity};
57pub use generate::{
58 Dependencies, GenerateError, GeneratedFile, Generation, TemplateContext, generate, render,
59 scaffold, template_context,
60};
61pub use go::GoDependency;
62pub use go::naming::go_file_name;
63pub use rust::RustDependency;
64pub use source::{Fidelity, Input, SourceDocument, SourceError, SourceVersion};
65pub use templates::{TEMPLATE_API, TEMPLATE_MANIFEST};
66pub use validate::{SourceValidationError, ValidatedSourceDocument, generation_options, validate};
67pub use write::{CheckReport, WriteError, WriteOptions, WriteReport, check, manifest_name, write};