feat(openapi): the OpenAPI document, and the paperwork the crate shipped without

`Cargo.toml` has declared `license = "MIT"` since the first release and the
published crate carried no license text, so anyone vendoring the source had the
claim without the grant. `LICENSE` is that text. `DCO` is the certificate the
README has been requiring a sign-off against without shipping, and
`CONTRIBUTING.md` says how — including that GitHub is a mirror of `main` and
tags, so a pull request there is carried upstream by a maintainer rather than
merged, which would put the two forges out of sync.

`CHANGELOG.md` reconstructs 26.7.0 and 26.8.0-beta.0 from their tags. The CLI
ships on its own version line, so the header says what that does and does not
mean about the core version a scaffold is pinned to, and each entry says when
that pin moved.

`matcha openapi` prints core's structural OpenAPI 3.1 for the route table —
`--title`, `--api-version`, `--out`. It reuses the entry resolution and the
generated-script runner that `graph` and `explain` already had, so it is the
same `app.ready()` that resolves the graph without booting providers. Structural
is the honest word: paths, methods and parameters come from the decorators, and
nothing invents a response schema.

The loose end from the capability table is closed. `cli.rs` still carried its own
copies of the `create` kinds and the `add` capabilities, so adding either meant
editing two files that could disagree — a value the parser accepts and the
dispatcher rejects. Both now read the list from the module that owns it, and the
three `create` piece kinds became rows in a table rather than near-identical
match arms, which also retires a `too_many_arguments` allow.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-05 16:01:49 -05:00
1 parent a3250da225
commit 5c8f72b409
12 files changed
+542 -47

No files matched your search

+68 -43
View File
@@ -7,61 +7,86 @@ use std::path::Path;
use crate::{entry, wire};
/// A piece that lives inside a module: a file under `src/<subdir>/` plus an
/// entry in one of `@Module`'s arrays.
///
/// `module` is not one of these — it is registered in the `createApp` call
/// rather than in a module array — so it stays a case of its own below.
struct Piece {
/// Name as typed on the command line.
kind: &'static str,
/// Directory under `src/`, and the `@Module` key, which are the same word
/// for all three.
subdir: &'static str,
/// Filename infix: `users.controller.ts`.
ext: &'static str,
/// Appended to the given name to form the exported symbol.
suffix: &'static str,
stub: fn(&str) -> String,
}
const PIECES: &[Piece] = &[
Piece {
kind: "controller",
subdir: "controllers",
ext: "controller",
suffix: "Controller",
stub: controller_stub,
},
Piece {
kind: "step",
subdir: "steps",
ext: "step",
suffix: "Step",
stub: step_stub,
},
Piece {
kind: "provider",
subdir: "providers",
ext: "provider",
suffix: "Provider",
stub: provider_stub,
},
];
/// Every `create` kind, for clap's `value_parser` and for error messages. One
/// list, so a new kind cannot be accepted by the parser and rejected by `run`
/// (or the reverse).
pub fn kinds() -> Vec<&'static str> {
std::iter::once("module")
.chain(PIECES.iter().map(|p| p.kind))
.collect()
}
pub fn run(kind: &str, name: &str, check: bool) -> std::io::Result<()> {
match kind {
"controller" => create_piece(
name,
check,
"controllers",
"controller",
"Controller",
"controllers",
controller_stub(name),
),
"step" => create_piece(
name,
check,
"steps",
"step",
"Step",
"steps",
step_stub(name),
),
"provider" => create_piece(
name,
check,
"providers",
"provider",
"Provider",
"providers",
provider_stub(name),
),
"module" => create_module(name, check),
other => Err(Error::new(
if kind == "module" {
return create_module(name, check);
}
match PIECES.iter().find(|p| p.kind == kind) {
Some(piece) => create_piece(name, check, piece),
None => Err(Error::new(
ErrorKind::InvalidInput,
format!("unknown kind {other}"),
format!("unknown kind {kind} (try: {})", kinds().join(", ")),
)),
}
}
/// Writes a piece file under `src/<subdir>/` and wires it into the `@Module`
/// in `src/app.module.ts` (`module_key` array). Emit-only + hint on failure.
#[allow(clippy::too_many_arguments)]
fn create_piece(
name: &str,
check: bool,
subdir: &str,
ext: &str,
suffix: &str,
module_key: &str,
stub: String,
) -> std::io::Result<()> {
/// in `src/app.module.ts`. Emit-only + hint on failure.
fn create_piece(name: &str, check: bool, piece: &Piece) -> std::io::Result<()> {
let Piece {
subdir,
ext,
suffix,
..
} = *piece;
let module_key = subdir;
let lower = name.to_lowercase();
let file = Path::new("src")
.join(subdir)
.join(format!("{lower}.{ext}.ts"));
std::fs::create_dir_all(file.parent().unwrap())?;
std::fs::write(&file, stub)?;
std::fs::write(&file, (piece.stub)(name))?;
println!("✓ {}", file.display());
let symbol = format!("{name}{suffix}");