Skip to main content

Crate ploidy_core

Crate ploidy_core 

Source
Expand description

Language-agnostic intermediate representation and type graph for OpenAPI code generation.

ploidy-core transforms a parsed OpenAPI document into a typed dependency graph that ploidy-codegen-* backends traverse to emit code.

§Pipeline

use ploidy_core::{arena::Arena, ir::{RawGraph, Spec}, parse::Document};

let doc = Document::from_yaml(&source)?;

let arena = Arena::new();
let spec = Spec::from_doc(&arena, &doc)?;
let mut raw = RawGraph::new(&arena, &spec);
raw.inline_tagged_variants();
let graph = raw.cook();

for view in graph.schemas() { /* ... */ }
for view in graph.operations() { /* ... */ }

§Arena

An Arena is a bump allocator that owns all long-lived data. Types throughout the pipeline hold borrowed references to other arena-allocated types, making them cheaply copyable. Callers create an arena at the start, and pass it to each constructor.

§Named vs. inline types

The IR distinguishes two kinds of types:

  • Named schema types originate from components/schemas in the OpenAPI document. Each carries a SchemaTypeInfo with the schema name and additional metadata.
  • Inline types are anonymous schemas nested inside other types. Each carries an InlineTypePath that encodes the type’s position in the document.

The two kinds carry different metadata, but share the same structural shapes: any, containers, enums, primitives, structs, tagged unions, and untagged unions.

§Using the graph

A RawGraph represents types and references as they exist in the OpenAPI document. Transformations on this graph rewrite it in-place. The transformed graph is then “cooked” into a CookedGraph that’s ready for codegen.

CookedGraph::schemas() yields SchemaTypeViews. Match on the variant to get the specific shape (e.g., SchemaTypeView::Struct) for generating type models.

CookedGraph::operations() yields OperationViews. Use these to access paths, methods, query parameters, and request and response types for generating client endpoints.

See the ir::views module for all view types and traversal methods.

Modules§

arena
codegen
Code generation output and file writing.
error
ir
Intermediate representation for OpenAPI code generation.
parse