Эта страница ещё не переведена
Ниже показан английский оригинал.
Formats
to_json and to_yaml serialize the document in the two formats AsyncAPI tools read.
to_json writes pretty-printed JSON, and to_yaml writes YAML.
Each returns its serializer's error; a document build_spec built serializes without one.
Servers, channels, operations and components are maps sorted by name, so the output is the same on every run and a change reads as a plain diff in review.
The command the generated main understands prints the same text.
The example runs with cargo test --example asyncapi_generation --features macros,memory,asyncapi.
Example
/// Writes the document next to the service's code, in both formats AsyncAPI tools read.
fn write_document(dir: &Path) -> Result<(), Box<dyn Error>> {
let spec = build_spec(&app());
fs::write(dir.join("asyncapi.json"), spec.to_json()?)?;
fs::write(dir.join("asyncapi.yaml"), spec.to_yaml()?)?;
Ok(())
}