semiont-codegen
The build-time code generator of the Semiont Rust SDK.
It turns the Semiont specification, an OpenAPI
document and its JSON Schemas, into the Rust types of semiont::types.
You do not need to add it
semiont names this crate as a build
dependency, so Cargo fetches and builds it when it builds the SDK. It runs
in the SDK's build script and is linked into no program. It is published
because a published crate's build dependencies have to be.
To use Semiont from Rust, add semiont and
semiont-http-transport.
What it does
| Module | |
|---|---|
bundle |
Bundle::of(root_file) reads a spec document and follows every file $ref, giving one whole document. draft7_definitions gives its component schemas as JSON Schema draft 7. |
types |
generate(definitions, &generation) gives the Rust source of the types: a struct per object, an enum per string enumeration, an untagged enum per oneOf or anyOf, and a type of its own per kind of id, made only by a constructor that holds a value to the schema's pattern. |
It is not a general OpenAPI generator. It knows the shapes Semiont's schemas use and refuses any other, so a schema that grows a new shape fails the build rather than generating something wrong. Every function panics with the reason: a build script has nothing better to do with a spec it cannot read.
Two build scripts use it, and each is a worked example: the SDK's, for the protocol's types, and the services' shared crate's, for the types only a service needs. One generator, so the two are never generated two ways.
Every item is documented on docs.rs.
License
Apache-2.0. See LICENSE.