From e46cbf1b457bbd9adddc27ea80804e7fb19f3a39 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Fri, 23 Oct 2026 18:51:24 -0400 Subject: [PATCH 01/21] docs: add RFC 0001 for the metadata resolution layer (FORGE-1) --- rfcs/0001-metadata-resolution-layer.md | 157 +++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 rfcs/0001-metadata-resolution-layer.md diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md new file mode 100644 index 000000000..1c095258d --- /dev/null +++ b/rfcs/0001-metadata-resolution-layer.md @@ -0,0 +1,157 @@ +# RFC 0001: The metadata resolution layer + +- **Status:** Draft +- **Date:** 2026-10-23 +- **Ticket:** FORGE-1 — *section off the fern stuff into a compatibility layer* +- **Related:** FORGE-3 (vocabulary renames) · FORGE-4 (versioning RFC) · FORGE-5 (unread vendor key lint) + +## Summary + +Forge's engine reads vendor metadata extensions (`x-fern-*`, `x-stainless-skip`) directly, so everything downstream of the linked model inherits the vendors' vocabulary, formats, and limitations. This RFC adds a **metadata resolution layer** with three parts: + +1. a native `x-forge-*` vocabulary, designed on Forge's own terms rather than mirroring any vendor's; +2. a pure library that resolves keys to primitives — native first, vendor adapters as fallback; +3. a quarantined, feature-gated **compatibility layer** that is the only code holding vendor knowledge, and whose designed end state is wholesale deletion. + +After the boundary, the engine — reader, builder, linked model, plugin host, npm runtime — acts only on Forge primitives. Output for existing specs is unchanged, and the release is non-breaking. + +## Motivation + +Today the engine couples to vendors in five places: + +1. **Wire keys** — vendor names are hardcoded in the serde key enums (`DefinitionKey`, `ParameterKey::FieldName`, `SchemaKey::{ModelName, FieldName, Skip}` in `src/link/openapi.rs`). +2. **Vendor value formats** — Fern's dotted-or-array group strings, Fern's five-value availability vocabulary, Stainless's `x-stainless-skip` (where a list of target names means *false*). +3. **Error strings** — validation messages name vendor keys ("`x-fern-availability "ga" is not …`"). +4. **The consumed-key set** — the seven names excluded from the plugin passthrough are hand-listed in the deserializers and re-documented in the model docs. +5. **Documentation** — the public model, the WIT, and the JS runtime attribute primitives to vendor keys; the WIT's doc comments ship in the npm package. + +Anything downstream — including the cf codebase — therefore depends on a vendor's extension format. Adding another vendor (Stainless, Scalar) means touching the parser, the linker, the docs, and the filter again. + +### What the production specs actually use + +Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617…`): + +| Read by forge today | Uses | Present, **not** read | Uses | +|---|---|---|---| +| `x-fern-sdk-method-name` | 3,638 | `x-fern-enum` | 3,652 | +| `x-fern-sdk-group-name` | 3,638 | `x-stainless-terraform-configurability` | 407 | +| `x-fern-availability` | 3,444 | `x-stainless-deprecation-message` | 281 | +| `x-fern-ignore` | 449 | `x-stability` | 240 | +| `x-fern-parameter-name` | 108 | `x-stainless-collection-type` | 110 | +| `x-fern-property-name` | 38 | `x-fern-audiences` | 80 | +| `x-fern-type-name` | 2 | ~10 further Stainless / Fern keys | ~30 | +| `x-stainless-skip` | 114 | `x-fern-sdk-variables` | 0 | + +## Goals + +- Nothing outside the resolution layer references `x-fern-*` or `x-stainless-*` — enforced mechanically. +- Output for existing specs is unchanged, proven by byte-equality tests on the real aggregate. +- Tests cover each supported primitive, from each accepted key. +- No meaningful performance regression; parse throughput is benchmarked before and after. +- All Fern (and Stainless) compat code and tests live in one folder, imported only through an aggregating library. +- Native metadata is applied first; the compatibility layer is a fallback. +- The compatibility layer can be completely deleted or turned off without affecting any `x-forge-*` extension. +- The native vocabulary is not constrained by vendor naming, structure, or limitations — native keys are designed for Forge's model, and adapters do the translating. + +## Non-goals (this ticket) + +- Fern's structural behavior (allOf/anyOf handling, inline request types) — unchanged. +- Operation ID prefixing. +- Renaming Fern→Forge across the cf codebase (existing follow-up). +- Dotted `operationId` derivation (`a.b.c.d` → group `[a,b,c]` + method `d`) — a follow-up that will land *in this layer* behind an opt-in flag. +- New primitives for `x-fern-enum` (enum-value names — needs a model primitive that does not exist yet), `x-fern-audiences` (a visibility concept Forge has not designed), `x-stability`, `x-forge-sunset`, `x-stainless-deprecation-message`. These are flagged (FORGE-5) and stay unread; each would be a one-row additive addition later. +- Treating the `fern-forge` docs package's own `x-fern-*` reading (a downstream consumer, like cf) — follow-up. + +## The native vocabulary + +| Native key | Form | Meaning | Compat source (the adapter translates) | +|---|---|---|---| +| `x-forge-method` | string | the method's name | `x-fern-sdk-method-name` | +| `x-forge-group` | **array of strings**, top level first | the group path | `x-fern-sdk-group-name` (dotted string is Fern's format; the split lives in the adapter. Native has no dot syntax) | +| `x-forge-ignore` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | +| `x-forge-availability` | `alpha` \| `beta` \| `preview` \| `generally-available` \| `deprecated` | lifecycle stage. The values are Forge's shipped vocabulary (public enum across Rust, WIT, JS); Fern merely coincides | `x-fern-availability` | +| `x-forge-model-name` | string | the model's name (components / `$defs` schema) | `x-fern-type-name` | +| `x-forge-property-name` | string | the property's field name | `x-fern-property-name` | +| `x-forge-parameter-name` | string | the parameter's field name | `x-fern-parameter-name` | +| `x-forge-hidden`, `x-forge-require-confirmation`, `x-forge-aliases`, `x-forge-commands`, `x-sensitive` | *(existing, unchanged)* | | — no vendor source; now owned by the native table | + +Design notes: + +- **Explicit position keys over one positional name key.** Fern used three name keys because its reader architecture had one visitor per OpenAPI object kind. We use explicit keys for a different, real reason: tools in the wild mangle `$ref` structure (inlining targets, dropping siblings), and when placement lies, the key name still carries the role — `x-forge-model-name` on a property schema can be ignored or flagged, where a positional `x-forge-name` would silently become a field name. Explicitness here is corruption-detection, not verbosity. +- **One exclusion word, two positions.** "Excluded from generated surfaces" is one concept at two scopes; two words (`ignore` + `skip`) would be a memory tax for no disambiguation, and `skip` is Stainless's word. +- **Arrays for groups.** JSON's native way to write a path. Accepting dotted strings natively would permanently import Fern's format into the native vocabulary; array-only now keeps the option to loosen later (the reverse — tightening later — would break specs). Fern's dotted strings keep working through the adapter for as long as Fern keys do. +- **No misplacement validation in v1.** A known native key in a wrong position is silently ignored, exactly as Fern's keys are today. Adding validation later is a pure tightening that breaks no valid spec. + +## Resolution rules + +1. **Native applied, compat fallback** — per primitive, independently (a spec mid-migration may take the group from native and availability from Fern). +2. **Silent native-wins** — when both a native key and a compat key are present, the compat value is ignored without comparison machinery. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. +3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). +4. **Empty or punctuation-only values** fall back to the positional wire name, as today; validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. +5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. + +## Architecture + +``` +src/ +├─ metadata/ THE NATIVE LIBRARY — pure +│ │ The x-forge-* table, the resolve() entry (native first), +│ │ pure value readers, the consumed-key set. +│ │ Never references compat. No serde, no arena coupling: +│ │ its inputs are &str keys and small pure values. +├─ compat/ THE COMPATIBILITY LAYER — feature "compat" (default on) +│ ├─ mod.rs the aggregator; its only pub(crate) item is resolve(). +│ │ The designed end state: delete this folder + the feature. +│ ├─ fern.rs every x-fern-* literal; Fern formats (dotted group +│ │ split, availability vocabulary); Fern unit tests. +│ └─ stainless.rs the x-stainless-skip reader; its unit tests. +└─ link/ + ├─ openapi.rs OpenAPI's own keys only; every x- key asks metadata. + └─ read.rs serde helpers; the keys! macro hoisted to crate + visibility, since the library sits beside link/. +``` + +Properties, all deliberate: + +- **One-way dependencies**: `link → metadata → compat`, and nothing else imports compat. The reader asks native first, compat second — the fallback arm *is* the D4 rule. +- **Purity**: the library's contract is `&str` keys and small values (`Vec` of group names, an availability enum, bools). All serde wiring and arena writes stay in `link`. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). +- **Deletion is the designed end state.** `cargo build --no-default-features` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. +- **Dispatch, not semantics**: the layer maps keys to primitives and normalizes simple values. Structural behavior — `x-forge-aliases` becoming methods, `x-forge-commands` describing groups — stays in the builder. + +## Enforcement + +- **Structural boundary — compiler-enforced (built-in Rust):** every vendor key constant is private to its adapter; the only thing outside `compat/` that can touch vendor knowledge is the aggregator's `resolve()`, which the reader calls. The feature gate makes compat removable, and `--no-default-features` CI builds keep proving it. +- **Textual boundary — `tests/boundary.rs`:** scans `src/`, `tests/`, and `packages/forge/` (including the shipped `plugin/forge.wit`) for `x-fern` / `x-stainless` outside `src/compat/` and `tests/compat/`. Doc comments count — moving the WIT's "from `x-fern-availability`" attribution to `x-forge-availability` is part of the work. The test runs wherever `cargo test` runs; a `just boundary` alias targets it. +- **Criterion mapping:** (1) nothing outside the layer references `x-fern-*` → the two mechanisms above; (2) output unchanged → zero model-shape changes, Fern-keyed specs resolve identically (equivalence tests + the full-aggregate native-vs-wasm byte-equality bench); (3) tests per primitive → below. + +## Test plan + +- `tests/parse/` — every fixture rewrites to native keys. Not find-and-replace: group values `"a.b"` become `["a","b"]`; the three Fern name keys become their explicit native keys; error assertions naming Fern keys move out. +- `tests/compat/` — the vendor suite, mirroring `tests/parse`'s harness: for each primitive, parse(Fern-keyed fixture) == parse(native-keyed fixture); Fern format specifics (dotted vs array groups, duplicate-key errors, provenance error strings, Stainless's skip-list semantics). +- `tests/boundary.rs` — the guard. +- Existing tripwires keep working: `wit_is_current` (WIT regeneration is mechanical via `wit.mjs`), the wasm dump equality, native-vs-wasm generated-output byte equality. +- Performance: divan parse benches before/after on the real aggregate (`FORGE_SPEC`); `tests/wasm.rs::bench` re-run; forge-bench re-pinned upstream after merge. + +## Release shape + +Non-breaking. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release (new native keys accepted, compat module added); the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. + +## Alternatives considered + +- **Resolve-after-parse** (keep all `x-` keys as raw JSON, normalize in a second pass): most literal reading of "a resolution step", trivially provenance-aware — but it must retain every schema-level extension on the 27 MB aggregate (5,366 `x-auditable` alone) unless the reader consults a key table anyway, at which point it collapses into the chosen design with extra memory and a reimplementation of duplicate-key errors. Rejected on performance and diff size. +- **Vendor-trait machinery** (a `Vendor` trait with Fern/Stainless/Scalar impls): no primitive overlaps across vendors today; the key table grows rows when one does. Rejected as over-engineering for now. +- **One positional `x-forge-name`**: mirrors the model's single `Name` concept and is cleaner in the abstract — but when toolchains inline `$ref` targets, the model's name key rides into property positions and silently renames fields. Explicit keys turn that corruption into something ignorable or flaggable. Rejected on robustness. +- **Separate `x-forge-skip` for properties**: two words for one concept, and `skip` is Stainless's word. Rejected. +- **Accepting dotted group strings natively**: ergonomic continuity, but it permanently imports Fern's format into the native vocabulary; array-only now is the reversible choice. Rejected. +- **Error on native/compat disagreement**: the strictest conflict rule, and consistent with the engine's general strictness — deferred as an open question in FORGE-4 in favor of silent native-wins (zero comparison machinery, no cost for correct specs; the drift risk is documented). +- **Full crate split now** (workspace with a separate metadata crate): delivers "separate library" literally today at the cost of restructuring the OSS repo mid-beta and moving `Availability` into the library. Deferred: the pure contract makes the split a `git mv` when the first standalone consumer exists. +- **Renaming `Group`/`Availability` now**: both are Fern-inherited words, but both renames break the plugin contract. Deferred to FORGE-3's single breaking wave. + +## Follow-ups + +| Ticket | What | +|---|---| +| FORGE-3 | Vocabulary renames in one breaking release: `group` → `namespace`, plus the availability word review; `x-forge-group`/`x-forge-availability` become permanent alias keys (one table row each). | +| FORGE-4 | The versioning RFC: the four contracts, the rules this RFC assumes, and open questions (1.0 timing, warning channel, vendor-key EoL policy). | +| FORGE-5 | Informational Forge CI lint flagging vendor keys the engine doesn't read, sourced from this layer's key table. | +| (FORGE-1 follow-ups) | cf codebase Fern→Forge rename; dotted `operationId` derivation behind an opt-in flag. | From b5cb379d582c7ab8855dc81339aa057c16056609 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Sun, 25 Oct 2026 22:00:51 -0400 Subject: [PATCH 02/21] docs: fix RFC 0001 dependency direction, vocabulary ownership and ignored-value rules --- rfcs/0001-metadata-resolution-layer.md | 44 +++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 1c095258d..0b95958cd 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -59,7 +59,8 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… - Operation ID prefixing. - Renaming Fern→Forge across the cf codebase (existing follow-up). - Dotted `operationId` derivation (`a.b.c.d` → group `[a,b,c]` + method `d`) — a follow-up that will land *in this layer* behind an opt-in flag. -- New primitives for `x-fern-enum` (enum-value names — needs a model primitive that does not exist yet), `x-fern-audiences` (a visibility concept Forge has not designed), `x-stability`, `x-forge-sunset`, `x-stainless-deprecation-message`. These are flagged (FORGE-5) and stay unread; each would be a one-row additive addition later. +- Audiences. The ticket lists audiences as a lower-priority primitive; this RFC deliberately leaves `x-fern-audiences` unread (it needs a visibility concept Forge has not designed), flagged by FORGE-5. This is a scope deviation from the ticket text and needs the reviewers' agreement. +- New primitives for `x-fern-enum` (enum-value names — needs a model primitive that does not exist yet), `x-stability`, `x-forge-sunset`, `x-stainless-deprecation-message`. These are flagged (FORGE-5) and stay unread; each would be a one-row additive addition later. - Treating the `fern-forge` docs package's own `x-fern-*` reading (a downstream consumer, like cf) — follow-up. ## The native vocabulary @@ -85,7 +86,7 @@ Design notes: ## Resolution rules 1. **Native applied, compat fallback** — per primitive, independently (a spec mid-migration may take the group from native and availability from Fern). -2. **Silent native-wins** — when both a native key and a compat key are present, the compat value is ignored without comparison machinery. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. +2. **Silent native-wins** — when both a native key and a compat key are present, the compat value is ignored without comparison machinery. Only the winning value is validated: an invalid compat `availability` does not error when a native one wins. A value of the wrong JSON type (a number where a string is expected) is still a document-shape error at read time, whichever key it is on and in whatever order the keys are written, so errors never depend on key order. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. 3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). 4. **Empty or punctuation-only values** fall back to the positional wire name, as today; validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. 5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. @@ -95,32 +96,39 @@ Design notes: ``` src/ ├─ metadata/ THE NATIVE LIBRARY — pure -│ │ The x-forge-* table, the resolve() entry (native first), -│ │ pure value readers, the consumed-key set. -│ │ Never references compat. No serde, no arena coupling: -│ │ its inputs are &str keys and small pure values. +│ │ The x-forge-* table (per kind of object: definition, +│ │ parameter, schema, document), the primitives and format +│ │ descriptors, the availability vocabulary, the consumed-key +│ │ set. Imports neither compat nor link. No serde, no arena +│ │ coupling: its inputs are &str keys, its outputs small +│ │ pure values. ├─ compat/ THE COMPATIBILITY LAYER — feature "compat" (default on) -│ ├─ mod.rs the aggregator; its only pub(crate) item is resolve(). +│ ├─ mod.rs the aggregator: one resolver per kind of object, trying +│ │ each vendor in turn. The only thing link imports from here. │ │ The designed end state: delete this folder + the feature. -│ ├─ fern.rs every x-fern-* literal; Fern formats (dotted group -│ │ split, availability vocabulary); Fern unit tests. -│ └─ stainless.rs the x-stainless-skip reader; its unit tests. +│ ├─ fern.rs every x-fern-* literal, mapped onto metadata's primitives; +│ │ Fern's value formats, as data (e.g. "a string splits on +│ │ dots"); Fern unit tests. +│ └─ stainless.rs the x-stainless-skip mapping and its format-as-data +│ (a list of targets counts as false); unit tests. └─ link/ - ├─ openapi.rs OpenAPI's own keys only; every x- key asks metadata. - └─ read.rs serde helpers; the keys! macro hoisted to crate - visibility, since the library sits beside link/. + ├─ resolve.rs the orchestrator: native first, then compat behind + │ #[cfg(feature = "compat")] — the only cfg point. + ├─ openapi.rs OpenAPI's own keys only; every x- key asks resolve.rs. + └─ read.rs serde helpers, as today. ``` Properties, all deliberate: -- **One-way dependencies**: `link → metadata → compat`, and nothing else imports compat. The reader asks native first, compat second — the fallback arm *is* the D4 rule. -- **Purity**: the library's contract is `&str` keys and small values (`Vec` of group names, an availability enum, bools). All serde wiring and arena writes stay in `link`. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). -- **Deletion is the designed end state.** `cargo build --no-default-features` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. +- **Dependencies**: `link → metadata` and `link → compat` (behind the feature), and `compat → metadata` (an adapter produces metadata's primitives). `metadata` imports neither of the others, so compat sits *beside* the native table rather than under it. `link/resolve.rs` asks native first, compat second — that fallback arm *is* the D4 rule. +- **Purity**: the library's contract is `&str` keys in and small values out: primitives, key names, and *format descriptors as data* (for example "a string splits on `.`" or "a list of targets counts as `false`"). The serde reading and the arena writes stay in `link` and are generic, driven by those descriptors. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). +- **The availability vocabulary is native.** The five values live in the native table (they are shipped public API); `fern.rs` only maps `x-fern-availability` onto that primitive. +- **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` and the one cfg arm in `link/resolve.rs` touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. - **Dispatch, not semantics**: the layer maps keys to primitives and normalizes simple values. Structural behavior — `x-forge-aliases` becoming methods, `x-forge-commands` describing groups — stays in the builder. ## Enforcement -- **Structural boundary — compiler-enforced (built-in Rust):** every vendor key constant is private to its adapter; the only thing outside `compat/` that can touch vendor knowledge is the aggregator's `resolve()`, which the reader calls. The feature gate makes compat removable, and `--no-default-features` CI builds keep proving it. +- **Structural boundary — compiler-enforced (built-in Rust):** every vendor key literal is private to its adapter; the only thing outside `compat/` that can touch vendor knowledge is the aggregator's per-object resolvers, which `link/resolve.rs` calls. The feature gate makes compat removable, and builds without the `compat` feature keep proving it. - **Textual boundary — `tests/boundary.rs`:** scans `src/`, `tests/`, and `packages/forge/` (including the shipped `plugin/forge.wit`) for `x-fern` / `x-stainless` outside `src/compat/` and `tests/compat/`. Doc comments count — moving the WIT's "from `x-fern-availability`" attribution to `x-forge-availability` is part of the work. The test runs wherever `cargo test` runs; a `just boundary` alias targets it. - **Criterion mapping:** (1) nothing outside the layer references `x-fern-*` → the two mechanisms above; (2) output unchanged → zero model-shape changes, Fern-keyed specs resolve identically (equivalence tests + the full-aggregate native-vs-wasm byte-equality bench); (3) tests per primitive → below. @@ -144,7 +152,7 @@ Non-breaking. The WIT changes are doc comments only — `forge:plugin@0.3.0` sta - **Separate `x-forge-skip` for properties**: two words for one concept, and `skip` is Stainless's word. Rejected. - **Accepting dotted group strings natively**: ergonomic continuity, but it permanently imports Fern's format into the native vocabulary; array-only now is the reversible choice. Rejected. - **Error on native/compat disagreement**: the strictest conflict rule, and consistent with the engine's general strictness — deferred as an open question in FORGE-4 in favor of silent native-wins (zero comparison machinery, no cost for correct specs; the drift risk is documented). -- **Full crate split now** (workspace with a separate metadata crate): delivers "separate library" literally today at the cost of restructuring the OSS repo mid-beta and moving `Availability` into the library. Deferred: the pure contract makes the split a `git mv` when the first standalone consumer exists. +- **Full crate split now** (a separate `metadata` member crate): delivers "separate library" literally today. The root `Cargo.toml` is already a `[workspace]`, so adding a member does not mean moving the engine; the real cost is that a separate crate cannot depend on the engine, so `Availability` and the other primitive value types would move into it and be re-exported by `forge`. Deferred: the pure contract keeps that move mechanical for when the first standalone consumer exists. - **Renaming `Group`/`Availability` now**: both are Fern-inherited words, but both renames break the plugin contract. Deferred to FORGE-3's single breaking wave. ## Follow-ups From c14688baffe0d7d448b610ef514bd8228e2f1944 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Sun, 25 Oct 2026 22:57:32 -0400 Subject: [PATCH 03/21] feat: resolve extensions through a native table with a compat fallback (FORGE-1) Add the metadata resolution layer of RFC 0001. - src/metadata: the native x-forge-* vocabulary, per kind of object, as pure key tables, primitives and value-format descriptors. - src/compat: the compatibility layer, behind the default-on `compat` feature. The Fern and Stainless adapters map their keys onto the same primitives; every vendor name lives here. - src/link/resolve.rs: native first, compat second. A native key's value is kept over a compat one's, whatever order they are written in. - Errors name the key the document wrote. - Docs and the WIT speak the native keys; the WIT copies are regenerated (doc comments only, so forge:plugin stays at 0.3.0). Output is unchanged: the unmodified Fern-keyed suite passes against it, and the real aggregate builds the same files and the same model dump. --- Cargo.toml | 10 +- packages/forge/plugin/forge.wit | 2 +- packages/forge/src/index.ts | 4 +- src/compat/fern.rs | 118 ++++++++++ src/compat/mod.rs | 36 +++ src/compat/stainless.rs | 45 ++++ src/lib.rs | 45 ++-- src/link.rs | 53 ++--- src/link/openapi.rs | 374 ++++++++++++++++++++++---------- src/link/resolve.rs | 91 ++++++++ src/metadata/mod.rs | 306 ++++++++++++++++++++++++++ src/plugin/wasm.rs | 2 +- src/types.rs | 8 +- tests/compat/common.rs | 105 +++++++++ tests/compat/fern.rs | 280 ++++++++++++++++++++++++ tests/compat/main.rs | 15 ++ tests/compat/native_first.rs | 196 +++++++++++++++++ tests/compat/stainless.rs | 90 ++++++++ tests/wasm/ts/wit/forge.wit | 2 +- 19 files changed, 1611 insertions(+), 171 deletions(-) create mode 100644 src/compat/fern.rs create mode 100644 src/compat/mod.rs create mode 100644 src/compat/stainless.rs create mode 100644 src/link/resolve.rs create mode 100644 src/metadata/mod.rs create mode 100644 tests/compat/common.rs create mode 100644 tests/compat/fern.rs create mode 100644 tests/compat/main.rs create mode 100644 tests/compat/native_first.rs create mode 100644 tests/compat/stainless.rs diff --git a/Cargo.toml b/Cargo.toml index 184531c7a..46373a6f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,11 @@ name = "parse" harness = false [features] -default = ["cli"] +default = ["cli", "compat"] +# The compatibility layer: it reads the extensions other tools' metadata is +# written with in place of the native `x-forge-*` ones, when a document has +# no native one. Without it, only the native extensions mean anything. +compat = [] # The `forge` command. Library users can turn it off with # `default-features = false`. cli = ["dep:clap", "dep:serde_json"] @@ -49,6 +53,10 @@ required-features = ["cli"] name = "wasm" required-features = ["cli", "wasm"] +[[test]] +name = "compat" +required-features = ["compat"] + [lints.clippy] # https://rust-lang.github.io/rust-clippy/rust-1.88.0/index.html diff --git a/packages/forge/plugin/forge.wit b/packages/forge/plugin/forge.wit index af93aa10e..7a489f74e 100644 --- a/packages/forge/plugin/forge.wit +++ b/packages/forge/plugin/forge.wit @@ -82,7 +82,7 @@ interface forge { json: option, } - /// The stage of the API a method is in, from `x-fern-availability`. + /// The stage of the API a method is in, from `x-forge-availability`. enum availability { alpha, beta, preview, generally-available, deprecated, } diff --git a/packages/forge/src/index.ts b/packages/forge/src/index.ts index 9b374eab9..983a4bb14 100644 --- a/packages/forge/src/index.ts +++ b/packages/forge/src/index.ts @@ -144,7 +144,7 @@ export interface Method { * way around. */ readonly deprecated: boolean; - /** The stage of the API the method is in, from `x-fern-availability`, or undefined if it doesn't say. */ + /** The stage of the API the method is in, from `x-forge-availability`, or undefined if it doesn't say. */ readonly availability: Availability | undefined; /** * Whether to leave the method out of listings of methods, such as a CLI's @@ -197,7 +197,7 @@ export interface Method { */ export type Location = { readonly in: 'path' } | { readonly in: 'query'; readonly exploded: boolean }; -/** The stage of the API a method is in, as `x-fern-availability` writes it. */ +/** The stage of the API a method is in, as `x-forge-availability` writes it. */ export type Availability = 'alpha' | 'beta' | 'preview' | 'generally-available' | 'deprecated'; /** diff --git a/src/compat/fern.rs b/src/compat/fern.rs new file mode 100644 index 000000000..5c57b4690 --- /dev/null +++ b/src/compat/fern.rs @@ -0,0 +1,118 @@ +//! The adapter for Fern's `x-fern-*` extensions. +//! +//! | Key | Says | Format | +//! |---|---|---| +//! | `x-fern-sdk-method-name` | the name of the method | a string | +//! | `x-fern-sdk-group-name` | the group path of the method | an array of group names, or one string of them separated by dots | +//! | `x-fern-ignore` | the definition makes no method | a boolean | +//! | `x-fern-availability` | the stage of the API | a string, one of the native spellings | +//! | `x-fern-parameter-name` | the name of a parameter's field | a string | +//! | `x-fern-property-name` | the name of a property's field | a string | +//! | `x-fern-type-name` | the name of a model | a string | +//! +//! Its other extensions, such as `x-fern-enum` and `x-fern-audiences`, are +//! not read: they say things forge has no primitive for. + +use crate::metadata::{BoolFormat, DefinitionField, GroupFormat, Hit, ParameterField, SchemaField}; + +const METHOD_NAME: &str = "x-fern-sdk-method-name"; +const GROUP_NAME: &str = "x-fern-sdk-group-name"; +const IGNORE: &str = "x-fern-ignore"; +const AVAILABILITY: &str = "x-fern-availability"; +const PARAMETER_NAME: &str = "x-fern-parameter-name"; +const PROPERTY_NAME: &str = "x-fern-property-name"; +const TYPE_NAME: &str = "x-fern-type-name"; + +pub(super) fn definition(key: &str) -> Option> { + Some(match key { + METHOD_NAME => Hit::compat(DefinitionField::Method, METHOD_NAME, 0), + GROUP_NAME => Hit::compat( + DefinitionField::Group(GroupFormat::StringOrArray { separator: '.' }), + GROUP_NAME, + 1, + ), + IGNORE => Hit::compat(DefinitionField::Ignore(BoolFormat::Bool), IGNORE, 2), + AVAILABILITY => Hit::compat(DefinitionField::Availability, AVAILABILITY, 3), + _ => return None, + }) +} + +pub(super) fn parameter(key: &str) -> Option> { + Some(match key { + PARAMETER_NAME => Hit::compat(ParameterField::Name, PARAMETER_NAME, 0), + _ => return None, + }) +} + +/// Slots 0 and 1 of the compatibility keys of a Schema Object are Fern's; +/// the next adapter's start at 2. +pub(super) fn schema(key: &str) -> Option> { + Some(match key { + TYPE_NAME => Hit::compat(SchemaField::ModelName, TYPE_NAME, 0), + PROPERTY_NAME => Hit::compat(SchemaField::PropertyName, PROPERTY_NAME, 1), + _ => return None, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn each_key_is_read_as_itself_and_as_not_native() { + for key in [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY] { + let hit = definition(key).unwrap_or_else(|| panic!("{key} is not a definition key")); + assert_eq!((hit.key, hit.native), (key, false)); + } + let hit = parameter(PARAMETER_NAME).unwrap(); + assert_eq!((hit.key, hit.native), (PARAMETER_NAME, false)); + for key in [TYPE_NAME, PROPERTY_NAME] { + let hit = schema(key).unwrap_or_else(|| panic!("{key} is not a schema key")); + assert_eq!((hit.key, hit.native), (key, false)); + } + } + + #[test] + fn a_key_is_read_only_where_it_says_something() { + assert!(definition(PARAMETER_NAME).is_none()); + assert!(definition(PROPERTY_NAME).is_none()); + assert!(parameter(METHOD_NAME).is_none()); + assert!(schema(IGNORE).is_none()); + assert!(schema(METHOD_NAME).is_none()); + } + + #[test] + fn slots_are_unique_among_the_keys_of_an_object() { + let mut slots: Vec = [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY] + .iter() + .map(|key| definition(key).unwrap().slot) + .collect(); + slots.sort_unstable(); + slots.dedup(); + assert_eq!(slots.len(), 4); + assert!(slots.iter().all(|&slot| slot >= 32), "slots of other keys start at 32"); + } + + #[test] + fn the_group_is_a_string_split_on_dots_or_an_array() { + let hit = definition(GROUP_NAME).unwrap(); + assert!(matches!( + hit.field, + DefinitionField::Group(GroupFormat::StringOrArray { separator: '.' }) + )); + } + + #[test] + fn unread_extensions_are_not_read() { + for key in [ + "x-fern-enum", + "x-fern-audiences", + "x-fern-pagination", + "x-fern-sdk-variables", + ] { + assert!(definition(key).is_none(), "{key}"); + assert!(parameter(key).is_none(), "{key}"); + assert!(schema(key).is_none(), "{key}"); + } + } +} diff --git a/src/compat/mod.rs b/src/compat/mod.rs new file mode 100644 index 000000000..2545a0124 --- /dev/null +++ b/src/compat/mod.rs @@ -0,0 +1,36 @@ +//! The compatibility layer: the keys other tools' metadata is written with, +//! read as the native extensions of [`metadata`](crate::metadata) say the +//! same things. +//! +//! Each adapter, [`fern`] and [`stainless`], maps its tool's keys onto the +//! native primitives and says, as data, what format each value is written +//! in. This module is what `link` asks, once per kind of object, after the +//! native keys have said no. It is the only way in: every key an adapter +//! reads is private to it. +//! +//! The layer is built only with the `compat` feature, and is meant to go: +//! once nobody writes these keys, deleting this folder and the calls to it in +//! `link/resolve.rs` changes nothing about what any native extension means. The keys are read in place of a native key only when there is none, +//! as `link` decides. + +mod fern; +mod stainless; + +use crate::metadata::{DefinitionField, Hit, ParameterField, SchemaField}; + +/// Returns what `key` says on an operation or an alias, if an adapter reads +/// it there. +pub(crate) fn definition(key: &str) -> Option> { + fern::definition(key) +} + +/// Returns what `key` says on a Parameter Object, if an adapter reads it +/// there. +pub(crate) fn parameter(key: &str) -> Option> { + fern::parameter(key) +} + +/// Returns what `key` says on a Schema Object, if an adapter reads it there. +pub(crate) fn schema(key: &str) -> Option> { + fern::schema(key).or_else(|| stainless::schema(key)) +} diff --git a/src/compat/stainless.rs b/src/compat/stainless.rs new file mode 100644 index 000000000..9338545a0 --- /dev/null +++ b/src/compat/stainless.rs @@ -0,0 +1,45 @@ +//! The adapter for Stainless's `x-stainless-*` extensions. +//! +//! | Key | Says | Format | +//! |---|---|---| +//! | `x-stainless-skip` | the property makes no field | a boolean, or an array of the targets to skip it for, which counts as `false` | +//! +//! Its other extensions, such as `x-stainless-terraform-configurability` and +//! `x-stainless-deprecation-message`, are not read: they say things forge has +//! no primitive for. + +use crate::metadata::{BoolFormat, Hit, SchemaField}; + +const SKIP: &str = "x-stainless-skip"; + +/// Slot 2 among the compatibility keys of a Schema Object: Fern's are the +/// first two. +pub(super) fn schema(key: &str) -> Option> { + Some(match key { + SKIP => Hit::compat(SchemaField::Ignore(BoolFormat::BoolOrTargets), SKIP, 2), + _ => return None, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_skip_is_read_on_a_schema_as_a_boolean_or_targets_and_not_native() { + let hit = schema(SKIP).unwrap(); + assert_eq!((hit.key, hit.native), (SKIP, false)); + assert!(matches!(hit.field, SchemaField::Ignore(BoolFormat::BoolOrTargets))); + } + + #[test] + fn other_keys_are_not_read() { + for key in [ + "x-stainless-terraform-configurability", + "x-stainless-deprecation-message", + "x-fern-ignore", + ] { + assert!(schema(key).is_none(), "{key}"); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 55e1611d5..3895b7e5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,11 @@ use std::{iter, ptr}; mod arena; +#[cfg(feature = "compat")] +mod compat; mod json; mod link; +mod metadata; mod method; mod name; mod plugin; @@ -223,7 +226,7 @@ impl std::fmt::Debug for Group<'_> { /// own group and name, with the `x-forge-aliases` extension: an array of /// objects, each an alias that is a method of the operation. The /// operation's own group and name then make no method, and its own -/// `x-fern-ignore` does not stop its aliases. An empty array makes no +/// `x-forge-ignore` does not stop its aliases. An empty array makes no /// method, an element that is not an object is ignored, and a value that /// is not an array is an error. Aliases do not nest: an `x-forge-aliases` /// in an alias is ignored, as are its keys that are not extensions. @@ -233,7 +236,7 @@ impl std::fmt::Debug for Group<'_> { /// [`availability`](Method::availability), whether it is /// [hidden](Method::is_hidden), its [`confirmation`](Method::confirmation) /// and its [`extensions`](Method::extensions), and whether it is ignored -/// with `x-fern-ignore`. None of these come from the operation: an alias +/// with `x-forge-ignore`. None of these come from the operation: an alias /// without an extension does not have the operation's. The rest, from the /// HTTP method and path to the responses, is the operation's, and every /// alias has it. Each alias is a method of its own group, so a model one @@ -250,7 +253,7 @@ pub struct Method<'f> { impl<'f> Method<'f> { /// Returns the name of the method, which is unique within its group. /// - /// Corresponds to the `x-fern-sdk-method-name` extension of the + /// Corresponds to the `x-forge-method` extension of the /// operation, or of the alias the method comes from. An operation or /// alias without one, or with an empty one, is not a method, and one /// with no letters or digits is an error. Two methods in a group with @@ -261,12 +264,12 @@ impl<'f> Method<'f> { /// Returns the group the method is in. /// - /// Corresponds to the `x-fern-sdk-group-name` extension of the - /// operation, or of the alias the method comes from: a string of group - /// names separated by dots, such as `accounts.members`, or an array - /// with one group name per element, top level first. An operation or - /// alias without one, with an empty one, or with `x-fern-ignore: true` - /// is not a method. A group name with no letters or digits is an error. + /// Corresponds to the `x-forge-group` extension of the operation, or + /// of the alias the method comes from: an array with one group name per + /// element, top level first, such as `[accounts, members]`. An + /// operation or alias without one, with an empty one, or with + /// `x-forge-ignore: true` is not a method. A group name with no letters + /// or digits is an error. pub fn group(self) -> Group<'f> { self.forge.group(self.data().group) } @@ -314,7 +317,7 @@ impl<'f> Method<'f> { /// Returns the stage of the API the method is in, such as /// [`Availability::Beta`], or `None` if the operation does not say. /// - /// Corresponds to the `x-fern-availability` extension of the + /// Corresponds to the `x-forge-availability` extension of the /// operation, a string that is one of `alpha`, `beta`, `preview`, /// `generally-available` and `deprecated`, as [`Availability`] lists. /// Any other value, including one that differs only in case, is an @@ -323,7 +326,7 @@ impl<'f> Method<'f> { /// /// It is apart from [`is_deprecated`](Method::is_deprecated), which /// comes from OpenAPI's own `deprecated`: an operation with - /// `x-fern-availability: deprecated` and without `deprecated: true` is + /// `x-forge-availability: deprecated` and without `deprecated: true` is /// [`Availability::Deprecated`] but not deprecated, and one with /// `deprecated: true` has whatever availability it says, or none. pub fn availability(self) -> Option { @@ -335,7 +338,7 @@ impl<'f> Method<'f> { /// /// Corresponds to the `x-forge-hidden` extension of the operation, a /// boolean, which is false without it. A value that is not a boolean - /// is an error, as for `x-fern-ignore`. Unlike `x-fern-ignore`, a + /// is an error, as for `x-forge-ignore`. Unlike `x-forge-ignore`, a /// hidden operation is still a method. pub fn is_hidden(self) -> bool { self.data().hidden @@ -384,7 +387,7 @@ impl<'f> Method<'f> { /// client sends the fields that [`Field::is_read_only`] reports. A /// parameter's field is never read-only. /// - /// A parameter's field is named after the `x-fern-parameter-name` + /// A parameter's field is named after the `x-forge-parameter-name` /// extension of the parameter, or else its wire name. Its description /// is the parameter's, or else its schema's, following `$ref`s, as /// [`Field::description`] says; from OpenAPI 3.1, the `description` of @@ -494,11 +497,13 @@ impl<'f> Method<'f> { /// /// An extension is a key of the /// [Operation Object](https://spec.openapis.org/oas/latest.html#operation-object) - /// that starts with `x-`. Those forge reads, `x-fern-sdk-method-name`, - /// `x-fern-sdk-group-name`, `x-fern-ignore`, `x-fern-availability`, + /// that starts with `x-`. Those forge reads, `x-forge-method`, + /// `x-forge-group`, `x-forge-ignore`, `x-forge-availability`, /// `x-forge-hidden`, `x-forge-require-confirmation` and - /// `x-forge-aliases`, are left out, and other keys forge does not read - /// are not kept. An extension written more than once is there once, + /// `x-forge-aliases`, are left out, and so are the keys the + /// compatibility layer reads in their place, when forge is built with + /// it. Other keys forge does not read are not kept. An extension + /// written more than once is there once, /// with the last value written, in the place of the first, as with /// `JSON.parse`. Extensions of the path item, the parameters, the body, /// the responses and the schemas are not kept. @@ -588,7 +593,7 @@ impl HttpMethod { /// The stage of the API a [`Method`] is in, as /// [`Method::availability`] gives it. /// -/// Corresponds to the value of the `x-fern-availability` extension of an +/// Corresponds to the value of the `x-forge-availability` extension of an /// operation, which each variant names. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Availability { @@ -606,7 +611,7 @@ pub enum Availability { } impl Availability { - /// Returns the availability as `x-fern-availability` writes it, such + /// Returns the availability as `x-forge-availability` writes it, such /// as `generally-available`. pub fn as_str(self) -> &'static str { match self { @@ -646,7 +651,7 @@ impl<'f> Model<'f> { /// Returns the name of the model. /// - /// Corresponds to the `x-fern-type-name` extension of the schema. A + /// Corresponds to the `x-forge-model-name` extension of the schema. A /// schema without one is named after its schema name, leaving out /// `$defs`, so `Tree/$defs/Node` has the name `Tree Node`. pub fn name(self) -> &'f Name { diff --git a/src/link.rs b/src/link.rs index e77314894..fcca41f55 100644 --- a/src/link.rs +++ b/src/link.rs @@ -8,6 +8,7 @@ mod openapi; mod read; +mod resolve; use std::borrow::Cow; use std::collections::HashMap; @@ -20,13 +21,14 @@ use serde::de::{self, Deserializer}; use crate::arena::Id; use crate::arena::{List, Span, Str, Strings}; use crate::json::Json; +use crate::metadata; use crate::method::{BodyData, ContentData, ResponseData, is_json}; use crate::types::{ ArrayData, DiscriminatorData, EnumData, FieldData, NameId, ObjectData, TypeData, TypeId, UnionData, }; use crate::{ - Availability, EnumValue, Forge, GroupData, GroupId, HttpMethod, Location, MethodData, MethodId, ModelData, ModelId, - Name, Number, Scalar, + EnumValue, Forge, GroupData, GroupId, HttpMethod, Location, MethodData, MethodId, ModelData, ModelId, Name, Number, + Scalar, }; use openapi::{ Commands, ContentEncoding, Definition, Discriminator, Doc, Format, Info, Item, Literal, Operation, Parameter, @@ -543,8 +545,8 @@ impl<'d> Builder<'d> { self.add_method(path, item, operation, &operation.definition, http_method); return; }; - // The operation's own definition makes no method, so its - // `x-fern-ignore` does not stop its aliases. + // The operation's own definition makes no method, so its being + // ignored does not stop its aliases. for (i, alias) in doc.list(aliases).iter().enumerate() { self.context = Context::Alias(method, path, i); self.add_method(path, item, operation, alias, http_method.clone()); @@ -563,35 +565,39 @@ impl<'d> Builder<'d> { http_method: HttpMethod, ) { let doc = self.doc; - if definition.ignore { + if definition.ignore.value { return; } - if definition.method_name.is_empty() { + if definition.method_name.value.is_empty() { return; } - let group_names = doc.list(definition.group_names); + let group_names = doc.list(definition.group_names.value); if group_names.is_empty() { return; } let group_names: Vec = group_names.iter().map(|&name| Name::new(doc.str(name))).collect(); for name in &group_names { if name.is_empty() { - self.error("x-fern-sdk-group-name has a group name with no letters or digits"); + self.error(format_args!( + "{} has a group name with no letters or digits", + definition.group_names.key + )); return; } } - let name = Name::new(doc.str(definition.method_name)); + let name = Name::new(doc.str(definition.method_name.value)); if name.is_empty() { - self.error("x-fern-sdk-method-name has no letters or digits"); + self.error(format_args!("{} has no letters or digits", definition.method_name.key)); return; } let mut availability = None; - if let Some(value) = definition.availability { + if let Some(value) = definition.availability.value { let value = doc.str(value); - availability = parse_availability(value); + availability = metadata::availability(value); if availability.is_none() { self.error(format_args!( - "x-fern-availability {value:?} is not alpha, beta, preview, generally-available or deprecated" + "{} {value:?} is not alpha, beta, preview, generally-available or deprecated", + definition.availability.key )); } } @@ -950,7 +956,7 @@ impl<'d> Builder<'d> { } /// Returns the name of the field of a property or parameter written as - /// `wire_name`, whose name extension, such as `x-fern-property-name`, + /// `wire_name`, whose name extension, such as `x-forge-property-name`, /// is `extension`. The extension gives the name if it has letters or /// digits. fn field_name(&mut self, extension: Str, wire_name: &'d str) -> NameId { @@ -1267,19 +1273,6 @@ fn fixed_method(method: &str) -> Option { } } -/// Returns the availability `value` is as `x-fern-availability` writes -/// it, such as `beta`, or `None` if it is none of them. Case matters. -fn parse_availability(value: &str) -> Option { - match value { - "alpha" => Some(Availability::Alpha), - "beta" => Some(Availability::Beta), - "preview" => Some(Availability::Preview), - "generally-available" => Some(Availability::GenerallyAvailable), - "deprecated" => Some(Availability::Deprecated), - _ => None, - } -} - /// Reports whether `a` and `b` are the same parameter, so that one replaces /// the other: they have the same location and name. Header names are /// compared ignoring ASCII case, since HTTP field names are @@ -1599,7 +1592,7 @@ impl<'d> Builder<'d> { Schema::Bool(true) => {} Schema::Object(object) => { let object = doc.get(object); - if object.skip { + if object.ignore { continue; } extension = object.field_name; @@ -2162,7 +2155,7 @@ fn item(list: &[Schema], index: &str) -> Option { list.get(index.parse::().ok()?).copied() } -/// Returns the name an extension such as `x-fern-type-name` gives, or +/// Returns the name an extension such as `x-forge-model-name` gives, or /// `None` if there is none, or it has no letters or digits. fn name_of(doc: &Doc, extension: Str) -> Option { if extension.is_empty() { @@ -2212,7 +2205,7 @@ fn decode(segment: &str) -> Cow<'_, str> { Cow::Owned(decoded.replace("~1", "/").replace("~0", "~")) } -/// Returns the name of a model without `x-fern-type-name`: its schema +/// Returns the name of a model without `x-forge-model-name`: its schema /// name without `$defs`. fn model_name(schema_name: &str) -> Name { let mut words = String::with_capacity(schema_name.len()); diff --git a/src/link/openapi.rs b/src/link/openapi.rs index ba7fa4906..877b6df47 100644 --- a/src/link/openapi.rs +++ b/src/link/openapi.rs @@ -24,9 +24,13 @@ use serde::Deserialize; use serde::de::{self, DeserializeSeed, Deserializer, IgnoredAny, MapAccess, SeqAccess, Visitor}; use super::read::{first, keys}; +use super::resolve; use crate::Name; use crate::arena::{Id, List, Span, Str, Strings}; use crate::json::{self, Json}; +use crate::metadata::{ + self, BoolFormat, DefinitionField, DocumentField, GroupFormat, Hit, ParameterField, SchemaField, +}; /// An OpenAPI document: the fields of the OpenAPI Object at its root, and /// the arenas of the objects in it. @@ -236,26 +240,57 @@ pub(super) struct Operation { pub(super) responses: Span<(Str, Id)>, } +/// A value an extension gives, and the key it came from, so that an error can +/// name the key the document wrote. A native key's value is kept over any +/// other's, whatever order they are written in. +#[derive(Default)] +pub(super) struct Val { + pub(super) value: T, + /// The key as written, or empty if no key gave the value. + pub(super) key: &'static str, + native: bool, +} + +impl Val { + /// Keeps `value`, which `hit` gave, unless a native key gave the value + /// held and `hit` is not native. + fn set(&mut self, hit: &Hit, value: T) { + if takes(hit, &mut self.native) { + self.value = value; + self.key = hit.key; + } + } +} + +/// Reports whether a value from the key of `hit` replaces the one read so +/// far, which came from a native key if `native` is set, and records where +/// the value kept came from. +fn takes(hit: &Hit, native: &mut bool) -> bool { + if hit.native || !*native { + *native = hit.native; + return true; + } + false +} + /// The extensions that make an Operation Object, or an alias of one in its /// `x-forge-aliases`, a method. #[derive(Default)] pub(super) struct Definition { - /// The `x-fern-sdk-method-name`, or empty for none. - pub(super) method_name: Str, - /// The `x-fern-sdk-group-name`: the group path, top level first, or - /// empty for none. - pub(super) group_names: Span, - /// `x-fern-ignore`. - pub(super) ignore: bool, - /// `x-forge-hidden`. + /// The name of the method, or empty for none. + pub(super) method_name: Val, + /// The group path, top level first, or empty for none. + pub(super) group_names: Val>, + /// Whether the definition makes no method. + pub(super) ignore: Val, + /// Whether the method is left out of listings. pub(super) hidden: bool, - /// The `x-forge-require-confirmation`, or `None` for none. An empty - /// one is `Some`. + /// The sentence to confirm with, or `None` for none. An empty one is + /// `Some`. pub(super) confirmation: Option, - /// The `x-fern-availability` as written, or `None` for none. It is - /// checked as the method is built, so that an error can name the - /// operation. - pub(super) availability: Option, + /// The availability as written, or `None` for none. It is checked as + /// the method is built, so that an error can name the operation. + pub(super) availability: Val>, /// Each other extension, which is not read, in `Doc::extensions`, in /// the order they are written. One written more than once has the last /// value written, in the place of the first. @@ -280,8 +315,10 @@ pub(super) struct Parameter { /// The schema of each media type of a parameter described by /// `content` rather than `schema`, in the order they are written. pub(super) content: Span<(Str, Schema)>, - /// The `x-fern-parameter-name`, or empty for none. + /// The name of the parameter's field, or empty for none. pub(super) field_name: Str, + /// Whether a native key gave `field_name`. + field_name_native: bool, } /// Where a parameter is sent: the `in` of a Parameter Object. @@ -399,15 +436,19 @@ pub(super) struct SchemaObject { /// Whether the schema is marked `x-sensitive: true`: the value is a /// secret, such as a password or a token. pub(super) sensitive: bool, - /// The `x-fern-type-name`: the name of the model, for a schema in - /// `components.schemas`, or empty for none. + /// The name of the model, for a schema in `components.schemas`, or + /// empty for none. pub(super) model_name: Str, - /// The `x-fern-property-name`: the name of the field, for a property's - /// schema, or empty for none. + /// The name of the field, for a property's schema, or empty for none. pub(super) field_name: Str, - /// Whether a property's schema is marked `x-stainless-skip: true`. A - /// list of the targets to skip it for is ignored. - pub(super) skip: bool, + /// Whether a property's schema is marked to be left out: it makes no + /// field. + pub(super) ignore: bool, + /// Whether a native key gave `model_name`, `field_name` and `ignore`, + /// each, so that no other key replaces it. + model_name_native: bool, + field_name_native: bool, + ignore_native: bool, } /// A value of `type` in a Schema Object. @@ -851,29 +892,36 @@ impl Read for Types { } } -/// Reads an `x-fern-sdk-group-name`: a string split on dots, or an array of -/// strings that are not split. The empty string is no group. -struct GroupNames; +/// What reads a group path into a `Doc`, in the format it is written in: +/// an array of strings, which are not split, and, if the format says so, a +/// string split on its separator, where the empty string is no group. +struct GroupNames<'a>(&'a mut Doc, GroupFormat); -impl Read for GroupNames { - type Out = Span; +impl<'de> DeserializeSeed<'de> for GroupNames<'_> { + type Value = Span; - fn read<'de, D: Deserializer<'de>>(doc: &mut Doc, deserializer: D) -> Result, D::Error> { - struct GroupNamesVisitor<'a>(&'a mut Doc); + fn deserialize>(self, deserializer: D) -> Result, D::Error> { + struct GroupNamesVisitor<'a>(&'a mut Doc, GroupFormat); impl<'de> Visitor<'de> for GroupNamesVisitor<'_> { type Value = Span; fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("a string or an array of strings") + match self.1 { + GroupFormat::Array => f.write_str("an array of strings"), + GroupFormat::StringOrArray { .. } => f.write_str("a string or an array of strings"), + } } fn visit_str(self, v: &str) -> Result, E> { + let GroupFormat::StringOrArray { separator } = self.1 else { + return Err(E::invalid_type(de::Unexpected::Str(v), &self)); + }; if v.is_empty() { return Ok(Span::default()); } let doc = self.0; - Ok(doc.strings.push_split(v, '.', &mut doc.str_lists)) + Ok(doc.strings.push_split(v, separator, &mut doc.str_lists)) } fn visit_seq>(self, seq: A) -> Result, A::Error> { @@ -882,7 +930,16 @@ impl Read for GroupNames { } } - deserializer.deserialize_any(GroupNamesVisitor(doc)) + deserializer.deserialize_any(GroupNamesVisitor(self.0, self.1)) + } +} + +/// Reads a boolean in the format it is written in: `true` or `false`, and, +/// if the format says so, an array of targets, which is `false`. +fn read_bool<'de, A: MapAccess<'de>>(map: &mut A, format: BoolFormat) -> Result { + match format { + BoolFormat::Bool => map.next_value(), + BoolFormat::BoolOrTargets => Ok(map.next_value::()?.0), } } @@ -1036,6 +1093,47 @@ impl<'de> Deserialize<'de> for FirstServer { } } +/// Declares `$name`, a key of an object that has extensions: what `$resolve` +/// says if it is an `x-` key that means something there, and else one of the +/// OpenAPI keys `$keys` declares, or `Other`. The extensions are kept apart +/// from `$keys`, since they have their own way of being written twice. +macro_rules! entry { + ($name:ident, $keys:ident, $field:ty, $resolve:path) => { + enum $name { + Key($keys), + Extension(Hit<$field>), + } + + impl<'de> Deserialize<'de> for $name { + fn deserialize>(deserializer: D) -> Result<$name, D::Error> { + struct EntryVisitor; + + impl Visitor<'_> for EntryVisitor { + type Value = $name; + + fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("a key") + } + + fn visit_str(self, v: &str) -> Result<$name, E> { + // The OpenAPI keys first: most keys of a document are + // one of them, and none is an extension. + Ok(match $keys::from_key(v) { + $keys::Other => match $resolve(v) { + Some(hit) => $name::Extension(hit), + None => $name::Key($keys::Other), + }, + key => $name::Key(key), + }) + } + } + + deserializer.deserialize_identifier(EntryVisitor) + } + } + }; +} + keys! { DocumentKey { Openapi = "openapi", @@ -1043,10 +1141,11 @@ keys! { Servers = "servers", Paths = "paths", Components = "components", - Commands = "x-forge-commands", } } +entry!(DocumentEntry, DocumentKey, DocumentField, resolve::document); + struct DocumentVisitor<'a>(&'a mut Doc); impl<'de> Visitor<'de> for DocumentVisitor<'_> { @@ -1059,7 +1158,18 @@ impl<'de> Visitor<'de> for DocumentVisitor<'_> { fn visit_map>(self, mut map: A) -> Result<(), A::Error> { let doc = self.0; let mut seen = 0; - while let Some(key) = map.next_key::()? { + let mut seen_extensions = 0; + while let Some(entry) = map.next_key::()? { + let key = match entry { + DocumentEntry::Extension(hit) => { + resolve::once(&hit, &mut seen_extensions)?; + match hit.field { + DocumentField::Commands => doc.commands = map.next_value()?, + } + continue; + } + DocumentEntry::Key(key) => key, + }; key.once(&mut seen)?; match key { DocumentKey::Openapi => doc.openapi = map.next_value()?, @@ -1071,7 +1181,6 @@ impl<'de> Visitor<'de> for DocumentVisitor<'_> { DocumentKey::Components => { doc.components = map.next_value_seed(seed::(doc))?; } - DocumentKey::Commands => doc.commands = map.next_value()?, DocumentKey::Other => skip(&mut map)?, } } @@ -1182,38 +1291,37 @@ impl ReadObject for PathItem { } } -keys! { - /// The keys of a [`Definition`], in an Operation Object or an alias. - DefinitionKey { - MethodName = "x-fern-sdk-method-name", - GroupNames = "x-fern-sdk-group-name", - Ignore = "x-fern-ignore", - Hidden = "x-forge-hidden", - Confirmation = "x-forge-require-confirmation", - Availability = "x-fern-availability", - } -} - impl Definition { - /// Reads the value of `key`, the key of the entry `map` is reading. + /// Reads the value of the key `hit` says, the key of the entry `map` is + /// reading. A value of a key that is not native is kept only until a + /// native key gives one. fn read_value<'de, A: MapAccess<'de>>( &mut self, doc: &mut Doc, map: &mut A, - key: DefinitionKey, + hit: Hit, ) -> Result<(), A::Error> { - match key { - DefinitionKey::MethodName => self.method_name = map.next_value_seed(seed::(doc))?, - DefinitionKey::GroupNames => self.group_names = map.next_value_seed(seed::(doc))?, - DefinitionKey::Ignore => self.ignore = map.next_value()?, - DefinitionKey::Hidden => self.hidden = map.next_value()?, - DefinitionKey::Confirmation => { - self.confirmation = Some(map.next_value_seed(seed::(doc))?); + match hit.field { + DefinitionField::Method => { + let name = map.next_value_seed(seed::(doc))?; + self.method_name.set(&hit, name); } - DefinitionKey::Availability => { - self.availability = Some(map.next_value_seed(seed::(doc))?); + DefinitionField::Group(format) => { + let names = map.next_value_seed(GroupNames(doc, format))?; + self.group_names.set(&hit, names); + } + DefinitionField::Ignore(format) => { + let ignore = read_bool(map, format)?; + self.ignore.set(&hit, ignore); + } + DefinitionField::Availability => { + let availability = map.next_value_seed(seed::(doc))?; + self.availability.set(&hit, Some(availability)); + } + DefinitionField::Hidden => self.hidden = map.next_value()?, + DefinitionField::Confirmation => { + self.confirmation = Some(map.next_value_seed(seed::(doc))?); } - DefinitionKey::Other => skip(map)?, } Ok(()) } @@ -1236,9 +1344,9 @@ impl ReadObject for Alias { let mut extensions = Vec::new(); while let Some(field) = map.next_key::()? { match field { - AliasField::Definition(key) => { - key.once(&mut seen)?; - definition.read_value(doc, &mut map, key)?; + AliasField::Definition(hit) => { + resolve::once(&hit, &mut seen)?; + definition.read_value(doc, &mut map, hit)?; } AliasField::Extension(name) => json::insert(&mut extensions, name, map.next_value()?), AliasField::Other => skip(&mut map)?, @@ -1346,7 +1454,7 @@ impl<'de> Visitor<'de> for MaybeAlias<'_> { /// which is kept by its name, or any other key, which is skipped, as /// [`Alias`] says. enum AliasField { - Definition(DefinitionKey), + Definition(Hit), Extension(String), Other, } @@ -1363,13 +1471,13 @@ impl<'de> Deserialize<'de> for AliasField { } fn visit_str(self, v: &str) -> Result { - Ok(match DefinitionKey::from_key(v) { - DefinitionKey::Other if !v.starts_with("x-") => AliasField::Other, - DefinitionKey::Other => match OperationKey::from_key(v) { - OperationKey::Aliases => AliasField::Other, - _ => AliasField::Extension(v.to_owned()), - }, - key => AliasField::Definition(key), + if !v.starts_with("x-") { + return Ok(AliasField::Other); + } + Ok(match resolve::definition(v) { + Some(hit) => AliasField::Definition(hit), + None if metadata::is_aliases(v) => AliasField::Other, + None => AliasField::Extension(v.to_owned()), }) } } @@ -1380,7 +1488,6 @@ impl<'de> Deserialize<'de> for AliasField { keys! { OperationKey { - Aliases = "x-forge-aliases", Summary = "summary", Description = "description", Deprecated = "deprecated", @@ -1404,9 +1511,16 @@ impl ReadObject for Operation { while let Some(field) = map.next_key::()? { let key = match field { OperationField::Key(key) => key, - OperationField::Definition(key) => { - key.once(&mut seen_definition)?; - operation.definition.read_value(doc, &mut map, key)?; + OperationField::Definition(hit) => { + resolve::once(&hit, &mut seen_definition)?; + operation.definition.read_value(doc, &mut map, hit)?; + continue; + } + OperationField::Aliases => { + if operation.aliases.is_some() { + return Err(de::Error::duplicate_field(metadata::ALIASES)); + } + operation.aliases = Some(map.next_value_seed(seed::(doc))?); continue; } OperationField::Extension(name) => { @@ -1416,9 +1530,6 @@ impl ReadObject for Operation { }; key.once(&mut seen)?; match key { - OperationKey::Aliases => { - operation.aliases = Some(map.next_value_seed(seed::(doc))?); - } OperationKey::Summary => operation.summary = map.next_value_seed(seed::(doc))?, OperationKey::Description => { operation.description = map.next_value_seed(seed::(doc))?; @@ -1441,11 +1552,12 @@ impl ReadObject for Operation { } } -/// A key of an Operation Object: one of its definition, another that is -/// read, or an extension that is not, which is kept by its name. Any other -/// key is `OperationKey::Other`. +/// A key of an Operation Object: one of its definition, its aliases, +/// another that is read, or an extension that is not, which is kept by its +/// name. Any other key is `OperationKey::Other`. enum OperationField { - Definition(DefinitionKey), + Definition(Hit), + Aliases, Key(OperationKey), Extension(String), } @@ -1462,12 +1574,13 @@ impl<'de> Deserialize<'de> for OperationField { } fn visit_str(self, v: &str) -> Result { - match DefinitionKey::from_key(v) { - DefinitionKey::Other => {} - key => return Ok(OperationField::Definition(key)), - } + // The OpenAPI keys first, as for any other object. Ok(match OperationKey::from_key(v) { - OperationKey::Other if v.starts_with("x-") => OperationField::Extension(v.to_owned()), + OperationKey::Other if v.starts_with("x-") => match resolve::definition(v) { + Some(hit) => OperationField::Definition(hit), + None if metadata::is_aliases(v) => OperationField::Aliases, + None => OperationField::Extension(v.to_owned()), + }, key => OperationField::Key(key), }) } @@ -1489,10 +1602,11 @@ keys! { Explode = "explode", Schema = "schema", Content = "content", - FieldName = "x-fern-parameter-name", } } +entry!(ParameterEntry, ParameterKey, ParameterField, resolve::parameter); + impl ReadObject for Parameter { type Out = Id; const EXPECTING: &'static str = "a Parameter Object"; @@ -1500,7 +1614,23 @@ impl ReadObject for Parameter { fn read_object<'de, A: MapAccess<'de>>(doc: &mut Doc, mut map: A) -> Result, A::Error> { let mut param = Parameter::default(); let mut seen = 0; - while let Some(key) = map.next_key::()? { + let mut seen_extensions = 0; + while let Some(entry) = map.next_key::()? { + let key = match entry { + ParameterEntry::Extension(hit) => { + resolve::once(&hit, &mut seen_extensions)?; + match hit.field { + ParameterField::Name => { + let name = map.next_value_seed(seed::(doc))?; + if takes(&hit, &mut param.field_name_native) { + param.field_name = name; + } + } + } + continue; + } + ParameterEntry::Key(key) => key, + }; key.once(&mut seen)?; match key { ParameterKey::Ref => param.reference = map.next_value_seed(seed::(doc))?, @@ -1517,7 +1647,6 @@ impl ReadObject for Parameter { ParameterKey::Content => { param.content = map.next_value_seed(seed::>(doc))?; } - ParameterKey::FieldName => param.field_name = map.next_value_seed(seed::(doc))?, ParameterKey::Other => skip(&mut map)?, } } @@ -1619,13 +1748,11 @@ keys! { Default = "default", Deprecated = "deprecated", ReadOnly = "readOnly", - Sensitive = "x-sensitive", - ModelName = "x-fern-type-name", - FieldName = "x-fern-property-name", - Skip = "x-stainless-skip", } } +entry!(SchemaEntry, SchemaKey, SchemaField, resolve::schema); + impl ReadObject for SchemaObject { type Out = Id; const EXPECTING: &'static str = "a Schema Object"; @@ -1633,7 +1760,36 @@ impl ReadObject for SchemaObject { fn read_object<'de, A: MapAccess<'de>>(doc: &mut Doc, mut map: A) -> Result, A::Error> { let mut schema = SchemaObject::default(); let mut seen = 0; - while let Some(key) = map.next_key::()? { + let mut seen_extensions = 0; + while let Some(entry) = map.next_key::()? { + let key = match entry { + SchemaEntry::Extension(hit) => { + resolve::once(&hit, &mut seen_extensions)?; + match hit.field { + SchemaField::ModelName => { + let name = map.next_value_seed(seed::(doc))?; + if takes(&hit, &mut schema.model_name_native) { + schema.model_name = name; + } + } + SchemaField::PropertyName => { + let name = map.next_value_seed(seed::(doc))?; + if takes(&hit, &mut schema.field_name_native) { + schema.field_name = name; + } + } + SchemaField::Ignore(format) => { + let ignore = read_bool(&mut map, format)?; + if takes(&hit, &mut schema.ignore_native) { + schema.ignore = ignore; + } + } + SchemaField::Sensitive => schema.sensitive = map.next_value()?, + } + continue; + } + SchemaEntry::Key(key) => key, + }; key.once(&mut seen)?; match key { SchemaKey::Ref => schema.reference = map.next_value_seed(seed::(doc))?, @@ -1676,10 +1832,6 @@ impl ReadObject for SchemaObject { SchemaKey::Default => schema.default = Some(doc.add(map.next_value::()?)), SchemaKey::Deprecated => schema.deprecated = map.next_value()?, SchemaKey::ReadOnly => schema.read_only = map.next_value()?, - SchemaKey::Sensitive => schema.sensitive = map.next_value()?, - SchemaKey::ModelName => schema.model_name = map.next_value_seed(seed::(doc))?, - SchemaKey::FieldName => schema.field_name = map.next_value_seed(seed::(doc))?, - SchemaKey::Skip => schema.skip = map.next_value::()?.0, SchemaKey::Other => skip(&mut map)?, } } @@ -1783,32 +1935,32 @@ impl<'de> Deserialize<'de> for Count { } } -/// An `x-stainless-skip`: `true` or `false`, or a list of the targets to -/// skip for, which is not `true`. -struct StainlessSkip(bool); +/// A boolean that can also be written as a list of targets, which is not +/// `true`: the targets it would hold for are not read. +struct BoolOrTargets(bool); -impl<'de> Deserialize<'de> for StainlessSkip { - fn deserialize>(deserializer: D) -> Result { - struct SkipVisitor; +impl<'de> Deserialize<'de> for BoolOrTargets { + fn deserialize>(deserializer: D) -> Result { + struct TargetsVisitor; - impl<'de> Visitor<'de> for SkipVisitor { - type Value = StainlessSkip; + impl<'de> Visitor<'de> for TargetsVisitor { + type Value = BoolOrTargets; fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("a boolean or an array of targets") } - fn visit_bool(self, v: bool) -> Result { - Ok(StainlessSkip(v)) + fn visit_bool(self, v: bool) -> Result { + Ok(BoolOrTargets(v)) } - fn visit_seq>(self, mut seq: A) -> Result { + fn visit_seq>(self, mut seq: A) -> Result { while let Some(IgnoredAny) = seq.next_element()? {} - Ok(StainlessSkip(false)) + Ok(BoolOrTargets(false)) } } - deserializer.deserialize_any(SkipVisitor) + deserializer.deserialize_any(TargetsVisitor) } } diff --git a/src/link/resolve.rs b/src/link/resolve.rs new file mode 100644 index 000000000..87b2db0bc --- /dev/null +++ b/src/link/resolve.rs @@ -0,0 +1,91 @@ +//! Resolving the `x-` keys of the objects in [`openapi`](super::openapi). +//! +//! A key is native, when [`metadata`] reads it, or else, if forge is built +//! with the `compat` feature, one the compatibility layer reads in its place. +//! That is the whole fallback: native first, and the compatibility layer for +//! a key that is not native. This is the only place the layer is called, so +//! leaving it out takes one cfg arm for each kind of object, here. +//! +//! Only `x-` keys are asked about. Every other key is OpenAPI's own, which +//! `openapi` knows. + +use serde::de; + +use crate::metadata::{self, DefinitionField, DocumentField, Hit, ParameterField, SchemaField}; + +/// Returns what `key` says on an operation or an alias, if it is a key of +/// one. +pub(super) fn definition(key: &str) -> Option> { + if !key.starts_with("x-") { + return None; + } + metadata::definition(key).or_else(|| compat_definition(key)) +} + +/// Returns what `key` says on a Parameter Object, if it is a key of one. +pub(super) fn parameter(key: &str) -> Option> { + if !key.starts_with("x-") { + return None; + } + metadata::parameter(key).or_else(|| compat_parameter(key)) +} + +/// Returns what `key` says on a Schema Object, if it is a key of one. +pub(super) fn schema(key: &str) -> Option> { + if !key.starts_with("x-") { + return None; + } + metadata::schema(key).or_else(|| compat_schema(key)) +} + +/// Returns what `key` says at the root of the document, if it is a key of +/// it. No compatibility key says anything there. +pub(super) fn document(key: &str) -> Option> { + if !key.starts_with("x-") { + return None; + } + metadata::document(key) +} + +/// Returns an error if the key of `hit` is in `seen`, which has a bit for +/// each key read so far from the object, and else adds it. A native key and +/// a compatibility key of the same meaning are different keys, so both can +/// be written: the native one's value is kept. +pub(super) fn once(hit: &Hit, seen: &mut u64) -> Result<(), E> { + let bit = 1u64 << hit.slot; + if *seen & bit != 0 { + return Err(E::duplicate_field(hit.key)); + } + *seen |= bit; + Ok(()) +} + +#[cfg(feature = "compat")] +fn compat_definition(key: &str) -> Option> { + crate::compat::definition(key) +} + +#[cfg(not(feature = "compat"))] +fn compat_definition(_: &str) -> Option> { + None +} + +#[cfg(feature = "compat")] +fn compat_parameter(key: &str) -> Option> { + crate::compat::parameter(key) +} + +#[cfg(not(feature = "compat"))] +fn compat_parameter(_: &str) -> Option> { + None +} + +#[cfg(feature = "compat")] +fn compat_schema(key: &str) -> Option> { + crate::compat::schema(key) +} + +#[cfg(not(feature = "compat"))] +fn compat_schema(_: &str) -> Option> { + None +} diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs new file mode 100644 index 000000000..559869b8f --- /dev/null +++ b/src/metadata/mod.rs @@ -0,0 +1,306 @@ +//! The native extensions: the `x-forge-*` keys a document uses to say what a +//! `Forge` is built from, and what each of them means. +//! +//! This is the whole vocabulary, for each kind of object that has any: +//! [`definition`] for an Operation Object or an alias in its +//! `x-forge-aliases`, [`parameter`], [`schema`] and [`document`]. Each reads +//! a key as the document writes it, and says what it is as a [`Hit`], or +//! `None` if the key is not one of them. +//! +//! Nothing here reads a document or allocates: the keys come in as `&str`s, +//! and what goes out is small values, including the formats a key's value is +//! written in, as data. Reading the values, and building a `Forge` from +//! them, is the work of `link`, which asks this module first and a +//! compatibility layer, if forge is built with one, second; so a native key +//! always has the last word, and the compatibility layer can be left out +//! without changing what any native key means. + +use crate::Availability; + +/// The `x-forge-aliases` key of an Operation Object. It is not in +/// [`definition`], since an alias cannot have one. +pub(crate) const ALIASES: &str = "x-forge-aliases"; + +/// A key that says something about the object it is on. +#[derive(Clone, Copy)] +pub(crate) struct Hit { + /// What the key says. + pub(crate) field: F, + /// The key as the document writes it, for errors. + pub(crate) key: &'static str, + /// Whether the key is native. A value from a native key is kept over one + /// from any other, whatever order they are written in. + pub(crate) native: bool, + /// The bit of the key in a set of the keys read from an object so far, + /// which is how a key written twice is found. Unique among the keys of + /// one kind of object, native or not. + pub(crate) slot: u8, +} + +/// The first slot of the keys that are not native, so that slots never +/// collide with the native ones, which count up from zero. +#[cfg(feature = "compat")] +const COMPAT_SLOTS: u8 = 32; + +impl Hit { + /// Returns a native key, in slot `slot`, which is under 32. + const fn native(field: F, key: &'static str, slot: u8) -> Hit { + Hit { + field, + key, + native: true, + slot, + } + } + + /// Returns a key that is not native, which a compatibility layer + /// reads in place of a native one. It is the `n`th of its kind of + /// object, counting from zero, `n` under 32. + #[cfg(feature = "compat")] + pub(crate) const fn compat(field: F, key: &'static str, n: u8) -> Hit { + Hit { + field, + key, + native: false, + slot: COMPAT_SLOTS + n, + } + } +} + +/// What a key says on an operation, or on an alias of one. +#[derive(Clone, Copy)] +pub(crate) enum DefinitionField { + /// The name of the method. + Method, + /// The group path of the method. + Group(GroupFormat), + /// Whether the definition makes no method. + Ignore(BoolFormat), + /// The stage of the API the method is in. + Availability, + /// Whether the method is left out of listings. + Hidden, + /// The sentence to show before calling the method. + Confirmation, +} + +/// What a key says on a Parameter Object. +#[derive(Clone, Copy)] +pub(crate) enum ParameterField { + /// The name of the parameter's field. + Name, +} + +/// What a key says on a Schema Object. +#[derive(Clone, Copy)] +pub(crate) enum SchemaField { + /// The name of the model, for a schema in `components.schemas`. + ModelName, + /// The name of a property's field. + PropertyName, + /// Whether the property makes no field. + Ignore(BoolFormat), + /// Whether the schema's value is a secret. + Sensitive, +} + +/// What a key says at the root of the document. +#[derive(Clone, Copy)] +pub(crate) enum DocumentField { + /// The descriptions of the groups. + Commands, +} + +/// How the value of a group path is written. +#[derive(Clone, Copy)] +pub(crate) enum GroupFormat { + /// An array of group names, top level first. + Array, + /// An array of group names, or one string of them separated by + /// `separator`. The empty string is no group. + #[cfg_attr(not(feature = "compat"), expect(dead_code))] + StringOrArray { separator: char }, +} + +/// How the value of a boolean is written. +#[derive(Clone, Copy)] +pub(crate) enum BoolFormat { + /// `true` or `false`. + Bool, + /// `true` or `false`, or an array of targets, which counts as `false`. + #[cfg_attr(not(feature = "compat"), expect(dead_code))] + BoolOrTargets, +} + +/// Returns what `key` says on an operation or an alias, if it is a native +/// key of one. +pub(crate) fn definition(key: &str) -> Option> { + const METHOD: &str = "x-forge-method"; + const GROUP: &str = "x-forge-group"; + const IGNORE: &str = "x-forge-ignore"; + const AVAILABILITY: &str = "x-forge-availability"; + const HIDDEN: &str = "x-forge-hidden"; + const CONFIRMATION: &str = "x-forge-require-confirmation"; + Some(match key { + METHOD => Hit::native(DefinitionField::Method, METHOD, 0), + GROUP => Hit::native(DefinitionField::Group(GroupFormat::Array), GROUP, 1), + IGNORE => Hit::native(DefinitionField::Ignore(BoolFormat::Bool), IGNORE, 2), + AVAILABILITY => Hit::native(DefinitionField::Availability, AVAILABILITY, 3), + HIDDEN => Hit::native(DefinitionField::Hidden, HIDDEN, 4), + CONFIRMATION => Hit::native(DefinitionField::Confirmation, CONFIRMATION, 5), + _ => return None, + }) +} + +/// Returns whether `key` is the `x-forge-aliases` of an operation. +pub(crate) fn is_aliases(key: &str) -> bool { + key == ALIASES +} + +/// Returns what `key` says on a Parameter Object, if it is a native key of +/// one. +pub(crate) fn parameter(key: &str) -> Option> { + const NAME: &str = "x-forge-parameter-name"; + Some(match key { + NAME => Hit::native(ParameterField::Name, NAME, 0), + _ => return None, + }) +} + +/// Returns what `key` says on a Schema Object, if it is a native key of one. +pub(crate) fn schema(key: &str) -> Option> { + const MODEL_NAME: &str = "x-forge-model-name"; + const PROPERTY_NAME: &str = "x-forge-property-name"; + const IGNORE: &str = "x-forge-ignore"; + const SENSITIVE: &str = "x-sensitive"; + Some(match key { + MODEL_NAME => Hit::native(SchemaField::ModelName, MODEL_NAME, 0), + PROPERTY_NAME => Hit::native(SchemaField::PropertyName, PROPERTY_NAME, 1), + IGNORE => Hit::native(SchemaField::Ignore(BoolFormat::Bool), IGNORE, 2), + SENSITIVE => Hit::native(SchemaField::Sensitive, SENSITIVE, 3), + _ => return None, + }) +} + +/// Returns what `key` says at the root of the document, if it is a native +/// key of it. +pub(crate) fn document(key: &str) -> Option> { + const COMMANDS: &str = "x-forge-commands"; + Some(match key { + COMMANDS => Hit::native(DocumentField::Commands, COMMANDS, 0), + _ => return None, + }) +} + +/// Returns the availability `value` is, such as `beta`, or `None` if it is +/// none of them. Case matters. +pub(crate) fn availability(value: &str) -> Option { + match value { + "alpha" => Some(Availability::Alpha), + "beta" => Some(Availability::Beta), + "preview" => Some(Availability::Preview), + "generally-available" => Some(Availability::GenerallyAvailable), + "deprecated" => Some(Availability::Deprecated), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Every native key of each kind of object, as `(key, slot)`. + fn native_keys() -> [&'static [&'static str]; 4] { + [ + &[ + "x-forge-method", + "x-forge-group", + "x-forge-ignore", + "x-forge-availability", + "x-forge-hidden", + "x-forge-require-confirmation", + ], + &["x-forge-parameter-name"], + &[ + "x-forge-model-name", + "x-forge-property-name", + "x-forge-ignore", + "x-sensitive", + ], + &["x-forge-commands"], + ] + } + + #[test] + fn each_native_key_is_read_as_itself_and_as_native() { + let [definitions, parameters, schemas, documents] = native_keys(); + for &key in definitions { + let hit = definition(key).unwrap_or_else(|| panic!("{key} is not a definition key")); + assert_eq!((hit.key, hit.native), (key, true)); + } + for &key in parameters { + let hit = parameter(key).unwrap_or_else(|| panic!("{key} is not a parameter key")); + assert_eq!((hit.key, hit.native), (key, true)); + } + for &key in schemas { + let hit = schema(key).unwrap_or_else(|| panic!("{key} is not a schema key")); + assert_eq!((hit.key, hit.native), (key, true)); + } + for &key in documents { + let hit = document(key).unwrap_or_else(|| panic!("{key} is not a document key")); + assert_eq!((hit.key, hit.native), (key, true)); + } + } + + #[test] + fn slots_are_unique_among_the_keys_of_an_object_and_under_the_compat_ones() { + let [definitions, _, schemas, _] = native_keys(); + let slots = |keys: &[&str], hit: &dyn Fn(&str) -> u8| { + let mut slots: Vec = keys.iter().map(|key| hit(key)).collect(); + slots.sort_unstable(); + let len = slots.len(); + slots.dedup(); + assert_eq!(slots.len(), len, "duplicate slot among {keys:?}"); + assert!(slots.iter().all(|&slot| slot < 32), "native slots are under 32"); + }; + slots(definitions, &|key| definition(key).map_or(u8::MAX, |hit| hit.slot)); + slots(schemas, &|key| schema(key).map_or(u8::MAX, |hit| hit.slot)); + } + + #[test] + fn other_keys_are_not_native() { + for key in [ + "x-other-method-name", + "x-other-skip", + "x-custom", + "summary", + "x-forge-nope", + ] { + assert!(definition(key).is_none(), "{key}"); + assert!(parameter(key).is_none(), "{key}"); + assert!(schema(key).is_none(), "{key}"); + assert!(document(key).is_none(), "{key}"); + } + } + + #[test] + fn aliases_are_not_a_definition_key() { + assert!(is_aliases("x-forge-aliases")); + assert!(definition("x-forge-aliases").is_none()); + } + + #[test] + fn availability_is_one_of_five_spellings_and_case_matters() { + for (value, availability) in [ + ("alpha", Availability::Alpha), + ("beta", Availability::Beta), + ("preview", Availability::Preview), + ("generally-available", Availability::GenerallyAvailable), + ("deprecated", Availability::Deprecated), + ] { + assert_eq!(super::availability(value), Some(availability)); + } + assert_eq!(super::availability("Beta"), None); + assert_eq!(super::availability("ga"), None); + } +} diff --git a/src/plugin/wasm.rs b/src/plugin/wasm.rs index 97220a570..6d5729cd7 100644 --- a/src/plugin/wasm.rs +++ b/src/plugin/wasm.rs @@ -143,7 +143,7 @@ interface forge { json: option, } - /// The stage of the API a method is in, from `x-fern-availability`. + /// The stage of the API a method is in, from `x-forge-availability`. enum availability { alpha, beta, preview, generally-available, deprecated, } diff --git a/src/types.rs b/src/types.rs index 34aab173f..2386d8467 100644 --- a/src/types.rs +++ b/src/types.rs @@ -293,7 +293,7 @@ impl<'f> Object<'f> { /// except in a [`Method::request`](crate::Method::request) and in /// [`Method::headers`](crate::Method::headers). /// - /// A property marked `x-stainless-skip: true`, or whose schema is + /// A property marked `x-forge-ignore: true`, or whose schema is /// `false`, has no field. A name in `required` that is not a property is /// ignored. Two fields with equal names are an error. pub fn fields(self) -> impl ExactSizeIterator> { @@ -330,7 +330,7 @@ impl<'f> Field<'f> { /// Returns the name of the field. /// - /// Corresponds to the `x-fern-property-name` extension of the + /// Corresponds to the `x-forge-property-name` extension of the /// property, or its wire name if it has none. pub fn name(self) -> &'f Name { &self.forge.names[self.data.name.index()] @@ -416,7 +416,7 @@ impl<'f> Field<'f> { /// `readOnly`, an `x-sensitive` next to a `$ref` counts in every /// version of OpenAPI, since tools commonly honour extensions there. A /// value that is not a boolean is an error, as it is for a schema's - /// `x-stainless-skip` and an operation's `x-forge-hidden`. + /// `x-forge-ignore` and an operation's `x-forge-hidden`. /// /// A field for a parameter, whether in the request or in /// [`Method::headers`](crate::Method::headers), is sensitive when the @@ -509,7 +509,7 @@ impl<'f> Discriminator<'f> { } /// Returns the name of the property's field: the - /// `x-fern-property-name` of the property in the members, or else its + /// `x-forge-property-name` of the property in the members, or else its /// wire name. pub fn name(self) -> &'f Name { &self.data.name diff --git a/tests/compat/common.rs b/tests/compat/common.rs new file mode 100644 index 000000000..4649783ea --- /dev/null +++ b/tests/compat/common.rs @@ -0,0 +1,105 @@ +//! Helpers to build documents and to compare what two of them make, so that +//! each test is about one thing. + +use forge::{Forge, Type}; + +/// Parses `json` as a whole document. +#[track_caller] +pub fn parse(json: &str) -> Forge { + match serde_json::from_str(json) { + Ok(forge) => forge, + Err(err) => panic!("parse: {err}"), + } +} + +/// Parses `json`, which must fail, and returns the error message. +#[track_caller] +pub fn parse_err(json: &str) -> String { + match serde_json::from_str::(json) { + Ok(_) => panic!("parse: want an error, got a Forge"), + Err(err) => err.to_string(), + } +} + +/// Returns an OpenAPI 3.0.3 document with one operation, `GET /a`, that has +/// the members `keys`, written as the inside of a JSON object, each followed +/// by a comma, such as `"x-forge-method": "get",`. +pub fn operation_with(keys: &str) -> String { + format!( + r#"{{"openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, + "paths": {{"/a": {{"get": {{{keys} "responses": {{"204": {{"description": "ok"}}}}}}}}}}}}"# + ) +} + +/// Returns an OpenAPI 3.0.3 document with one method, `a.get`, whose JSON +/// response has the schema `schema`, and `components.schemas` of `schemas`. +pub fn responding_with(schema: &str, schemas: &str) -> String { + format!( + r#"{{"openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", + "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}}, + "components": {{"schemas": {schemas}}}}}"# + ) +} + +/// Asserts that `a` and `b` build the same `Forge`, as far as `describe` +/// says. +#[track_caller] +pub fn assert_same(a: &str, b: &str) { + let (a, b) = (describe(&parse(a)), describe(&parse(b))); + assert_eq!(a, b, "the documents build different Forges"); +} + +/// Writes what a `Forge` says about every group, method and model, down to +/// the name of each field, so that two `Forge`s that differ in any name, +/// availability or shape differ in what this returns. +pub fn describe(forge: &Forge) -> String { + let mut out = String::new(); + for group in forge.groups() { + let path: Vec = group.path().map(|name| name.snake()).collect(); + out += &format!("group {}\n", path.join(".")); + for method in group.methods() { + let request = method.request().map_or_else(|| "-".to_string(), shape); + let response = method + .responses() + .map(|response| response.json().map_or_else(|| "-".to_string(), |json| shape(json.ty()))) + .collect::>() + .join(","); + out += &format!( + " method {} {} {} availability={:?} hidden={} request={request} response={response}\n", + method.name().snake(), + method.http_method().as_str(), + method.path(), + method.availability().map(|availability| availability.as_str()), + method.is_hidden(), + ); + } + for model in group.models() { + out += &format!(" model {} = {}\n", model.name().snake(), shape(model.ty())); + } + } + for model in forge.models() { + out += &format!("model {} = {}\n", model.name().snake(), shape(model.ty())); + } + out +} + +/// Writes a type, with the wire name and name of every field, and a model by +/// name. +fn shape(ty: Type<'_>) -> String { + match ty { + Type::Scalar(scalar) => format!("{scalar:?}"), + Type::Enum(values) => format!("enum{values:?}"), + Type::Array(array) => format!("[{}]", shape(array.elem())), + Type::Object(object) => { + let fields: Vec = object + .fields() + .map(|field| format!("{}:{}={}", field.wire_name(), field.name().snake(), shape(field.ty()))) + .collect(); + format!("{{{}}}", fields.join(",")) + } + Type::Union(union) => union.members().map(shape).collect::>().join("|"), + Type::Intersection(intersection) => intersection.members().map(shape).collect::>().join("&"), + Type::Model(model) => format!("Model({})", model.name().snake()), + } +} diff --git a/tests/compat/fern.rs b/tests/compat/fern.rs new file mode 100644 index 000000000..3f7eff586 --- /dev/null +++ b/tests/compat/fern.rs @@ -0,0 +1,280 @@ +//! Fern's `x-fern-*` extensions: each is read as the native extension that +//! says the same, and as nothing else. + +use super::common::{assert_same, describe, operation_with, parse, parse_err, responding_with}; + +#[test] +fn method_group_and_availability_are_read_as_native() { + assert_same( + &operation_with( + r#""x-fern-sdk-group-name": ["accounts"], "x-fern-sdk-method-name": "list", "x-fern-availability": "beta","#, + ), + &operation_with(r#""x-forge-group": ["accounts"], "x-forge-method": "list", "x-forge-availability": "beta","#), + ); +} + +#[test] +fn every_availability_is_read() { + for availability in ["alpha", "beta", "preview", "generally-available", "deprecated"] { + assert_same( + &operation_with(&format!( + r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "{availability}","# + )), + &operation_with(&format!( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "{availability}","# + )), + ); + } +} + +#[test] +fn a_group_written_as_a_string_is_split_on_dots() { + assert_same( + &operation_with(r#""x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get","#), + &operation_with(r#""x-forge-group": ["a", "b", "c"], "x-forge-method": "get","#), + ); +} + +#[test] +fn a_group_written_as_an_array_is_not_split() { + assert_same( + &operation_with(r#""x-fern-sdk-group-name": ["a.b", "c"], "x-fern-sdk-method-name": "get","#), + &operation_with(r#""x-forge-group": ["a.b", "c"], "x-forge-method": "get","#), + ); +} + +#[test] +fn an_empty_group_string_is_no_group_and_so_no_method() { + let forge = parse(&operation_with( + r#""x-fern-sdk-group-name": "", "x-fern-sdk-method-name": "get","#, + )); + + assert_eq!(forge.groups().count(), 0); +} + +#[test] +fn a_group_that_is_neither_a_string_nor_an_array_is_an_error() { + let err = parse_err(&operation_with( + r#""x-fern-sdk-group-name": 1, "x-fern-sdk-method-name": "get","#, + )); + + assert!(err.contains("a string or an array of strings"), "{err}"); +} + +#[test] +fn ignore_makes_no_method() { + assert_same( + &operation_with(r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": true,"#), + &operation_with(r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": true,"#), + ); + assert_eq!( + parse(&operation_with( + r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": true,"# + )) + .groups() + .count(), + 0 + ); +} + +#[test] +fn ignore_set_to_false_keeps_the_method() { + assert_same( + &operation_with(r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": false,"#), + &operation_with(r#""x-forge-group": ["a"], "x-forge-method": "get","#), + ); +} + +#[test] +fn a_parameter_name_is_read_as_native() { + let parameters = |key: &str| { + operation_with(&format!( + r#""x-forge-group": ["a"], "x-forge-method": "list", + "parameters": [{{"name": "q", "in": "query", "{key}": "query", "schema": {{"type": "string"}}}}],"# + )) + }; + + assert_same( + ¶meters("x-fern-parameter-name"), + ¶meters("x-forge-parameter-name"), + ); + assert!(describe(&parse(¶meters("x-fern-parameter-name"))).contains("q:query=")); +} + +#[test] +fn a_property_name_is_read_as_native() { + let schema = |key: &str| { + responding_with( + &format!(r#"{{"type": "object", "properties": {{"owner": {{"type": "string", "{key}": "person"}}}}}}"#), + "{}", + ) + }; + + assert_same(&schema("x-fern-property-name"), &schema("x-forge-property-name")); + assert!(describe(&parse(&schema("x-fern-property-name"))).contains("owner:person=")); +} + +#[test] +fn a_type_name_is_read_as_the_name_of_a_model() { + let schemas = |key: &str| { + responding_with( + r##"{"$ref": "#/components/schemas/not_found"}"##, + &format!(r#"{{"not_found": {{"type": "object", "{key}": "Missing"}}}}"#), + ) + }; + + assert_same(&schemas("x-fern-type-name"), &schemas("x-forge-model-name")); + assert!(describe(&parse(&schemas("x-fern-type-name"))).contains("model missing =")); +} + +#[test] +fn the_keys_of_an_alias_are_read_too() { + let alias = |group: &str, method: &str, availability: &str, ignore: &str| { + operation_with(&format!( + r#""x-forge-aliases": [{{"{group}": {}, "{method}": "pause", "{availability}": "beta", "{ignore}": false}}],"#, + if group.starts_with("x-fern") { + r#""a.b""# + } else { + r#"["a", "b"]"# + }, + )) + }; + + assert_same( + &alias( + "x-fern-sdk-group-name", + "x-fern-sdk-method-name", + "x-fern-availability", + "x-fern-ignore", + ), + &alias( + "x-forge-group", + "x-forge-method", + "x-forge-availability", + "x-forge-ignore", + ), + ); +} + +#[test] +fn a_key_that_is_read_is_not_an_extension_of_the_method() { + let forge = parse(&operation_with( + r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": false, + "x-fern-availability": "beta", "x-a": 1,"#, + )); + let method = forge.groups().next().unwrap().methods().next().unwrap(); + + assert_eq!(method.extensions().map(|(name, _)| name).collect::>(), ["x-a"]); + for key in [ + "x-fern-sdk-group-name", + "x-fern-sdk-method-name", + "x-fern-ignore", + "x-fern-availability", + ] { + assert_eq!(method.extension(key), None, "{key}"); + } +} + +#[test] +fn a_key_that_is_not_read_stays_an_extension_of_the_method() { + let forge = parse(&operation_with( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-fern-audiences": ["internal"], "x-fern-pagination": {"offset": "o"},"#, + )); + let method = forge.groups().next().unwrap().methods().next().unwrap(); + + assert_eq!( + method.extensions().map(|(name, _)| name).collect::>(), + ["x-fern-audiences", "x-fern-pagination"] + ); +} + +#[test] +fn an_extension_on_a_schema_that_is_not_read_has_no_effect() { + let with = responding_with( + r#"{"type": "string", "x-fern-enum": {"a": {"name": "A"}}, "x-fern-audiences": ["x"]}"#, + "{}", + ); + let without = responding_with(r#"{"type": "string"}"#, "{}"); + + assert_same(&with, &without); +} + +#[test] +fn an_error_names_the_key_the_document_wrote() { + let err = parse_err(&operation_with( + r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "ga","#, + )); + assert!(err.contains(r#"GET /a: x-fern-availability "ga" is not"#), "{err}"); + + let err = parse_err(&operation_with( + r#""x-fern-sdk-group-name": "accounts..members", "x-fern-sdk-method-name": "get","#, + )); + assert!( + err.contains("GET /a: x-fern-sdk-group-name has a group name with no letters or digits"), + "{err}" + ); + + let err = parse_err(&operation_with( + r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "-","#, + )); + assert!( + err.contains("GET /a: x-fern-sdk-method-name has no letters or digits"), + "{err}" + ); +} + +#[test] +fn an_error_in_an_alias_names_the_key_the_document_wrote() { + let err = parse_err(&operation_with( + r#""x-forge-aliases": [1, {"x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "pause", "x-fern-availability": "ga"}],"#, + )); + + assert!( + err.contains(r#"x-forge-aliases[1]: x-fern-availability "ga" is not"#), + "{err}" + ); +} + +#[test] +fn a_key_written_twice_is_an_error_naming_it() { + for (keys, key) in [ + (r#""x-fern-ignore": false, "x-fern-ignore": false,"#, "x-fern-ignore"), + ( + r#""x-fern-sdk-method-name": "a", "x-fern-sdk-method-name": "b","#, + "x-fern-sdk-method-name", + ), + ( + r#""x-fern-availability": "beta", "x-fern-availability": "beta","#, + "x-fern-availability", + ), + ( + r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-group-name": ["b"],"#, + "x-fern-sdk-group-name", + ), + ] { + let err = parse_err(&operation_with(keys)); + + assert!(err.contains(&format!("duplicate field `{key}`")), "{key}: {err}"); + } +} + +#[test] +fn the_vendor_keys_of_a_kind_of_object_are_read_only_there() { + // A name key on an operation, or a method key on a schema, says nothing. + let forge = parse(&operation_with( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-fern-property-name": "p", "x-fern-type-name": "T", + "x-fern-parameter-name": "q","#, + )); + let method = forge.groups().next().unwrap().methods().next().unwrap(); + assert_eq!(method.extensions().count(), 3); + + let schema = responding_with( + r#"{"type": "object", "properties": {"a": {"type": "string", "x-fern-sdk-method-name": "m", "x-fern-ignore": true}}}"#, + "{}", + ); + assert!( + describe(&parse(&schema)).contains("a:a="), + "{}", + describe(&parse(&schema)) + ); +} diff --git a/tests/compat/main.rs b/tests/compat/main.rs new file mode 100644 index 000000000..c44b04ea4 --- /dev/null +++ b/tests/compat/main.rs @@ -0,0 +1,15 @@ +//! Tests for the compatibility layer: the keys other tools write, read as the +//! native extensions say the same things. +//! +//! Each primitive is tested the same way: a document written with a tool's +//! keys must build the same `Forge` as its native twin. The tests that only +//! the compatibility layer can pass, such as a value format native keys do +//! not have, or a key a tool writes that forge does not read, are written out. +//! +//! They only build with the `compat` feature. The suite of `tests/parse`, +//! which has no vendor names in it, runs without it. + +mod common; +mod fern; +mod native_first; +mod stainless; diff --git a/tests/compat/native_first.rs b/tests/compat/native_first.rs new file mode 100644 index 000000000..9e97fe767 --- /dev/null +++ b/tests/compat/native_first.rs @@ -0,0 +1,196 @@ +//! A native key is applied, and the compatibility layer is the fallback: when +//! a document has both, the compat value is ignored, whatever order they are +//! written in and whatever the compat value is, so long as it is a value at +//! all. + +use super::common::{assert_same, describe, operation_with, parse, parse_err, responding_with}; + +/// Asserts that every ordering of `native` and `compat`, which are members of +/// an operation, builds what `expected` alone does. +#[track_caller] +fn native_wins(native: &str, compat: &str, expected: &str) { + for keys in [format!("{native} {compat}"), format!("{compat} {native}")] { + assert_same(&operation_with(&keys), &operation_with(expected)); + } +} + +#[test] +fn the_native_method_wins() { + native_wins( + r#""x-forge-group": ["a"], "x-forge-method": "native","#, + r#""x-fern-sdk-method-name": "vendor","#, + r#""x-forge-group": ["a"], "x-forge-method": "native","#, + ); + assert!( + describe(&parse(&operation_with( + r#""x-forge-group": ["a"], "x-forge-method": "native", "x-fern-sdk-method-name": "vendor","# + ))) + .contains("method native") + ); +} + +#[test] +fn the_native_group_wins() { + native_wins( + r#""x-forge-method": "get", "x-forge-group": ["native"],"#, + r#""x-fern-sdk-group-name": "vendor.group","#, + r#""x-forge-method": "get", "x-forge-group": ["native"],"#, + ); +} + +#[test] +fn the_native_availability_wins_and_an_invalid_compat_one_is_not_checked() { + native_wins( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "beta","#, + r#""x-fern-availability": "ga","#, + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "beta","#, + ); +} + +#[test] +fn a_native_ignore_of_false_keeps_the_method_a_compat_one_would_drop() { + native_wins( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": false,"#, + r#""x-fern-ignore": true,"#, + r#""x-forge-group": ["a"], "x-forge-method": "get","#, + ); +} + +#[test] +fn a_native_ignore_of_true_drops_the_method_a_compat_one_would_keep() { + native_wins( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": true,"#, + r#""x-fern-ignore": false,"#, + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": true,"#, + ); +} + +#[test] +fn the_native_parameter_name_wins() { + let parameter = |keys: &str| { + operation_with(&format!( + r#""x-forge-group": ["a"], "x-forge-method": "list", + "parameters": [{{"name": "q", "in": "query", {keys} "schema": {{"type": "string"}}}}],"# + )) + }; + let native = parameter(r#""x-forge-parameter-name": "native","#); + + for keys in [ + r#""x-forge-parameter-name": "native", "x-fern-parameter-name": "vendor","#, + r#""x-fern-parameter-name": "vendor", "x-forge-parameter-name": "native","#, + ] { + assert_same(¶meter(keys), &native); + } + assert!(describe(&parse(&native)).contains("q:native=")); +} + +#[test] +fn the_native_property_and_model_names_win() { + let schema = |keys: &str| { + responding_with( + &format!(r#"{{"type": "object", "properties": {{"owner": {{"type": "string", {keys}}}}}}}"#), + "{}", + ) + }; + let native = schema(r#""x-forge-property-name": "native""#); + + for keys in [ + r#""x-forge-property-name": "native", "x-fern-property-name": "vendor""#, + r#""x-fern-property-name": "vendor", "x-forge-property-name": "native""#, + ] { + assert_same(&schema(keys), &native); + } + + let model = |keys: &str| { + responding_with( + r##"{"$ref": "#/components/schemas/m"}"##, + &format!(r#"{{"m": {{"type": "object", {keys}}}}}"#), + ) + }; + for keys in [ + r#""x-forge-model-name": "Native", "x-fern-type-name": "Vendor""#, + r#""x-fern-type-name": "Vendor", "x-forge-model-name": "Native""#, + ] { + assert_same(&model(keys), &model(r#""x-forge-model-name": "Native""#)); + } +} + +#[test] +fn the_native_ignore_of_a_property_wins_over_a_skip() { + let property = |keys: &str| { + responding_with( + &format!(r#"{{"type": "object", "properties": {{"a": {{"type": "string", {keys}}}}}}}"#), + "{}", + ) + }; + for keys in [ + r#""x-forge-ignore": false, "x-stainless-skip": true"#, + r#""x-stainless-skip": true, "x-forge-ignore": false"#, + ] { + assert!(describe(&parse(&property(keys))).contains("a:a="), "{keys}"); + } + for keys in [ + r#""x-forge-ignore": true, "x-stainless-skip": false"#, + r#""x-stainless-skip": false, "x-forge-ignore": true"#, + ] { + assert!(!describe(&parse(&property(keys))).contains("a:a="), "{keys}"); + } +} + +#[test] +fn both_keys_with_the_same_value_are_the_same_as_one() { + assert_same( + &operation_with( + r#""x-forge-group": ["a", "b"], "x-fern-sdk-group-name": "a.b", + "x-forge-method": "get", "x-fern-sdk-method-name": "get", + "x-forge-availability": "beta", "x-fern-availability": "beta","#, + ), + &operation_with(r#""x-forge-group": ["a", "b"], "x-forge-method": "get", "x-forge-availability": "beta","#), + ); +} + +#[test] +fn each_primitive_is_resolved_on_its_own() { + // The group is native and the method and availability are not. + assert_same( + &operation_with(r#""x-forge-group": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "beta","#), + &operation_with(r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "beta","#), + ); +} + +#[test] +fn a_compat_value_of_the_wrong_type_is_an_error_even_when_a_native_key_wins() { + for keys in [ + r#""x-forge-availability": "beta", "x-fern-availability": 1,"#, + r#""x-fern-availability": 1, "x-forge-availability": "beta","#, + ] { + let err = parse_err(&operation_with(&format!( + r#""x-forge-group": ["a"], "x-forge-method": "get", {keys}"# + ))); + + assert!(err.contains("invalid type"), "{keys}: {err}"); + } +} + +#[test] +fn a_native_key_written_twice_is_an_error_naming_it() { + let err = parse_err(&operation_with(r#""x-forge-ignore": false, "x-forge-ignore": false,"#)); + + assert!(err.contains("duplicate field `x-forge-ignore`"), "{err}"); +} + +#[test] +fn a_native_group_written_as_a_string_is_an_error() { + let err = parse_err(&operation_with(r#""x-forge-group": "a.b", "x-forge-method": "get","#)); + + assert!(err.contains("an array of strings"), "{err}"); +} + +#[test] +fn an_error_names_the_native_key_when_the_native_key_gave_the_value() { + let err = parse_err(&operation_with( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "ga","#, + )); + + assert!(err.contains(r#"GET /a: x-forge-availability "ga" is not"#), "{err}"); +} diff --git a/tests/compat/stainless.rs b/tests/compat/stainless.rs new file mode 100644 index 000000000..496a2124a --- /dev/null +++ b/tests/compat/stainless.rs @@ -0,0 +1,90 @@ +//! Stainless's `x-stainless-skip`: a property that makes no field, written as +//! a boolean or as a list of targets. + +use super::common::{assert_same, describe, operation_with, parse, parse_err, responding_with}; + +fn with_skip(value: &str) -> String { + responding_with( + &format!( + r#"{{"type": "object", "properties": {{"id": {{"type": "string"}}, "old_id": {{"type": "string", "x-stainless-skip": {value}}}}}}}"# + ), + "{}", + ) +} + +fn with_ignore(value: &str) -> String { + responding_with( + &format!( + r#"{{"type": "object", "properties": {{"id": {{"type": "string"}}, "old_id": {{"type": "string", "x-forge-ignore": {value}}}}}}}"# + ), + "{}", + ) +} + +#[test] +fn a_skipped_property_is_read_as_an_ignored_one() { + assert_same(&with_skip("true"), &with_ignore("true")); + assert!(!describe(&parse(&with_skip("true"))).contains("old_id")); +} + +#[test] +fn a_property_skipped_as_false_keeps_its_field() { + assert_same(&with_skip("false"), &with_ignore("false")); + assert!(describe(&parse(&with_skip("false"))).contains("old_id")); +} + +#[test] +fn a_list_of_targets_is_not_a_skip() { + assert_same(&with_skip(r#"["typescript", "go"]"#), &with_ignore("false")); + assert!(describe(&parse(&with_skip(r#"["typescript"]"#))).contains("old_id")); + assert!(describe(&parse(&with_skip("[]"))).contains("old_id")); +} + +#[test] +fn a_skip_that_is_not_a_boolean_or_a_list_is_an_error() { + let err = parse_err(&with_skip(r#""yes""#)); + + assert!(err.contains("a boolean or an array of targets"), "{err}"); +} + +#[test] +fn a_list_of_targets_is_an_error_for_the_native_key() { + let err = parse_err(&with_ignore(r#"["typescript"]"#)); + + assert!(err.contains("invalid type"), "{err}"); +} + +#[test] +fn a_skip_written_twice_is_an_error_naming_it() { + let schema = responding_with( + r#"{"type": "object", "properties": {"a": {"type": "string", "x-stainless-skip": false, "x-stainless-skip": false}}}"#, + "{}", + ); + + assert!(parse_err(&schema).contains("duplicate field `x-stainless-skip`")); +} + +#[test] +fn a_skip_on_an_operation_says_nothing_and_stays_an_extension() { + let forge = parse(&operation_with( + r#""x-forge-group": ["a"], "x-forge-method": "get", "x-stainless-skip": true,"#, + )); + let method = forge.groups().next().unwrap().methods().next().unwrap(); + + assert_eq!( + method.extensions().map(|(name, _)| name).collect::>(), + ["x-stainless-skip"] + ); +} + +#[test] +fn the_other_stainless_keys_are_not_read() { + let with = responding_with( + r#"{"type": "object", "x-stainless-terraform-configurability": "computed", + "properties": {"a": {"type": "string", "x-stainless-deprecation-message": "gone", "x-stainless-collection-type": "set"}}}"#, + "{}", + ); + let without = responding_with(r#"{"type": "object", "properties": {"a": {"type": "string"}}}"#, "{}"); + + assert_same(&with, &without); +} diff --git a/tests/wasm/ts/wit/forge.wit b/tests/wasm/ts/wit/forge.wit index af93aa10e..7a489f74e 100644 --- a/tests/wasm/ts/wit/forge.wit +++ b/tests/wasm/ts/wit/forge.wit @@ -82,7 +82,7 @@ interface forge { json: option, } - /// The stage of the API a method is in, from `x-fern-availability`. + /// The stage of the API a method is in, from `x-forge-availability`. enum availability { alpha, beta, preview, generally-available, deprecated, } From 96c2266928c075a203c06a61be54095099b4c971 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Sun, 25 Oct 2026 22:57:32 -0400 Subject: [PATCH 04/21] test: write the fixtures with the native keys x-fern-* and x-stainless-skip become their x-forge-* equivalents; a dotted group string becomes an array. What only the compat layer does is covered by tests/compat. --- src/plugin/ts/tests.rs | 6 +- tests/cli.rs | 2 +- tests/parse/aliases.rs | 81 +++++++++--------- tests/parse/bodies.rs | 28 +++---- tests/parse/common.rs | 4 +- tests/parse/document.rs | 4 +- tests/parse/extensions.rs | 34 ++++---- tests/parse/groups.rs | 71 ++++++++-------- tests/parse/headers.rs | 52 ++++++------ tests/parse/methods.rs | 68 +++++++-------- tests/parse/models.rs | 40 ++++----- tests/parse/requests.rs | 130 ++++++++++++++--------------- tests/parse/responses.rs | 12 +-- tests/parse/types/arrays.rs | 4 +- tests/parse/types/enums.rs | 2 +- tests/parse/types/intersections.rs | 4 +- tests/parse/types/nulls.rs | 8 +- tests/parse/types/objects.rs | 10 +-- tests/parse/types/refs.rs | 18 ++-- tests/parse/types/scalars.rs | 6 +- tests/parse/types/unions.rs | 10 +-- tests/wasm.rs | 20 ++--- 22 files changed, 308 insertions(+), 306 deletions(-) diff --git a/src/plugin/ts/tests.rs b/src/plugin/ts/tests.rs index f6c095bde..bf7b8c80c 100644 --- a/src/plugin/ts/tests.rs +++ b/src/plugin/ts/tests.rs @@ -370,11 +370,11 @@ fn models() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": ["pet-store", "list_all"], "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["pet-store", "list_all"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/pet_owner"}}}}}}}, - "/b": {"get": {"x-fern-sdk-group-name": "pet-store", "x-fern-sdk-method-name": "get", + "/b": {"get": {"x-forge-group": ["pet-store"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/2fa"}}}}}}}, - "/c": {"get": {"x-fern-sdk-group-name": "other", "x-fern-sdk-method-name": "get", + "/c": {"get": {"x-forge-group": ["other"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/2fa"}}}}}}} }, "components": {"schemas": {"pet_owner": {"type": "string"}, "2fa": {"type": "string"}}} diff --git a/tests/cli.rs b/tests/cli.rs index 6b85c5fc4..f59b30727 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -6,7 +6,7 @@ use std::process::{Command, Output, Stdio}; /// A document with one method, `a.get`. const SPEC: &str = r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok"}}}}} }"#; diff --git a/tests/parse/aliases.rs b/tests/parse/aliases.rs index eb299ef5f..c36579065 100644 --- a/tests/parse/aliases.rs +++ b/tests/parse/aliases.rs @@ -10,7 +10,7 @@ fn aliased(aliases: &str, fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a/{{id}}/status": {{"patch": {{{fields} - "x-fern-sdk-group-name": ["a", "status"], "x-fern-sdk-method-name": "edit", + "x-forge-group": ["a", "status"], "x-forge-method": "edit", "x-forge-aliases": {aliases}, "summary": "Edit status", "description": "Changes the status.", "parameters": [{{"name": "id", "in": "path", "required": true, "schema": {{"type": "string"}}}}], @@ -39,8 +39,8 @@ fn methods(forge: &Forge) -> Vec { } const PAUSE_AND_TERMINATE: &str = r#"[ - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"}, - {"x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "terminate"} + {"x-forge-group": ["a"], "x-forge-method": "pause"}, + {"x-forge-group": ["a"], "x-forge-method": "terminate"} ]"#; #[test] @@ -77,11 +77,11 @@ fn aliases_share_the_rest_of_the_operation() { fn each_alias_has_its_own_availability_hidden_confirmation_and_extensions() { let forge = parse(&aliased( r#"[ - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause", - "x-fern-availability": "generally-available", "x-forge-hidden": true, + {"x-forge-group": ["a"], "x-forge-method": "pause", + "x-forge-availability": "generally-available", "x-forge-hidden": true, "x-forge-params": {"status": {"default": "pause", "hidden": true}}}, - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "terminate", - "x-fern-availability": "beta", "x-forge-require-confirmation": "Sure?", "x-a": 1, "x-b": 2} + {"x-forge-group": ["a"], "x-forge-method": "terminate", + "x-forge-availability": "beta", "x-forge-require-confirmation": "Sure?", "x-a": 1, "x-b": 2} ]"#, "", )); @@ -111,8 +111,8 @@ fn each_alias_has_its_own_availability_hidden_confirmation_and_extensions() { #[test] fn alias_does_not_fall_back_to_the_operation() { let forge = parse(&aliased( - r#"[{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"}]"#, - r#""x-fern-availability": "beta", "x-forge-hidden": true, "x-forge-require-confirmation": "Sure?", + r#"[{"x-forge-group": ["a"], "x-forge-method": "pause"}]"#, + r#""x-forge-availability": "beta", "x-forge-hidden": true, "x-forge-require-confirmation": "Sure?", "x-forge-params": {"status": {}},"#, )); @@ -128,10 +128,10 @@ fn alias_does_not_fall_back_to_the_operation() { fn alias_without_a_group_or_name_is_not_a_method() { let forge = parse(&aliased( r#"[ - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"}, - {"x-fern-sdk-group-name": "a"}, - {"x-fern-sdk-method-name": "resume"}, - {"x-fern-sdk-group-name": "", "x-fern-sdk-method-name": "restart"} + {"x-forge-group": ["a"], "x-forge-method": "pause"}, + {"x-forge-group": ["a"]}, + {"x-forge-method": "resume"}, + {"x-forge-group": [], "x-forge-method": "restart"} ]"#, "", )); @@ -142,7 +142,7 @@ fn alias_without_a_group_or_name_is_not_a_method() { #[test] fn element_that_is_not_an_object_is_ignored() { let forge = parse(&aliased( - r#"["pause", null, 1, true, ["a"], {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"}]"#, + r#"["pause", null, 1, true, ["a"], {"x-forge-group": ["a"], "x-forge-method": "pause"}]"#, "", )); @@ -158,10 +158,7 @@ fn empty_aliases_make_no_method() { #[test] fn aliases_that_are_not_an_array_are_an_error() { - let err = parse_err(&aliased( - r#"{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"}"#, - "", - )); + let err = parse_err(&aliased(r#"{"x-forge-group": ["a"], "x-forge-method": "pause"}"#, "")); assert!(err.contains("an array of aliases"), "{err}"); } @@ -172,11 +169,11 @@ fn alias_and_another_method_with_equal_names_are_an_error() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "pause", "responses": {"204": {"description": "ok"}}}}, "/b": {"post": {"x-forge-aliases": [ - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "resume"}, - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "Pause"} + {"x-forge-group": ["a"], "x-forge-method": "resume"}, + {"x-forge-group": ["a"], "x-forge-method": "Pause"} ], "responses": {"204": {"description": "ok"}}}} } }"#, @@ -192,8 +189,8 @@ fn alias_and_another_method_with_equal_names_are_an_error() { fn two_aliases_with_equal_names_are_an_error() { let err = parse_err(&aliased( r#"[ - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"}, - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause"} + {"x-forge-group": ["a"], "x-forge-method": "pause"}, + {"x-forge-group": ["a"], "x-forge-method": "pause"} ]"#, "", )); @@ -207,12 +204,12 @@ fn two_aliases_with_equal_names_are_an_error() { #[test] fn alias_group_name_without_letters_is_an_error_naming_the_alias() { let err = parse_err(&aliased( - r#"[{"x-fern-sdk-group-name": "a..b", "x-fern-sdk-method-name": "pause"}]"#, + r#"[{"x-forge-group": ["a", "", "b"], "x-forge-method": "pause"}]"#, "", )); assert!( - err.contains("PATCH /a/{id}/status: x-forge-aliases[0]: x-fern-sdk-group-name"), + err.contains("PATCH /a/{id}/status: x-forge-aliases[0]: x-forge-group"), "{err}" ); } @@ -220,12 +217,12 @@ fn alias_group_name_without_letters_is_an_error_naming_the_alias() { #[test] fn alias_availability_is_checked() { let err = parse_err(&aliased( - r#"[1, {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause", "x-fern-availability": "ga"}]"#, + r#"[1, {"x-forge-group": ["a"], "x-forge-method": "pause", "x-forge-availability": "ga"}]"#, "", )); assert!( - err.contains(r#"x-forge-aliases[1]: x-fern-availability "ga" is not"#), + err.contains(r#"x-forge-aliases[1]: x-forge-availability "ga" is not"#), "{err}" ); } @@ -233,16 +230,16 @@ fn alias_availability_is_checked() { #[test] fn repeated_key_forge_reads_in_an_alias_is_an_error() { let err = parse_err(&aliased( - r#"[{"x-fern-sdk-method-name": "pause", "x-fern-sdk-method-name": "resume"}]"#, + r#"[{"x-forge-method": "pause", "x-forge-method": "resume"}]"#, "", )); - assert!(err.contains("duplicate field `x-fern-sdk-method-name`"), "{err}"); + assert!(err.contains("duplicate field `x-forge-method`"), "{err}"); } #[test] fn ignored_operation_still_has_its_aliases() { - let forge = parse(&aliased(PAUSE_AND_TERMINATE, r#""x-fern-ignore": true,"#)); + let forge = parse(&aliased(PAUSE_AND_TERMINATE, r#""x-forge-ignore": true,"#)); assert_eq!(methods(&forge), ["a.pause", "a.terminate"]); } @@ -251,8 +248,8 @@ fn ignored_operation_still_has_its_aliases() { fn ignored_alias_is_not_a_method() { let forge = parse(&aliased( r#"[ - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause", "x-fern-ignore": true}, - {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "terminate", "x-fern-ignore": false} + {"x-forge-group": ["a"], "x-forge-method": "pause", "x-forge-ignore": true}, + {"x-forge-group": ["a"], "x-forge-method": "terminate", "x-forge-ignore": false} ]"#, "", )); @@ -263,8 +260,8 @@ fn ignored_alias_is_not_a_method() { #[test] fn aliases_are_not_extensions() { let forge = parse(&aliased( - r#"[{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause", "x-a": 1, - "x-forge-aliases": [{"x-fern-sdk-group-name": "b", "x-fern-sdk-method-name": "nested"}]}]"#, + r#"[{"x-forge-group": ["a"], "x-forge-method": "pause", "x-a": 1, + "x-forge-aliases": [{"x-forge-group": ["b"], "x-forge-method": "nested"}]}]"#, "", )); @@ -277,7 +274,7 @@ fn aliases_are_not_extensions() { #[test] fn keys_of_an_alias_that_are_not_extensions_are_ignored() { let forge = parse(&aliased( - r#"[{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "pause", + r#"[{"x-forge-group": ["a"], "x-forge-method": "pause", "summary": "Pause", "deprecated": false, "path": "/b"}]"#, "", )); @@ -293,7 +290,7 @@ fn operation_without_aliases_keeps_its_own_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -307,10 +304,10 @@ fn model_used_by_aliases_in_two_top_level_groups_is_at_the_top_level() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/m": {"get": { - "x-fern-sdk-group-name": "a.b", "x-fern-sdk-method-name": "get", + "x-forge-group": ["a", "b"], "x-forge-method": "get", "x-forge-aliases": [ - {"x-fern-sdk-group-name": "a.b", "x-fern-sdk-method-name": "get"}, - {"x-fern-sdk-group-name": "x", "x-fern-sdk-method-name": "get"} + {"x-forge-group": ["a", "b"], "x-forge-method": "get"}, + {"x-forge-group": ["x"], "x-forge-method": "get"} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}}, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -328,10 +325,10 @@ fn model_used_by_aliases_in_one_group_is_in_that_group() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/m": {"get": { - "x-fern-sdk-group-name": "x", "x-fern-sdk-method-name": "get", + "x-forge-group": ["x"], "x-forge-method": "get", "x-forge-aliases": [ - {"x-fern-sdk-group-name": "a.b", "x-fern-sdk-method-name": "get"}, - {"x-fern-sdk-group-name": "a.c", "x-fern-sdk-method-name": "get"} + {"x-forge-group": ["a", "b"], "x-forge-method": "get"}, + {"x-forge-group": ["a", "c"], "x-forge-method": "get"} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}}, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} diff --git a/tests/parse/bodies.rs b/tests/parse/bodies.rs index 4b09e2967..cb96a46e5 100644 --- a/tests/parse/bodies.rs +++ b/tests/parse/bodies.rs @@ -21,7 +21,7 @@ fn body_has_its_required_and_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"required": true, "description": "The pet.", "content": {"application/json": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -38,7 +38,7 @@ fn body_is_optional_by_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/json": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -52,7 +52,7 @@ fn contents_are_sorted_by_media_type() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": { "text/plain": {"schema": {"type": "string"}}, "multipart/form-data": {"schema": {"type": "object"}}, @@ -73,7 +73,7 @@ fn json_is_application_json_before_other_json_types() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": { "application/geo+json": {"schema": {"type": "object"}}, "application/json": {"schema": {"type": "string"}} @@ -90,7 +90,7 @@ fn json_is_otherwise_the_first_json_type() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"patch": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"patch": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": { "multipart/form-data": {"schema": {"type": "object"}}, "application/scim+json": {"schema": {"type": "object"}}, @@ -111,7 +111,7 @@ fn json_ignores_case_and_parameters() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"Application/JSON; charset=utf-8": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -127,7 +127,7 @@ fn multipart_content_is_typed() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "required": ["file"], "properties": { "file": {"type": "string", "format": "binary"}, @@ -151,7 +151,7 @@ fn octet_stream_content_of_a_binary_string_is_binary() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/octet-stream": {"schema": { "type": "string", "format": "binary" }}}}, @@ -169,7 +169,7 @@ fn json_ignores_content_that_is_not_json() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": { "multipart/form-data": {"schema": {"type": "object", "properties": {"name": {"type": "string"}}}}, "text/plain": {"schema": {"type": "string"}} @@ -189,7 +189,7 @@ fn content_that_is_not_json_without_a_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/octet-stream": {}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -204,7 +204,7 @@ fn content_without_a_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/json": {}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -219,7 +219,7 @@ fn body_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"$ref": "#/components/requestBodies/Pet"}, "responses": {"204": {"description": "ok"}}}}}, "components": {"requestBodies": { @@ -239,7 +239,7 @@ fn with_body_schema(version: &str, schema: &str, schemas: &str) -> String { format!( r#"{{ "openapi": "{version}", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"post": {{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {{"/a": {{"post": {{"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {{"content": {{"application/json": {{"schema": {schema}}}}}}}, "responses": {{"204": {{"description": "ok"}}}}}}}}}}, "components": {{"schemas": {schemas}}} @@ -301,7 +301,7 @@ fn response_content_has_its_schema_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": { "schema": {"type": "string", "description": "The name."}}}}}}}} }"#, diff --git a/tests/parse/common.rs b/tests/parse/common.rs index ed8854cd2..39d178462 100644 --- a/tests/parse/common.rs +++ b/tests/parse/common.rs @@ -19,7 +19,7 @@ pub fn responding_with(schema: &str) -> String { format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}} }}"# ) @@ -31,7 +31,7 @@ pub fn responding_with_schemas(schema: &str, schemas: &str) -> String { format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}}, "components": {{"schemas": {schemas}}} }}"# diff --git a/tests/parse/document.rs b/tests/parse/document.rs index 282c6744b..6bfec98fa 100644 --- a/tests/parse/document.rs +++ b/tests/parse/document.rs @@ -103,7 +103,7 @@ fn every_version_of_3_0_3_1_and_3_2_is_read() { let forge = parse(&format!( r#"{{ "openapi": "{version}", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# )); @@ -118,7 +118,7 @@ fn errors_are_reported_together() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "servers": [{"url": "https://{region}.example.com"}], - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a..b", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a", "", "b"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); diff --git a/tests/parse/extensions.rs b/tests/parse/extensions.rs index f626036f4..9726355af 100644 --- a/tests/parse/extensions.rs +++ b/tests/parse/extensions.rs @@ -9,7 +9,7 @@ fn operation_with(fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a": {{"get": {{{fields} - "x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "x-forge-group": ["a"], "x-forge-method": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# ) @@ -71,7 +71,7 @@ fn method_without_extensions_has_none() { let get = method(&forge, "a.get"); assert_eq!(get.extensions().len(), 0); - assert_eq!(get.extension("x-fern-sdk-method-name"), None); + assert_eq!(get.extension("x-forge-method"), None); } #[test] @@ -85,24 +85,24 @@ fn keys_that_are_not_extensions_are_not_kept() { #[test] fn extensions_forge_reads_are_not_kept() { - let forge = parse(&operation_with(r#""x-fern-ignore": false, "x-a": 1,"#)); + let forge = parse(&operation_with(r#""x-forge-ignore": false, "x-a": 1,"#)); let get = method(&forge, "a.get"); assert_eq!(names(&forge, "a.get"), ["x-a"]); - assert_eq!(get.extension("x-fern-sdk-group-name"), None); - assert_eq!(get.extension("x-fern-ignore"), None); + assert_eq!(get.extension("x-forge-group"), None); + assert_eq!(get.extension("x-forge-ignore"), None); } #[test] fn availability_hidden_and_confirmation_are_not_kept() { let forge = parse(&operation_with( - r#""x-a": 1, "x-fern-availability": "beta", "x-forge-hidden": true, + r#""x-a": 1, "x-forge-availability": "beta", "x-forge-hidden": true, "x-forge-require-confirmation": "Sure?", "x-b": 2,"#, )); let get = method(&forge, "a.get"); assert_eq!(names(&forge, "a.get"), ["x-a", "x-b"]); - assert_eq!(get.extension("x-fern-availability"), None); + assert_eq!(get.extension("x-forge-availability"), None); assert_eq!(get.extension("x-forge-hidden"), None); assert_eq!(get.extension("x-forge-require-confirmation"), None); } @@ -113,9 +113,9 @@ fn extensions_forge_reads_are_still_read() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-fern-sdk-group-name": ["a", "b"], "x-fern-sdk-method-name": "list", "x-a": 1, + "get": {"x-forge-group": ["a", "b"], "x-forge-method": "list", "x-a": 1, "responses": {"204": {"description": "ok"}}}, - "post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", "x-fern-ignore": true, + "post": {"x-forge-group": ["a"], "x-forge-method": "create", "x-forge-ignore": true, "x-a": 1, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -136,9 +136,9 @@ fn repeated_extension_has_the_last_value_in_the_place_of_the_first() { #[test] fn repeated_extension_forge_reads_is_still_an_error() { - let err = parse_err(&operation_with(r#""x-fern-ignore": false, "x-fern-ignore": false,"#)); + let err = parse_err(&operation_with(r#""x-forge-ignore": false, "x-forge-ignore": false,"#)); - assert!(err.contains("duplicate field `x-fern-ignore`"), "{err}"); + assert!(err.contains("duplicate field `x-forge-ignore`"), "{err}"); } #[test] @@ -147,11 +147,11 @@ fn each_method_keeps_its_own_extensions() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", "x-a": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "x-a": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "/b": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}, - "/c": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", "x-a": "create", + "/c": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "x-a": "create", "x-b": [], "responses": {"204": {"description": "ok"}}}} } }"#, @@ -170,7 +170,7 @@ fn extensions_outside_the_operation_are_not_kept() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "x-root": 1, - "paths": {"/a": {"x-path-item": 1, "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"x-path-item": 1, "get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "q", "in": "query", "x-parameter": 1, "schema": {"type": "string", "x-schema": 1}}], "responses": {"204": {"description": "ok", "x-response": 1}}}}} }"#, @@ -186,11 +186,11 @@ fn operation_of_a_referenced_path_item_keeps_its_extensions() { "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, "paths": { "/a": {"$ref": "#/components/pathItems/A"}, - "/b": {"get": {"x-fern-sdk-group-name": "b", "x-fern-sdk-method-name": "get", "x-b": 2, + "/b": {"get": {"x-forge-group": ["b"], "x-forge-method": "get", "x-b": 2, "responses": {"204": {"description": "ok"}}}} }, "components": {"pathItems": { - "A": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", "x-a": 1, + "A": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "x-a": 1, "responses": {"204": {"description": "ok"}}}} }} }"##, diff --git a/tests/parse/groups.rs b/tests/parse/groups.rs index 18618c70e..b5d6f918a 100644 --- a/tests/parse/groups.rs +++ b/tests/parse/groups.rs @@ -7,7 +7,7 @@ fn string_group_name_splits_on_dots() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "accounts.members", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -21,7 +21,7 @@ fn array_group_name_has_a_group_per_element() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": ["accounts", "members"], "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -35,7 +35,7 @@ fn array_element_with_a_dot_is_one_group() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": ["zones.settings"], "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["zones.settings"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -54,9 +54,9 @@ fn groups_with_equal_names_are_one_group() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "abuse-reports", "x-fern-sdk-method-name": "list", + "/a": {"get": {"x-forge-group": ["abuse-reports"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-fern-sdk-group-name": ["abuse_reports"], "x-fern-sdk-method-name": "get", + "/b": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -72,9 +72,9 @@ fn subgroup_and_method_can_share_a_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"delete": {"x-fern-sdk-group-name": "members", "x-fern-sdk-method-name": "delete", + "/a": {"delete": {"x-forge-group": ["members"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}}}, - "/b": {"post": {"x-fern-sdk-group-name": "members.delete", "x-fern-sdk-method-name": "bulk", + "/b": {"post": {"x-forge-group": ["members", "delete"], "x-forge-method": "bulk", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -89,7 +89,7 @@ fn operation_without_a_group_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -102,7 +102,7 @@ fn empty_group_name_is_no_group() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": [], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -115,7 +115,7 @@ fn operation_without_a_method_name_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -128,7 +128,7 @@ fn empty_method_name_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -142,9 +142,9 @@ fn ignored_operation_is_not_a_method() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "get": {"x-forge-group": ["a"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}, - "post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", "x-fern-ignore": true, + "post": {"x-forge-group": ["a"], "x-forge-method": "create", "x-forge-ignore": true, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -159,7 +159,7 @@ fn group_name_without_letters_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "accounts..members", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "", "members"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -173,9 +173,9 @@ fn duplicate_method_in_a_group_is_an_error() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "/b": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -190,9 +190,9 @@ fn method_names_are_equal_as_names() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list_all", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list_all", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "listAll", + "/b": {"get": {"x-forge-group": ["a"], "x-forge-method": "listAll", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -207,11 +207,11 @@ fn groups_are_depth_first() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-fern-sdk-group-name": "x", "x-fern-sdk-method-name": "get", + "/b": {"get": {"x-forge-group": ["x"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}, - "/c": {"get": {"x-fern-sdk-group-name": "a.d", "x-fern-sdk-method-name": "get", + "/c": {"get": {"x-forge-group": ["a", "d"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -241,7 +241,7 @@ fn group_description_comes_from_x_forge_commands() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "accounts", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"accounts": {"description": "Accounts."}} }"#, @@ -255,7 +255,7 @@ fn subgroup_description_is_in_its_parents_command() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "accounts.members", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"accounts": {"groups": {"members": {"description": "Members."}}}} }"#, @@ -271,8 +271,13 @@ fn with_commands(groups: &[&str], commands: &str) -> String { .iter() .enumerate() .map(|(i, group)| { + let group = group + .split('.') + .map(|name| format!("{name:?}")) + .collect::>() + .join(", "); format!( - r#""/{i}": {{"get": {{"x-fern-sdk-group-name": "{group}", "x-fern-sdk-method-name": "list", + r#""/{i}": {{"get": {{"x-forge-group": [{group}], "x-forge-method": "list", "responses": {{"204": {{"description": "ok"}}}}}}}}"# ) }) @@ -341,7 +346,7 @@ fn command_matches_a_group_with_an_equal_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "abuse_reports", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"abuse-reports": {"description": "Abuse reports."}} }"#, @@ -355,7 +360,7 @@ fn group_without_a_command_has_no_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "accounts", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"zones": {"description": "Zones."}} }"#, @@ -384,13 +389,13 @@ fn groups_are_sorted_by_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "zones", "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["zones"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-fern-sdk-group-name": "accounts.members", "x-fern-sdk-method-name": "get", + "/b": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}, - "/c": {"get": {"x-fern-sdk-group-name": "dns", "x-fern-sdk-method-name": "get", + "/c": {"get": {"x-forge-group": ["dns"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}, - "/d": {"get": {"x-fern-sdk-group-name": "accounts.billing", "x-fern-sdk-method-name": "get", + "/d": {"get": {"x-forge-group": ["accounts", "billing"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -412,11 +417,11 @@ fn methods_are_sorted_by_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "get": {"x-forge-group": ["a"], "x-forge-method": "list", "responses": {"204": {"description": "ok"}}}, - "post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "post": {"x-forge-group": ["a"], "x-forge-method": "create", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "delete", + "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, diff --git a/tests/parse/headers.rs b/tests/parse/headers.rs index 49f34a22a..1ab012b02 100644 --- a/tests/parse/headers.rs +++ b/tests/parse/headers.rs @@ -17,7 +17,7 @@ fn header_param_is_a_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Request-ID", "in": "header", "required": true, "description": "Traces the request.", "schema": {"type": "integer", "format": "int64"}}, @@ -43,8 +43,8 @@ fn header_field_is_named_by_x_fern_parameter_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", - "parameters": [{"name": "cf-r2-jurisdiction", "in": "header", "x-fern-parameter-name": "jurisdiction", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "parameters": [{"name": "cf-r2-jurisdiction", "in": "header", "x-forge-parameter-name": "jurisdiction", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -59,7 +59,7 @@ fn header_description_is_the_params_or_else_its_schemas() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Own", "in": "header", "description": "Param.", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "X-Inherited", "in": "header", "schema": {"$ref": "#/components/schemas/Id"}}, @@ -81,7 +81,7 @@ fn deprecated_header_is_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "X-Old", "in": "header", "deprecated": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -95,7 +95,7 @@ fn header_is_sensitive_when_its_schema_is_and_never_read_only() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Api-Key", "in": "header", "schema": {"type": "string", "x-sensitive": true, "readOnly": true}}, {"name": "X-Auth-Token", "in": "header", "schema": {"$ref": "#/components/schemas/Token"}}, @@ -119,7 +119,7 @@ fn header_has_the_default_of_its_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Version", "in": "header", "schema": {"type": "string", "default": "2024-01-01"}}, {"name": "X-Retries", "in": "header", "schema": {"$ref": "#/components/schemas/Retries"}}, @@ -144,7 +144,7 @@ fn header_param_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "parameters": [{"$ref": "#/components/parameters/IdempotencyKey"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"IdempotencyKey": {"name": "Idempotency-Key", "in": "header", @@ -163,8 +163,8 @@ fn path_item_headers_belong_to_each_operation() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Account", "in": "header", "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -181,7 +181,7 @@ fn operation_header_replaces_the_path_item_header() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Limit", "in": "header", "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "X-Limit", "in": "header", "required": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -202,7 +202,7 @@ fn operation_header_replaces_the_path_item_header_ignoring_case() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Request-ID", "in": "header", "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "x-request-id", "in": "header", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -221,7 +221,7 @@ fn query_param_does_not_replace_a_header_with_its_name() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "version", "in": "header", "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "version", "in": "query", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}} }} @@ -243,7 +243,7 @@ fn headers_are_in_declared_order_the_path_items_first() { {"name": "X-First", "in": "header", "schema": {"type": "string"}}, {"name": "X-Second", "in": "header", "schema": {"type": "string"}} ], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Third", "in": "header", "schema": {"type": "string"}}, {"name": "x-first", "in": "header", "schema": {"type": "string"}} @@ -264,7 +264,7 @@ fn headers_with_equal_names_are_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Rate-Limit", "in": "header", "schema": {"type": "string"}}, {"name": "X_Rate_Limit", "in": "header", "schema": {"type": "string"}} @@ -289,7 +289,7 @@ fn path_item_headers_differing_in_case_are_an_error() { {"name": "X-A", "in": "header", "schema": {"type": "string"}}, {"name": "x-a", "in": "header", "schema": {"type": "string"}} ], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}} }} }"#, @@ -303,7 +303,7 @@ fn header_and_param_with_equal_names_are_not_an_error() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{account_id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{account_id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "account_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "Account-Id", "in": "header", "schema": {"type": "string"}} @@ -320,7 +320,7 @@ fn cookie_params_are_not_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "session", "in": "cookie", "schema": {"type": "string"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} @@ -337,7 +337,7 @@ fn method_with_only_cookie_params_has_no_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "session", "in": "cookie", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -351,7 +351,7 @@ fn accept_content_type_and_authorization_headers_are_kept() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "upload", + "paths": {"/a": {"put": {"x-forge-group": ["a"], "x-forge-method": "upload", "parameters": [ {"name": "Content-Type", "in": "header", "required": true, "schema": {"type": "string"}}, {"name": "Content-Length", "in": "header", "schema": {"type": "integer"}}, @@ -376,7 +376,7 @@ fn method_without_header_params_has_no_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -391,7 +391,7 @@ fn headers_are_not_in_the_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "parameters": [ {"name": "page", "in": "query", "schema": {"type": "integer"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} @@ -411,7 +411,7 @@ fn method_with_only_headers_has_no_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "X-Trace", "in": "header", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -427,7 +427,7 @@ fn model_used_only_by_a_header_is_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a.b", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a", "b"], "x-forge-method": "get", "parameters": [{"name": "cf-r2-storage-class", "in": "header", "schema": {"$ref": "#/components/schemas/StorageClass"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": {"StorageClass": {"type": "string", "enum": ["Standard", "InfrequentAccess"]}}} @@ -446,7 +446,7 @@ fn header_with_content_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "X-Filter", "in": "header", "content": {"application/json": {"schema": { "type": "object", "properties": {"status": {"type": "string"}} }}}}], @@ -465,7 +465,7 @@ fn header_style_other_than_simple_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "X-Ids", "in": "header", "style": "form", "schema": {"type": "array", "items": {"type": "string"}}}], "responses": {"204": {"description": "ok"}}}}} diff --git a/tests/parse/methods.rs b/tests/parse/methods.rs index 5daea4ea9..664905303 100644 --- a/tests/parse/methods.rs +++ b/tests/parse/methods.rs @@ -9,7 +9,7 @@ fn operation_with(fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a": {{"get": {{{fields} - "x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "x-forge-group": ["a"], "x-forge-method": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# ) @@ -21,14 +21,14 @@ fn each_operation_field_is_its_http_method() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "put", "responses": {"204": {"description": "ok"}}}, - "post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "post", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "delete", "responses": {"204": {"description": "ok"}}}, - "options": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "options", "responses": {"204": {"description": "ok"}}}, - "head": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "head", "responses": {"204": {"description": "ok"}}}, - "patch": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "patch", "responses": {"204": {"description": "ok"}}}, - "trace": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "trace", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, + "put": {"x-forge-group": ["a"], "x-forge-method": "put", "responses": {"204": {"description": "ok"}}}, + "post": {"x-forge-group": ["a"], "x-forge-method": "post", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}}, + "options": {"x-forge-group": ["a"], "x-forge-method": "options", "responses": {"204": {"description": "ok"}}}, + "head": {"x-forge-group": ["a"], "x-forge-method": "head", "responses": {"204": {"description": "ok"}}}, + "patch": {"x-forge-group": ["a"], "x-forge-method": "patch", "responses": {"204": {"description": "ok"}}}, + "trace": {"x-forge-group": ["a"], "x-forge-method": "trace", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -54,7 +54,7 @@ fn query_operation_is_query() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"query": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "search", + "paths": {"/a": {"query": {"x-forge-group": ["a"], "x-forge-method": "search", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -68,7 +68,7 @@ fn additional_operation_is_its_method_as_written() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "COPY": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "copy", + "COPY": {"x-forge-group": ["a"], "x-forge-method": "copy", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -86,7 +86,7 @@ fn additional_operation_with_the_method_of_a_field_is_that_variant() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "GET": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "GET": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -101,7 +101,7 @@ fn additional_operation_methods_are_case_sensitive() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -118,7 +118,7 @@ fn method_has_the_summary_description_and_deprecation_of_its_operation() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "summary": "Get an a.", "description": "Gets an a.", "deprecated": true, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -135,7 +135,7 @@ fn method_without_docs_is_empty_and_not_deprecated() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -153,7 +153,7 @@ fn path_item_ref_is_followed() { "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"$ref": "#/components/pathItems/A"}}, "components": {"pathItems": { - "A": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "A": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}} }} }"##, @@ -168,11 +168,11 @@ fn extensions_in_paths_and_path_items_are_not_operations() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "x-paths-extension": {"get": {"x-fern-sdk-group-name": "x", "x-fern-sdk-method-name": "get", + "x-paths-extension": {"get": {"x-forge-group": ["x"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}, "/a": { "x-forge-commands": {"a": {"description": "A."}}, - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}} } } @@ -189,9 +189,9 @@ fn additional_operation_with_the_method_of_a_present_field_is_skipped() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, - "additionalOperations": {"GET": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "shadowed", + "additionalOperations": {"GET": {"x-forge-group": ["a"], "x-forge-method": "shadowed", "responses": {"204": {"description": "ok"}}}} }} }"#, @@ -206,7 +206,7 @@ fn webhooks_are_not_methods() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "webhooks": {"newPet": {"post": {"x-fern-sdk-group-name": "pets", "x-fern-sdk-method-name": "created", + "webhooks": {"newPet": {"post": {"x-forge-group": ["pets"], "x-forge-method": "created", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -219,9 +219,9 @@ fn callbacks_are_not_methods() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/subscribe": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "subscribe", + "paths": {"/subscribe": {"post": {"x-forge-group": ["a"], "x-forge-method": "subscribe", "callbacks": {"event": {"{$request.query.url}": {"post": { - "x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "event", + "x-forge-group": ["a"], "x-forge-method": "event", "responses": {"204": {"description": "ok"}} }}}}, "responses": {"204": {"description": "ok"}}}}} @@ -297,7 +297,7 @@ fn each_availability_is_its_variant() { ("generally-available", Availability::GenerallyAvailable), ("deprecated", Availability::Deprecated), ] { - let forge = parse(&operation_with(&format!(r#""x-fern-availability": "{written}","#))); + let forge = parse(&operation_with(&format!(r#""x-forge-availability": "{written}","#))); assert_eq!(method(&forge, "a.get").availability(), Some(want), "{written}"); assert_eq!(want.as_str(), written); @@ -306,21 +306,21 @@ fn each_availability_is_its_variant() { #[test] fn unknown_availability_is_an_error_naming_the_operation() { - let err = parse_err(&operation_with(r#""x-fern-availability": "stable","#)); + let err = parse_err(&operation_with(r#""x-forge-availability": "stable","#)); - assert!(err.contains(r#"GET /a: x-fern-availability "stable" is not"#), "{err}"); + assert!(err.contains(r#"GET /a: x-forge-availability "stable" is not"#), "{err}"); } #[test] fn availability_is_case_sensitive() { - let err = parse_err(&operation_with(r#""x-fern-availability": "Beta","#)); + let err = parse_err(&operation_with(r#""x-forge-availability": "Beta","#)); - assert!(err.contains(r#"GET /a: x-fern-availability "Beta" is not"#), "{err}"); + assert!(err.contains(r#"GET /a: x-forge-availability "Beta" is not"#), "{err}"); } #[test] fn availability_that_is_not_a_string_is_an_error() { - let err = parse_err(&operation_with(r#""x-fern-availability": 1,"#)); + let err = parse_err(&operation_with(r#""x-forge-availability": 1,"#)); assert!(err.contains("expected a string"), "{err}"); } @@ -331,13 +331,13 @@ fn availability_and_deprecation_are_apart() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", - "deprecated": true, "x-fern-availability": "generally-available", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "deprecated": true, "x-forge-availability": "generally-available", "responses": {"204": {"description": "ok"}}}, - "put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "put", - "x-fern-availability": "deprecated", + "put": {"x-forge-group": ["a"], "x-forge-method": "put", + "x-forge-availability": "deprecated", "responses": {"204": {"description": "ok"}}}, - "post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "post", + "post": {"x-forge-group": ["a"], "x-forge-method": "post", "deprecated": true, "responses": {"204": {"description": "ok"}}} }} }"#, diff --git a/tests/parse/models.rs b/tests/parse/models.rs index d6373aafe..40f7ca110 100644 --- a/tests/parse/models.rs +++ b/tests/parse/models.rs @@ -13,8 +13,8 @@ fn response_model_is_placed_in_its_group() { "paths": { "/zones": { "get": { - "x-fern-sdk-group-name": "zones", - "x-fern-sdk-method-name": "list", + "x-forge-group": ["zones"], + "x-forge-method": "list", "responses": { "200": { "description": "OK", @@ -43,9 +43,9 @@ fn model_used_in_sibling_groups_is_in_their_parent() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/c": {"get": {"x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get", + "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/d": {"get": {"x-fern-sdk-group-name": "a.b.d", "x-fern-sdk-method-name": "get", + "/d": {"get": {"x-forge-group": ["a", "b", "d"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -61,9 +61,9 @@ fn model_used_in_a_group_and_its_subgroup_is_in_the_group() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/c": {"get": {"x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get", + "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -79,9 +79,9 @@ fn model_used_in_top_level_groups_is_at_the_top_level() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/x": {"get": {"x-fern-sdk-group-name": "x", "x-fern-sdk-method-name": "get", + "/x": {"get": {"x-forge-group": ["x"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -99,9 +99,9 @@ fn model_used_through_another_model_is_placed_by_every_use() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/b": {"get": {"x-fern-sdk-group-name": "a.b", "x-fern-sdk-method-name": "get", + "/b": {"get": {"x-forge-group": ["a", "b"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Outer"}}}}}}}, - "/c": {"get": {"x-fern-sdk-group-name": "a.c", "x-fern-sdk-method-name": "get", + "/c": {"get": {"x-forge-group": ["a", "c"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Inner"}}}}}}} }, "components": {"schemas": { @@ -120,7 +120,7 @@ fn params_bodies_and_errors_use_models() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "parameters": [{"name": "filter", "in": "query", "schema": {"$ref": "#/components/schemas/Filter"}}], "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Input"}}}}, "responses": {"400": {"description": "no", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Failure"}}}}}}}}, @@ -144,11 +144,11 @@ fn schema_no_method_uses_is_not_a_model() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Used"}}}}}}}, - "/ignored": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "ignored", "x-fern-ignore": true, + "/ignored": {"get": {"x-forge-group": ["a"], "x-forge-method": "ignored", "x-forge-ignore": true, "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ignored"}}}}}}}, - "/ungrouped": {"get": {"x-fern-sdk-method-name": "ungrouped", + "/ungrouped": {"get": {"x-forge-method": "ungrouped", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ungrouped"}}}}}}} }, "components": {"schemas": { @@ -189,7 +189,7 @@ fn model_is_named_after_its_schema() { fn model_is_named_by_x_fern_type_name() { let forge = parse(&responding_with_schemas( r##"{"$ref": "#/components/schemas/not_found"}"##, - r#"{"not_found": {"type": "object", "x-fern-type-name": "Missing"}}"#, + r#"{"not_found": {"type": "object", "x-forge-model-name": "Missing"}}"#, )); assert_eq!(model(&forge, "not_found").name(), &Name::new("Missing")); @@ -224,7 +224,7 @@ fn schema_in_defs_is_a_model() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Tree/$defs/Node"}}}}}}}}, "components": {"schemas": { "Tree": {"type": "object", "$defs": {"Node": {"type": "string"}}} @@ -256,7 +256,7 @@ fn schema_used_only_by_content_that_is_not_json_is_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a.files", "x-fern-sdk-method-name": "upload", + "paths": {"/a": {"post": {"x-forge-group": ["a", "files"], "x-forge-method": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": {"$ref": "#/components/schemas/Upload"}}}}, "responses": {"200": {"description": "ok", "content": {"text/csv": {"schema": {"$ref": "#/components/schemas/Report"}}}}}}}}, "components": {"schemas": { @@ -287,9 +287,9 @@ fn use_by_content_that_is_not_json_places_a_model() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/b": {"post": {"x-fern-sdk-group-name": "b", "x-fern-sdk-method-name": "upload", + "/b": {"post": {"x-forge-group": ["b"], "x-forge-method": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"meta": {"$ref": "#/components/schemas/M"}} }}}}, @@ -307,7 +307,7 @@ fn schema_used_only_in_a_response_header_is_not_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "X-Trace", "in": "header", "schema": {"$ref": "#/components/schemas/Trace"}}], "responses": {"204": {"description": "ok", "headers": {"X-Rate-Limit": {"schema": {"$ref": "#/components/schemas/RateLimit"}}}}}}}}, diff --git a/tests/parse/requests.rs b/tests/parse/requests.rs index 31ad98776..9fe63590c 100644 --- a/tests/parse/requests.rs +++ b/tests/parse/requests.rs @@ -13,8 +13,8 @@ fn path_param_is_a_required_request_field() { "paths": { "/zones/{zone_id}": { "get": { - "x-fern-sdk-group-name": "zones", - "x-fern-sdk-method-name": "get", + "x-forge-group": ["zones"], + "x-forge-method": "get", "parameters": [ { "name": "zone_id", "in": "path", "required": true, "schema": { "type": "string" } } ], @@ -44,7 +44,7 @@ fn query_param_is_optional_and_exploded_by_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -61,7 +61,7 @@ fn query_param_can_be_required() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "page", "in": "query", "required": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -76,7 +76,7 @@ fn query_param_with_explode_false_is_not_exploded() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "ids", "in": "query", "style": "form", "explode": false, "schema": {"type": "array", "items": {"type": "string"}}}], "responses": {"204": {"description": "ok"}}}}} @@ -93,7 +93,7 @@ fn header_and_cookie_params_are_not_fields() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "X-Trace", "in": "header", "schema": {"type": "string"}}, {"name": "session", "in": "cookie", "schema": {"type": "string"}} @@ -111,8 +111,8 @@ fn param_field_is_named_by_x_fern_parameter_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", - "parameters": [{"name": "q", "in": "query", "x-fern-parameter-name": "query", "schema": {"type": "string"}}], + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "parameters": [{"name": "q", "in": "query", "x-forge-parameter-name": "query", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -126,7 +126,7 @@ fn param_description_falls_back_to_an_inline_schema() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "own", "in": "query", "description": "Param.", "schema": {"type": "string", "description": "Schema."}}, {"name": "inherited", "in": "query", "schema": {"type": "string", "description": "Schema."}} @@ -145,7 +145,7 @@ fn param_description_comes_from_a_ref_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "own", "in": "query", "description": "Param.", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id"}} @@ -165,7 +165,7 @@ fn param_description_follows_a_chain_of_refs() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"$ref": "#/components/schemas/Id"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": { @@ -184,7 +184,7 @@ fn param_description_is_never_a_schema_title() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "inline", "in": "query", "schema": {"type": "string", "title": "Inline"}} @@ -204,7 +204,7 @@ fn description_next_to_a_param_schema_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id", "description": "The ID to find."}}], "responses": {"204": {"description": "ok"}}}}}, @@ -221,7 +221,7 @@ fn param_description_comes_from_an_all_of_member_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "region", "in": "query", "schema": {"allOf": [{"$ref": "#/components/schemas/Region"}, {"default": "us"}]}}], "responses": {"204": {"description": "ok"}}}}}, @@ -238,7 +238,7 @@ fn param_description_from_an_all_of_member_is_ignored_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "region", "in": "query", "schema": {"allOf": [{"$ref": "#/components/schemas/Region"}, {"default": "us"}]}}], "responses": {"204": {"description": "ok"}}}}}, @@ -255,7 +255,7 @@ fn param_ref_description_overrides_the_params_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"$ref": "#/components/parameters/Page", "description": "The page of pets."}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -272,7 +272,7 @@ fn param_ref_description_is_ignored_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"$ref": "#/components/parameters/Page", "description": "The page of pets."}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -289,7 +289,7 @@ fn param_ref_without_a_description_has_the_params() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"$ref": "#/components/parameters/Page"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -306,7 +306,7 @@ fn param_field_is_never_read_only() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "id", "in": "path", "required": true, "schema": {"type": "string", "readOnly": true}}, {"name": "since", "in": "query", "schema": {"$ref": "#/components/schemas/Since", "readOnly": true}}, @@ -331,7 +331,7 @@ fn query_string_property_is_never_read_only() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": { "type": "object", "properties": {"status": {"type": "string", "readOnly": true, "x-sensitive": true}} }}}}], @@ -349,7 +349,7 @@ fn param_field_is_sensitive_when_its_schema_is() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "token", "in": "query", "schema": {"type": "string", "x-sensitive": true}}, {"name": "page", "in": "query", "schema": {"type": "integer"}} @@ -368,7 +368,7 @@ fn param_field_is_sensitive_when_its_ref_schema_is() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "token", "in": "query", "schema": {"$ref": "#/components/schemas/Token"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": { @@ -386,7 +386,7 @@ fn sensitive_next_to_a_param_schema_ref_counts_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "token", "in": "query", "schema": {"$ref": "#/components/schemas/Token", "x-sensitive": true}}], "responses": {"204": {"description": "ok"}}}}}, @@ -402,7 +402,7 @@ fn sensitive_on_the_param_itself_is_ignored() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "token", "in": "query", "x-sensitive": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -416,7 +416,7 @@ fn param_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"$ref": "#/components/parameters/Page"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "schema": {"type": "integer"}}}} @@ -435,8 +435,8 @@ fn path_item_params_belong_to_each_operation() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -455,7 +455,7 @@ fn operation_param_replaces_the_path_item_param() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "page", "in": "query", "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -472,7 +472,7 @@ fn undeclared_path_placeholder_is_a_required_string() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -491,7 +491,7 @@ fn params_are_in_path_template_then_declared_order() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{second}/{first}": { "parameters": [{"name": "item_query", "in": "query", "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "op_query", "in": "query", "schema": {"type": "string"}}, {"name": "first", "in": "path", "required": true, "schema": {"type": "string"}}, @@ -511,7 +511,7 @@ fn query_string_object_is_query_fields() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": { "type": "object", "properties": {"status": {"type": "string"}, "limit": {"type": "integer"}} }}}}], @@ -532,7 +532,7 @@ fn no_params_and_no_body_is_no_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -545,7 +545,7 @@ fn body_without_params_is_the_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -559,7 +559,7 @@ fn object_body_is_intersected_with_the_params() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "properties": {"name": {"type": "string"}} @@ -582,7 +582,7 @@ fn model_body_is_intersected_with_the_params() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, "responses": {"204": {"description": "ok"}}}}}, @@ -604,7 +604,7 @@ fn union_body_is_intersected_with_the_params() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "oneOf": [{"$ref": "#/components/schemas/Cat"}, {"$ref": "#/components/schemas/Dog"}] @@ -631,7 +631,7 @@ fn array_body_is_the_last_field_of_the_params() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -651,7 +651,7 @@ fn body_field_is_neither_read_only_nor_sensitive() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "readOnly": true, "x-sensitive": true @@ -670,7 +670,7 @@ fn read_only_field_of_a_body_model_is_kept() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}}}}}, "components": {"schemas": {"Pet": {"type": "object", "properties": { @@ -690,7 +690,7 @@ fn map_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "additionalProperties": {"type": "string"} @@ -708,7 +708,7 @@ fn unknown_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -724,7 +724,7 @@ fn nullable_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "nullable": true, "properties": {"name": {"type": "string"}} @@ -742,7 +742,7 @@ fn body_with_the_name_of_a_param_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{zone_id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{zone_id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "zone_id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "properties": {"zoneId": {"type": "string"}, "name": {"type": "string"}} @@ -762,8 +762,8 @@ fn field_of_another_method_has_no_location() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -779,7 +779,7 @@ fn body_that_is_not_json_is_an_unknown_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "upload", + "paths": {"/a/{id}": {"post": {"x-forge-group": ["a"], "x-forge-method": "upload", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"file": {"type": "string", "format": "binary"}} @@ -798,7 +798,7 @@ fn body_that_is_only_multipart_is_an_unknown_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "upload", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"file": {"type": "string", "format": "binary"}} }}}}, @@ -816,7 +816,7 @@ fn path_param_missing_from_the_template_is_dropped() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "account_id", "in": "path", "required": true, "schema": {"type": "string"}} @@ -833,7 +833,7 @@ fn deprecated_query_param_is_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "page", "in": "query", "deprecated": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -847,7 +847,7 @@ fn deprecated_path_param_is_not_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{"name": "id", "in": "path", "required": true, "deprecated": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -861,7 +861,7 @@ fn all_of_body_is_one_member_of_the_intersection() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}] @@ -888,7 +888,7 @@ fn param_with_content_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "filter", "in": "query", "content": {"application/json": {"schema": { "type": "object", "properties": {"status": {"type": "string"}} }}}}], @@ -912,7 +912,7 @@ fn query_style_other_than_form_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{{"name": "filter", "in": "query", "style": "{style}", "schema": {schema}}}], "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# @@ -927,7 +927,7 @@ fn two_query_string_params_are_an_error() { let err = parse_err( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "one", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}}, {"name": "two", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}} @@ -946,7 +946,7 @@ fn query_and_query_string_params_are_an_error() { "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], - "get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}}], "responses": {"204": {"description": "ok"}}} }} @@ -963,10 +963,10 @@ fn body_field_is_required_when_the_body_is() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "replace", + "put": {"x-forge-group": ["a"], "x-forge-method": "replace", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}, - "patch": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "append", + "patch": {"x-forge-group": ["a"], "x-forge-method": "append", "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}} }} @@ -983,7 +983,7 @@ fn params_with_equal_names_are_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{zone_id}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a/{zone_id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [ {"name": "zone_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "zoneId", "in": "query", "schema": {"type": "string"}} @@ -1001,7 +1001,7 @@ fn path_style_other_than_simple_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a/{{id}}": {{"get": {{"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {{"/a/{{id}}": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", "parameters": [{{"name": "id", "in": "path", "required": true, "style": "{style}", "schema": {{"type": "string"}}}}], "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# @@ -1016,7 +1016,7 @@ fn param_field_has_the_default_of_its_schema() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "per_page", "in": "query", "schema": {"type": "integer", "default": 20}}, {"name": "page", "in": "query", "schema": {"type": "integer"}} @@ -1035,7 +1035,7 @@ fn param_field_has_the_default_of_its_ref_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{order}": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a/{order}": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [ {"name": "order", "in": "path", "required": true, "schema": {"$ref": "#/components/schemas/Order"}}, {"$ref": "#/components/parameters/Direction"} @@ -1062,7 +1062,7 @@ fn default_next_to_a_param_schema_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "per_page", "in": "query", "schema": {"$ref": "#/components/schemas/PerPage", "default": 50}}], "responses": {"204": {"description": "ok"}}}}}, @@ -1079,7 +1079,7 @@ fn default_on_the_param_itself_is_ignored() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", "parameters": [{"name": "per_page", "in": "query", "default": 20, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -1096,7 +1096,7 @@ fn body_field_and_undeclared_placeholder_have_no_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "default": ["x"] }}}}, @@ -1114,7 +1114,7 @@ fn array_body_keeps_its_max_items() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "maxItems": 100 }}}}, diff --git a/tests/parse/responses.rs b/tests/parse/responses.rs index a34167acc..eab8ea51d 100644 --- a/tests/parse/responses.rs +++ b/tests/parse/responses.rs @@ -7,7 +7,7 @@ fn responses_are_the_2xx_sorted_by_status() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "responses": { "2XX": {"description": "ok"}, "201": {"description": "ok"}, @@ -29,7 +29,7 @@ fn errors_are_the_rest_sorted_with_default_last() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": { "default": {"description": "no"}, "500": {"description": "no"}, @@ -54,7 +54,7 @@ fn response_has_its_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "The pet."}}}}} }"#, ); @@ -68,7 +68,7 @@ fn response_without_content_has_none() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"delete": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "delete", + "paths": {"/a": {"delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -83,7 +83,7 @@ fn response_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"4XX": {"$ref": "#/components/responses/Failure"}}}}}, "components": {"responses": { "Failure": {"description": "Failed.", "content": {"application/json": {"schema": {"type": "string"}}}} @@ -102,7 +102,7 @@ fn response_content_that_is_not_json_is_typed() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "download", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "download", "responses": {"200": {"description": "ok", "content": { "application/octet-stream": {"schema": {"type": "string", "format": "binary"}}, "text/csv": {"schema": {"type": "string"}} diff --git a/tests/parse/types/arrays.rs b/tests/parse/types/arrays.rs index 262c601e1..bf5d85931 100644 --- a/tests/parse/types/arrays.rs +++ b/tests/parse/types/arrays.rs @@ -92,7 +92,7 @@ fn array_without_items_has_unknown_elements() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "array" }}}}}}}} @@ -107,7 +107,7 @@ fn tuple_is_unknown() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "array", "prefixItems": [{"type": "string"}, {"type": "integer"}], "items": false }}}}}}}} diff --git a/tests/parse/types/enums.rs b/tests/parse/types/enums.rs index d2b3b497e..101ea434d 100644 --- a/tests/parse/types/enums.rs +++ b/tests/parse/types/enums.rs @@ -59,7 +59,7 @@ fn const_is_an_enum_of_one_value() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "const": "a" }}}}}}}} diff --git a/tests/parse/types/intersections.rs b/tests/parse/types/intersections.rs index 7c5d6564b..ca373866b 100644 --- a/tests/parse/types/intersections.rs +++ b/tests/parse/types/intersections.rs @@ -49,7 +49,7 @@ fn true_member_is_dropped() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}, true, {"$ref": "#/components/schemas/B"}] }}}}}}}}, @@ -141,7 +141,7 @@ fn unevaluated_properties_is_an_object_member() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}], "unevaluatedProperties": {"type": "string"} diff --git a/tests/parse/types/nulls.rs b/tests/parse/types/nulls.rs index a3794823e..b191b43cc 100644 --- a/tests/parse/types/nulls.rs +++ b/tests/parse/types/nulls.rs @@ -95,7 +95,7 @@ fn nullable_is_read_in_3_1() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "nullable": true }}}}}}}} @@ -110,7 +110,7 @@ fn null_in_a_type_array_is_a_union_with_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "null"] }}}}}}}} @@ -125,7 +125,7 @@ fn null_type_is_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "null" }}}}}}}} @@ -140,7 +140,7 @@ fn const_null_is_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "const": null }}}}}}}} diff --git a/tests/parse/types/objects.rs b/tests/parse/types/objects.rs index 1b5139d46..f3e9bf7dc 100644 --- a/tests/parse/types/objects.rs +++ b/tests/parse/types/objects.rs @@ -38,7 +38,7 @@ fn required_names_without_a_property_are_ignored() { #[test] fn field_is_named_by_x_fern_property_name() { let forge = parse(&responding_with( - r#"{"type": "object", "properties": {"owner": {"type": "string", "x-fern-property-name": "person"}}}"#, + r#"{"type": "object", "properties": {"owner": {"type": "string", "x-forge-property-name": "person"}}}"#, )); let owner = field(object(response_type(&forge, "a.get")), "owner"); @@ -195,7 +195,7 @@ fn pattern_properties_are_ignored() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"type": "string"}}, "patternProperties": {"^x-": {"type": "string"}} }}}}}}}} @@ -212,7 +212,7 @@ fn false_property_is_no_field() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"type": "string"}, "gone": false} }}}}}}}} @@ -223,9 +223,9 @@ fn false_property_is_no_field() { } #[test] -fn property_skipped_by_x_stainless_skip_is_no_field() { +fn property_ignored_by_x_forge_ignore_is_no_field() { let forge = parse(&responding_with( - r#"{"type": "object", "properties": {"id": {"type": "string"}, "old_id": {"type": "string", "x-stainless-skip": true}}}"#, + r#"{"type": "object", "properties": {"id": {"type": "string"}, "old_id": {"type": "string", "x-forge-ignore": true}}}"#, )); assert_eq!(field_names(object(response_type(&forge, "a.get"))), ["id"]); diff --git a/tests/parse/types/refs.rs b/tests/parse/types/refs.rs index 0e39e86e3..a00c96c9c 100644 --- a/tests/parse/types/refs.rs +++ b/tests/parse/types/refs.rs @@ -65,7 +65,7 @@ fn annotations_next_to_a_ref_keep_the_model_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "description": "The zone.", "deprecated": true }}}}}}}}, @@ -81,7 +81,7 @@ fn shape_next_to_a_ref_is_intersected_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "properties": {"extra": {"type": "string"}} }}}}}}}}, @@ -97,7 +97,7 @@ fn nullable_next_to_a_ref_is_a_union_with_null_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "nullable": true }}}}}}}}, @@ -153,7 +153,7 @@ fn description_next_to_a_property_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"home": {"$ref": "#/components/schemas/Zone", "description": "The home zone."}} }}}}}}}}, @@ -324,7 +324,7 @@ fn read_only_next_to_a_property_ref_counts_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"$ref": "#/components/schemas/Id", "readOnly": true}} }}}}}}}}, @@ -350,7 +350,7 @@ fn read_only_false_next_to_a_ref_does_not_undo_its_schemas_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"$ref": "#/components/schemas/Id", "readOnly": false}} }}}}}}}}, @@ -386,7 +386,7 @@ fn sensitive_next_to_a_property_ref_counts_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token", "x-sensitive": true}} }}}}}}}}, @@ -424,7 +424,7 @@ fn property_default_is_the_first_along_a_chain_of_refs_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"size": {"$ref": "#/components/schemas/Size"}} }}}}}}}}, @@ -454,7 +454,7 @@ fn default_next_to_a_property_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": { "size": {"$ref": "#/components/schemas/Size", "default": 5}, diff --git a/tests/parse/types/scalars.rs b/tests/parse/types/scalars.rs index 810e9954a..21e442f53 100644 --- a/tests/parse/types/scalars.rs +++ b/tests/parse/types/scalars.rs @@ -140,7 +140,7 @@ fn base64_content_encoding_is_bytes() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "contentEncoding": "base64" }}}}}}}} @@ -155,7 +155,7 @@ fn binary_format_is_binary_even_with_base64_content_encoding() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "format": "binary", "contentEncoding": "base64" }}}}}}}} @@ -198,7 +198,7 @@ fn true_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": true}}}}}}} }"#, ); diff --git a/tests/parse/types/unions.rs b/tests/parse/types/unions.rs index 45f11f81d..40df4abf4 100644 --- a/tests/parse/types/unions.rs +++ b/tests/parse/types/unions.rs @@ -76,7 +76,7 @@ fn type_array_is_exclusive() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "integer"] }}}}}}}} @@ -138,7 +138,7 @@ fn types_in_a_type_array_are_a_union() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "integer"] }}}}}}}} @@ -298,8 +298,8 @@ fn discriminator_is_named_by_x_fern_property_name() { "discriminator": {"propertyName": "kind"} }"##, r#"{ - "A": {"type": "object", "properties": {"kind": {"type": "string", "x-fern-property-name": "pet_kind"}}}, - "B": {"type": "object", "properties": {"kind": {"type": "string", "x-fern-property-name": "pet_kind"}}} + "A": {"type": "object", "properties": {"kind": {"type": "string", "x-forge-property-name": "pet_kind"}}}, + "B": {"type": "object", "properties": {"kind": {"type": "string", "x-forge-property-name": "pet_kind"}}} }"#, )); @@ -329,7 +329,7 @@ fn discriminator_default_mapping_is_the_default() { let forge = parse( r##"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-fern-sdk-group-name": "a", "x-fern-sdk-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "oneOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}], "discriminator": {"propertyName": "kind", "mapping": {"a": "#/components/schemas/A"}, "defaultMapping": "#/components/schemas/B"} diff --git a/tests/wasm.rs b/tests/wasm.rs index 7278ead1d..2e733443b 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -41,7 +41,7 @@ const SPEC: &str = r##"{ "paths": { "/pets": { "get": { - "x-fern-sdk-group-name": "pets", "x-fern-sdk-method-name": "list", "summary": "Lists pets.", + "x-forge-group": ["pets"], "x-forge-method": "list", "summary": "Lists pets.", "parameters": [ {"name": "limit", "in": "query", "schema": {"type": "integer", "format": "int32"}}, {"name": "tags", "in": "query", "explode": false, "schema": {"type": "array", "items": {"type": "string"}}} @@ -52,14 +52,14 @@ const SPEC: &str = r##"{ } }, "post": { - "x-fern-sdk-group-name": "pets", "x-fern-sdk-method-name": "create", "deprecated": true, + "x-forge-group": ["pets"], "x-forge-method": "create", "deprecated": true, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/NewPet"}}}}, "responses": {"201": {"description": "created", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}} } }, "/pets/{pet_id}": { "get": { - "x-fern-sdk-group-name": "pets", "x-fern-sdk-method-name": "get", + "x-forge-group": ["pets"], "x-forge-method": "get", "parameters": [{"name": "pet_id", "in": "path", "required": true, "schema": {"type": "string", "format": "uuid"}}], "responses": { "200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, @@ -69,7 +69,7 @@ const SPEC: &str = r##"{ }, "/pets/{pet_id}/photos": { "put": { - "x-fern-sdk-group-name": "pets.photos", "x-fern-sdk-method-name": "upload", + "x-forge-group": ["pets", "photos"], "x-forge-method": "upload", "parameters": [{"name": "pet_id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/octet-stream": {"schema": {"type": "string", "format": "binary"}}}}, "responses": {"204": {"description": "done"}} @@ -77,7 +77,7 @@ const SPEC: &str = r##"{ }, "/owners": { "get": { - "x-fern-sdk-group-name": "owners", "x-fern-sdk-method-name": "list", + "x-forge-group": ["owners"], "x-forge-method": "list", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": { @@ -138,8 +138,8 @@ const FEATURES: &str = r##"{ "/pets/{id}": { "parameters": [{"name": "X-Trace", "in": "header", "schema": {"type": "string"}}], "get": { - "x-fern-sdk-group-name": "pets", "x-fern-sdk-method-name": "get", - "x-fern-availability": "beta", "x-forge-hidden": true, + "x-forge-group": ["pets"], "x-forge-method": "get", + "x-forge-availability": "beta", "x-forge-hidden": true, "x-custom": {"b": 1, "a": [1.5, "two \"quoted\"\n", null, true, {}], "b": 2}, "x-flag": false, "x-count": 9007199254740993, "x-text": "é 😀", "parameters": [ @@ -152,9 +152,9 @@ const FEATURES: &str = r##"{ }, "delete": { "x-forge-aliases": [ - {"x-fern-sdk-group-name": "pets", "x-fern-sdk-method-name": "remove", "x-fern-availability": "deprecated", + {"x-forge-group": ["pets"], "x-forge-method": "remove", "x-forge-availability": "deprecated", "x-forge-require-confirmation": "This deletes the pet.", "x-alias": [1]}, - {"x-fern-sdk-group-name": "admin.pets", "x-fern-sdk-method-name": "delete", "x-forge-require-confirmation": ""} + {"x-forge-group": ["admin", "pets"], "x-forge-method": "delete", "x-forge-require-confirmation": ""} ], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "gone"}} @@ -162,7 +162,7 @@ const FEATURES: &str = r##"{ }, "/pets/{id}/photo": { "put": { - "x-fern-sdk-group-name": "pets.photos", "x-fern-sdk-method-name": "upload", + "x-forge-group": ["pets", "photos"], "x-forge-method": "upload", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"required": true, "content": { "application/octet-stream": {"schema": {"type": "string", "format": "binary", "description": "The photo."}}, From f3189e3fa8cc26b77d4841a1e8bbeac3e0f3b2d4 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Sun, 25 Oct 2026 22:57:32 -0400 Subject: [PATCH 05/21] test: guard the boundary of the compatibility layer tests/boundary.rs fails, naming the file and line, when an x-fern or x-stainless name appears in src/, tests/ or packages/forge/ outside src/compat/ and tests/compat/. `just boundary` runs it. --- justfile | 4 ++ tests/boundary.rs | 118 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/boundary.rs diff --git a/justfile b/justfile index 77cc872cf..c3b7d5819 100644 --- a/justfile +++ b/justfile @@ -27,6 +27,10 @@ lint: cargo clippy --locked --all-targets --all-features -- -D warnings cargo clippy --locked --all-targets --no-default-features -- -D warnings +# Check that no other tool's extension is named outside the compatibility layer +boundary: + cargo test --locked --test boundary + # Release builds # # Every way of getting release binaries puts them in target/binaries// diff --git a/tests/boundary.rs b/tests/boundary.rs new file mode 100644 index 000000000..c91c59d13 --- /dev/null +++ b/tests/boundary.rs @@ -0,0 +1,118 @@ +//! The boundary of the compatibility layer: no other tool's extension is named +//! anywhere but in it. +//! +//! The compiler keeps what the layer reads out of reach of the rest of the +//! crate, but it cannot see a name in a doc comment, a match arm or a test +//! document, so this searches for them. It reads the engine, its tests, and +//! the npm package that ships its docs and its WIT, and fails with the file +//! and line of each name it finds outside the layer and its tests. + +use std::fs; +use std::path::{Path, PathBuf}; + +/// What the extensions of each tool forge reads begin with. +const VENDORS: [&str; 2] = ["x-fern", "x-stainless"]; + +/// Where those names may be: the layer, its tests, and this file, which +/// writes them to look for them. +const ALLOWED: [&str; 3] = ["src/compat/", "tests/compat/", "tests/boundary.rs"]; + +/// What is searched, from the root of the repository. +const SEARCHED: [&str; 3] = ["src", "tests", "packages/forge"]; + +/// The folders that hold what is built or installed, not what is written. +const SKIPPED: [&str; 4] = ["target", "node_modules", "dist", ".git"]; + +/// Adds every file under `dir` to `out`, leaving out the `SKIPPED` folders. +fn files(dir: &Path, out: &mut Vec) { + let Ok(entries) = fs::read_dir(dir) else { + return; + }; + for entry in entries.flatten() { + let path = entry.path(); + if path.is_dir() { + let name = path.file_name().and_then(|name| name.to_str()); + if name.is_some_and(|name| SKIPPED.contains(&name)) { + continue; + } + files(&path, out); + } else { + out.push(path); + } + } +} + +/// Returns each file under `SEARCHED` as its path from the root, with `/` +/// between folders, and what it says. A file that is not text is left out. +fn searched() -> Vec<(String, String)> { + let root = Path::new(env!("CARGO_MANIFEST_DIR")); + let mut paths = Vec::new(); + for dir in SEARCHED { + files(&root.join(dir), &mut paths); + } + let mut searched = Vec::new(); + for path in paths { + let Ok(text) = fs::read_to_string(&path) else { + continue; + }; + let relative = path + .strip_prefix(root) + .unwrap_or(&path) + .to_string_lossy() + .replace('\\', "/"); + searched.push((relative, text)); + } + searched +} + +#[test] +fn no_extension_of_another_tool_is_named_outside_the_compatibility_layer() { + let mut found = Vec::new(); + for (path, text) in searched() { + if ALLOWED.iter().any(|allowed| path.starts_with(allowed)) { + continue; + } + for (i, line) in text.lines().enumerate() { + if VENDORS.iter().any(|vendor| line.contains(vendor)) { + found.push(format!("{path}:{}: {}", i + 1, line.trim())); + } + } + } + + assert!( + found.is_empty(), + "the extensions of other tools are named only in src/compat/ and tests/compat/, but:\n{}", + found.join("\n") + ); +} + +#[test] +fn the_search_covers_the_engine_its_tests_and_the_npm_package() { + let searched = searched(); + let has = |path: &str| searched.iter().any(|(searched, _)| searched == path); + + for path in [ + "src/lib.rs", + "src/link/openapi.rs", + "src/plugin/wasm.rs", + "tests/parse/main.rs", + "packages/forge/src/index.ts", + "packages/forge/plugin/forge.wit", + ] { + assert!(has(path), "{path} is not searched"); + } +} + +#[test] +fn the_search_finds_the_names_it_looks_for_where_they_are_allowed() { + // So that finding none elsewhere means something. + let searched = searched(); + for vendor in VENDORS { + assert!( + searched + .iter() + .any(|(path, text)| path.starts_with("src/compat/") && text.contains(vendor)), + "src/compat/ does not name {vendor}" + ); + } +} From f6264734d4cbf23a8f95828a9d3ae4b0fcaa7ed5 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Sun, 25 Oct 2026 22:57:32 -0400 Subject: [PATCH 06/21] docs: record how RFC 0001 was verified --- rfcs/0001-metadata-resolution-layer.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 0b95958cd..2b6bab71c 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -123,7 +123,7 @@ Properties, all deliberate: - **Dependencies**: `link → metadata` and `link → compat` (behind the feature), and `compat → metadata` (an adapter produces metadata's primitives). `metadata` imports neither of the others, so compat sits *beside* the native table rather than under it. `link/resolve.rs` asks native first, compat second — that fallback arm *is* the D4 rule. - **Purity**: the library's contract is `&str` keys in and small values out: primitives, key names, and *format descriptors as data* (for example "a string splits on `.`" or "a list of targets counts as `false`"). The serde reading and the arena writes stay in `link` and are generic, driven by those descriptors. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). - **The availability vocabulary is native.** The five values live in the native table (they are shipped public API); `fern.rs` only maps `x-fern-availability` onto that primitive. -- **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` and the one cfg arm in `link/resolve.rs` touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. +- **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` and the cfg arms in `link/resolve.rs` (one for each kind of object) touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. - **Dispatch, not semantics**: the layer maps keys to primitives and normalizes simple values. Structural behavior — `x-forge-aliases` becoming methods, `x-forge-commands` describing groups — stays in the builder. ## Enforcement @@ -140,6 +140,18 @@ Properties, all deliberate: - Existing tripwires keep working: `wit_is_current` (WIT regeneration is mechanical via `wit.mjs`), the wasm dump equality, native-vs-wasm generated-output byte equality. - Performance: divan parse benches before/after on the real aggregate (`FORGE_SPEC`); `tests/wasm.rs::bench` re-run; forge-bench re-pinned upstream after merge. +## Verification + +The implementation was checked against the unmodified engine on the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617…`): + +- **Fern-keyed behavior.** The original, untouched suite — 379 parse tests written with Fern keys — passed against the new engine before any fixture was migrated. +- **Generated output.** `forge --target ts` on the aggregate writes the same 3,381 files, byte for byte (`diff -r`). +- **The model.** The full model dump (the repo's own `tests/wasm/dump.rs`: every group, method, availability, hidden flag, confirmation, extension and field name) is identical between the old and new engines: 197,702 lines, covering 3,021 availability values, 1,259 hidden flags, 217 confirmations and 4,695 extension entries. The generated TypeScript consumes none of those four, which is why the dump, not the output diff, is what proves them. +- **Across the plugin boundary.** `tests/wasm.rs`, including the ignored `bench` on the aggregate, reports identical output and dump, native versus WASM, for 1,317 groups and 3,381 files; `wit_is_current` holds with the regenerated WIT. +- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 438 tests of the native suite; with compat on, 486 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. +- **The checks can fail.** Breaking the native-wins rule fails 8 compat tests; planting a vendor name in a doc comment fails the boundary test, naming the file and line. +- **Performance** (parse and link of the aggregate, `cargo bench --bench parse`, six alternating runs against the unmodified code): fastest 40.8 ms against 40.3 ms (+1.2%), median 42.2 ms against 41.5 ms (+1.6%), peak memory 69.13 MB against 68.75 MB (+0.55%), the same peak allocation count. The cost is the dispatch of the ~15k extension keys through the native table and the adapters, and the provenance kept on each operation's definition. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is about 0.1%. + ## Release shape Non-breaking. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release (new native keys accepted, compat module added); the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. From abc48965f83292c395b2f6977c2318e83ff3b439 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 11:12:20 -0400 Subject: [PATCH 07/21] perf: turn away other keys early, and keep a resolved key small - Each table checks its prefix (x-forge-, x-fern-, x-stainless-) before matching, and only x- keys are resolved, so a skipped key costs one compare instead of a match per table. - A Hit holds only its field and slot; a key's name comes from the slot, in the per-kind name tables, when an error needs it. The reader's per-key result is back to 16 bytes, which fits in registers. Output and the model dump of the aggregate are unchanged. --- src/compat/fern.rs | 45 +++++++---- src/compat/mod.rs | 67 +++++++++++++++- src/compat/stainless.rs | 15 +++- src/link.rs | 9 ++- src/link/openapi.rs | 17 +++-- src/link/resolve.rs | 81 ++++++++++++++++---- src/metadata/mod.rs | 165 +++++++++++++++++++++++++--------------- 7 files changed, 294 insertions(+), 105 deletions(-) diff --git a/src/compat/fern.rs b/src/compat/fern.rs index 5c57b4690..ccb5707ca 100644 --- a/src/compat/fern.rs +++ b/src/compat/fern.rs @@ -15,6 +15,9 @@ use crate::metadata::{BoolFormat, DefinitionField, GroupFormat, Hit, ParameterField, SchemaField}; +/// What every key of the adapter begins with. A key without it is turned +/// away before it is matched against the table. +const PREFIX: &str = "x-fern-"; const METHOD_NAME: &str = "x-fern-sdk-method-name"; const GROUP_NAME: &str = "x-fern-sdk-group-name"; const IGNORE: &str = "x-fern-ignore"; @@ -23,33 +26,43 @@ const PARAMETER_NAME: &str = "x-fern-parameter-name"; const PROPERTY_NAME: &str = "x-fern-property-name"; const TYPE_NAME: &str = "x-fern-type-name"; +/// The names of the adapter's keys of an operation or an alias, by slot. +pub(super) const DEFINITION_NAMES: [&str; 4] = [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY]; +/// The names of the adapter's keys of a Parameter Object, by slot. +pub(super) const PARAMETER_NAMES: [&str; 1] = [PARAMETER_NAME]; +/// The names of the adapter's keys of a Schema Object, by slot. +pub(super) const SCHEMA_NAMES: [&str; 2] = [TYPE_NAME, PROPERTY_NAME]; + pub(super) fn definition(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - METHOD_NAME => Hit::compat(DefinitionField::Method, METHOD_NAME, 0), - GROUP_NAME => Hit::compat( - DefinitionField::Group(GroupFormat::StringOrArray { separator: '.' }), - GROUP_NAME, - 1, - ), - IGNORE => Hit::compat(DefinitionField::Ignore(BoolFormat::Bool), IGNORE, 2), - AVAILABILITY => Hit::compat(DefinitionField::Availability, AVAILABILITY, 3), + METHOD_NAME => Hit::compat(DefinitionField::Method, 0), + GROUP_NAME => Hit::compat(DefinitionField::Group(GroupFormat::StringOrArray { separator: '.' }), 1), + IGNORE => Hit::compat(DefinitionField::Ignore(BoolFormat::Bool), 2), + AVAILABILITY => Hit::compat(DefinitionField::Availability, 3), _ => return None, }) } pub(super) fn parameter(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - PARAMETER_NAME => Hit::compat(ParameterField::Name, PARAMETER_NAME, 0), + PARAMETER_NAME => Hit::compat(ParameterField::Name, 0), _ => return None, }) } -/// Slots 0 and 1 of the compatibility keys of a Schema Object are Fern's; -/// the next adapter's start at 2. pub(super) fn schema(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - TYPE_NAME => Hit::compat(SchemaField::ModelName, TYPE_NAME, 0), - PROPERTY_NAME => Hit::compat(SchemaField::PropertyName, PROPERTY_NAME, 1), + TYPE_NAME => Hit::compat(SchemaField::ModelName, 0), + PROPERTY_NAME => Hit::compat(SchemaField::PropertyName, 1), _ => return None, }) } @@ -62,13 +75,13 @@ mod tests { fn each_key_is_read_as_itself_and_as_not_native() { for key in [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY] { let hit = definition(key).unwrap_or_else(|| panic!("{key} is not a definition key")); - assert_eq!((hit.key, hit.native), (key, false)); + assert!(!hit.is_native(), "{key}"); } let hit = parameter(PARAMETER_NAME).unwrap(); - assert_eq!((hit.key, hit.native), (PARAMETER_NAME, false)); + assert!(!hit.is_native(), "{PARAMETER_NAME}"); for key in [TYPE_NAME, PROPERTY_NAME] { let hit = schema(key).unwrap_or_else(|| panic!("{key} is not a schema key")); - assert_eq!((hit.key, hit.native), (key, false)); + assert!(!hit.is_native(), "{key}"); } } diff --git a/src/compat/mod.rs b/src/compat/mod.rs index 2545a0124..555f2d7cf 100644 --- a/src/compat/mod.rs +++ b/src/compat/mod.rs @@ -31,6 +31,71 @@ pub(crate) fn parameter(key: &str) -> Option> { } /// Returns what `key` says on a Schema Object, if an adapter reads it there. +/// Each adapter counts its keys from zero, so Stainless's come after Fern's. pub(crate) fn schema(key: &str) -> Option> { - fern::schema(key).or_else(|| stainless::schema(key)) + fern::schema(key).or_else(|| stainless::schema(key).map(|hit| hit.after(FERN_SCHEMA_KEYS))) +} + +/// How many keys of a Schema Object Fern has, which is where Stainless's +/// start. +const FERN_SCHEMA_KEYS: u8 = fern::SCHEMA_NAMES.len() as u8; + +/// Returns the name of the key of an operation or an alias that is `n`th +/// among the keys of the adapters. +pub(crate) fn definition_name(n: u8) -> &'static str { + fern::DEFINITION_NAMES[usize::from(n)] +} + +/// Returns the name of the key of a Parameter Object that is `n`th among the +/// keys of the adapters. +pub(crate) fn parameter_name(n: u8) -> &'static str { + fern::PARAMETER_NAMES[usize::from(n)] +} + +/// Returns the name of the key of a Schema Object that is `n`th among the +/// keys of the adapters. +pub(crate) fn schema_name(n: u8) -> &'static str { + match n.checked_sub(FERN_SCHEMA_KEYS) { + None => fern::SCHEMA_NAMES[usize::from(n)], + Some(n) => stainless::SCHEMA_NAMES[usize::from(n)], + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::metadata::COMPAT_SLOTS; + + /// Asserts that each key in `names` is read by `read` as a key that is + /// not native, whose slot `name` names it by. + #[track_caller] + fn read_as_itself(names: &[&'static str], read: fn(&str) -> Option>, name: fn(u8) -> &'static str) { + for &key in names { + let hit = read(key).unwrap_or_else(|| panic!("{key} is not read")); + assert!(!hit.is_native(), "{key}"); + assert_eq!(name(hit.slot - COMPAT_SLOTS), key); + } + } + + #[test] + fn each_key_of_each_adapter_is_named_by_its_slot() { + read_as_itself(&fern::DEFINITION_NAMES, definition, definition_name); + read_as_itself(&fern::PARAMETER_NAMES, parameter, parameter_name); + read_as_itself(&fern::SCHEMA_NAMES, schema, schema_name); + read_as_itself(&stainless::SCHEMA_NAMES, schema, schema_name); + } + + #[test] + fn the_slots_of_the_adapters_do_not_collide_and_fit_in_a_set() { + let mut slots: Vec = fern::SCHEMA_NAMES + .iter() + .chain(&stainless::SCHEMA_NAMES) + .map(|key| schema(key).unwrap().slot) + .collect(); + let len = slots.len(); + slots.sort_unstable(); + slots.dedup(); + assert_eq!(slots.len(), len); + assert!(slots.iter().all(|&slot| slot < 64)); + } } diff --git a/src/compat/stainless.rs b/src/compat/stainless.rs index 9338545a0..90f9dc265 100644 --- a/src/compat/stainless.rs +++ b/src/compat/stainless.rs @@ -10,13 +10,20 @@ use crate::metadata::{BoolFormat, Hit, SchemaField}; +/// What every key of the adapter begins with. A key without it is turned +/// away before it is matched against the table. +const PREFIX: &str = "x-stainless-"; const SKIP: &str = "x-stainless-skip"; -/// Slot 2 among the compatibility keys of a Schema Object: Fern's are the -/// first two. +/// The names of the adapter's keys of a Schema Object, by slot. +pub(super) const SCHEMA_NAMES: [&str; 1] = [SKIP]; + pub(super) fn schema(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - SKIP => Hit::compat(SchemaField::Ignore(BoolFormat::BoolOrTargets), SKIP, 2), + SKIP => Hit::compat(SchemaField::Ignore(BoolFormat::BoolOrTargets), 0), _ => return None, }) } @@ -28,7 +35,7 @@ mod tests { #[test] fn the_skip_is_read_on_a_schema_as_a_boolean_or_targets_and_not_native() { let hit = schema(SKIP).unwrap(); - assert_eq!((hit.key, hit.native), (SKIP, false)); + assert!(!hit.is_native(), "{SKIP}"); assert!(matches!(hit.field, SchemaField::Ignore(BoolFormat::BoolOrTargets))); } diff --git a/src/link.rs b/src/link.rs index fcca41f55..84072a4cd 100644 --- a/src/link.rs +++ b/src/link.rs @@ -580,14 +580,17 @@ impl<'d> Builder<'d> { if name.is_empty() { self.error(format_args!( "{} has a group name with no letters or digits", - definition.group_names.key + resolve::definition_name(definition.group_names.slot) )); return; } } let name = Name::new(doc.str(definition.method_name.value)); if name.is_empty() { - self.error(format_args!("{} has no letters or digits", definition.method_name.key)); + self.error(format_args!( + "{} has no letters or digits", + resolve::definition_name(definition.method_name.slot) + )); return; } let mut availability = None; @@ -597,7 +600,7 @@ impl<'d> Builder<'d> { if availability.is_none() { self.error(format_args!( "{} {value:?} is not alpha, beta, preview, generally-available or deprecated", - definition.availability.key + resolve::definition_name(definition.availability.slot) )); } } diff --git a/src/link/openapi.rs b/src/link/openapi.rs index 877b6df47..0a99e81a5 100644 --- a/src/link/openapi.rs +++ b/src/link/openapi.rs @@ -246,8 +246,9 @@ pub(super) struct Operation { #[derive(Default)] pub(super) struct Val { pub(super) value: T, - /// The key as written, or empty if no key gave the value. - pub(super) key: &'static str, + /// The slot of the key that gave the value, which names it. It means + /// nothing if no key gave one. + pub(super) slot: u8, native: bool, } @@ -257,7 +258,7 @@ impl Val { fn set(&mut self, hit: &Hit, value: T) { if takes(hit, &mut self.native) { self.value = value; - self.key = hit.key; + self.slot = hit.slot; } } } @@ -266,8 +267,8 @@ impl Val { /// far, which came from a native key if `native` is set, and records where /// the value kept came from. fn takes(hit: &Hit, native: &mut bool) -> bool { - if hit.native || !*native { - *native = hit.native; + if hit.is_native() || !*native { + *native = hit.is_native(); return true; } false @@ -1117,9 +1118,11 @@ macro_rules! entry { fn visit_str(self, v: &str) -> Result<$name, E> { // The OpenAPI keys first: most keys of a document are - // one of them, and none is an extension. + // one of them, and none is an extension. Of the rest, + // only an `x-` key is asked about, so that a key that + // is skipped costs one compare. Ok(match $keys::from_key(v) { - $keys::Other => match $resolve(v) { + $keys::Other if v.starts_with("x-") => match $resolve(v) { Some(hit) => $name::Extension(hit), None => $name::Key($keys::Other), }, diff --git a/src/link/resolve.rs b/src/link/resolve.rs index 87b2db0bc..956351c13 100644 --- a/src/link/resolve.rs +++ b/src/link/resolve.rs @@ -16,45 +16,63 @@ use crate::metadata::{self, DefinitionField, DocumentField, Hit, ParameterField, /// Returns what `key` says on an operation or an alias, if it is a key of /// one. pub(super) fn definition(key: &str) -> Option> { - if !key.starts_with("x-") { - return None; - } metadata::definition(key).or_else(|| compat_definition(key)) } /// Returns what `key` says on a Parameter Object, if it is a key of one. pub(super) fn parameter(key: &str) -> Option> { - if !key.starts_with("x-") { - return None; - } metadata::parameter(key).or_else(|| compat_parameter(key)) } /// Returns what `key` says on a Schema Object, if it is a key of one. pub(super) fn schema(key: &str) -> Option> { - if !key.starts_with("x-") { - return None; - } metadata::schema(key).or_else(|| compat_schema(key)) } /// Returns what `key` says at the root of the document, if it is a key of /// it. No compatibility key says anything there. pub(super) fn document(key: &str) -> Option> { - if !key.starts_with("x-") { - return None; - } metadata::document(key) } +/// A kind of object with extensions, which can name its keys by slot. +pub(super) trait Kind { + /// Returns the name of the key in `slot`, as the document writes it. + fn name(slot: u8) -> &'static str; +} + +impl Kind for DefinitionField { + fn name(slot: u8) -> &'static str { + metadata::native_name(&metadata::DEFINITION_NAMES, slot).unwrap_or_else(|| compat_definition_name(slot)) + } +} + +impl Kind for ParameterField { + fn name(slot: u8) -> &'static str { + metadata::native_name(&metadata::PARAMETER_NAMES, slot).unwrap_or_else(|| compat_parameter_name(slot)) + } +} + +impl Kind for SchemaField { + fn name(slot: u8) -> &'static str { + metadata::native_name(&metadata::SCHEMA_NAMES, slot).unwrap_or_else(|| compat_schema_name(slot)) + } +} + +impl Kind for DocumentField { + fn name(slot: u8) -> &'static str { + metadata::native_name(&metadata::DOCUMENT_NAMES, slot).unwrap_or_default() + } +} + /// Returns an error if the key of `hit` is in `seen`, which has a bit for /// each key read so far from the object, and else adds it. A native key and /// a compatibility key of the same meaning are different keys, so both can /// be written: the native one's value is kept. -pub(super) fn once(hit: &Hit, seen: &mut u64) -> Result<(), E> { +pub(super) fn once(hit: &Hit, seen: &mut u64) -> Result<(), E> { let bit = 1u64 << hit.slot; if *seen & bit != 0 { - return Err(E::duplicate_field(hit.key)); + return Err(E::duplicate_field(F::name(hit.slot))); } *seen |= bit; Ok(()) @@ -89,3 +107,38 @@ fn compat_schema(key: &str) -> Option> { fn compat_schema(_: &str) -> Option> { None } + +#[cfg(feature = "compat")] +fn compat_definition_name(slot: u8) -> &'static str { + crate::compat::definition_name(slot - metadata::COMPAT_SLOTS) +} + +#[cfg(not(feature = "compat"))] +fn compat_definition_name(_: u8) -> &'static str { + "" +} + +#[cfg(feature = "compat")] +fn compat_parameter_name(slot: u8) -> &'static str { + crate::compat::parameter_name(slot - metadata::COMPAT_SLOTS) +} + +#[cfg(not(feature = "compat"))] +fn compat_parameter_name(_: u8) -> &'static str { + "" +} + +#[cfg(feature = "compat")] +fn compat_schema_name(slot: u8) -> &'static str { + crate::compat::schema_name(slot - metadata::COMPAT_SLOTS) +} + +#[cfg(not(feature = "compat"))] +fn compat_schema_name(_: u8) -> &'static str { + "" +} + +/// Returns the name of the key of an operation or an alias in `slot`. +pub(super) fn definition_name(slot: u8) -> &'static str { + DefinitionField::name(slot) +} diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index 559869b8f..97c986388 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -21,50 +21,68 @@ use crate::Availability; /// [`definition`], since an alias cannot have one. pub(crate) const ALIASES: &str = "x-forge-aliases"; +/// What every native key begins with, but `x-sensitive`. A key without it is +/// turned away before it is matched against the table: most extensions in a +/// document are no key of any table, and this is the cheap way to say so. +const PREFIX: &str = "x-forge-"; + /// A key that says something about the object it is on. +/// +/// It is kept to a few bytes, since one is read for every key of every +/// object: the key's name, which only an error needs, is found from its +/// `slot`, in the table of names of its kind of object. #[derive(Clone, Copy)] pub(crate) struct Hit { /// What the key says. pub(crate) field: F, - /// The key as the document writes it, for errors. - pub(crate) key: &'static str, - /// Whether the key is native. A value from a native key is kept over one - /// from any other, whatever order they are written in. - pub(crate) native: bool, /// The bit of the key in a set of the keys read from an object so far, - /// which is how a key written twice is found. Unique among the keys of - /// one kind of object, native or not. + /// which is how a key written twice is found, and the index of its name. + /// Unique among the keys of one kind of object, native or not: the + /// native keys count up from zero, and the others from [`COMPAT_SLOTS`]. pub(crate) slot: u8, } /// The first slot of the keys that are not native, so that slots never /// collide with the native ones, which count up from zero. -#[cfg(feature = "compat")] -const COMPAT_SLOTS: u8 = 32; +pub(crate) const COMPAT_SLOTS: u8 = 32; impl Hit { /// Returns a native key, in slot `slot`, which is under 32. - const fn native(field: F, key: &'static str, slot: u8) -> Hit { - Hit { - field, - key, - native: true, - slot, - } + const fn native(field: F, slot: u8) -> Hit { + Hit { field, slot } } /// Returns a key that is not native, which a compatibility layer /// reads in place of a native one. It is the `n`th of its kind of /// object, counting from zero, `n` under 32. #[cfg(feature = "compat")] - pub(crate) const fn compat(field: F, key: &'static str, n: u8) -> Hit { + pub(crate) const fn compat(field: F, n: u8) -> Hit { Hit { field, - key, - native: false, slot: COMPAT_SLOTS + n, } } + + /// Returns this key moved `n` slots on, for a compatibility layer that + /// puts the keys of several adapters one after another. + #[cfg(feature = "compat")] + pub(crate) fn after(self, n: u8) -> Hit { + Hit { + field: self.field, + slot: self.slot + n, + } + } + + /// Returns whether the key is native. A value from a native key is kept + /// over one from any other, whatever order they are written in. + pub(crate) const fn is_native(&self) -> bool { + self.slot < COMPAT_SLOTS + } +} + +/// Returns the name in `names` of the key in `slot`, if it is a native one. +pub(crate) fn native_name(names: &[&'static str], slot: u8) -> Option<&'static str> { + names.get(usize::from(slot)).copied() } /// What a key says on an operation, or on an alias of one. @@ -135,23 +153,41 @@ pub(crate) enum BoolFormat { /// Returns what `key` says on an operation or an alias, if it is a native /// key of one. pub(crate) fn definition(key: &str) -> Option> { - const METHOD: &str = "x-forge-method"; - const GROUP: &str = "x-forge-group"; - const IGNORE: &str = "x-forge-ignore"; - const AVAILABILITY: &str = "x-forge-availability"; - const HIDDEN: &str = "x-forge-hidden"; - const CONFIRMATION: &str = "x-forge-require-confirmation"; + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - METHOD => Hit::native(DefinitionField::Method, METHOD, 0), - GROUP => Hit::native(DefinitionField::Group(GroupFormat::Array), GROUP, 1), - IGNORE => Hit::native(DefinitionField::Ignore(BoolFormat::Bool), IGNORE, 2), - AVAILABILITY => Hit::native(DefinitionField::Availability, AVAILABILITY, 3), - HIDDEN => Hit::native(DefinitionField::Hidden, HIDDEN, 4), - CONFIRMATION => Hit::native(DefinitionField::Confirmation, CONFIRMATION, 5), + METHOD => Hit::native(DefinitionField::Method, 0), + GROUP => Hit::native(DefinitionField::Group(GroupFormat::Array), 1), + IGNORE => Hit::native(DefinitionField::Ignore(BoolFormat::Bool), 2), + AVAILABILITY => Hit::native(DefinitionField::Availability, 3), + HIDDEN => Hit::native(DefinitionField::Hidden, 4), + CONFIRMATION => Hit::native(DefinitionField::Confirmation, 5), _ => return None, }) } +const METHOD: &str = "x-forge-method"; +const GROUP: &str = "x-forge-group"; +const IGNORE: &str = "x-forge-ignore"; +const AVAILABILITY: &str = "x-forge-availability"; +const HIDDEN: &str = "x-forge-hidden"; +const CONFIRMATION: &str = "x-forge-require-confirmation"; +const PARAMETER_NAME: &str = "x-forge-parameter-name"; +const MODEL_NAME: &str = "x-forge-model-name"; +const PROPERTY_NAME: &str = "x-forge-property-name"; +const SENSITIVE: &str = "x-sensitive"; +const COMMANDS: &str = "x-forge-commands"; + +/// The names of the native keys of an operation or an alias, by slot. +pub(crate) const DEFINITION_NAMES: [&str; 6] = [METHOD, GROUP, IGNORE, AVAILABILITY, HIDDEN, CONFIRMATION]; +/// The names of the native keys of a Parameter Object, by slot. +pub(crate) const PARAMETER_NAMES: [&str; 1] = [PARAMETER_NAME]; +/// The names of the native keys of a Schema Object, by slot. +pub(crate) const SCHEMA_NAMES: [&str; 4] = [MODEL_NAME, PROPERTY_NAME, IGNORE, SENSITIVE]; +/// The names of the native keys of the document, by slot. +pub(crate) const DOCUMENT_NAMES: [&str; 1] = [COMMANDS]; + /// Returns whether `key` is the `x-forge-aliases` of an operation. pub(crate) fn is_aliases(key: &str) -> bool { key == ALIASES @@ -160,24 +196,26 @@ pub(crate) fn is_aliases(key: &str) -> bool { /// Returns what `key` says on a Parameter Object, if it is a native key of /// one. pub(crate) fn parameter(key: &str) -> Option> { - const NAME: &str = "x-forge-parameter-name"; + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - NAME => Hit::native(ParameterField::Name, NAME, 0), + PARAMETER_NAME => Hit::native(ParameterField::Name, 0), _ => return None, }) } /// Returns what `key` says on a Schema Object, if it is a native key of one. pub(crate) fn schema(key: &str) -> Option> { - const MODEL_NAME: &str = "x-forge-model-name"; - const PROPERTY_NAME: &str = "x-forge-property-name"; - const IGNORE: &str = "x-forge-ignore"; - const SENSITIVE: &str = "x-sensitive"; + // `x-sensitive` is the one native key outside the prefix. + if !key.starts_with(PREFIX) && key != SENSITIVE { + return None; + } Some(match key { - MODEL_NAME => Hit::native(SchemaField::ModelName, MODEL_NAME, 0), - PROPERTY_NAME => Hit::native(SchemaField::PropertyName, PROPERTY_NAME, 1), - IGNORE => Hit::native(SchemaField::Ignore(BoolFormat::Bool), IGNORE, 2), - SENSITIVE => Hit::native(SchemaField::Sensitive, SENSITIVE, 3), + MODEL_NAME => Hit::native(SchemaField::ModelName, 0), + PROPERTY_NAME => Hit::native(SchemaField::PropertyName, 1), + IGNORE => Hit::native(SchemaField::Ignore(BoolFormat::Bool), 2), + SENSITIVE => Hit::native(SchemaField::Sensitive, 3), _ => return None, }) } @@ -185,9 +223,11 @@ pub(crate) fn schema(key: &str) -> Option> { /// Returns what `key` says at the root of the document, if it is a native /// key of it. pub(crate) fn document(key: &str) -> Option> { - const COMMANDS: &str = "x-forge-commands"; + if !key.starts_with(PREFIX) { + return None; + } Some(match key { - COMMANDS => Hit::native(DocumentField::Commands, COMMANDS, 0), + COMMANDS => Hit::native(DocumentField::Commands, 0), _ => return None, }) } @@ -209,7 +249,7 @@ pub(crate) fn availability(value: &str) -> Option { mod tests { use super::*; - /// Every native key of each kind of object, as `(key, slot)`. + /// Every native key of each kind of object, in slot order. fn native_keys() -> [&'static [&'static str]; 4] { [ &[ @@ -231,25 +271,30 @@ mod tests { ] } + /// Asserts that each of `keys` is read by `read` as a native key whose + /// slot names it in `names`. + #[track_caller] + fn read_as_itself(keys: &[&str], names: &[&'static str], read: fn(&str) -> Option>) { + for &key in keys { + let hit = read(key).unwrap_or_else(|| panic!("{key} is not read")); + assert!(hit.is_native(), "{key}"); + assert_eq!(native_name(names, hit.slot), Some(key)); + } + assert_eq!(keys.len(), names.len(), "every name is a key that is read"); + } + #[test] fn each_native_key_is_read_as_itself_and_as_native() { let [definitions, parameters, schemas, documents] = native_keys(); - for &key in definitions { - let hit = definition(key).unwrap_or_else(|| panic!("{key} is not a definition key")); - assert_eq!((hit.key, hit.native), (key, true)); - } - for &key in parameters { - let hit = parameter(key).unwrap_or_else(|| panic!("{key} is not a parameter key")); - assert_eq!((hit.key, hit.native), (key, true)); - } - for &key in schemas { - let hit = schema(key).unwrap_or_else(|| panic!("{key} is not a schema key")); - assert_eq!((hit.key, hit.native), (key, true)); - } - for &key in documents { - let hit = document(key).unwrap_or_else(|| panic!("{key} is not a document key")); - assert_eq!((hit.key, hit.native), (key, true)); - } + read_as_itself(definitions, &DEFINITION_NAMES, definition); + read_as_itself(parameters, &PARAMETER_NAMES, parameter); + read_as_itself(schemas, &SCHEMA_NAMES, schema); + read_as_itself(documents, &DOCUMENT_NAMES, document); + } + + #[test] + fn a_slot_past_the_native_ones_has_no_native_name() { + assert_eq!(native_name(&DEFINITION_NAMES, COMPAT_SLOTS), None); } #[test] From 7a9dee1ddaa287af0193d10309767258f478d1c8 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 11:12:20 -0400 Subject: [PATCH 08/21] chore: add benches/compare.sh, a paired benchmark against a revision Builds REV in a throwaway worktree and runs the parse bench of both in ABBA order, so drift in the machine's speed cancels, leaving out pairs in which it changed speed. `just bench-compare [rev] [pairs]` runs it. --- benches/compare.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++ justfile | 4 +++ 2 files changed, 85 insertions(+) create mode 100755 benches/compare.sh diff --git a/benches/compare.sh b/benches/compare.sh new file mode 100755 index 000000000..d79406d66 --- /dev/null +++ b/benches/compare.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# Compares the parse benchmark of the working tree against a git revision: +# +# FORGE_SPEC=/path/to/openapi.json benches/compare.sh [REV] [PAIRS] +# +# REV defaults to main and PAIRS to 12. The revision is built in a throwaway +# worktree, so the working tree is left as it is. +# +# Each pair runs the two in ABBA order (base, new, new, base) and takes the +# mean of each side's two runs, so a machine that warms up or cools down +# through the session does not bias one side. Three warm-up pairs are +# discarded first. The statistics are paired, on divan's fastest sample of +# each run. A pair whose four runs differ by more than 10% is reported and +# left out: the machine changed speed in the middle of it. +# +# A difference under about twice its standard error is not one this can see. +set -eu + +REV=${1:-main} +PAIRS=${2:-12} +: "${FORGE_SPEC:?set FORGE_SPEC to the document to benchmark}" +export FORGE_SPEC + +ROOT=$(git rev-parse --show-toplevel) +WORK=$(mktemp -d) +trap 'git -C "$ROOT" worktree remove --force "$WORK/base" > /dev/null 2>&1 || true; rm -rf "$WORK"' EXIT + +# Builds the parse benchmark of the tree at $1 into the target folder $2, and +# copies it to $3. +build() { + (cd "$1" && CARGO_TARGET_DIR=$2 cargo bench --locked --bench parse --no-run 2>&1 | tail -1) >&2 + local bin + bin=$(ls -t "$2"/release/deps/parse-* | grep -vE '\.(d|o)$' | head -1) + cp "$bin" "$3" +} + +git -C "$ROOT" worktree add --detach "$WORK/base" "$REV" > /dev/null 2>&1 +build "$WORK/base" "$WORK/target-base" "$WORK/base.bin" +build "$ROOT" "$ROOT/target" "$WORK/new.bin" + +# Writes the fastest sample of a divan run of $1, in ms. +measure() { + "$1" --bench forge > "$WORK/run.out" 2> /dev/null + awk ' + /├─ forge/ {f = 1} + f && /╰─|├─/ && /[0-9] (ms|µs|s) / { + for (i = 1; i <= NF; i++) + if ($i ~ /^[0-9]+(\.[0-9]+)?$/) { + v = $i; u = $(i+1) + print (u == "µs" ? v / 1000 : u == "s" ? v * 1000 : v) + exit + } + }' "$WORK/run.out" +} + +for i in 1 2 3; do + measure "$WORK/base.bin" > /dev/null; measure "$WORK/new.bin" > /dev/null +done +: > "$WORK/pairs" +for i in $(seq "$PAIRS"); do + b1=$(measure "$WORK/base.bin"); n1=$(measure "$WORK/new.bin") + n2=$(measure "$WORK/new.bin"); b2=$(measure "$WORK/base.bin") + echo "$b1 $n1 $n2 $b2" >> "$WORK/pairs" + printf 'pair %2d base %s %s ms new %s %s ms\n' "$i" "$b1" "$b2" "$n1" "$n2" >&2 +done + +awk -v rev="$REV" ' + { + lo = $1; hi = $1 + for (i = 2; i <= 4; i++) { if ($i < lo) lo = $i; if ($i > hi) hi = $i } + if (hi > lo * 1.1) { printf "pair %d left out: the machine changed speed\n", NR; next } + n++; b = ($1 + $4) / 2; d = ($2 + $3) / 2 - b + sb += b; sd += d; sd2 += d * d; if (d > 0) up++ + } + END { + if (n < 2) { print "too few pairs to compare"; exit 1 } + mean = sd / n; se = sqrt((sd2 - n * mean * mean) / (n - 1) / n) + printf "%s: %.2f ms\n", rev, sb / n + printf "working tree - %s: %+.3f ms (%+.2f%%), standard error %.3f ms, t = %.1f, slower in %d of %d pairs\n", + rev, mean, 100 * mean / (sb / n), se, (se > 0 ? mean / se : 0), up, n + }' "$WORK/pairs" diff --git a/justfile b/justfile index c3b7d5819..ffbadbc88 100644 --- a/justfile +++ b/justfile @@ -27,6 +27,10 @@ lint: cargo clippy --locked --all-targets --all-features -- -D warnings cargo clippy --locked --all-targets --no-default-features -- -D warnings +# Compare the parse benchmark against a revision, with FORGE_SPEC set to a document +bench-compare rev="main" pairs="12": + benches/compare.sh {{rev}} {{pairs}} + # Check that no other tool's extension is named outside the compatibility layer boundary: cargo test --locked --test boundary From 9f47d32858eed048efdcbd37dbc25ecd260c19d7 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 11:12:20 -0400 Subject: [PATCH 09/21] docs: record the measured performance of RFC 0001 and where it went --- rfcs/0001-metadata-resolution-layer.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 2b6bab71c..c94a91d5a 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -148,9 +148,11 @@ The implementation was checked against the unmodified engine on the released agg - **Generated output.** `forge --target ts` on the aggregate writes the same 3,381 files, byte for byte (`diff -r`). - **The model.** The full model dump (the repo's own `tests/wasm/dump.rs`: every group, method, availability, hidden flag, confirmation, extension and field name) is identical between the old and new engines: 197,702 lines, covering 3,021 availability values, 1,259 hidden flags, 217 confirmations and 4,695 extension entries. The generated TypeScript consumes none of those four, which is why the dump, not the output diff, is what proves them. - **Across the plugin boundary.** `tests/wasm.rs`, including the ignored `bench` on the aggregate, reports identical output and dump, native versus WASM, for 1,317 groups and 3,381 files; `wit_is_current` holds with the regenerated WIT. -- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 438 tests of the native suite; with compat on, 486 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. +- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 439 tests of the native suite; with compat on, 489 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. - **The checks can fail.** Breaking the native-wins rule fails 8 compat tests; planting a vendor name in a doc comment fails the boundary test, naming the file and line. -- **Performance** (parse and link of the aggregate, `cargo bench --bench parse`, six alternating runs against the unmodified code): fastest 40.8 ms against 40.3 ms (+1.2%), median 42.2 ms against 41.5 ms (+1.6%), peak memory 69.13 MB against 68.75 MB (+0.55%), the same peak allocation count. The cost is the dispatch of the ~15k extension keys through the native table and the adapters, and the provenance kept on each operation's definition. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is about 0.1%. +- **Performance.** Measured with `benches/compare.sh` (`just bench-compare`): parse and link of the aggregate, paired against the unmodified engine, each pair run base–new–new–base so that drift in the machine's speed cancels, and pairs in which the machine changed speed left out. The working tree is 0–1% slower (about +0.45 ms of 41.8 ms, standard error 0.17 ms, on a machine at full speed; −0.04 ms, standard error 0.28, on the same machine throttled). Peak memory is +0.55%, with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. + - *Where it went.* Profiling (samply, with line tables, attributing inlined frames) found no hot spot of the layer's own: most of the difference is LLVM inlining parts of serde_json's key loop into `SchemaObject::read_object` and laying the code out differently, which moves with any change. Three things were measured and kept: each table turns away keys outside its prefix (`x-forge-`, `x-fern-`, `x-stainless-`) before matching, and only `x-` keys are asked about, so a skipped key costs one compare; and a `Hit` carries only its field and slot, the key's name looked up by slot when an error needs it, so the reader's per-key result fits in registers (16 bytes, as before, not 24). + - *Ruling things out.* Unpaired, sequential runs had suggested +1.5–1.9%; that was the machine warming up through the session, which the ABBA order removes. A single run of either binary differs from the next by about as much as the change measured here, so a smaller difference needs more pairs, not a better single run. ## Release shape From 74a1453d5a3c1f0641cadad5b6a2c057acfa43ba Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 12:29:11 -0400 Subject: [PATCH 10/21] feat: rename x-forge-method to x-forge-method-name, add x-forge-sensitive - x-forge-method-name, in line with the other -name keys. x-forge-method never shipped, so it gets no alias. - x-forge-sensitive replaces x-sensitive, so every native key begins with x-forge-. x-sensitive stays readable as a deprecated native alias: a new Tier (native, deprecated, compat) decides which key's value is kept, and the alias works with compat off. - tests/boundary.rs also catches vendor names spelled as identifiers (x_fern_...), and the five test names that still had them are renamed. Output and the model dump of the aggregate are unchanged. --- packages/forge/src/index.ts | 2 +- src/compat/fern.rs | 7 +- src/compat/mod.rs | 3 +- src/compat/stainless.rs | 3 +- src/lib.rs | 4 +- src/link.rs | 4 +- src/link/openapi.rs | 60 +++++++------ src/metadata/mod.rs | 89 ++++++++++++++---- src/plugin/ts/tests.rs | 6 +- src/types.rs | 12 +-- tests/boundary.rs | 8 +- tests/cli.rs | 2 +- tests/compat/common.rs | 4 +- tests/compat/fern.rs | 22 ++--- tests/compat/native_first.rs | 40 +++++---- tests/compat/stainless.rs | 2 +- tests/parse/aliases.rs | 67 +++++++------- tests/parse/bodies.rs | 28 +++--- tests/parse/common.rs | 4 +- tests/parse/document.rs | 4 +- tests/parse/extensions.rs | 20 ++--- tests/parse/groups.rs | 64 ++++++------- tests/parse/headers.rs | 56 ++++++------ tests/parse/methods.rs | 65 ++++++++------ tests/parse/models.rs | 38 ++++---- tests/parse/requests.rs | 140 ++++++++++++++--------------- tests/parse/responses.rs | 12 +-- tests/parse/types/arrays.rs | 4 +- tests/parse/types/enums.rs | 2 +- tests/parse/types/intersections.rs | 4 +- tests/parse/types/nulls.rs | 8 +- tests/parse/types/objects.rs | 61 +++++++++++-- tests/parse/types/refs.rs | 24 ++--- tests/parse/types/scalars.rs | 6 +- tests/parse/types/unions.rs | 8 +- tests/wasm.rs | 22 ++--- 36 files changed, 524 insertions(+), 381 deletions(-) diff --git a/packages/forge/src/index.ts b/packages/forge/src/index.ts index 983a4bb14..d40d60c63 100644 --- a/packages/forge/src/index.ts +++ b/packages/forge/src/index.ts @@ -267,7 +267,7 @@ export interface Field { * though the same model's field appears in responses: `readOnly`. */ readonly readOnly: boolean; - /** Whether the value is a secret, such as a password or a token, to keep out of logs: `x-sensitive`. */ + /** Whether the value is a secret, such as a password or a token, to keep out of logs: `x-forge-sensitive`. */ readonly sensitive: boolean; /** The `default` of the property's schema, or undefined if it has none. */ readonly default: Json | undefined; diff --git a/src/compat/fern.rs b/src/compat/fern.rs index ccb5707ca..fe7358fdf 100644 --- a/src/compat/fern.rs +++ b/src/compat/fern.rs @@ -70,18 +70,19 @@ pub(super) fn schema(key: &str) -> Option> { #[cfg(test)] mod tests { use super::*; + use crate::metadata::Tier; #[test] fn each_key_is_read_as_itself_and_as_not_native() { for key in [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY] { let hit = definition(key).unwrap_or_else(|| panic!("{key} is not a definition key")); - assert!(!hit.is_native(), "{key}"); + assert_eq!(hit.tier, Tier::Compat, "{key}"); } let hit = parameter(PARAMETER_NAME).unwrap(); - assert!(!hit.is_native(), "{PARAMETER_NAME}"); + assert_eq!(hit.tier, Tier::Compat, "{PARAMETER_NAME}"); for key in [TYPE_NAME, PROPERTY_NAME] { let hit = schema(key).unwrap_or_else(|| panic!("{key} is not a schema key")); - assert!(!hit.is_native(), "{key}"); + assert_eq!(hit.tier, Tier::Compat, "{key}"); } } diff --git a/src/compat/mod.rs b/src/compat/mod.rs index 555f2d7cf..48a6a6e42 100644 --- a/src/compat/mod.rs +++ b/src/compat/mod.rs @@ -65,6 +65,7 @@ pub(crate) fn schema_name(n: u8) -> &'static str { mod tests { use super::*; use crate::metadata::COMPAT_SLOTS; + use crate::metadata::Tier; /// Asserts that each key in `names` is read by `read` as a key that is /// not native, whose slot `name` names it by. @@ -72,7 +73,7 @@ mod tests { fn read_as_itself(names: &[&'static str], read: fn(&str) -> Option>, name: fn(u8) -> &'static str) { for &key in names { let hit = read(key).unwrap_or_else(|| panic!("{key} is not read")); - assert!(!hit.is_native(), "{key}"); + assert_eq!(hit.tier, Tier::Compat, "{key}"); assert_eq!(name(hit.slot - COMPAT_SLOTS), key); } } diff --git a/src/compat/stainless.rs b/src/compat/stainless.rs index 90f9dc265..320957172 100644 --- a/src/compat/stainless.rs +++ b/src/compat/stainless.rs @@ -31,11 +31,12 @@ pub(super) fn schema(key: &str) -> Option> { #[cfg(test)] mod tests { use super::*; + use crate::metadata::Tier; #[test] fn the_skip_is_read_on_a_schema_as_a_boolean_or_targets_and_not_native() { let hit = schema(SKIP).unwrap(); - assert!(!hit.is_native(), "{SKIP}"); + assert_eq!(hit.tier, Tier::Compat, "{SKIP}"); assert!(matches!(hit.field, SchemaField::Ignore(BoolFormat::BoolOrTargets))); } diff --git a/src/lib.rs b/src/lib.rs index 3895b7e5b..bc07c7d84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -253,7 +253,7 @@ pub struct Method<'f> { impl<'f> Method<'f> { /// Returns the name of the method, which is unique within its group. /// - /// Corresponds to the `x-forge-method` extension of the + /// Corresponds to the `x-forge-method-name` extension of the /// operation, or of the alias the method comes from. An operation or /// alias without one, or with an empty one, is not a method, and one /// with no letters or digits is an error. Two methods in a group with @@ -497,7 +497,7 @@ impl<'f> Method<'f> { /// /// An extension is a key of the /// [Operation Object](https://spec.openapis.org/oas/latest.html#operation-object) - /// that starts with `x-`. Those forge reads, `x-forge-method`, + /// that starts with `x-`. Those forge reads, `x-forge-method-name`, /// `x-forge-group`, `x-forge-ignore`, `x-forge-availability`, /// `x-forge-hidden`, `x-forge-require-confirmation` and /// `x-forge-aliases`, are left out, and so are the keys the diff --git a/src/link.rs b/src/link.rs index 84072a4cd..197ab42da 100644 --- a/src/link.rs +++ b/src/link.rs @@ -2002,11 +2002,11 @@ impl<'d> Builder<'d> { /// Returns whether `schema` is read-only and sensitive, as a field /// gives them: whether it or any schema along its chain of `$ref`s has - /// `readOnly: true`, and `x-sensitive: true`. + /// `readOnly: true`, and `x-forge-sensitive: true`. /// /// A `readOnly` next to a `$ref` counts from OpenAPI 3.1, and is /// ignored in 3.0, as every keyword next to a `$ref` is. An - /// `x-sensitive` next to a `$ref` counts in every version, since tools + /// `x-forge-sensitive` next to a `$ref` counts in every version, since tools /// commonly honour extensions there. The chain stops at a `$ref` that /// does not point to a schema, which reading the schema's type /// reports, and after 32 `$ref`s, which lead back to themselves. diff --git a/src/link/openapi.rs b/src/link/openapi.rs index 0a99e81a5..05b4867ce 100644 --- a/src/link/openapi.rs +++ b/src/link/openapi.rs @@ -29,7 +29,7 @@ use crate::Name; use crate::arena::{Id, List, Span, Str, Strings}; use crate::json::{self, Json}; use crate::metadata::{ - self, BoolFormat, DefinitionField, DocumentField, GroupFormat, Hit, ParameterField, SchemaField, + self, BoolFormat, DefinitionField, DocumentField, GroupFormat, Hit, ParameterField, SchemaField, Tier, }; /// An OpenAPI document: the fields of the OpenAPI Object at its root, and @@ -241,22 +241,22 @@ pub(super) struct Operation { } /// A value an extension gives, and the key it came from, so that an error can -/// name the key the document wrote. A native key's value is kept over any -/// other's, whatever order they are written in. +/// name the key the document wrote. The value of the strongest [`Tier`] of +/// key is kept, whatever order the keys are written in. #[derive(Default)] pub(super) struct Val { pub(super) value: T, /// The slot of the key that gave the value, which names it. It means /// nothing if no key gave one. pub(super) slot: u8, - native: bool, + tier: Tier, } impl Val { - /// Keeps `value`, which `hit` gave, unless a native key gave the value - /// held and `hit` is not native. + /// Keeps `value`, which `hit` gave, unless a key of a stronger tier + /// gave the value held. fn set(&mut self, hit: &Hit, value: T) { - if takes(hit, &mut self.native) { + if takes(hit, &mut self.tier) { self.value = value; self.slot = hit.slot; } @@ -264,11 +264,13 @@ impl Val { } /// Reports whether a value from the key of `hit` replaces the one read so -/// far, which came from a native key if `native` is set, and records where -/// the value kept came from. -fn takes(hit: &Hit, native: &mut bool) -> bool { - if hit.is_native() || !*native { - *native = hit.is_native(); +/// far, which came from a key of tier `tier`, and records the tier of the +/// value kept. Keys of the same tier that say the same thing are different +/// keys of the same object, which no table has, so equal tiers do not +/// happen; were they to, the last written would be kept. +fn takes(hit: &Hit, tier: &mut Tier) -> bool { + if hit.tier >= *tier { + *tier = hit.tier; return true; } false @@ -318,8 +320,8 @@ pub(super) struct Parameter { pub(super) content: Span<(Str, Schema)>, /// The name of the parameter's field, or empty for none. pub(super) field_name: Str, - /// Whether a native key gave `field_name`. - field_name_native: bool, + /// The tier of the key that gave `field_name`. + field_name_tier: Tier, } /// Where a parameter is sent: the `in` of a Parameter Object. @@ -434,8 +436,8 @@ pub(super) struct SchemaObject { /// `readOnly`: the value appears in responses, and a client should not /// send it. pub(super) read_only: bool, - /// Whether the schema is marked `x-sensitive: true`: the value is a - /// secret, such as a password or a token. + /// Whether the schema is marked `x-forge-sensitive: true`: the value is + /// a secret, such as a password or a token. pub(super) sensitive: bool, /// The name of the model, for a schema in `components.schemas`, or /// empty for none. @@ -445,11 +447,12 @@ pub(super) struct SchemaObject { /// Whether a property's schema is marked to be left out: it makes no /// field. pub(super) ignore: bool, - /// Whether a native key gave `model_name`, `field_name` and `ignore`, - /// each, so that no other key replaces it. - model_name_native: bool, - field_name_native: bool, - ignore_native: bool, + /// The tier of the key that gave each of `model_name`, `field_name`, + /// `ignore` and `sensitive`, so that no weaker key replaces it. + model_name_tier: Tier, + field_name_tier: Tier, + ignore_tier: Tier, + sensitive_tier: Tier, } /// A value of `type` in a Schema Object. @@ -1625,7 +1628,7 @@ impl ReadObject for Parameter { match hit.field { ParameterField::Name => { let name = map.next_value_seed(seed::(doc))?; - if takes(&hit, &mut param.field_name_native) { + if takes(&hit, &mut param.field_name_tier) { param.field_name = name; } } @@ -1771,23 +1774,28 @@ impl ReadObject for SchemaObject { match hit.field { SchemaField::ModelName => { let name = map.next_value_seed(seed::(doc))?; - if takes(&hit, &mut schema.model_name_native) { + if takes(&hit, &mut schema.model_name_tier) { schema.model_name = name; } } SchemaField::PropertyName => { let name = map.next_value_seed(seed::(doc))?; - if takes(&hit, &mut schema.field_name_native) { + if takes(&hit, &mut schema.field_name_tier) { schema.field_name = name; } } SchemaField::Ignore(format) => { let ignore = read_bool(&mut map, format)?; - if takes(&hit, &mut schema.ignore_native) { + if takes(&hit, &mut schema.ignore_tier) { schema.ignore = ignore; } } - SchemaField::Sensitive => schema.sensitive = map.next_value()?, + SchemaField::Sensitive => { + let sensitive = map.next_value()?; + if takes(&hit, &mut schema.sensitive_tier) { + schema.sensitive = sensitive; + } + } } continue; } diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index 97c986388..ae40ba42c 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -21,9 +21,10 @@ use crate::Availability; /// [`definition`], since an alias cannot have one. pub(crate) const ALIASES: &str = "x-forge-aliases"; -/// What every native key begins with, but `x-sensitive`. A key without it is -/// turned away before it is matched against the table: most extensions in a -/// document are no key of any table, and this is the cheap way to say so. +/// What every native key begins with, but the deprecated `x-sensitive`. A key +/// without it is turned away before it is matched against the table: most +/// extensions in a document are no key of any table, and this is the cheap +/// way to say so. const PREFIX: &str = "x-forge-"; /// A key that says something about the object it is on. @@ -35,6 +36,9 @@ const PREFIX: &str = "x-forge-"; pub(crate) struct Hit { /// What the key says. pub(crate) field: F, + /// Which kind of key it is, which decides whose value is kept when + /// several keys say the same thing. + pub(crate) tier: Tier, /// The bit of the key in a set of the keys read from an object so far, /// which is how a key written twice is found, and the index of its name. /// Unique among the keys of one kind of object, native or not: the @@ -42,14 +46,48 @@ pub(crate) struct Hit { pub(crate) slot: u8, } +/// Which kind of key gave a value, from the weakest to the strongest. When +/// keys of different tiers say the same thing about an object, the value of +/// the strongest is kept, whatever order they are written in. +#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)] +pub(crate) enum Tier { + /// No key has given a value yet. + #[default] + Unset, + /// A key a compatibility layer reads in place of a native one. + #[cfg_attr(not(any(feature = "compat", test)), expect(dead_code))] + Compat, + /// A native key that is kept working under an old name, in place of + /// the one that replaced it. + Deprecated, + /// A native key, under its current name. + Native, +} + /// The first slot of the keys that are not native, so that slots never /// collide with the native ones, which count up from zero. +#[cfg_attr(not(any(feature = "compat", test)), expect(dead_code))] pub(crate) const COMPAT_SLOTS: u8 = 32; impl Hit { /// Returns a native key, in slot `slot`, which is under 32. const fn native(field: F, slot: u8) -> Hit { - Hit { field, slot } + Hit { + field, + tier: Tier::Native, + slot, + } + } + + /// Returns a deprecated native key, in slot `slot`, which is under 32: + /// an old name of a native key, read only when the current one is not + /// written. + const fn deprecated(field: F, slot: u8) -> Hit { + Hit { + field, + tier: Tier::Deprecated, + slot, + } } /// Returns a key that is not native, which a compatibility layer @@ -59,6 +97,7 @@ impl Hit { pub(crate) const fn compat(field: F, n: u8) -> Hit { Hit { field, + tier: Tier::Compat, slot: COMPAT_SLOTS + n, } } @@ -69,15 +108,10 @@ impl Hit { pub(crate) fn after(self, n: u8) -> Hit { Hit { field: self.field, + tier: self.tier, slot: self.slot + n, } } - - /// Returns whether the key is native. A value from a native key is kept - /// over one from any other, whatever order they are written in. - pub(crate) const fn is_native(&self) -> bool { - self.slot < COMPAT_SLOTS - } } /// Returns the name in `names` of the key in `slot`, if it is a native one. @@ -157,7 +191,7 @@ pub(crate) fn definition(key: &str) -> Option> { return None; } Some(match key { - METHOD => Hit::native(DefinitionField::Method, 0), + METHOD_NAME => Hit::native(DefinitionField::Method, 0), GROUP => Hit::native(DefinitionField::Group(GroupFormat::Array), 1), IGNORE => Hit::native(DefinitionField::Ignore(BoolFormat::Bool), 2), AVAILABILITY => Hit::native(DefinitionField::Availability, 3), @@ -167,7 +201,7 @@ pub(crate) fn definition(key: &str) -> Option> { }) } -const METHOD: &str = "x-forge-method"; +const METHOD_NAME: &str = "x-forge-method-name"; const GROUP: &str = "x-forge-group"; const IGNORE: &str = "x-forge-ignore"; const AVAILABILITY: &str = "x-forge-availability"; @@ -176,15 +210,19 @@ const CONFIRMATION: &str = "x-forge-require-confirmation"; const PARAMETER_NAME: &str = "x-forge-parameter-name"; const MODEL_NAME: &str = "x-forge-model-name"; const PROPERTY_NAME: &str = "x-forge-property-name"; -const SENSITIVE: &str = "x-sensitive"; +const SENSITIVE: &str = "x-forge-sensitive"; +/// The old name of `x-forge-sensitive`, from before every native key began +/// with `x-forge-`. Deprecated: it is read only where `x-forge-sensitive` is +/// not written. +const DEPRECATED_SENSITIVE: &str = "x-sensitive"; const COMMANDS: &str = "x-forge-commands"; /// The names of the native keys of an operation or an alias, by slot. -pub(crate) const DEFINITION_NAMES: [&str; 6] = [METHOD, GROUP, IGNORE, AVAILABILITY, HIDDEN, CONFIRMATION]; +pub(crate) const DEFINITION_NAMES: [&str; 6] = [METHOD_NAME, GROUP, IGNORE, AVAILABILITY, HIDDEN, CONFIRMATION]; /// The names of the native keys of a Parameter Object, by slot. pub(crate) const PARAMETER_NAMES: [&str; 1] = [PARAMETER_NAME]; /// The names of the native keys of a Schema Object, by slot. -pub(crate) const SCHEMA_NAMES: [&str; 4] = [MODEL_NAME, PROPERTY_NAME, IGNORE, SENSITIVE]; +pub(crate) const SCHEMA_NAMES: [&str; 5] = [MODEL_NAME, PROPERTY_NAME, IGNORE, SENSITIVE, DEPRECATED_SENSITIVE]; /// The names of the native keys of the document, by slot. pub(crate) const DOCUMENT_NAMES: [&str; 1] = [COMMANDS]; @@ -208,7 +246,7 @@ pub(crate) fn parameter(key: &str) -> Option> { /// Returns what `key` says on a Schema Object, if it is a native key of one. pub(crate) fn schema(key: &str) -> Option> { // `x-sensitive` is the one native key outside the prefix. - if !key.starts_with(PREFIX) && key != SENSITIVE { + if !key.starts_with(PREFIX) && key != DEPRECATED_SENSITIVE { return None; } Some(match key { @@ -216,6 +254,7 @@ pub(crate) fn schema(key: &str) -> Option> { PROPERTY_NAME => Hit::native(SchemaField::PropertyName, 1), IGNORE => Hit::native(SchemaField::Ignore(BoolFormat::Bool), 2), SENSITIVE => Hit::native(SchemaField::Sensitive, 3), + DEPRECATED_SENSITIVE => Hit::deprecated(SchemaField::Sensitive, 4), _ => return None, }) } @@ -253,7 +292,7 @@ mod tests { fn native_keys() -> [&'static [&'static str]; 4] { [ &[ - "x-forge-method", + "x-forge-method-name", "x-forge-group", "x-forge-ignore", "x-forge-availability", @@ -265,6 +304,7 @@ mod tests { "x-forge-model-name", "x-forge-property-name", "x-forge-ignore", + "x-forge-sensitive", "x-sensitive", ], &["x-forge-commands"], @@ -277,7 +317,7 @@ mod tests { fn read_as_itself(keys: &[&str], names: &[&'static str], read: fn(&str) -> Option>) { for &key in keys { let hit = read(key).unwrap_or_else(|| panic!("{key} is not read")); - assert!(hit.is_native(), "{key}"); + assert_ne!(hit.tier, Tier::Compat, "{key}"); assert_eq!(native_name(names, hit.slot), Some(key)); } assert_eq!(keys.len(), names.len(), "every name is a key that is read"); @@ -292,6 +332,18 @@ mod tests { read_as_itself(documents, &DOCUMENT_NAMES, document); } + #[test] + fn x_sensitive_is_a_deprecated_name_of_x_forge_sensitive() { + let (current, old) = (schema("x-forge-sensitive").unwrap(), schema("x-sensitive").unwrap()); + + assert!(matches!( + (current.field, old.field), + (SchemaField::Sensitive, SchemaField::Sensitive) + )); + assert_eq!((current.tier, old.tier), (Tier::Native, Tier::Deprecated)); + assert!(Tier::Native > Tier::Deprecated && Tier::Deprecated > Tier::Compat && Tier::Compat > Tier::Unset); + } + #[test] fn a_slot_past_the_native_ones_has_no_native_name() { assert_eq!(native_name(&DEFINITION_NAMES, COMPAT_SLOTS), None); @@ -320,6 +372,7 @@ mod tests { "x-custom", "summary", "x-forge-nope", + "x-forge-method", ] { assert!(definition(key).is_none(), "{key}"); assert!(parameter(key).is_none(), "{key}"); diff --git a/src/plugin/ts/tests.rs b/src/plugin/ts/tests.rs index bf7b8c80c..60dc043b5 100644 --- a/src/plugin/ts/tests.rs +++ b/src/plugin/ts/tests.rs @@ -370,11 +370,11 @@ fn models() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["pet-store", "list_all"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["pet-store", "list_all"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/pet_owner"}}}}}}}, - "/b": {"get": {"x-forge-group": ["pet-store"], "x-forge-method": "get", + "/b": {"get": {"x-forge-group": ["pet-store"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/2fa"}}}}}}}, - "/c": {"get": {"x-forge-group": ["other"], "x-forge-method": "get", + "/c": {"get": {"x-forge-group": ["other"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/2fa"}}}}}}} }, "components": {"schemas": {"pet_owner": {"type": "string"}, "2fa": {"type": "string"}}} diff --git a/src/types.rs b/src/types.rs index 2386d8467..9d5c26b94 100644 --- a/src/types.rs +++ b/src/types.rs @@ -411,17 +411,19 @@ impl<'f> Field<'f> { /// Reports whether the field holds a secret, such as a password or a /// token, which a client should mask when it shows it. /// - /// Corresponds to the `x-sensitive: true` extension on the property's - /// schema, or on any schema along its chain of `$ref`s. Unlike - /// `readOnly`, an `x-sensitive` next to a `$ref` counts in every + /// Corresponds to the `x-forge-sensitive: true` extension on the property's + /// schema, or on any schema along its chain of `$ref`s. Its old name, + /// `x-sensitive`, is deprecated and still read on a schema without + /// `x-forge-sensitive`. Unlike + /// `readOnly`, an `x-forge-sensitive` next to a `$ref` counts in every /// version of OpenAPI, since tools commonly honour extensions there. A /// value that is not a boolean is an error, as it is for a schema's /// `x-forge-ignore` and an operation's `x-forge-hidden`. /// /// A field for a parameter, whether in the request or in /// [`Method::headers`](crate::Method::headers), is sensitive when the - /// parameter's schema is, in the same way: `x-sensitive` next to its - /// `$ref` or along its chain. An `x-sensitive` on the Parameter Object + /// parameter's schema is, in the same way: `x-forge-sensitive` next to its + /// `$ref` or along its chain. An `x-forge-sensitive` on the Parameter Object /// itself, rather than its schema, is ignored. The `body` field of a /// request, and a path template placeholder that no parameter /// declares, are never sensitive. diff --git a/tests/boundary.rs b/tests/boundary.rs index c91c59d13..95b048d48 100644 --- a/tests/boundary.rs +++ b/tests/boundary.rs @@ -13,6 +13,12 @@ use std::path::{Path, PathBuf}; /// What the extensions of each tool forge reads begin with. const VENDORS: [&str; 2] = ["x-fern", "x-stainless"]; +/// Returns whether `line` names `vendor`, as written or as an identifier +/// spells it, with `_` for `-`, as in a test named after a key. +fn names(line: &str, vendor: &str) -> bool { + line.contains(vendor) || line.contains(&vendor.replace('-', "_")) +} + /// Where those names may be: the layer, its tests, and this file, which /// writes them to look for them. const ALLOWED: [&str; 3] = ["src/compat/", "tests/compat/", "tests/boundary.rs"]; @@ -73,7 +79,7 @@ fn no_extension_of_another_tool_is_named_outside_the_compatibility_layer() { continue; } for (i, line) in text.lines().enumerate() { - if VENDORS.iter().any(|vendor| line.contains(vendor)) { + if VENDORS.iter().any(|vendor| names(line, vendor)) { found.push(format!("{path}:{}: {}", i + 1, line.trim())); } } diff --git a/tests/cli.rs b/tests/cli.rs index f59b30727..bcb1ea4df 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -6,7 +6,7 @@ use std::process::{Command, Output, Stdio}; /// A document with one method, `a.get`. const SPEC: &str = r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok"}}}}} }"#; diff --git a/tests/compat/common.rs b/tests/compat/common.rs index 4649783ea..86c6b96c4 100644 --- a/tests/compat/common.rs +++ b/tests/compat/common.rs @@ -23,7 +23,7 @@ pub fn parse_err(json: &str) -> String { /// Returns an OpenAPI 3.0.3 document with one operation, `GET /a`, that has /// the members `keys`, written as the inside of a JSON object, each followed -/// by a comma, such as `"x-forge-method": "get",`. +/// by a comma, such as `"x-forge-method-name": "get",`. pub fn operation_with(keys: &str) -> String { format!( r#"{{"openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, @@ -36,7 +36,7 @@ pub fn operation_with(keys: &str) -> String { pub fn responding_with(schema: &str, schemas: &str) -> String { format!( r#"{{"openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}}, "components": {{"schemas": {schemas}}}}}"# ) diff --git a/tests/compat/fern.rs b/tests/compat/fern.rs index 3f7eff586..a710822fd 100644 --- a/tests/compat/fern.rs +++ b/tests/compat/fern.rs @@ -9,7 +9,9 @@ fn method_group_and_availability_are_read_as_native() { &operation_with( r#""x-fern-sdk-group-name": ["accounts"], "x-fern-sdk-method-name": "list", "x-fern-availability": "beta","#, ), - &operation_with(r#""x-forge-group": ["accounts"], "x-forge-method": "list", "x-forge-availability": "beta","#), + &operation_with( + r#""x-forge-group": ["accounts"], "x-forge-method-name": "list", "x-forge-availability": "beta","#, + ), ); } @@ -21,7 +23,7 @@ fn every_availability_is_read() { r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "{availability}","# )), &operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "{availability}","# + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "{availability}","# )), ); } @@ -31,7 +33,7 @@ fn every_availability_is_read() { fn a_group_written_as_a_string_is_split_on_dots() { assert_same( &operation_with(r#""x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get","#), - &operation_with(r#""x-forge-group": ["a", "b", "c"], "x-forge-method": "get","#), + &operation_with(r#""x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get","#), ); } @@ -39,7 +41,7 @@ fn a_group_written_as_a_string_is_split_on_dots() { fn a_group_written_as_an_array_is_not_split() { assert_same( &operation_with(r#""x-fern-sdk-group-name": ["a.b", "c"], "x-fern-sdk-method-name": "get","#), - &operation_with(r#""x-forge-group": ["a.b", "c"], "x-forge-method": "get","#), + &operation_with(r#""x-forge-group": ["a.b", "c"], "x-forge-method-name": "get","#), ); } @@ -65,7 +67,7 @@ fn a_group_that_is_neither_a_string_nor_an_array_is_an_error() { fn ignore_makes_no_method() { assert_same( &operation_with(r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": true,"#), - &operation_with(r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": true,"#), + &operation_with(r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": true,"#), ); assert_eq!( parse(&operation_with( @@ -81,7 +83,7 @@ fn ignore_makes_no_method() { fn ignore_set_to_false_keeps_the_method() { assert_same( &operation_with(r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": false,"#), - &operation_with(r#""x-forge-group": ["a"], "x-forge-method": "get","#), + &operation_with(r#""x-forge-group": ["a"], "x-forge-method-name": "get","#), ); } @@ -89,7 +91,7 @@ fn ignore_set_to_false_keeps_the_method() { fn a_parameter_name_is_read_as_native() { let parameters = |key: &str| { operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method": "list", + r#""x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{{"name": "q", "in": "query", "{key}": "query", "schema": {{"type": "string"}}}}],"# )) }; @@ -149,7 +151,7 @@ fn the_keys_of_an_alias_are_read_too() { ), &alias( "x-forge-group", - "x-forge-method", + "x-forge-method-name", "x-forge-availability", "x-forge-ignore", ), @@ -178,7 +180,7 @@ fn a_key_that_is_read_is_not_an_extension_of_the_method() { #[test] fn a_key_that_is_not_read_stays_an_extension_of_the_method() { let forge = parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-fern-audiences": ["internal"], "x-fern-pagination": {"offset": "o"},"#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-fern-audiences": ["internal"], "x-fern-pagination": {"offset": "o"},"#, )); let method = forge.groups().next().unwrap().methods().next().unwrap(); @@ -262,7 +264,7 @@ fn a_key_written_twice_is_an_error_naming_it() { fn the_vendor_keys_of_a_kind_of_object_are_read_only_there() { // A name key on an operation, or a method key on a schema, says nothing. let forge = parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-fern-property-name": "p", "x-fern-type-name": "T", + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-fern-property-name": "p", "x-fern-type-name": "T", "x-fern-parameter-name": "q","#, )); let method = forge.groups().next().unwrap().methods().next().unwrap(); diff --git a/tests/compat/native_first.rs b/tests/compat/native_first.rs index 9e97fe767..f26bde3f2 100644 --- a/tests/compat/native_first.rs +++ b/tests/compat/native_first.rs @@ -17,13 +17,13 @@ fn native_wins(native: &str, compat: &str, expected: &str) { #[test] fn the_native_method_wins() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method": "native","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "native","#, r#""x-fern-sdk-method-name": "vendor","#, - r#""x-forge-group": ["a"], "x-forge-method": "native","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "native","#, ); assert!( describe(&parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method": "native", "x-fern-sdk-method-name": "vendor","# + r#""x-forge-group": ["a"], "x-forge-method-name": "native", "x-fern-sdk-method-name": "vendor","# ))) .contains("method native") ); @@ -32,36 +32,36 @@ fn the_native_method_wins() { #[test] fn the_native_group_wins() { native_wins( - r#""x-forge-method": "get", "x-forge-group": ["native"],"#, + r#""x-forge-method-name": "get", "x-forge-group": ["native"],"#, r#""x-fern-sdk-group-name": "vendor.group","#, - r#""x-forge-method": "get", "x-forge-group": ["native"],"#, + r#""x-forge-method-name": "get", "x-forge-group": ["native"],"#, ); } #[test] fn the_native_availability_wins_and_an_invalid_compat_one_is_not_checked() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "beta","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, r#""x-fern-availability": "ga","#, - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "beta","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, ); } #[test] fn a_native_ignore_of_false_keeps_the_method_a_compat_one_would_drop() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": false,"#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": false,"#, r#""x-fern-ignore": true,"#, - r#""x-forge-group": ["a"], "x-forge-method": "get","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, ); } #[test] fn a_native_ignore_of_true_drops_the_method_a_compat_one_would_keep() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": true,"#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": true,"#, r#""x-fern-ignore": false,"#, - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-ignore": true,"#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": true,"#, ); } @@ -69,7 +69,7 @@ fn a_native_ignore_of_true_drops_the_method_a_compat_one_would_keep() { fn the_native_parameter_name_wins() { let parameter = |keys: &str| { operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method": "list", + r#""x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{{"name": "q", "in": "query", {keys} "schema": {{"type": "string"}}}}],"# )) }; @@ -142,10 +142,12 @@ fn both_keys_with_the_same_value_are_the_same_as_one() { assert_same( &operation_with( r#""x-forge-group": ["a", "b"], "x-fern-sdk-group-name": "a.b", - "x-forge-method": "get", "x-fern-sdk-method-name": "get", + "x-forge-method-name": "get", "x-fern-sdk-method-name": "get", "x-forge-availability": "beta", "x-fern-availability": "beta","#, ), - &operation_with(r#""x-forge-group": ["a", "b"], "x-forge-method": "get", "x-forge-availability": "beta","#), + &operation_with( + r#""x-forge-group": ["a", "b"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, + ), ); } @@ -154,7 +156,7 @@ fn each_primitive_is_resolved_on_its_own() { // The group is native and the method and availability are not. assert_same( &operation_with(r#""x-forge-group": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "beta","#), - &operation_with(r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "beta","#), + &operation_with(r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#), ); } @@ -165,7 +167,7 @@ fn a_compat_value_of_the_wrong_type_is_an_error_even_when_a_native_key_wins() { r#""x-fern-availability": 1, "x-forge-availability": "beta","#, ] { let err = parse_err(&operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method": "get", {keys}"# + r#""x-forge-group": ["a"], "x-forge-method-name": "get", {keys}"# ))); assert!(err.contains("invalid type"), "{keys}: {err}"); @@ -181,7 +183,9 @@ fn a_native_key_written_twice_is_an_error_naming_it() { #[test] fn a_native_group_written_as_a_string_is_an_error() { - let err = parse_err(&operation_with(r#""x-forge-group": "a.b", "x-forge-method": "get","#)); + let err = parse_err(&operation_with( + r#""x-forge-group": "a.b", "x-forge-method-name": "get","#, + )); assert!(err.contains("an array of strings"), "{err}"); } @@ -189,7 +193,7 @@ fn a_native_group_written_as_a_string_is_an_error() { #[test] fn an_error_names_the_native_key_when_the_native_key_gave_the_value() { let err = parse_err(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-forge-availability": "ga","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "ga","#, )); assert!(err.contains(r#"GET /a: x-forge-availability "ga" is not"#), "{err}"); diff --git a/tests/compat/stainless.rs b/tests/compat/stainless.rs index 496a2124a..7f4cd1a4c 100644 --- a/tests/compat/stainless.rs +++ b/tests/compat/stainless.rs @@ -67,7 +67,7 @@ fn a_skip_written_twice_is_an_error_naming_it() { #[test] fn a_skip_on_an_operation_says_nothing_and_stays_an_extension() { let forge = parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method": "get", "x-stainless-skip": true,"#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-stainless-skip": true,"#, )); let method = forge.groups().next().unwrap().methods().next().unwrap(); diff --git a/tests/parse/aliases.rs b/tests/parse/aliases.rs index c36579065..bcb6c580b 100644 --- a/tests/parse/aliases.rs +++ b/tests/parse/aliases.rs @@ -10,7 +10,7 @@ fn aliased(aliases: &str, fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a/{{id}}/status": {{"patch": {{{fields} - "x-forge-group": ["a", "status"], "x-forge-method": "edit", + "x-forge-group": ["a", "status"], "x-forge-method-name": "edit", "x-forge-aliases": {aliases}, "summary": "Edit status", "description": "Changes the status.", "parameters": [{{"name": "id", "in": "path", "required": true, "schema": {{"type": "string"}}}}], @@ -39,8 +39,8 @@ fn methods(forge: &Forge) -> Vec { } const PAUSE_AND_TERMINATE: &str = r#"[ - {"x-forge-group": ["a"], "x-forge-method": "pause"}, - {"x-forge-group": ["a"], "x-forge-method": "terminate"} + {"x-forge-group": ["a"], "x-forge-method-name": "pause"}, + {"x-forge-group": ["a"], "x-forge-method-name": "terminate"} ]"#; #[test] @@ -77,10 +77,10 @@ fn aliases_share_the_rest_of_the_operation() { fn each_alias_has_its_own_availability_hidden_confirmation_and_extensions() { let forge = parse(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method": "pause", + {"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-forge-availability": "generally-available", "x-forge-hidden": true, "x-forge-params": {"status": {"default": "pause", "hidden": true}}}, - {"x-forge-group": ["a"], "x-forge-method": "terminate", + {"x-forge-group": ["a"], "x-forge-method-name": "terminate", "x-forge-availability": "beta", "x-forge-require-confirmation": "Sure?", "x-a": 1, "x-b": 2} ]"#, "", @@ -111,7 +111,7 @@ fn each_alias_has_its_own_availability_hidden_confirmation_and_extensions() { #[test] fn alias_does_not_fall_back_to_the_operation() { let forge = parse(&aliased( - r#"[{"x-forge-group": ["a"], "x-forge-method": "pause"}]"#, + r#"[{"x-forge-group": ["a"], "x-forge-method-name": "pause"}]"#, r#""x-forge-availability": "beta", "x-forge-hidden": true, "x-forge-require-confirmation": "Sure?", "x-forge-params": {"status": {}},"#, )); @@ -128,10 +128,10 @@ fn alias_does_not_fall_back_to_the_operation() { fn alias_without_a_group_or_name_is_not_a_method() { let forge = parse(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method": "pause"}, + {"x-forge-group": ["a"], "x-forge-method-name": "pause"}, {"x-forge-group": ["a"]}, - {"x-forge-method": "resume"}, - {"x-forge-group": [], "x-forge-method": "restart"} + {"x-forge-method-name": "resume"}, + {"x-forge-group": [], "x-forge-method-name": "restart"} ]"#, "", )); @@ -142,7 +142,7 @@ fn alias_without_a_group_or_name_is_not_a_method() { #[test] fn element_that_is_not_an_object_is_ignored() { let forge = parse(&aliased( - r#"["pause", null, 1, true, ["a"], {"x-forge-group": ["a"], "x-forge-method": "pause"}]"#, + r#"["pause", null, 1, true, ["a"], {"x-forge-group": ["a"], "x-forge-method-name": "pause"}]"#, "", )); @@ -158,7 +158,10 @@ fn empty_aliases_make_no_method() { #[test] fn aliases_that_are_not_an_array_are_an_error() { - let err = parse_err(&aliased(r#"{"x-forge-group": ["a"], "x-forge-method": "pause"}"#, "")); + let err = parse_err(&aliased( + r#"{"x-forge-group": ["a"], "x-forge-method-name": "pause"}"#, + "", + )); assert!(err.contains("an array of aliases"), "{err}"); } @@ -169,11 +172,11 @@ fn alias_and_another_method_with_equal_names_are_an_error() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "pause", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "pause", "responses": {"204": {"description": "ok"}}}}, "/b": {"post": {"x-forge-aliases": [ - {"x-forge-group": ["a"], "x-forge-method": "resume"}, - {"x-forge-group": ["a"], "x-forge-method": "Pause"} + {"x-forge-group": ["a"], "x-forge-method-name": "resume"}, + {"x-forge-group": ["a"], "x-forge-method-name": "Pause"} ], "responses": {"204": {"description": "ok"}}}} } }"#, @@ -189,8 +192,8 @@ fn alias_and_another_method_with_equal_names_are_an_error() { fn two_aliases_with_equal_names_are_an_error() { let err = parse_err(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method": "pause"}, - {"x-forge-group": ["a"], "x-forge-method": "pause"} + {"x-forge-group": ["a"], "x-forge-method-name": "pause"}, + {"x-forge-group": ["a"], "x-forge-method-name": "pause"} ]"#, "", )); @@ -204,7 +207,7 @@ fn two_aliases_with_equal_names_are_an_error() { #[test] fn alias_group_name_without_letters_is_an_error_naming_the_alias() { let err = parse_err(&aliased( - r#"[{"x-forge-group": ["a", "", "b"], "x-forge-method": "pause"}]"#, + r#"[{"x-forge-group": ["a", "", "b"], "x-forge-method-name": "pause"}]"#, "", )); @@ -217,7 +220,7 @@ fn alias_group_name_without_letters_is_an_error_naming_the_alias() { #[test] fn alias_availability_is_checked() { let err = parse_err(&aliased( - r#"[1, {"x-forge-group": ["a"], "x-forge-method": "pause", "x-forge-availability": "ga"}]"#, + r#"[1, {"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-forge-availability": "ga"}]"#, "", )); @@ -230,11 +233,11 @@ fn alias_availability_is_checked() { #[test] fn repeated_key_forge_reads_in_an_alias_is_an_error() { let err = parse_err(&aliased( - r#"[{"x-forge-method": "pause", "x-forge-method": "resume"}]"#, + r#"[{"x-forge-method-name": "pause", "x-forge-method-name": "resume"}]"#, "", )); - assert!(err.contains("duplicate field `x-forge-method`"), "{err}"); + assert!(err.contains("duplicate field `x-forge-method-name`"), "{err}"); } #[test] @@ -248,8 +251,8 @@ fn ignored_operation_still_has_its_aliases() { fn ignored_alias_is_not_a_method() { let forge = parse(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method": "pause", "x-forge-ignore": true}, - {"x-forge-group": ["a"], "x-forge-method": "terminate", "x-forge-ignore": false} + {"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-forge-ignore": true}, + {"x-forge-group": ["a"], "x-forge-method-name": "terminate", "x-forge-ignore": false} ]"#, "", )); @@ -260,8 +263,8 @@ fn ignored_alias_is_not_a_method() { #[test] fn aliases_are_not_extensions() { let forge = parse(&aliased( - r#"[{"x-forge-group": ["a"], "x-forge-method": "pause", "x-a": 1, - "x-forge-aliases": [{"x-forge-group": ["b"], "x-forge-method": "nested"}]}]"#, + r#"[{"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-a": 1, + "x-forge-aliases": [{"x-forge-group": ["b"], "x-forge-method-name": "nested"}]}]"#, "", )); @@ -274,7 +277,7 @@ fn aliases_are_not_extensions() { #[test] fn keys_of_an_alias_that_are_not_extensions_are_ignored() { let forge = parse(&aliased( - r#"[{"x-forge-group": ["a"], "x-forge-method": "pause", + r#"[{"x-forge-group": ["a"], "x-forge-method-name": "pause", "summary": "Pause", "deprecated": false, "path": "/b"}]"#, "", )); @@ -290,7 +293,7 @@ fn operation_without_aliases_keeps_its_own_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -304,10 +307,10 @@ fn model_used_by_aliases_in_two_top_level_groups_is_at_the_top_level() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/m": {"get": { - "x-forge-group": ["a", "b"], "x-forge-method": "get", + "x-forge-group": ["a", "b"], "x-forge-method-name": "get", "x-forge-aliases": [ - {"x-forge-group": ["a", "b"], "x-forge-method": "get"}, - {"x-forge-group": ["x"], "x-forge-method": "get"} + {"x-forge-group": ["a", "b"], "x-forge-method-name": "get"}, + {"x-forge-group": ["x"], "x-forge-method-name": "get"} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}}, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -325,10 +328,10 @@ fn model_used_by_aliases_in_one_group_is_in_that_group() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/m": {"get": { - "x-forge-group": ["x"], "x-forge-method": "get", + "x-forge-group": ["x"], "x-forge-method-name": "get", "x-forge-aliases": [ - {"x-forge-group": ["a", "b"], "x-forge-method": "get"}, - {"x-forge-group": ["a", "c"], "x-forge-method": "get"} + {"x-forge-group": ["a", "b"], "x-forge-method-name": "get"}, + {"x-forge-group": ["a", "c"], "x-forge-method-name": "get"} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}}, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} diff --git a/tests/parse/bodies.rs b/tests/parse/bodies.rs index cb96a46e5..76b28f6fc 100644 --- a/tests/parse/bodies.rs +++ b/tests/parse/bodies.rs @@ -21,7 +21,7 @@ fn body_has_its_required_and_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"required": true, "description": "The pet.", "content": {"application/json": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -38,7 +38,7 @@ fn body_is_optional_by_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -52,7 +52,7 @@ fn contents_are_sorted_by_media_type() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "text/plain": {"schema": {"type": "string"}}, "multipart/form-data": {"schema": {"type": "object"}}, @@ -73,7 +73,7 @@ fn json_is_application_json_before_other_json_types() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "application/geo+json": {"schema": {"type": "object"}}, "application/json": {"schema": {"type": "string"}} @@ -90,7 +90,7 @@ fn json_is_otherwise_the_first_json_type() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"patch": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"patch": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "multipart/form-data": {"schema": {"type": "object"}}, "application/scim+json": {"schema": {"type": "object"}}, @@ -111,7 +111,7 @@ fn json_ignores_case_and_parameters() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"Application/JSON; charset=utf-8": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -127,7 +127,7 @@ fn multipart_content_is_typed() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "required": ["file"], "properties": { "file": {"type": "string", "format": "binary"}, @@ -151,7 +151,7 @@ fn octet_stream_content_of_a_binary_string_is_binary() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/octet-stream": {"schema": { "type": "string", "format": "binary" }}}}, @@ -169,7 +169,7 @@ fn json_ignores_content_that_is_not_json() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "multipart/form-data": {"schema": {"type": "object", "properties": {"name": {"type": "string"}}}}, "text/plain": {"schema": {"type": "string"}} @@ -189,7 +189,7 @@ fn content_that_is_not_json_without_a_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/octet-stream": {}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -204,7 +204,7 @@ fn content_without_a_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -219,7 +219,7 @@ fn body_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"$ref": "#/components/requestBodies/Pet"}, "responses": {"204": {"description": "ok"}}}}}, "components": {"requestBodies": { @@ -239,7 +239,7 @@ fn with_body_schema(version: &str, schema: &str, schemas: &str) -> String { format!( r#"{{ "openapi": "{version}", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"post": {{"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {{"/a": {{"post": {{"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {{"content": {{"application/json": {{"schema": {schema}}}}}}}, "responses": {{"204": {{"description": "ok"}}}}}}}}}}, "components": {{"schemas": {schemas}}} @@ -301,7 +301,7 @@ fn response_content_has_its_schema_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": { "schema": {"type": "string", "description": "The name."}}}}}}}} }"#, diff --git a/tests/parse/common.rs b/tests/parse/common.rs index 39d178462..ddfeccfe9 100644 --- a/tests/parse/common.rs +++ b/tests/parse/common.rs @@ -19,7 +19,7 @@ pub fn responding_with(schema: &str) -> String { format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}} }}"# ) @@ -31,7 +31,7 @@ pub fn responding_with_schemas(schema: &str, schemas: &str) -> String { format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}}, "components": {{"schemas": {schemas}}} }}"# diff --git a/tests/parse/document.rs b/tests/parse/document.rs index 6bfec98fa..934a48ae9 100644 --- a/tests/parse/document.rs +++ b/tests/parse/document.rs @@ -103,7 +103,7 @@ fn every_version_of_3_0_3_1_and_3_2_is_read() { let forge = parse(&format!( r#"{{ "openapi": "{version}", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# )); @@ -118,7 +118,7 @@ fn errors_are_reported_together() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "servers": [{"url": "https://{region}.example.com"}], - "paths": {"/a": {"get": {"x-forge-group": ["a", "", "b"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a", "", "b"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); diff --git a/tests/parse/extensions.rs b/tests/parse/extensions.rs index 9726355af..58f214836 100644 --- a/tests/parse/extensions.rs +++ b/tests/parse/extensions.rs @@ -9,7 +9,7 @@ fn operation_with(fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a": {{"get": {{{fields} - "x-forge-group": ["a"], "x-forge-method": "get", + "x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# ) @@ -71,7 +71,7 @@ fn method_without_extensions_has_none() { let get = method(&forge, "a.get"); assert_eq!(get.extensions().len(), 0); - assert_eq!(get.extension("x-forge-method"), None); + assert_eq!(get.extension("x-forge-method-name"), None); } #[test] @@ -113,9 +113,9 @@ fn extensions_forge_reads_are_still_read() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a", "b"], "x-forge-method": "list", "x-a": 1, + "get": {"x-forge-group": ["a", "b"], "x-forge-method-name": "list", "x-a": 1, "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method": "create", "x-forge-ignore": true, + "post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "x-forge-ignore": true, "x-a": 1, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -147,11 +147,11 @@ fn each_method_keeps_its_own_extensions() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "x-a": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "x-a": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "/b": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}, - "/c": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", "x-a": "create", + "/c": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "x-a": "create", "x-b": [], "responses": {"204": {"description": "ok"}}}} } }"#, @@ -170,7 +170,7 @@ fn extensions_outside_the_operation_are_not_kept() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "x-root": 1, - "paths": {"/a": {"x-path-item": 1, "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"x-path-item": 1, "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "q", "in": "query", "x-parameter": 1, "schema": {"type": "string", "x-schema": 1}}], "responses": {"204": {"description": "ok", "x-response": 1}}}}} }"#, @@ -186,11 +186,11 @@ fn operation_of_a_referenced_path_item_keeps_its_extensions() { "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, "paths": { "/a": {"$ref": "#/components/pathItems/A"}, - "/b": {"get": {"x-forge-group": ["b"], "x-forge-method": "get", "x-b": 2, + "/b": {"get": {"x-forge-group": ["b"], "x-forge-method-name": "get", "x-b": 2, "responses": {"204": {"description": "ok"}}}} }, "components": {"pathItems": { - "A": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", "x-a": 1, + "A": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "x-a": 1, "responses": {"204": {"description": "ok"}}}} }} }"##, diff --git a/tests/parse/groups.rs b/tests/parse/groups.rs index b5d6f918a..b22306d41 100644 --- a/tests/parse/groups.rs +++ b/tests/parse/groups.rs @@ -7,7 +7,7 @@ fn string_group_name_splits_on_dots() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -21,7 +21,7 @@ fn array_group_name_has_a_group_per_element() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -35,7 +35,7 @@ fn array_element_with_a_dot_is_one_group() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["zones.settings"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["zones.settings"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -54,9 +54,9 @@ fn groups_with_equal_names_are_one_group() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["abuse-reports"], "x-forge-method": "list", + "/a": {"get": {"x-forge-group": ["abuse-reports"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method": "get", + "/b": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -72,9 +72,9 @@ fn subgroup_and_method_can_share_a_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"delete": {"x-forge-group": ["members"], "x-forge-method": "delete", + "/a": {"delete": {"x-forge-group": ["members"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}}, - "/b": {"post": {"x-forge-group": ["members", "delete"], "x-forge-method": "bulk", + "/b": {"post": {"x-forge-group": ["members", "delete"], "x-forge-method-name": "bulk", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -89,7 +89,7 @@ fn operation_without_a_group_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -102,7 +102,7 @@ fn empty_group_name_is_no_group() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": [], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": [], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -128,7 +128,7 @@ fn empty_method_name_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -142,9 +142,9 @@ fn ignored_operation_is_not_a_method() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method": "list", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method": "create", "x-forge-ignore": true, + "post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "x-forge-ignore": true, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -159,7 +159,7 @@ fn group_name_without_letters_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "", "members"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "", "members"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -173,9 +173,9 @@ fn duplicate_method_in_a_group_is_an_error() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "/b": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -190,9 +190,9 @@ fn method_names_are_equal_as_names() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list_all", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list_all", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["a"], "x-forge-method": "listAll", + "/b": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "listAll", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -207,11 +207,11 @@ fn groups_are_depth_first() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["x"], "x-forge-method": "get", + "/b": {"get": {"x-forge-group": ["x"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/c": {"get": {"x-forge-group": ["a", "d"], "x-forge-method": "get", + "/c": {"get": {"x-forge-group": ["a", "d"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -241,7 +241,7 @@ fn group_description_comes_from_x_forge_commands() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"accounts": {"description": "Accounts."}} }"#, @@ -255,7 +255,7 @@ fn subgroup_description_is_in_its_parents_command() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"accounts": {"groups": {"members": {"description": "Members."}}}} }"#, @@ -277,7 +277,7 @@ fn with_commands(groups: &[&str], commands: &str) -> String { .collect::>() .join(", "); format!( - r#""/{i}": {{"get": {{"x-forge-group": [{group}], "x-forge-method": "list", + r#""/{i}": {{"get": {{"x-forge-group": [{group}], "x-forge-method-name": "list", "responses": {{"204": {{"description": "ok"}}}}}}}}"# ) }) @@ -346,7 +346,7 @@ fn command_matches_a_group_with_an_equal_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"abuse-reports": {"description": "Abuse reports."}} }"#, @@ -360,7 +360,7 @@ fn group_without_a_command_has_no_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"zones": {"description": "Zones."}} }"#, @@ -389,13 +389,13 @@ fn groups_are_sorted_by_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["zones"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["zones"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method": "get", + "/b": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/c": {"get": {"x-forge-group": ["dns"], "x-forge-method": "get", + "/c": {"get": {"x-forge-group": ["dns"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/d": {"get": {"x-forge-group": ["accounts", "billing"], "x-forge-method": "get", + "/d": {"get": {"x-forge-group": ["accounts", "billing"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -417,11 +417,11 @@ fn methods_are_sorted_by_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method": "list", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method": "create", + "post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", + "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, diff --git a/tests/parse/headers.rs b/tests/parse/headers.rs index 1ab012b02..cbba07620 100644 --- a/tests/parse/headers.rs +++ b/tests/parse/headers.rs @@ -17,7 +17,7 @@ fn header_param_is_a_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Request-ID", "in": "header", "required": true, "description": "Traces the request.", "schema": {"type": "integer", "format": "int64"}}, @@ -39,11 +39,11 @@ fn header_param_is_a_field() { } #[test] -fn header_field_is_named_by_x_fern_parameter_name() { +fn header_field_is_named_by_x_forge_parameter_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "cf-r2-jurisdiction", "in": "header", "x-forge-parameter-name": "jurisdiction", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} @@ -59,7 +59,7 @@ fn header_description_is_the_params_or_else_its_schemas() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Own", "in": "header", "description": "Param.", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "X-Inherited", "in": "header", "schema": {"$ref": "#/components/schemas/Id"}}, @@ -81,7 +81,7 @@ fn deprecated_header_is_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Old", "in": "header", "deprecated": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -95,14 +95,14 @@ fn header_is_sensitive_when_its_schema_is_and_never_read_only() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ - {"name": "X-Api-Key", "in": "header", "schema": {"type": "string", "x-sensitive": true, "readOnly": true}}, + {"name": "X-Api-Key", "in": "header", "schema": {"type": "string", "x-forge-sensitive": true, "readOnly": true}}, {"name": "X-Auth-Token", "in": "header", "schema": {"$ref": "#/components/schemas/Token"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} ], "responses": {"204": {"description": "ok"}}}}}, - "components": {"schemas": {"Token": {"type": "string", "x-sensitive": true, "readOnly": true}}} + "components": {"schemas": {"Token": {"type": "string", "x-forge-sensitive": true, "readOnly": true}}} }"##, ); @@ -119,7 +119,7 @@ fn header_has_the_default_of_its_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Version", "in": "header", "schema": {"type": "string", "default": "2024-01-01"}}, {"name": "X-Retries", "in": "header", "schema": {"$ref": "#/components/schemas/Retries"}}, @@ -144,7 +144,7 @@ fn header_param_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "parameters": [{"$ref": "#/components/parameters/IdempotencyKey"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"IdempotencyKey": {"name": "Idempotency-Key", "in": "header", @@ -163,8 +163,8 @@ fn path_item_headers_belong_to_each_operation() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Account", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -181,7 +181,7 @@ fn operation_header_replaces_the_path_item_header() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Limit", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Limit", "in": "header", "required": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -202,7 +202,7 @@ fn operation_header_replaces_the_path_item_header_ignoring_case() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Request-ID", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "x-request-id", "in": "header", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -221,7 +221,7 @@ fn query_param_does_not_replace_a_header_with_its_name() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "version", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "version", "in": "query", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}} }} @@ -243,7 +243,7 @@ fn headers_are_in_declared_order_the_path_items_first() { {"name": "X-First", "in": "header", "schema": {"type": "string"}}, {"name": "X-Second", "in": "header", "schema": {"type": "string"}} ], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Third", "in": "header", "schema": {"type": "string"}}, {"name": "x-first", "in": "header", "schema": {"type": "string"}} @@ -264,7 +264,7 @@ fn headers_with_equal_names_are_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Rate-Limit", "in": "header", "schema": {"type": "string"}}, {"name": "X_Rate_Limit", "in": "header", "schema": {"type": "string"}} @@ -289,7 +289,7 @@ fn path_item_headers_differing_in_case_are_an_error() { {"name": "X-A", "in": "header", "schema": {"type": "string"}}, {"name": "x-a", "in": "header", "schema": {"type": "string"}} ], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} }} }"#, @@ -303,7 +303,7 @@ fn header_and_param_with_equal_names_are_not_an_error() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{account_id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{account_id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "account_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "Account-Id", "in": "header", "schema": {"type": "string"}} @@ -320,7 +320,7 @@ fn cookie_params_are_not_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "session", "in": "cookie", "schema": {"type": "string"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} @@ -337,7 +337,7 @@ fn method_with_only_cookie_params_has_no_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "session", "in": "cookie", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -351,7 +351,7 @@ fn accept_content_type_and_authorization_headers_are_kept() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"put": {"x-forge-group": ["a"], "x-forge-method": "upload", + "paths": {"/a": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "upload", "parameters": [ {"name": "Content-Type", "in": "header", "required": true, "schema": {"type": "string"}}, {"name": "Content-Length", "in": "header", "schema": {"type": "integer"}}, @@ -376,7 +376,7 @@ fn method_without_header_params_has_no_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -391,7 +391,7 @@ fn headers_are_not_in_the_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "parameters": [ {"name": "page", "in": "query", "schema": {"type": "integer"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} @@ -411,7 +411,7 @@ fn method_with_only_headers_has_no_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Trace", "in": "header", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -427,7 +427,7 @@ fn model_used_only_by_a_header_is_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a", "b"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a", "b"], "x-forge-method-name": "get", "parameters": [{"name": "cf-r2-storage-class", "in": "header", "schema": {"$ref": "#/components/schemas/StorageClass"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": {"StorageClass": {"type": "string", "enum": ["Standard", "InfrequentAccess"]}}} @@ -446,7 +446,7 @@ fn header_with_content_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Filter", "in": "header", "content": {"application/json": {"schema": { "type": "object", "properties": {"status": {"type": "string"}} }}}}], @@ -465,7 +465,7 @@ fn header_style_other_than_simple_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Ids", "in": "header", "style": "form", "schema": {"type": "array", "items": {"type": "string"}}}], "responses": {"204": {"description": "ok"}}}}} diff --git a/tests/parse/methods.rs b/tests/parse/methods.rs index 664905303..c03f128e5 100644 --- a/tests/parse/methods.rs +++ b/tests/parse/methods.rs @@ -9,7 +9,7 @@ fn operation_with(fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a": {{"get": {{{fields} - "x-forge-group": ["a"], "x-forge-method": "get", + "x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# ) @@ -21,14 +21,14 @@ fn each_operation_field_is_its_http_method() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, - "put": {"x-forge-group": ["a"], "x-forge-method": "put", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method": "post", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}}, - "options": {"x-forge-group": ["a"], "x-forge-method": "options", "responses": {"204": {"description": "ok"}}}, - "head": {"x-forge-group": ["a"], "x-forge-method": "head", "responses": {"204": {"description": "ok"}}}, - "patch": {"x-forge-group": ["a"], "x-forge-method": "patch", "responses": {"204": {"description": "ok"}}}, - "trace": {"x-forge-group": ["a"], "x-forge-method": "trace", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "put": {"x-forge-group": ["a"], "x-forge-method-name": "put", "responses": {"204": {"description": "ok"}}}, + "post": {"x-forge-group": ["a"], "x-forge-method-name": "post", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}, + "options": {"x-forge-group": ["a"], "x-forge-method-name": "options", "responses": {"204": {"description": "ok"}}}, + "head": {"x-forge-group": ["a"], "x-forge-method-name": "head", "responses": {"204": {"description": "ok"}}}, + "patch": {"x-forge-group": ["a"], "x-forge-method-name": "patch", "responses": {"204": {"description": "ok"}}}, + "trace": {"x-forge-group": ["a"], "x-forge-method-name": "trace", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -54,7 +54,7 @@ fn query_operation_is_query() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"query": {"x-forge-group": ["a"], "x-forge-method": "search", + "paths": {"/a": {"query": {"x-forge-group": ["a"], "x-forge-method-name": "search", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -68,7 +68,7 @@ fn additional_operation_is_its_method_as_written() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "COPY": {"x-forge-group": ["a"], "x-forge-method": "copy", + "COPY": {"x-forge-group": ["a"], "x-forge-method-name": "copy", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -86,7 +86,7 @@ fn additional_operation_with_the_method_of_a_field_is_that_variant() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "GET": {"x-forge-group": ["a"], "x-forge-method": "get", + "GET": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -101,7 +101,7 @@ fn additional_operation_methods_are_case_sensitive() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -118,7 +118,7 @@ fn method_has_the_summary_description_and_deprecation_of_its_operation() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "summary": "Get an a.", "description": "Gets an a.", "deprecated": true, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -135,7 +135,7 @@ fn method_without_docs_is_empty_and_not_deprecated() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -153,7 +153,7 @@ fn path_item_ref_is_followed() { "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"$ref": "#/components/pathItems/A"}}, "components": {"pathItems": { - "A": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "A": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} }} }"##, @@ -168,11 +168,11 @@ fn extensions_in_paths_and_path_items_are_not_operations() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "x-paths-extension": {"get": {"x-forge-group": ["x"], "x-forge-method": "get", + "x-paths-extension": {"get": {"x-forge-group": ["x"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, "/a": { "x-forge-commands": {"a": {"description": "A."}}, - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} } } @@ -189,9 +189,9 @@ fn additional_operation_with_the_method_of_a_present_field_is_skipped() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "additionalOperations": {"GET": {"x-forge-group": ["a"], "x-forge-method": "shadowed", + "additionalOperations": {"GET": {"x-forge-group": ["a"], "x-forge-method-name": "shadowed", "responses": {"204": {"description": "ok"}}}} }} }"#, @@ -206,7 +206,7 @@ fn webhooks_are_not_methods() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "webhooks": {"newPet": {"post": {"x-forge-group": ["pets"], "x-forge-method": "created", + "webhooks": {"newPet": {"post": {"x-forge-group": ["pets"], "x-forge-method-name": "created", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -219,9 +219,9 @@ fn callbacks_are_not_methods() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/subscribe": {"post": {"x-forge-group": ["a"], "x-forge-method": "subscribe", + "paths": {"/subscribe": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "subscribe", "callbacks": {"event": {"{$request.query.url}": {"post": { - "x-forge-group": ["a"], "x-forge-method": "event", + "x-forge-group": ["a"], "x-forge-method-name": "event", "responses": {"204": {"description": "ok"}} }}}}, "responses": {"204": {"description": "ok"}}}}} @@ -331,13 +331,13 @@ fn availability_and_deprecation_are_apart() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "deprecated": true, "x-forge-availability": "generally-available", "responses": {"204": {"description": "ok"}}}, - "put": {"x-forge-group": ["a"], "x-forge-method": "put", + "put": {"x-forge-group": ["a"], "x-forge-method-name": "put", "x-forge-availability": "deprecated", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method": "post", + "post": {"x-forge-group": ["a"], "x-forge-method-name": "post", "deprecated": true, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -353,3 +353,16 @@ fn availability_and_deprecation_are_apart() { assert!(post.is_deprecated()); assert_eq!(post.availability(), None); } + +#[test] +fn x_forge_method_without_name_is_not_a_method_name() { + let forge = parse( + r#"{ + "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "responses": {"204": {"description": "ok"}}}}} + }"#, + ); + + assert_eq!(forge.groups().count(), 0); +} diff --git a/tests/parse/models.rs b/tests/parse/models.rs index 40f7ca110..dcb7af171 100644 --- a/tests/parse/models.rs +++ b/tests/parse/models.rs @@ -14,7 +14,7 @@ fn response_model_is_placed_in_its_group() { "/zones": { "get": { "x-forge-group": ["zones"], - "x-forge-method": "list", + "x-forge-method-name": "list", "responses": { "200": { "description": "OK", @@ -43,9 +43,9 @@ fn model_used_in_sibling_groups_is_in_their_parent() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method": "get", + "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/d": {"get": {"x-forge-group": ["a", "b", "d"], "x-forge-method": "get", + "/d": {"get": {"x-forge-group": ["a", "b", "d"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -61,9 +61,9 @@ fn model_used_in_a_group_and_its_subgroup_is_in_the_group() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method": "get", + "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -79,9 +79,9 @@ fn model_used_in_top_level_groups_is_at_the_top_level() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/x": {"get": {"x-forge-group": ["x"], "x-forge-method": "get", + "/x": {"get": {"x-forge-group": ["x"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -99,9 +99,9 @@ fn model_used_through_another_model_is_placed_by_every_use() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/b": {"get": {"x-forge-group": ["a", "b"], "x-forge-method": "get", + "/b": {"get": {"x-forge-group": ["a", "b"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Outer"}}}}}}}, - "/c": {"get": {"x-forge-group": ["a", "c"], "x-forge-method": "get", + "/c": {"get": {"x-forge-group": ["a", "c"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Inner"}}}}}}} }, "components": {"schemas": { @@ -120,7 +120,7 @@ fn params_bodies_and_errors_use_models() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "parameters": [{"name": "filter", "in": "query", "schema": {"$ref": "#/components/schemas/Filter"}}], "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Input"}}}}, "responses": {"400": {"description": "no", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Failure"}}}}}}}}, @@ -144,11 +144,11 @@ fn schema_no_method_uses_is_not_a_model() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Used"}}}}}}}, - "/ignored": {"get": {"x-forge-group": ["a"], "x-forge-method": "ignored", "x-forge-ignore": true, + "/ignored": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "ignored", "x-forge-ignore": true, "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ignored"}}}}}}}, - "/ungrouped": {"get": {"x-forge-method": "ungrouped", + "/ungrouped": {"get": {"x-forge-method-name": "ungrouped", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ungrouped"}}}}}}} }, "components": {"schemas": { @@ -186,7 +186,7 @@ fn model_is_named_after_its_schema() { } #[test] -fn model_is_named_by_x_fern_type_name() { +fn model_is_named_by_x_forge_model_name() { let forge = parse(&responding_with_schemas( r##"{"$ref": "#/components/schemas/not_found"}"##, r#"{"not_found": {"type": "object", "x-forge-model-name": "Missing"}}"#, @@ -224,7 +224,7 @@ fn schema_in_defs_is_a_model() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Tree/$defs/Node"}}}}}}}}, "components": {"schemas": { "Tree": {"type": "object", "$defs": {"Node": {"type": "string"}}} @@ -256,7 +256,7 @@ fn schema_used_only_by_content_that_is_not_json_is_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a", "files"], "x-forge-method": "upload", + "paths": {"/a": {"post": {"x-forge-group": ["a", "files"], "x-forge-method-name": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": {"$ref": "#/components/schemas/Upload"}}}}, "responses": {"200": {"description": "ok", "content": {"text/csv": {"schema": {"$ref": "#/components/schemas/Report"}}}}}}}}, "components": {"schemas": { @@ -287,9 +287,9 @@ fn use_by_content_that_is_not_json_places_a_model() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/b": {"post": {"x-forge-group": ["b"], "x-forge-method": "upload", + "/b": {"post": {"x-forge-group": ["b"], "x-forge-method-name": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"meta": {"$ref": "#/components/schemas/M"}} }}}}, @@ -307,7 +307,7 @@ fn schema_used_only_in_a_response_header_is_not_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Trace", "in": "header", "schema": {"$ref": "#/components/schemas/Trace"}}], "responses": {"204": {"description": "ok", "headers": {"X-Rate-Limit": {"schema": {"$ref": "#/components/schemas/RateLimit"}}}}}}}}, diff --git a/tests/parse/requests.rs b/tests/parse/requests.rs index 9fe63590c..e87904898 100644 --- a/tests/parse/requests.rs +++ b/tests/parse/requests.rs @@ -14,7 +14,7 @@ fn path_param_is_a_required_request_field() { "/zones/{zone_id}": { "get": { "x-forge-group": ["zones"], - "x-forge-method": "get", + "x-forge-method-name": "get", "parameters": [ { "name": "zone_id", "in": "path", "required": true, "schema": { "type": "string" } } ], @@ -44,7 +44,7 @@ fn query_param_is_optional_and_exploded_by_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -61,7 +61,7 @@ fn query_param_can_be_required() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "required": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -76,7 +76,7 @@ fn query_param_with_explode_false_is_not_exploded() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "ids", "in": "query", "style": "form", "explode": false, "schema": {"type": "array", "items": {"type": "string"}}}], "responses": {"204": {"description": "ok"}}}}} @@ -93,7 +93,7 @@ fn header_and_cookie_params_are_not_fields() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Trace", "in": "header", "schema": {"type": "string"}}, {"name": "session", "in": "cookie", "schema": {"type": "string"}} @@ -107,11 +107,11 @@ fn header_and_cookie_params_are_not_fields() { } #[test] -fn param_field_is_named_by_x_fern_parameter_name() { +fn param_field_is_named_by_x_forge_parameter_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "q", "in": "query", "x-forge-parameter-name": "query", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -126,7 +126,7 @@ fn param_description_falls_back_to_an_inline_schema() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "own", "in": "query", "description": "Param.", "schema": {"type": "string", "description": "Schema."}}, {"name": "inherited", "in": "query", "schema": {"type": "string", "description": "Schema."}} @@ -145,7 +145,7 @@ fn param_description_comes_from_a_ref_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "own", "in": "query", "description": "Param.", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id"}} @@ -165,7 +165,7 @@ fn param_description_follows_a_chain_of_refs() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"$ref": "#/components/schemas/Id"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": { @@ -184,7 +184,7 @@ fn param_description_is_never_a_schema_title() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "inline", "in": "query", "schema": {"type": "string", "title": "Inline"}} @@ -204,7 +204,7 @@ fn description_next_to_a_param_schema_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id", "description": "The ID to find."}}], "responses": {"204": {"description": "ok"}}}}}, @@ -221,7 +221,7 @@ fn param_description_comes_from_an_all_of_member_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "region", "in": "query", "schema": {"allOf": [{"$ref": "#/components/schemas/Region"}, {"default": "us"}]}}], "responses": {"204": {"description": "ok"}}}}}, @@ -238,7 +238,7 @@ fn param_description_from_an_all_of_member_is_ignored_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "region", "in": "query", "schema": {"allOf": [{"$ref": "#/components/schemas/Region"}, {"default": "us"}]}}], "responses": {"204": {"description": "ok"}}}}}, @@ -255,7 +255,7 @@ fn param_ref_description_overrides_the_params_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page", "description": "The page of pets."}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -272,7 +272,7 @@ fn param_ref_description_is_ignored_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page", "description": "The page of pets."}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -289,7 +289,7 @@ fn param_ref_without_a_description_has_the_params() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -306,7 +306,7 @@ fn param_field_is_never_read_only() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "id", "in": "path", "required": true, "schema": {"type": "string", "readOnly": true}}, {"name": "since", "in": "query", "schema": {"$ref": "#/components/schemas/Since", "readOnly": true}}, @@ -331,9 +331,9 @@ fn query_string_property_is_never_read_only() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": { - "type": "object", "properties": {"status": {"type": "string", "readOnly": true, "x-sensitive": true}} + "type": "object", "properties": {"status": {"type": "string", "readOnly": true, "x-forge-sensitive": true}} }}}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -349,9 +349,9 @@ fn param_field_is_sensitive_when_its_schema_is() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ - {"name": "token", "in": "query", "schema": {"type": "string", "x-sensitive": true}}, + {"name": "token", "in": "query", "schema": {"type": "string", "x-forge-sensitive": true}}, {"name": "page", "in": "query", "schema": {"type": "integer"}} ], "responses": {"204": {"description": "ok"}}}}} @@ -368,12 +368,12 @@ fn param_field_is_sensitive_when_its_ref_schema_is() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "token", "in": "query", "schema": {"$ref": "#/components/schemas/Token"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": { "Token": {"$ref": "#/components/schemas/Secret"}, - "Secret": {"type": "string", "x-sensitive": true} + "Secret": {"type": "string", "x-forge-sensitive": true} }} }"##, ); @@ -386,9 +386,9 @@ fn sensitive_next_to_a_param_schema_ref_counts_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "token", "in": "query", - "schema": {"$ref": "#/components/schemas/Token", "x-sensitive": true}}], + "schema": {"$ref": "#/components/schemas/Token", "x-forge-sensitive": true}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": {"Token": {"type": "string"}}} }"##, @@ -402,8 +402,8 @@ fn sensitive_on_the_param_itself_is_ignored() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", - "parameters": [{"name": "token", "in": "query", "x-sensitive": true, "schema": {"type": "string"}}], + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "parameters": [{"name": "token", "in": "query", "x-forge-sensitive": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -416,7 +416,7 @@ fn param_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "schema": {"type": "integer"}}}} @@ -435,8 +435,8 @@ fn path_item_params_belong_to_each_operation() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -455,7 +455,7 @@ fn operation_param_replaces_the_path_item_param() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "page", "in": "query", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "list", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -472,7 +472,7 @@ fn undeclared_path_placeholder_is_a_required_string() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -491,7 +491,7 @@ fn params_are_in_path_template_then_declared_order() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{second}/{first}": { "parameters": [{"name": "item_query", "in": "query", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "op_query", "in": "query", "schema": {"type": "string"}}, {"name": "first", "in": "path", "required": true, "schema": {"type": "string"}}, @@ -511,7 +511,7 @@ fn query_string_object_is_query_fields() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": { "type": "object", "properties": {"status": {"type": "string"}, "limit": {"type": "integer"}} }}}}], @@ -532,7 +532,7 @@ fn no_params_and_no_body_is_no_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -545,7 +545,7 @@ fn body_without_params_is_the_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -559,7 +559,7 @@ fn object_body_is_intersected_with_the_params() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "properties": {"name": {"type": "string"}} @@ -582,7 +582,7 @@ fn model_body_is_intersected_with_the_params() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, "responses": {"204": {"description": "ok"}}}}}, @@ -604,7 +604,7 @@ fn union_body_is_intersected_with_the_params() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "oneOf": [{"$ref": "#/components/schemas/Cat"}, {"$ref": "#/components/schemas/Dog"}] @@ -631,7 +631,7 @@ fn array_body_is_the_last_field_of_the_params() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -651,10 +651,10 @@ fn body_field_is_neither_read_only_nor_sensitive() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { - "type": "array", "items": {"type": "string"}, "readOnly": true, "x-sensitive": true + "type": "array", "items": {"type": "string"}, "readOnly": true, "x-forge-sensitive": true }}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -670,7 +670,7 @@ fn read_only_field_of_a_body_model_is_kept() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}}}}}, "components": {"schemas": {"Pet": {"type": "object", "properties": { @@ -690,7 +690,7 @@ fn map_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "additionalProperties": {"type": "string"} @@ -708,7 +708,7 @@ fn unknown_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -724,7 +724,7 @@ fn nullable_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "nullable": true, "properties": {"name": {"type": "string"}} @@ -742,7 +742,7 @@ fn body_with_the_name_of_a_param_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{zone_id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{zone_id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "zone_id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "properties": {"zoneId": {"type": "string"}, "name": {"type": "string"}} @@ -762,8 +762,8 @@ fn field_of_another_method_has_no_location() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -779,7 +779,7 @@ fn body_that_is_not_json_is_an_unknown_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"post": {"x-forge-group": ["a"], "x-forge-method": "upload", + "paths": {"/a/{id}": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "upload", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"file": {"type": "string", "format": "binary"}} @@ -798,7 +798,7 @@ fn body_that_is_only_multipart_is_an_unknown_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "upload", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"file": {"type": "string", "format": "binary"}} }}}}, @@ -816,7 +816,7 @@ fn path_param_missing_from_the_template_is_dropped() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "account_id", "in": "path", "required": true, "schema": {"type": "string"}} @@ -833,7 +833,7 @@ fn deprecated_query_param_is_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "deprecated": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -847,7 +847,7 @@ fn deprecated_path_param_is_not_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "id", "in": "path", "required": true, "deprecated": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -861,7 +861,7 @@ fn all_of_body_is_one_member_of_the_intersection() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}] @@ -888,7 +888,7 @@ fn param_with_content_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "query", "content": {"application/json": {"schema": { "type": "object", "properties": {"status": {"type": "string"}} }}}}], @@ -912,7 +912,7 @@ fn query_style_other_than_form_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{{"name": "filter", "in": "query", "style": "{style}", "schema": {schema}}}], "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# @@ -927,7 +927,7 @@ fn two_query_string_params_are_an_error() { let err = parse_err( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "one", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}}, {"name": "two", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}} @@ -946,7 +946,7 @@ fn query_and_query_string_params_are_an_error() { "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], - "get": {"x-forge-group": ["a"], "x-forge-method": "list", + "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}}], "responses": {"204": {"description": "ok"}}} }} @@ -963,10 +963,10 @@ fn body_field_is_required_when_the_body_is() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "put": {"x-forge-group": ["a"], "x-forge-method": "replace", + "put": {"x-forge-group": ["a"], "x-forge-method-name": "replace", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}, - "patch": {"x-forge-group": ["a"], "x-forge-method": "append", + "patch": {"x-forge-group": ["a"], "x-forge-method-name": "append", "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}} }} @@ -983,7 +983,7 @@ fn params_with_equal_names_are_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{zone_id}": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a/{zone_id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "zone_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "zoneId", "in": "query", "schema": {"type": "string"}} @@ -1001,7 +1001,7 @@ fn path_style_other_than_simple_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a/{{id}}": {{"get": {{"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {{"/a/{{id}}": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", "parameters": [{{"name": "id", "in": "path", "required": true, "style": "{style}", "schema": {{"type": "string"}}}}], "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# @@ -1016,7 +1016,7 @@ fn param_field_has_the_default_of_its_schema() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "per_page", "in": "query", "schema": {"type": "integer", "default": 20}}, {"name": "page", "in": "query", "schema": {"type": "integer"}} @@ -1035,7 +1035,7 @@ fn param_field_has_the_default_of_its_ref_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{order}": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a/{order}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "order", "in": "path", "required": true, "schema": {"$ref": "#/components/schemas/Order"}}, {"$ref": "#/components/parameters/Direction"} @@ -1062,7 +1062,7 @@ fn default_next_to_a_param_schema_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "per_page", "in": "query", "schema": {"$ref": "#/components/schemas/PerPage", "default": 50}}], "responses": {"204": {"description": "ok"}}}}}, @@ -1079,7 +1079,7 @@ fn default_on_the_param_itself_is_ignored() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "list", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "per_page", "in": "query", "default": 20, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -1096,7 +1096,7 @@ fn body_field_and_undeclared_placeholder_have_no_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "default": ["x"] }}}}, @@ -1114,7 +1114,7 @@ fn array_body_keeps_its_max_items() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "maxItems": 100 }}}}, diff --git a/tests/parse/responses.rs b/tests/parse/responses.rs index eab8ea51d..7ac12e940 100644 --- a/tests/parse/responses.rs +++ b/tests/parse/responses.rs @@ -7,7 +7,7 @@ fn responses_are_the_2xx_sorted_by_status() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method": "create", + "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "responses": { "2XX": {"description": "ok"}, "201": {"description": "ok"}, @@ -29,7 +29,7 @@ fn errors_are_the_rest_sorted_with_default_last() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": { "default": {"description": "no"}, "500": {"description": "no"}, @@ -54,7 +54,7 @@ fn response_has_its_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "The pet."}}}}} }"#, ); @@ -68,7 +68,7 @@ fn response_without_content_has_none() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"delete": {"x-forge-group": ["a"], "x-forge-method": "delete", + "paths": {"/a": {"delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -83,7 +83,7 @@ fn response_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"4XX": {"$ref": "#/components/responses/Failure"}}}}}, "components": {"responses": { "Failure": {"description": "Failed.", "content": {"application/json": {"schema": {"type": "string"}}}} @@ -102,7 +102,7 @@ fn response_content_that_is_not_json_is_typed() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "download", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "download", "responses": {"200": {"description": "ok", "content": { "application/octet-stream": {"schema": {"type": "string", "format": "binary"}}, "text/csv": {"schema": {"type": "string"}} diff --git a/tests/parse/types/arrays.rs b/tests/parse/types/arrays.rs index bf5d85931..3af14fdf8 100644 --- a/tests/parse/types/arrays.rs +++ b/tests/parse/types/arrays.rs @@ -92,7 +92,7 @@ fn array_without_items_has_unknown_elements() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "array" }}}}}}}} @@ -107,7 +107,7 @@ fn tuple_is_unknown() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "array", "prefixItems": [{"type": "string"}, {"type": "integer"}], "items": false }}}}}}}} diff --git a/tests/parse/types/enums.rs b/tests/parse/types/enums.rs index 101ea434d..a1511c847 100644 --- a/tests/parse/types/enums.rs +++ b/tests/parse/types/enums.rs @@ -59,7 +59,7 @@ fn const_is_an_enum_of_one_value() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "const": "a" }}}}}}}} diff --git a/tests/parse/types/intersections.rs b/tests/parse/types/intersections.rs index ca373866b..26c7b8ae3 100644 --- a/tests/parse/types/intersections.rs +++ b/tests/parse/types/intersections.rs @@ -49,7 +49,7 @@ fn true_member_is_dropped() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}, true, {"$ref": "#/components/schemas/B"}] }}}}}}}}, @@ -141,7 +141,7 @@ fn unevaluated_properties_is_an_object_member() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}], "unevaluatedProperties": {"type": "string"} diff --git a/tests/parse/types/nulls.rs b/tests/parse/types/nulls.rs index b191b43cc..ecf06e087 100644 --- a/tests/parse/types/nulls.rs +++ b/tests/parse/types/nulls.rs @@ -95,7 +95,7 @@ fn nullable_is_read_in_3_1() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "nullable": true }}}}}}}} @@ -110,7 +110,7 @@ fn null_in_a_type_array_is_a_union_with_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "null"] }}}}}}}} @@ -125,7 +125,7 @@ fn null_type_is_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "null" }}}}}}}} @@ -140,7 +140,7 @@ fn const_null_is_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "const": null }}}}}}}} diff --git a/tests/parse/types/objects.rs b/tests/parse/types/objects.rs index f3e9bf7dc..7135a1f19 100644 --- a/tests/parse/types/objects.rs +++ b/tests/parse/types/objects.rs @@ -36,7 +36,7 @@ fn required_names_without_a_property_are_ignored() { } #[test] -fn field_is_named_by_x_fern_property_name() { +fn field_is_named_by_x_forge_property_name() { let forge = parse(&responding_with( r#"{"type": "object", "properties": {"owner": {"type": "string", "x-forge-property-name": "person"}}}"#, )); @@ -78,7 +78,7 @@ fn field_is_read_only_when_its_property_is() { #[test] fn field_is_neither_read_only_nor_sensitive_by_default() { let forge = parse(&responding_with( - r#"{"type": "object", "properties": {"name": {"type": "string"}, "shown": {"type": "string", "readOnly": false, "x-sensitive": false}}}"#, + r#"{"type": "object", "properties": {"name": {"type": "string"}, "shown": {"type": "string", "readOnly": false, "x-forge-sensitive": false}}}"#, )); let object = object(response_type(&forge, "a.get")); @@ -100,7 +100,7 @@ fn read_only_that_is_not_a_boolean_is_an_error() { #[test] fn field_is_sensitive_when_its_property_is() { let forge = parse(&responding_with( - r#"{"type": "object", "properties": {"password": {"type": "string", "x-sensitive": true}}}"#, + r#"{"type": "object", "properties": {"password": {"type": "string", "x-forge-sensitive": true}}}"#, )); assert!(field(object(response_type(&forge, "a.get")), "password").is_sensitive()); @@ -109,7 +109,7 @@ fn field_is_sensitive_when_its_property_is() { #[test] fn sensitive_that_is_not_a_boolean_is_an_error() { let err = parse_err(&responding_with( - r#"{"type": "object", "properties": {"password": {"type": "string", "x-sensitive": "true"}}}"#, + r#"{"type": "object", "properties": {"password": {"type": "string", "x-forge-sensitive": "true"}}}"#, )); assert!(err.contains("expected a boolean"), "{err}"); @@ -195,7 +195,7 @@ fn pattern_properties_are_ignored() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"type": "string"}}, "patternProperties": {"^x-": {"type": "string"}} }}}}}}}} @@ -212,7 +212,7 @@ fn false_property_is_no_field() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"type": "string"}, "gone": false} }}}}}}}} @@ -297,3 +297,52 @@ fn default_is_not_checked_against_the_schema() { let limit = field(object(response_type(&forge, "a.get")), "limit"); assert_eq!(limit.default(), Some(&Json::String("ten".into()))); } + +#[test] +fn field_is_sensitive_by_the_deprecated_x_sensitive() { + let forge = parse(&responding_with( + r#"{"type": "object", "properties": {"password": {"type": "string", "x-sensitive": true}}}"#, + )); + + assert!(field(object(response_type(&forge, "a.get")), "password").is_sensitive()); +} + +#[test] +fn x_forge_sensitive_wins_over_the_deprecated_x_sensitive_in_either_order() { + for (keys, sensitive) in [ + (r#""x-forge-sensitive": false, "x-sensitive": true"#, false), + (r#""x-sensitive": true, "x-forge-sensitive": false"#, false), + (r#""x-forge-sensitive": true, "x-sensitive": false"#, true), + (r#""x-sensitive": false, "x-forge-sensitive": true"#, true), + ] { + let forge = parse(&responding_with(&format!( + r#"{{"type": "object", "properties": {{"password": {{"type": "string", {keys}}}}}}}"# + ))); + + assert_eq!( + field(object(response_type(&forge, "a.get")), "password").is_sensitive(), + sensitive, + "{keys}" + ); + } +} + +#[test] +fn deprecated_x_sensitive_that_is_not_a_boolean_is_an_error_even_beside_x_forge_sensitive() { + let err = parse_err(&responding_with( + r#"{"type": "object", "properties": {"password": {"type": "string", "x-forge-sensitive": true, "x-sensitive": "yes"}}}"#, + )); + + assert!(err.contains("invalid type"), "{err}"); +} + +#[test] +fn sensitive_written_twice_under_one_name_is_an_error_naming_it() { + for key in ["x-forge-sensitive", "x-sensitive"] { + let err = parse_err(&responding_with(&format!( + r#"{{"type": "object", "properties": {{"password": {{"type": "string", "{key}": true, "{key}": true}}}}}}"# + ))); + + assert!(err.contains(&format!("duplicate field `{key}`")), "{key}: {err}"); + } +} diff --git a/tests/parse/types/refs.rs b/tests/parse/types/refs.rs index a00c96c9c..c736bf622 100644 --- a/tests/parse/types/refs.rs +++ b/tests/parse/types/refs.rs @@ -65,7 +65,7 @@ fn annotations_next_to_a_ref_keep_the_model_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "description": "The zone.", "deprecated": true }}}}}}}}, @@ -81,7 +81,7 @@ fn shape_next_to_a_ref_is_intersected_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "properties": {"extra": {"type": "string"}} }}}}}}}}, @@ -97,7 +97,7 @@ fn nullable_next_to_a_ref_is_a_union_with_null_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "nullable": true }}}}}}}}, @@ -153,7 +153,7 @@ fn description_next_to_a_property_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"home": {"$ref": "#/components/schemas/Zone", "description": "The home zone."}} }}}}}}}}, @@ -324,7 +324,7 @@ fn read_only_next_to_a_property_ref_counts_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"$ref": "#/components/schemas/Id", "readOnly": true}} }}}}}}}}, @@ -350,7 +350,7 @@ fn read_only_false_next_to_a_ref_does_not_undo_its_schemas_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"$ref": "#/components/schemas/Id", "readOnly": false}} }}}}}}}}, @@ -365,7 +365,7 @@ fn read_only_false_next_to_a_ref_does_not_undo_its_schemas_in_3_1() { fn property_that_is_a_ref_is_sensitive_when_its_schema_is() { let forge = parse(&responding_with_schemas( r##"{"type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token"}}}"##, - r##"{"Token": {"$ref": "#/components/schemas/Secret"}, "Secret": {"type": "string", "x-sensitive": true}}"##, + r##"{"Token": {"$ref": "#/components/schemas/Secret"}, "Secret": {"type": "string", "x-forge-sensitive": true}}"##, )); assert!(field(object(response_type(&forge, "a.get")), "token").is_sensitive()); @@ -374,7 +374,7 @@ fn property_that_is_a_ref_is_sensitive_when_its_schema_is() { #[test] fn sensitive_next_to_a_property_ref_counts_in_3_0() { let forge = parse(&responding_with_schemas( - r##"{"type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token", "x-sensitive": true}}}"##, + r##"{"type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token", "x-forge-sensitive": true}}}"##, r#"{"Token": {"type": "string"}}"#, )); @@ -386,9 +386,9 @@ fn sensitive_next_to_a_property_ref_counts_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { - "type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token", "x-sensitive": true}} + "type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token", "x-forge-sensitive": true}} }}}}}}}}, "components": {"schemas": {"Token": {"type": "string"}}} }"##, @@ -424,7 +424,7 @@ fn property_default_is_the_first_along_a_chain_of_refs_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"size": {"$ref": "#/components/schemas/Size"}} }}}}}}}}, @@ -454,7 +454,7 @@ fn default_next_to_a_property_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": { "size": {"$ref": "#/components/schemas/Size", "default": 5}, diff --git a/tests/parse/types/scalars.rs b/tests/parse/types/scalars.rs index 21e442f53..65b9e455c 100644 --- a/tests/parse/types/scalars.rs +++ b/tests/parse/types/scalars.rs @@ -140,7 +140,7 @@ fn base64_content_encoding_is_bytes() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "contentEncoding": "base64" }}}}}}}} @@ -155,7 +155,7 @@ fn binary_format_is_binary_even_with_base64_content_encoding() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "format": "binary", "contentEncoding": "base64" }}}}}}}} @@ -198,7 +198,7 @@ fn true_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": true}}}}}}} }"#, ); diff --git a/tests/parse/types/unions.rs b/tests/parse/types/unions.rs index 40df4abf4..f8349fe71 100644 --- a/tests/parse/types/unions.rs +++ b/tests/parse/types/unions.rs @@ -76,7 +76,7 @@ fn type_array_is_exclusive() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "integer"] }}}}}}}} @@ -138,7 +138,7 @@ fn types_in_a_type_array_are_a_union() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "integer"] }}}}}}}} @@ -291,7 +291,7 @@ fn discriminator_of_members_written_in_place_uses_the_one_value_of_an_enum() { } #[test] -fn discriminator_is_named_by_x_fern_property_name() { +fn discriminator_is_named_by_x_forge_property_name() { let forge = parse(&responding_with_schemas( r##"{ "oneOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}], @@ -329,7 +329,7 @@ fn discriminator_default_mapping_is_the_default() { let forge = parse( r##"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "oneOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}], "discriminator": {"propertyName": "kind", "mapping": {"a": "#/components/schemas/A"}, "defaultMapping": "#/components/schemas/B"} diff --git a/tests/wasm.rs b/tests/wasm.rs index 2e733443b..95b4730cd 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -41,7 +41,7 @@ const SPEC: &str = r##"{ "paths": { "/pets": { "get": { - "x-forge-group": ["pets"], "x-forge-method": "list", "summary": "Lists pets.", + "x-forge-group": ["pets"], "x-forge-method-name": "list", "summary": "Lists pets.", "parameters": [ {"name": "limit", "in": "query", "schema": {"type": "integer", "format": "int32"}}, {"name": "tags", "in": "query", "explode": false, "schema": {"type": "array", "items": {"type": "string"}}} @@ -52,14 +52,14 @@ const SPEC: &str = r##"{ } }, "post": { - "x-forge-group": ["pets"], "x-forge-method": "create", "deprecated": true, + "x-forge-group": ["pets"], "x-forge-method-name": "create", "deprecated": true, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/NewPet"}}}}, "responses": {"201": {"description": "created", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}} } }, "/pets/{pet_id}": { "get": { - "x-forge-group": ["pets"], "x-forge-method": "get", + "x-forge-group": ["pets"], "x-forge-method-name": "get", "parameters": [{"name": "pet_id", "in": "path", "required": true, "schema": {"type": "string", "format": "uuid"}}], "responses": { "200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, @@ -69,7 +69,7 @@ const SPEC: &str = r##"{ }, "/pets/{pet_id}/photos": { "put": { - "x-forge-group": ["pets", "photos"], "x-forge-method": "upload", + "x-forge-group": ["pets", "photos"], "x-forge-method-name": "upload", "parameters": [{"name": "pet_id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/octet-stream": {"schema": {"type": "string", "format": "binary"}}}}, "responses": {"204": {"description": "done"}} @@ -77,7 +77,7 @@ const SPEC: &str = r##"{ }, "/owners": { "get": { - "x-forge-group": ["owners"], "x-forge-method": "list", + "x-forge-group": ["owners"], "x-forge-method-name": "list", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": { @@ -138,7 +138,7 @@ const FEATURES: &str = r##"{ "/pets/{id}": { "parameters": [{"name": "X-Trace", "in": "header", "schema": {"type": "string"}}], "get": { - "x-forge-group": ["pets"], "x-forge-method": "get", + "x-forge-group": ["pets"], "x-forge-method-name": "get", "x-forge-availability": "beta", "x-forge-hidden": true, "x-custom": {"b": 1, "a": [1.5, "two \"quoted\"\n", null, true, {}], "b": 2}, "x-flag": false, "x-count": 9007199254740993, "x-text": "é 😀", @@ -146,15 +146,15 @@ const FEATURES: &str = r##"{ {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "limit", "in": "query", "schema": {"type": "integer", "default": 10}}, {"name": "x-trace", "in": "header", "required": true, "description": "Traces the call.", "schema": {"type": "string"}}, - {"name": "Authorization", "in": "header", "schema": {"type": "string", "x-sensitive": true}} + {"name": "Authorization", "in": "header", "schema": {"type": "string", "x-forge-sensitive": true}} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}} }, "delete": { "x-forge-aliases": [ - {"x-forge-group": ["pets"], "x-forge-method": "remove", "x-forge-availability": "deprecated", + {"x-forge-group": ["pets"], "x-forge-method-name": "remove", "x-forge-availability": "deprecated", "x-forge-require-confirmation": "This deletes the pet.", "x-alias": [1]}, - {"x-forge-group": ["admin", "pets"], "x-forge-method": "delete", "x-forge-require-confirmation": ""} + {"x-forge-group": ["admin", "pets"], "x-forge-method-name": "delete", "x-forge-require-confirmation": ""} ], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "gone"}} @@ -162,7 +162,7 @@ const FEATURES: &str = r##"{ }, "/pets/{id}/photo": { "put": { - "x-forge-group": ["pets", "photos"], "x-forge-method": "upload", + "x-forge-group": ["pets", "photos"], "x-forge-method-name": "upload", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"required": true, "content": { "application/octet-stream": {"schema": {"type": "string", "format": "binary", "description": "The photo."}}, @@ -178,7 +178,7 @@ const FEATURES: &str = r##"{ "components": {"schemas": { "Pet": {"type": "object", "properties": { "id": {"type": "string", "readOnly": true}, - "password": {"type": "string", "x-sensitive": true}, + "password": {"type": "string", "x-forge-sensitive": true}, "tags": {"type": "array", "items": {"type": "string"}, "minItems": 0, "maxItems": 3}, "dataset_scope": {"oneOf": [ {"type": "object", "properties": {"type": {"const": "default"}}, "required": ["type"], "additionalProperties": false}, From afdad0f8efce70e683988f5ef7ef7f1532a3cf62 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 12:29:11 -0400 Subject: [PATCH 11/21] docs: RFC 0001 takes x-forge-method-name and x-forge-sensitive --- rfcs/0001-metadata-resolution-layer.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index c94a91d5a..e67994b98 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -67,26 +67,29 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… | Native key | Form | Meaning | Compat source (the adapter translates) | |---|---|---|---| -| `x-forge-method` | string | the method's name | `x-fern-sdk-method-name` | +| `x-forge-method-name` | string | the method's name | `x-fern-sdk-method-name` | | `x-forge-group` | **array of strings**, top level first | the group path | `x-fern-sdk-group-name` (dotted string is Fern's format; the split lives in the adapter. Native has no dot syntax) | | `x-forge-ignore` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | | `x-forge-availability` | `alpha` \| `beta` \| `preview` \| `generally-available` \| `deprecated` | lifecycle stage. The values are Forge's shipped vocabulary (public enum across Rust, WIT, JS); Fern merely coincides | `x-fern-availability` | | `x-forge-model-name` | string | the model's name (components / `$defs` schema) | `x-fern-type-name` | | `x-forge-property-name` | string | the property's field name | `x-fern-property-name` | | `x-forge-parameter-name` | string | the parameter's field name | `x-fern-parameter-name` | -| `x-forge-hidden`, `x-forge-require-confirmation`, `x-forge-aliases`, `x-forge-commands`, `x-sensitive` | *(existing, unchanged)* | | — no vendor source; now owned by the native table | +| `x-forge-sensitive` | bool | the schema's value is a secret, to mask | — (replaces `x-sensitive`, below) | +| `x-sensitive` | bool | **deprecated** name of `x-forge-sensitive`, read only where `x-forge-sensitive` is not written | — (a native key, not a vendor one) | +| `x-forge-hidden`, `x-forge-require-confirmation`, `x-forge-aliases`, `x-forge-commands` | *(existing, unchanged)* | | — no vendor source; now owned by the native table | Design notes: - **Explicit position keys over one positional name key.** Fern used three name keys because its reader architecture had one visitor per OpenAPI object kind. We use explicit keys for a different, real reason: tools in the wild mangle `$ref` structure (inlining targets, dropping siblings), and when placement lies, the key name still carries the role — `x-forge-model-name` on a property schema can be ignored or flagged, where a positional `x-forge-name` would silently become a field name. Explicitness here is corruption-detection, not verbosity. - **One exclusion word, two positions.** "Excluded from generated surfaces" is one concept at two scopes; two words (`ignore` + `skip`) would be a memory tax for no disambiguation, and `skip` is Stainless's word. - **Arrays for groups.** JSON's native way to write a path. Accepting dotted strings natively would permanently import Fern's format into the native vocabulary; array-only now keeps the option to loosen later (the reverse — tightening later — would break specs). Fern's dotted strings keep working through the adapter for as long as Fern keys do. +- **Every native key begins with `x-forge-`.** The `-name` keys (`method-name`, `model-name`, `property-name`, `parameter-name`) say the same kind of thing and are spelled alike. `x-sensitive` predates the rule; it becomes `x-forge-sensitive`, and the old name stays readable as a deprecated alias (155 production uses), so no spec breaks. A deprecated alias is part of the native vocabulary, not of the compatibility layer: it keeps working with compat off, and deleting compat does not remove it. - **No misplacement validation in v1.** A known native key in a wrong position is silently ignored, exactly as Fern's keys are today. Adding validation later is a pure tightening that breaks no valid spec. ## Resolution rules -1. **Native applied, compat fallback** — per primitive, independently (a spec mid-migration may take the group from native and availability from Fern). -2. **Silent native-wins** — when both a native key and a compat key are present, the compat value is ignored without comparison machinery. Only the winning value is validated: an invalid compat `availability` does not error when a native one wins. A value of the wrong JSON type (a number where a string is expected) is still a document-shape error at read time, whichever key it is on and in whatever order the keys are written, so errors never depend on key order. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. +1. **Native applied, compat fallback** — per primitive, independently (a spec mid-migration may take the group from native and availability from Fern). Keys rank in three tiers: a native key under its current name, then a deprecated native alias (`x-sensitive`), then a compat key. The strongest tier present wins. +2. **Silent native-wins** — when keys of two tiers are present (a native key and a deprecated alias or compat key), the weaker value is ignored without comparison machinery. Only the winning value is validated: an invalid compat `availability` does not error when a native one wins. A value of the wrong JSON type (a number where a string is expected) is still a document-shape error at read time, whichever key it is on and in whatever order the keys are written, so errors never depend on key order. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. 3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). 4. **Empty or punctuation-only values** fall back to the positional wire name, as today; validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. 5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. @@ -97,9 +100,9 @@ Design notes: src/ ├─ metadata/ THE NATIVE LIBRARY — pure │ │ The x-forge-* table (per kind of object: definition, -│ │ parameter, schema, document), the primitives and format -│ │ descriptors, the availability vocabulary, the consumed-key -│ │ set. Imports neither compat nor link. No serde, no arena +│ │ parameter, schema, document), deprecated native aliases, +│ │ the primitives and format descriptors, the availability +│ │ vocabulary, the consumed-key set. Imports neither compat nor link. No serde, no arena │ │ coupling: its inputs are &str keys, its outputs small │ │ pure values. ├─ compat/ THE COMPATIBILITY LAYER — feature "compat" (default on) @@ -145,10 +148,10 @@ Properties, all deliberate: The implementation was checked against the unmodified engine on the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617…`): - **Fern-keyed behavior.** The original, untouched suite — 379 parse tests written with Fern keys — passed against the new engine before any fixture was migrated. -- **Generated output.** `forge --target ts` on the aggregate writes the same 3,381 files, byte for byte (`diff -r`). +- **Generated output.** `forge --target ts` on the aggregate writes the same 3,381 files, byte for byte (`diff -r`). The aggregate's 155 `x-sensitive` keys are read through the deprecated alias; the dump's 210 sensitive fields are unchanged. - **The model.** The full model dump (the repo's own `tests/wasm/dump.rs`: every group, method, availability, hidden flag, confirmation, extension and field name) is identical between the old and new engines: 197,702 lines, covering 3,021 availability values, 1,259 hidden flags, 217 confirmations and 4,695 extension entries. The generated TypeScript consumes none of those four, which is why the dump, not the output diff, is what proves them. - **Across the plugin boundary.** `tests/wasm.rs`, including the ignored `bench` on the aggregate, reports identical output and dump, native versus WASM, for 1,317 groups and 3,381 files; `wit_is_current` holds with the regenerated WIT. -- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 439 tests of the native suite; with compat on, 489 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. +- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 445 tests of the native suite, including the deprecated `x-sensitive` alias; with compat on, 495 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. - **The checks can fail.** Breaking the native-wins rule fails 8 compat tests; planting a vendor name in a doc comment fails the boundary test, naming the file and line. - **Performance.** Measured with `benches/compare.sh` (`just bench-compare`): parse and link of the aggregate, paired against the unmodified engine, each pair run base–new–new–base so that drift in the machine's speed cancels, and pairs in which the machine changed speed left out. The working tree is 0–1% slower (about +0.45 ms of 41.8 ms, standard error 0.17 ms, on a machine at full speed; −0.04 ms, standard error 0.28, on the same machine throttled). Peak memory is +0.55%, with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. - *Where it went.* Profiling (samply, with line tables, attributing inlined frames) found no hot spot of the layer's own: most of the difference is LLVM inlining parts of serde_json's key loop into `SchemaObject::read_object` and laying the code out differently, which moves with any change. Three things were measured and kept: each table turns away keys outside its prefix (`x-forge-`, `x-fern-`, `x-stainless-`) before matching, and only `x-` keys are asked about, so a skipped key costs one compare; and a `Hit` carries only its field and slot, the key's name looked up by slot when an error needs it, so the reader's per-key result fits in registers (16 bytes, as before, not 24). @@ -156,7 +159,7 @@ The implementation was checked against the unmodified engine on the released agg ## Release shape -Non-breaking. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release (new native keys accepted, compat module added); the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. +Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensitive`; when it stops being read is FORGE-4's policy question. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release (new native keys accepted, compat module added); the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. ## Alternatives considered @@ -173,7 +176,7 @@ Non-breaking. The WIT changes are doc comments only — `forge:plugin@0.3.0` sta | Ticket | What | |---|---| -| FORGE-3 | Vocabulary renames in one breaking release: `group` → `namespace`, plus the availability word review; `x-forge-group`/`x-forge-availability` become permanent alias keys (one table row each). | +| FORGE-3 | Vocabulary renames in one breaking release: `group` → `namespace`, plus the availability word review; `x-forge-group`/`x-forge-availability` become deprecated aliases (one table row each, the same tier `x-sensitive` uses). | | FORGE-4 | The versioning RFC: the four contracts, the rules this RFC assumes, and open questions (1.0 timing, warning channel, vendor-key EoL policy). | | FORGE-5 | Informational Forge CI lint flagging vendor keys the engine doesn't read, sourced from this layer's key table. | | (FORGE-1 follow-ups) | cf codebase Fern→Forge rename; dotted `operationId` derivation behind an opt-in flag. | From 7ee6854118a3d743e86c62d10a6f18c799316a70 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 12:33:20 -0400 Subject: [PATCH 12/21] docs: correct RFC 0001 on empty values, the npm release and a stray decision number - Rule 4 now says per key what an empty or punctuation-only value does: names fall back to the wire name; an empty method name or group path is no method, and a punctuation-only one is an error. - The npm release adds no compat module: the engine binary it ships is built with the default compat feature. - "the D4 rule" is resolution rule 2; the D-numbers were never defined. --- rfcs/0001-metadata-resolution-layer.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index e67994b98..79e463098 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -91,7 +91,10 @@ Design notes: 1. **Native applied, compat fallback** — per primitive, independently (a spec mid-migration may take the group from native and availability from Fern). Keys rank in three tiers: a native key under its current name, then a deprecated native alias (`x-sensitive`), then a compat key. The strongest tier present wins. 2. **Silent native-wins** — when keys of two tiers are present (a native key and a deprecated alias or compat key), the weaker value is ignored without comparison machinery. Only the winning value is validated: an invalid compat `availability` does not error when a native one wins. A value of the wrong JSON type (a number where a string is expected) is still a document-shape error at read time, whichever key it is on and in whatever order the keys are written, so errors never depend on key order. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. 3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). -4. **Empty or punctuation-only values** fall back to the positional wire name, as today; validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. +4. **Empty or punctuation-only values** behave as today, which depends on the key: + - `x-forge-property-name`, `x-forge-parameter-name` and `x-forge-model-name`: a value with no letters or digits, empty included, is ignored, and the field or model is named after its wire name (the property, parameter or schema name). + - `x-forge-method-name` and `x-forge-group`: an empty method name, or an empty group path (`[]`, or Fern's `""`), means the operation or alias is not a method. A method name, or any group name in the path, that is not empty but has no letters or digits is an error. + - Validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. 5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. ## Architecture @@ -123,7 +126,7 @@ src/ Properties, all deliberate: -- **Dependencies**: `link → metadata` and `link → compat` (behind the feature), and `compat → metadata` (an adapter produces metadata's primitives). `metadata` imports neither of the others, so compat sits *beside* the native table rather than under it. `link/resolve.rs` asks native first, compat second — that fallback arm *is* the D4 rule. +- **Dependencies**: `link → metadata` and `link → compat` (behind the feature), and `compat → metadata` (an adapter produces metadata's primitives). `metadata` imports neither of the others, so compat sits *beside* the native table rather than under it. `link/resolve.rs` asks native first, compat second — that fallback arm *is* resolution rule 2. - **Purity**: the library's contract is `&str` keys in and small values out: primitives, key names, and *format descriptors as data* (for example "a string splits on `.`" or "a list of targets counts as `false`"). The serde reading and the arena writes stay in `link` and are generic, driven by those descriptors. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). - **The availability vocabulary is native.** The five values live in the native table (they are shipped public API); `fern.rs` only maps `x-fern-availability` onto that primitive. - **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` and the cfg arms in `link/resolve.rs` (one for each kind of object) touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. @@ -159,7 +162,7 @@ The implementation was checked against the unmodified engine on the released agg ## Release shape -Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensitive`; when it stops being read is FORGE-4's policy question. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release (new native keys accepted, compat module added); the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. +Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensitive`; when it stops being read is FORGE-4's policy question. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release: the engine binary it ships accepts the new native keys and, built with the default `compat` feature, still reads the vendor keys, and the JS runtime changes only in doc comments; the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. ## Alternatives considered From 17af41c351395cd24b8cd9c6579d45b8411b6660 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 12:36:25 -0400 Subject: [PATCH 13/21] docs: record in RFC 0001 that an empty group path should be the root Today x-forge-group: [] makes no method. The intended meaning is a method at the root, which needs root methods in the model, the WIT and the generators, so it is documented as a known gap rather than fixed here. --- rfcs/0001-metadata-resolution-layer.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 79e463098..a6e1126c4 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -68,7 +68,7 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… | Native key | Form | Meaning | Compat source (the adapter translates) | |---|---|---|---| | `x-forge-method-name` | string | the method's name | `x-fern-sdk-method-name` | -| `x-forge-group` | **array of strings**, top level first | the group path | `x-fern-sdk-group-name` (dotted string is Fern's format; the split lives in the adapter. Native has no dot syntax) | +| `x-forge-group` | **array of strings**, top level first | the group path; `[]` is meant to be the root, but is not yet (see [Known gaps](#known-gaps)) | `x-fern-sdk-group-name` (dotted string is Fern's format; the split lives in the adapter. Native has no dot syntax) | | `x-forge-ignore` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | | `x-forge-availability` | `alpha` \| `beta` \| `preview` \| `generally-available` \| `deprecated` | lifecycle stage. The values are Forge's shipped vocabulary (public enum across Rust, WIT, JS); Fern merely coincides | `x-fern-availability` | | `x-forge-model-name` | string | the model's name (components / `$defs` schema) | `x-fern-type-name` | @@ -93,10 +93,20 @@ Design notes: 3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). 4. **Empty or punctuation-only values** behave as today, which depends on the key: - `x-forge-property-name`, `x-forge-parameter-name` and `x-forge-model-name`: a value with no letters or digits, empty included, is ignored, and the field or model is named after its wire name (the property, parameter or schema name). - - `x-forge-method-name` and `x-forge-group`: an empty method name, or an empty group path (`[]`, or Fern's `""`), means the operation or alias is not a method. A method name, or any group name in the path, that is not empty but has no letters or digits is an error. + - `x-forge-method-name` and `x-forge-group`: an empty method name, or an empty group path (`[]`, or Fern's `""`), means the operation or alias is not a method. For `[]` this is the current behavior, not the intended one: see [Known gaps](#known-gaps). A method name, or any group name in the path, that is not empty but has no letters or digits is an error. - Validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. 5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. +## Known gaps + +### An empty group path + +- **Intended:** `x-forge-group: []` attaches the method to the root, in no group. An operation without `x-forge-group` at all is still not a method. +- **Today:** `[]` makes no method, exactly like a missing key. `add_method` in `src/link.rs` returns before building the method when the path is empty; `Method::group`'s docs in `src/lib.rs` say so; and `tests/parse/groups.rs::empty_group_name_is_no_group` and the empty-group alias case in `tests/parse/aliases.rs` assert it. +- **Why it is not fixed here:** the model has no place for a root method. Methods exist only inside groups (`Forge::groups` → `Group::methods`); `Forge` has top-level models but no top-level methods, and neither does the WIT. The fix needs a root method list in the model, a way for plugins to read it (a new WIT function is additive; a new field in an existing record is not), and generators that render root methods. That is beyond FORGE-1, which leaves the model unchanged. +- **Impact:** none today. The released aggregate has no empty group path and no method name without a group, so the fix will not change its output. +- **To decide with the fix:** whether Fern's empty string (`x-fern-sdk-group-name: ""`) should also mean the root, or keep meaning "not a method" in the compatibility layer. + ## Architecture ``` From dc80bba4a40fb19661f2abdf2d2b436aa761a95c Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 12:58:52 -0400 Subject: [PATCH 14/21] test: native keys win inside an alias, and only the winning names are checked - In an alias, the native method name, group, availability and ignore win over Fern's, in either order. - A Fern group path or method name that is an error on its own is not checked when a native key wins. Breaking the precedence rule fails all three. --- tests/compat/native_first.rs | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tests/compat/native_first.rs b/tests/compat/native_first.rs index f26bde3f2..368968940 100644 --- a/tests/compat/native_first.rs +++ b/tests/compat/native_first.rs @@ -198,3 +198,87 @@ fn an_error_names_the_native_key_when_the_native_key_gave_the_value() { assert!(err.contains(r#"GET /a: x-forge-availability "ga" is not"#), "{err}"); } + +#[test] +fn only_the_winning_group_and_method_name_are_checked() { + // Each compat value is an error on its own, so the document parsing at + // all shows it was not checked. + native_wins( + r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-fern-sdk-group-name": "a..b","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + ); + native_wins( + r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-fern-sdk-method-name": "-","#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + ); + assert!( + parse_err(&operation_with( + r#""x-fern-sdk-group-name": "a..b", "x-forge-method-name": "get","# + )) + .contains("x-fern-sdk-group-name") + ); + assert!( + parse_err(&operation_with( + r#""x-forge-group": ["a"], "x-fern-sdk-method-name": "-","# + )) + .contains("x-fern-sdk-method-name") + ); +} + +/// Asserts that every ordering of `native` and `compat`, which are members of +/// an alias, builds what an alias of `expected` alone does, and that it has a +/// method named `method`. +#[track_caller] +fn native_wins_in_an_alias(native: &str, compat: &str, expected: &str, method: &str) { + let alias = |keys: &str| operation_with(&format!(r#""x-forge-aliases": [{{{keys}}}],"#)); + for keys in [format!("{native}, {compat}"), format!("{compat}, {native}")] { + assert_same(&alias(&keys), &alias(expected)); + } + let described = describe(&parse(&alias(expected))); + assert!(described.contains(&format!("method {method} ")), "{described}"); +} + +#[test] +fn the_native_keys_of_an_alias_win() { + native_wins_in_an_alias( + r#""x-forge-group": ["a"], "x-forge-method-name": "native""#, + r#""x-fern-sdk-method-name": "vendor""#, + r#""x-forge-group": ["a"], "x-forge-method-name": "native""#, + "native", + ); + native_wins_in_an_alias( + r#""x-forge-method-name": "get", "x-forge-group": ["native"]"#, + r#""x-fern-sdk-group-name": "vendor.group""#, + r#""x-forge-method-name": "get", "x-forge-group": ["native"]"#, + "get", + ); + native_wins_in_an_alias( + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta""#, + r#""x-fern-availability": "ga""#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta""#, + "get", + ); + native_wins_in_an_alias( + r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": false"#, + r#""x-fern-ignore": true"#, + r#""x-forge-group": ["a"], "x-forge-method-name": "get""#, + "get", + ); +} + +#[test] +fn a_native_ignore_in_an_alias_drops_the_method_a_compat_one_would_keep() { + let alias = |keys: &str| { + operation_with(&format!( + r#""x-forge-aliases": [{{"x-forge-group": ["a"], "x-forge-method-name": "get", {keys}}}],"# + )) + }; + for keys in [ + r#""x-forge-ignore": true, "x-fern-ignore": false"#, + r#""x-fern-ignore": false, "x-forge-ignore": true"#, + ] { + assert_eq!(parse(&alias(keys)).groups().count(), 0, "{keys}"); + } +} From 1c1d5ea81f75fab22872e377169abe0e5186f8cb Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 13:16:15 -0400 Subject: [PATCH 15/21] docs: correct RFC 0001 where it claimed more than the code does - The boundary goal covers the engine; the docs packages read vendor keys themselves and are a non-goal. - resolve.rs is the only place link calls compat, not the only cfg point. - Deleting the layer lists every step, and what it leaves behind. - With compat off, vendor keys become ordinary extensions for plugins. - The name lookups are a second way vendor key names leave compat, as data, for errors. - Test counts, the mutation result, and performance and memory are re-measured on the final code. --- rfcs/0001-metadata-resolution-layer.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index a6e1126c4..9508b2c4a 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -44,7 +44,7 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… ## Goals -- Nothing outside the resolution layer references `x-fern-*` or `x-stainless-*` — enforced mechanically. +- Nothing in the engine outside the resolution layer references `x-fern-*` or `x-stainless-*` — enforced mechanically. The engine is `src/`, `tests/` and the `packages/forge` npm package; the docs packages in this repository (`astro-fern`, `fern-forge`, `cloudflare-api-site`) read vendor keys themselves and are outside this RFC (see Non-goals). - Output for existing specs is unchanged, proven by byte-equality tests on the real aggregate. - Tests cover each supported primitive, from each accepted key. - No meaningful performance regression; parse throughput is benchmarked before and after. @@ -61,7 +61,7 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… - Dotted `operationId` derivation (`a.b.c.d` → group `[a,b,c]` + method `d`) — a follow-up that will land *in this layer* behind an opt-in flag. - Audiences. The ticket lists audiences as a lower-priority primitive; this RFC deliberately leaves `x-fern-audiences` unread (it needs a visibility concept Forge has not designed), flagged by FORGE-5. This is a scope deviation from the ticket text and needs the reviewers' agreement. - New primitives for `x-fern-enum` (enum-value names — needs a model primitive that does not exist yet), `x-stability`, `x-forge-sunset`, `x-stainless-deprecation-message`. These are flagged (FORGE-5) and stay unread; each would be a one-row additive addition later. -- Treating the `fern-forge` docs package's own `x-fern-*` reading (a downstream consumer, like cf) — follow-up. +- The docs packages' own `x-fern-*` reading (`fern-forge`, `astro-fern`, `cloudflare-api-site`: downstream consumers, like cf) — follow-up. ## The native vocabulary @@ -120,7 +120,8 @@ src/ │ │ pure values. ├─ compat/ THE COMPATIBILITY LAYER — feature "compat" (default on) │ ├─ mod.rs the aggregator: one resolver per kind of object, trying -│ │ each vendor in turn. The only thing link imports from here. +│ │ each vendor in turn, and one name lookup per kind, for +│ │ errors. The only things link imports from here. │ │ The designed end state: delete this folder + the feature. │ ├─ fern.rs every x-fern-* literal, mapped onto metadata's primitives; │ │ Fern's value formats, as data (e.g. "a string splits on @@ -129,7 +130,9 @@ src/ │ (a list of targets counts as false); unit tests. └─ link/ ├─ resolve.rs the orchestrator: native first, then compat behind - │ #[cfg(feature = "compat")] — the only cfg point. + │ #[cfg(feature = "compat")] — the only place link calls + │ compat. (The feature's other cfg points: `mod compat` in + │ lib.rs, and the compat-only items in metadata.) ├─ openapi.rs OpenAPI's own keys only; every x- key asks resolve.rs. └─ read.rs serde helpers, as today. ``` @@ -139,12 +142,14 @@ Properties, all deliberate: - **Dependencies**: `link → metadata` and `link → compat` (behind the feature), and `compat → metadata` (an adapter produces metadata's primitives). `metadata` imports neither of the others, so compat sits *beside* the native table rather than under it. `link/resolve.rs` asks native first, compat second — that fallback arm *is* resolution rule 2. - **Purity**: the library's contract is `&str` keys in and small values out: primitives, key names, and *format descriptors as data* (for example "a string splits on `.`" or "a list of targets counts as `false`"). The serde reading and the arena writes stay in `link` and are generic, driven by those descriptors. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). - **The availability vocabulary is native.** The five values live in the native table (they are shipped public API); `fern.rs` only maps `x-fern-availability` onto that primitive. -- **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone; when vendor keys reach end-of-life, deleting `compat/` and the cfg arms in `link/resolve.rs` (one for each kind of object) touches nothing else — no `x-forge-*` extension changes, in behavior, docs, or WIT. +- **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone. When vendor keys reach end-of-life, deleting the layer means removing `src/compat/` and `tests/compat/`, `mod compat` in `src/lib.rs`, the `compat` cfg arms in `link/resolve.rs` (a resolver and a name lookup for each kind of object the layer reads: operations and aliases, parameters, schemas), and the `compat` feature and its `[[test]]` entry in `Cargo.toml`. No `x-forge-*` extension changes, in behavior, docs, or WIT. + - *What a deletion leaves behind.* Some native-side code exists only for the layer and compiles, unused, without it: `Hit::compat` and `Hit::after`, `Tier::Compat`, `COMPAT_SLOTS`, the value formats only vendors use (`GroupFormat::StringOrArray`, `BoolFormat::BoolOrTargets`) and their readers in `link/openapi.rs`, and the sentence in `Method::extensions`'s docs about the keys the compatibility layer reads. Removing them is a mechanical follow-on step, not a prerequisite. +- **With compat off, vendor keys are ordinary extensions.** Built without the feature, the engine does not drop `x-fern-*` and `x-stainless-*` keys: like any other `x-` key it does not read, an operation's vendor keys are kept and given to plugins by `Method::extensions`. Native behavior is the same either way; what plugins see in `extensions()` is not. - **Dispatch, not semantics**: the layer maps keys to primitives and normalizes simple values. Structural behavior — `x-forge-aliases` becoming methods, `x-forge-commands` describing groups — stays in the builder. ## Enforcement -- **Structural boundary — compiler-enforced (built-in Rust):** every vendor key literal is private to its adapter; the only thing outside `compat/` that can touch vendor knowledge is the aggregator's per-object resolvers, which `link/resolve.rs` calls. The feature gate makes compat removable, and builds without the `compat` feature keep proving it. +- **Structural boundary — compiler-enforced (built-in Rust):** every vendor key literal is private to its adapter; the only things outside `compat/` that can touch vendor knowledge are the aggregator's per-object resolvers and name lookups, which `link/resolve.rs` calls. The name lookups are how a vendor key's name reaches an error message (rule 4's provenance) without `link` holding the literal: it reaches `link` as data, never as code that matches on it. The feature gate makes compat removable, and builds without the `compat` feature keep proving it. - **Textual boundary — `tests/boundary.rs`:** scans `src/`, `tests/`, and `packages/forge/` (including the shipped `plugin/forge.wit`) for `x-fern` / `x-stainless` outside `src/compat/` and `tests/compat/`. Doc comments count — moving the WIT's "from `x-fern-availability`" attribution to `x-forge-availability` is part of the work. The test runs wherever `cargo test` runs; a `just boundary` alias targets it. - **Criterion mapping:** (1) nothing outside the layer references `x-fern-*` → the two mechanisms above; (2) output unchanged → zero model-shape changes, Fern-keyed specs resolve identically (equivalence tests + the full-aggregate native-vs-wasm byte-equality bench); (3) tests per primitive → below. @@ -164,9 +169,9 @@ The implementation was checked against the unmodified engine on the released agg - **Generated output.** `forge --target ts` on the aggregate writes the same 3,381 files, byte for byte (`diff -r`). The aggregate's 155 `x-sensitive` keys are read through the deprecated alias; the dump's 210 sensitive fields are unchanged. - **The model.** The full model dump (the repo's own `tests/wasm/dump.rs`: every group, method, availability, hidden flag, confirmation, extension and field name) is identical between the old and new engines: 197,702 lines, covering 3,021 availability values, 1,259 hidden flags, 217 confirmations and 4,695 extension entries. The generated TypeScript consumes none of those four, which is why the dump, not the output diff, is what proves them. - **Across the plugin boundary.** `tests/wasm.rs`, including the ignored `bench` on the aggregate, reports identical output and dump, native versus WASM, for 1,317 groups and 3,381 files; `wit_is_current` holds with the regenerated WIT. -- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 445 tests of the native suite, including the deprecated `x-sensitive` alias; with compat on, 495 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. -- **The checks can fail.** Breaking the native-wins rule fails 8 compat tests; planting a vendor name in a doc comment fails the boundary test, naming the file and line. -- **Performance.** Measured with `benches/compare.sh` (`just bench-compare`): parse and link of the aggregate, paired against the unmodified engine, each pair run base–new–new–base so that drift in the machine's speed cancels, and pairs in which the machine changed speed left out. The working tree is 0–1% slower (about +0.45 ms of 41.8 ms, standard error 0.17 ms, on a machine at full speed; −0.04 ms, standard error 0.28, on the same machine throttled). Peak memory is +0.55%, with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. +- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 445 tests of the native suite, including the deprecated `x-sensitive` alias; with compat on, 498 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. +- **The checks can fail.** Breaking the precedence rule (keeping the last value written, whatever its tier) fails 11 compat tests, and 1 `tests/parse` test, the deprecated `x-sensitive` one, with compat on and off; planting a vendor name in a doc comment fails the boundary test, naming the file and line. +- **Performance.** Measured with `benches/compare.sh` (`just bench-compare`): parse and link of the aggregate, paired against the unmodified engine, each pair run base–new–new–base so that drift in the machine's speed cancels, and pairs in which the machine changed speed left out. On the final code (`4e31404`), over 12 pairs, it is 0.8% slower: +0.34 ms of 42.0 ms, standard error 0.18 ms (t = 1.9), slower in 9 of 12 pairs. Earlier runs during the work put it between −0.1% and +1.1%, depending on the machine's speed state. Peak memory is 68.80 MB against 68.75 MB (+0.07%), with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. - *Where it went.* Profiling (samply, with line tables, attributing inlined frames) found no hot spot of the layer's own: most of the difference is LLVM inlining parts of serde_json's key loop into `SchemaObject::read_object` and laying the code out differently, which moves with any change. Three things were measured and kept: each table turns away keys outside its prefix (`x-forge-`, `x-fern-`, `x-stainless-`) before matching, and only `x-` keys are asked about, so a skipped key costs one compare; and a `Hit` carries only its field and slot, the key's name looked up by slot when an error needs it, so the reader's per-key result fits in registers (16 bytes, as before, not 24). - *Ruling things out.* Unpaired, sequential runs had suggested +1.5–1.9%; that was the machine warming up through the session, which the ABBA order removes. A single run of either binary differs from the next by about as much as the change measured here, so a smaller difference needs more pairs, not a better single run. From aed8392e662701c8d62700f1a1ed46377448d06c Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 16:12:20 -0400 Subject: [PATCH 16/21] feat: x-forge-group accepts a dotted string, as Cloudflare's specs write groups --- rfcs/0001-metadata-resolution-layer.md | 26 ++++++------ src/compat/fern.rs | 18 +++++---- src/lib.rs | 11 +++--- src/link/openapi.rs | 35 ++++++---------- src/metadata/mod.rs | 19 +++------ tests/compat/fern.rs | 4 +- tests/compat/native_first.rs | 12 +++--- tests/parse/groups.rs | 55 +++++++++++++++++--------- 8 files changed, 93 insertions(+), 87 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 9508b2c4a..4176308f2 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -20,7 +20,7 @@ After the boundary, the engine — reader, builder, linked model, plugin host, n Today the engine couples to vendors in five places: 1. **Wire keys** — vendor names are hardcoded in the serde key enums (`DefinitionKey`, `ParameterKey::FieldName`, `SchemaKey::{ModelName, FieldName, Skip}` in `src/link/openapi.rs`). -2. **Vendor value formats** — Fern's dotted-or-array group strings, Fern's five-value availability vocabulary, Stainless's `x-stainless-skip` (where a list of target names means *false*). +2. **Vendor value formats** — Fern's five-value availability vocabulary, Stainless's `x-stainless-skip` (where a list of target names means *false*). 3. **Error strings** — validation messages name vendor keys ("`x-fern-availability "ga" is not …`"). 4. **The consumed-key set** — the seven names excluded from the plugin passthrough are hand-listed in the deserializers and re-documented in the model docs. 5. **Documentation** — the public model, the WIT, and the JS runtime attribute primitives to vendor keys; the WIT's doc comments ship in the npm package. @@ -68,7 +68,7 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… | Native key | Form | Meaning | Compat source (the adapter translates) | |---|---|---|---| | `x-forge-method-name` | string | the method's name | `x-fern-sdk-method-name` | -| `x-forge-group` | **array of strings**, top level first | the group path; `[]` is meant to be the root, but is not yet (see [Known gaps](#known-gaps)) | `x-fern-sdk-group-name` (dotted string is Fern's format; the split lives in the adapter. Native has no dot syntax) | +| `x-forge-group` | **string of names separated by dots**, or **array of strings**, top level first (array elements are not split) | the group path; `""` and `[]` are meant to be the root, but are not yet (see [Known gaps](#known-gaps)) | `x-fern-sdk-group-name` (read the same way as the native key) | | `x-forge-ignore` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | | `x-forge-availability` | `alpha` \| `beta` \| `preview` \| `generally-available` \| `deprecated` | lifecycle stage. The values are Forge's shipped vocabulary (public enum across Rust, WIT, JS); Fern merely coincides | `x-fern-availability` | | `x-forge-model-name` | string | the model's name (components / `$defs` schema) | `x-fern-type-name` | @@ -82,7 +82,8 @@ Design notes: - **Explicit position keys over one positional name key.** Fern used three name keys because its reader architecture had one visitor per OpenAPI object kind. We use explicit keys for a different, real reason: tools in the wild mangle `$ref` structure (inlining targets, dropping siblings), and when placement lies, the key name still carries the role — `x-forge-model-name` on a property schema can be ignored or flagged, where a positional `x-forge-name` would silently become a field name. Explicitness here is corruption-detection, not verbosity. - **One exclusion word, two positions.** "Excluded from generated surfaces" is one concept at two scopes; two words (`ignore` + `skip`) would be a memory tax for no disambiguation, and `skip` is Stainless's word. -- **Arrays for groups.** JSON's native way to write a path. Accepting dotted strings natively would permanently import Fern's format into the native vocabulary; array-only now keeps the option to loosen later (the reverse — tightening later — would break specs). Fern's dotted strings keep working through the adapter for as long as Fern keys do. +- **Groups as a dotted string or an array.** The dotted string is how Cloudflare's specs write a group path today, and Forge CI's lint requires it, so moving a team to `x-forge-group` is a rename of the key, with the value unchanged. The array is JSON's own way to write a path, and the way to write a group name that has a dot in it. Both are read exactly as forge has always read groups. +- **The dotted string is Cloudflare's, not Fern's.** Fern reads a string `x-fern-sdk-group-name` as *one* group (`"a.b"` is a group named `a.b`) and an array as a path; it never splits on dots. The release pipeline converts Cloudflare's dotted strings to arrays before Fern sees them (the released aggregate has 3,591 arrays and no strings). Forge has always split them, and the adapter reads the Fern key the same way as the native one, so for a string with a dot the adapter and Fern disagree. That is deliberate: the specs forge reads write Fern's key in Cloudflare's convention, and reading the two keys alike keeps a key rename from changing a value's meaning. - **Every native key begins with `x-forge-`.** The `-name` keys (`method-name`, `model-name`, `property-name`, `parameter-name`) say the same kind of thing and are spelled alike. `x-sensitive` predates the rule; it becomes `x-forge-sensitive`, and the old name stays readable as a deprecated alias (155 production uses), so no spec breaks. A deprecated alias is part of the native vocabulary, not of the compatibility layer: it keeps working with compat off, and deleting compat does not remove it. - **No misplacement validation in v1.** A known native key in a wrong position is silently ignored, exactly as Fern's keys are today. Adding validation later is a pure tightening that breaks no valid spec. @@ -93,7 +94,7 @@ Design notes: 3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). 4. **Empty or punctuation-only values** behave as today, which depends on the key: - `x-forge-property-name`, `x-forge-parameter-name` and `x-forge-model-name`: a value with no letters or digits, empty included, is ignored, and the field or model is named after its wire name (the property, parameter or schema name). - - `x-forge-method-name` and `x-forge-group`: an empty method name, or an empty group path (`[]`, or Fern's `""`), means the operation or alias is not a method. For `[]` this is the current behavior, not the intended one: see [Known gaps](#known-gaps). A method name, or any group name in the path, that is not empty but has no letters or digits is an error. + - `x-forge-method-name` and `x-forge-group`: an empty method name, or an empty group path (`""` or `[]`), means the operation or alias is not a method. For the empty group path this is the current behavior, not the intended one: see [Known gaps](#known-gaps). A method name, or any group name in the path, that is not empty but has no letters or digits is an error. - Validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. 5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. @@ -101,11 +102,11 @@ Design notes: ### An empty group path -- **Intended:** `x-forge-group: []` attaches the method to the root, in no group. An operation without `x-forge-group` at all is still not a method. -- **Today:** `[]` makes no method, exactly like a missing key. `add_method` in `src/link.rs` returns before building the method when the path is empty; `Method::group`'s docs in `src/lib.rs` say so; and `tests/parse/groups.rs::empty_group_name_is_no_group` and the empty-group alias case in `tests/parse/aliases.rs` assert it. +- **Intended:** `x-forge-group: []` (or `""`) attaches the method to the root, in no group. An operation without `x-forge-group` at all is still not a method. +- **Today:** an empty group path makes no method, exactly like a missing key. `add_method` in `src/link.rs` returns before building the method when the path is empty; `Method::group`'s docs in `src/lib.rs` say so; and `tests/parse/groups.rs::empty_group_name_is_no_group` and the empty-group alias case in `tests/parse/aliases.rs` assert it. - **Why it is not fixed here:** the model has no place for a root method. Methods exist only inside groups (`Forge::groups` → `Group::methods`); `Forge` has top-level models but no top-level methods, and neither does the WIT. The fix needs a root method list in the model, a way for plugins to read it (a new WIT function is additive; a new field in an existing record is not), and generators that render root methods. That is beyond FORGE-1, which leaves the model unchanged. - **Impact:** none today. The released aggregate has no empty group path and no method name without a group, so the fix will not change its output. -- **To decide with the fix:** whether Fern's empty string (`x-fern-sdk-group-name: ""`) should also mean the root, or keep meaning "not a method" in the compatibility layer. +- **To decide with the fix:** whether an empty `x-fern-sdk-group-name` (`""` or `[]`) should also mean the root, or keep meaning "not a method" in the compatibility layer. Fern itself puts a method with no group, or an empty array, at the root of the client, so meaning the root would bring the adapter closer to Fern. ## Architecture @@ -124,8 +125,8 @@ src/ │ │ errors. The only things link imports from here. │ │ The designed end state: delete this folder + the feature. │ ├─ fern.rs every x-fern-* literal, mapped onto metadata's primitives; -│ │ Fern's value formats, as data (e.g. "a string splits on -│ │ dots"); Fern unit tests. +│ │ the value formats of those keys, as data; Fern unit +│ │ tests. │ └─ stainless.rs the x-stainless-skip mapping and its format-as-data │ (a list of targets counts as false); unit tests. └─ link/ @@ -143,7 +144,7 @@ Properties, all deliberate: - **Purity**: the library's contract is `&str` keys in and small values out: primitives, key names, and *format descriptors as data* (for example "a string splits on `.`" or "a list of targets counts as `false`"). The serde reading and the arena writes stay in `link` and are generic, driven by those descriptors. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). - **The availability vocabulary is native.** The five values live in the native table (they are shipped public API); `fern.rs` only maps `x-fern-availability` onto that primitive. - **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone. When vendor keys reach end-of-life, deleting the layer means removing `src/compat/` and `tests/compat/`, `mod compat` in `src/lib.rs`, the `compat` cfg arms in `link/resolve.rs` (a resolver and a name lookup for each kind of object the layer reads: operations and aliases, parameters, schemas), and the `compat` feature and its `[[test]]` entry in `Cargo.toml`. No `x-forge-*` extension changes, in behavior, docs, or WIT. - - *What a deletion leaves behind.* Some native-side code exists only for the layer and compiles, unused, without it: `Hit::compat` and `Hit::after`, `Tier::Compat`, `COMPAT_SLOTS`, the value formats only vendors use (`GroupFormat::StringOrArray`, `BoolFormat::BoolOrTargets`) and their readers in `link/openapi.rs`, and the sentence in `Method::extensions`'s docs about the keys the compatibility layer reads. Removing them is a mechanical follow-on step, not a prerequisite. + - *What a deletion leaves behind.* Some native-side code exists only for the layer and compiles, unused, without it: `Hit::compat` and `Hit::after`, `Tier::Compat`, `COMPAT_SLOTS`, the value format only a vendor uses (`BoolFormat::BoolOrTargets`) and its reader in `link/openapi.rs`, and the sentence in `Method::extensions`'s docs about the keys the compatibility layer reads. Removing them is a mechanical follow-on step, not a prerequisite. - **With compat off, vendor keys are ordinary extensions.** Built without the feature, the engine does not drop `x-fern-*` and `x-stainless-*` keys: like any other `x-` key it does not read, an operation's vendor keys are kept and given to plugins by `Method::extensions`. Native behavior is the same either way; what plugins see in `extensions()` is not. - **Dispatch, not semantics**: the layer maps keys to primitives and normalizes simple values. Structural behavior — `x-forge-aliases` becoming methods, `x-forge-commands` describing groups — stays in the builder. @@ -156,7 +157,7 @@ Properties, all deliberate: ## Test plan - `tests/parse/` — every fixture rewrites to native keys. Not find-and-replace: group values `"a.b"` become `["a","b"]`; the three Fern name keys become their explicit native keys; error assertions naming Fern keys move out. -- `tests/compat/` — the vendor suite, mirroring `tests/parse`'s harness: for each primitive, parse(Fern-keyed fixture) == parse(native-keyed fixture); Fern format specifics (dotted vs array groups, duplicate-key errors, provenance error strings, Stainless's skip-list semantics). +- `tests/compat/` — the vendor suite, mirroring `tests/parse`'s harness: for each primitive, parse(Fern-keyed fixture) == parse(native-keyed fixture); format specifics (dotted vs array groups, duplicate-key errors, provenance error strings, Stainless's skip-list semantics). - `tests/boundary.rs` — the guard. - Existing tripwires keep working: `wit_is_current` (WIT regeneration is mechanical via `wit.mjs`), the wasm dump equality, native-vs-wasm generated-output byte equality. - Performance: divan parse benches before/after on the real aggregate (`FORGE_SPEC`); `tests/wasm.rs::bench` re-run; forge-bench re-pinned upstream after merge. @@ -185,7 +186,8 @@ Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensi - **Vendor-trait machinery** (a `Vendor` trait with Fern/Stainless/Scalar impls): no primitive overlaps across vendors today; the key table grows rows when one does. Rejected as over-engineering for now. - **One positional `x-forge-name`**: mirrors the model's single `Name` concept and is cleaner in the abstract — but when toolchains inline `$ref` targets, the model's name key rides into property positions and silently renames fields. Explicit keys turn that corruption into something ignorable or flaggable. Rejected on robustness. - **Separate `x-forge-skip` for properties**: two words for one concept, and `skip` is Stainless's word. Rejected. -- **Accepting dotted group strings natively**: ergonomic continuity, but it permanently imports Fern's format into the native vocabulary; array-only now is the reversible choice. Rejected. +- **Arrays only for `x-forge-group`**: one form, which every tool reads the same way, and loosening later would break nothing. Rejected: Cloudflare's specs write dotted strings, so every migration would reshape values as well as rename keys, and Forge CI's lint would need an array rule. +- **Reading a string `x-fern-sdk-group-name` as one group, as Fern does**: faithful to Fern, but the native and Fern keys would then read the same value differently, and the specs forge reads use dots. Rejected. - **Error on native/compat disagreement**: the strictest conflict rule, and consistent with the engine's general strictness — deferred as an open question in FORGE-4 in favor of silent native-wins (zero comparison machinery, no cost for correct specs; the drift risk is documented). - **Full crate split now** (a separate `metadata` member crate): delivers "separate library" literally today. The root `Cargo.toml` is already a `[workspace]`, so adding a member does not mean moving the engine; the real cost is that a separate crate cannot depend on the engine, so `Availability` and the other primitive value types would move into it and be re-exported by `forge`. Deferred: the pure contract keeps that move mechanical for when the first standalone consumer exists. - **Renaming `Group`/`Availability` now**: both are Fern-inherited words, but both renames break the plugin contract. Deferred to FORGE-3's single breaking wave. diff --git a/src/compat/fern.rs b/src/compat/fern.rs index fe7358fdf..925f7e47a 100644 --- a/src/compat/fern.rs +++ b/src/compat/fern.rs @@ -3,17 +3,22 @@ //! | Key | Says | Format | //! |---|---|---| //! | `x-fern-sdk-method-name` | the name of the method | a string | -//! | `x-fern-sdk-group-name` | the group path of the method | an array of group names, or one string of them separated by dots | +//! | `x-fern-sdk-group-name` | the group path of the method | as `x-forge-group`: an array of group names, or one string of them separated by dots | //! | `x-fern-ignore` | the definition makes no method | a boolean | //! | `x-fern-availability` | the stage of the API | a string, one of the native spellings | //! | `x-fern-parameter-name` | the name of a parameter's field | a string | //! | `x-fern-property-name` | the name of a property's field | a string | //! | `x-fern-type-name` | the name of a model | a string | //! +//! A group path written as one string is split on dots, as for +//! `x-forge-group`, which Fern itself does not do: Fern reads a string as a +//! single group. A document written for Fern uses the array, which means the +//! same in both. +//! //! Its other extensions, such as `x-fern-enum` and `x-fern-audiences`, are //! not read: they say things forge has no primitive for. -use crate::metadata::{BoolFormat, DefinitionField, GroupFormat, Hit, ParameterField, SchemaField}; +use crate::metadata::{BoolFormat, DefinitionField, Hit, ParameterField, SchemaField}; /// What every key of the adapter begins with. A key without it is turned /// away before it is matched against the table. @@ -39,7 +44,7 @@ pub(super) fn definition(key: &str) -> Option> { } Some(match key { METHOD_NAME => Hit::compat(DefinitionField::Method, 0), - GROUP_NAME => Hit::compat(DefinitionField::Group(GroupFormat::StringOrArray { separator: '.' }), 1), + GROUP_NAME => Hit::compat(DefinitionField::Group, 1), IGNORE => Hit::compat(DefinitionField::Ignore(BoolFormat::Bool), 2), AVAILABILITY => Hit::compat(DefinitionField::Availability, 3), _ => return None, @@ -108,12 +113,9 @@ mod tests { } #[test] - fn the_group_is_a_string_split_on_dots_or_an_array() { + fn the_group_is_read_as_the_native_group() { let hit = definition(GROUP_NAME).unwrap(); - assert!(matches!( - hit.field, - DefinitionField::Group(GroupFormat::StringOrArray { separator: '.' }) - )); + assert!(matches!(hit.field, DefinitionField::Group)); } #[test] diff --git a/src/lib.rs b/src/lib.rs index bc07c7d84..df76e0b69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -265,11 +265,12 @@ impl<'f> Method<'f> { /// Returns the group the method is in. /// /// Corresponds to the `x-forge-group` extension of the operation, or - /// of the alias the method comes from: an array with one group name per - /// element, top level first, such as `[accounts, members]`. An - /// operation or alias without one, with an empty one, or with - /// `x-forge-ignore: true` is not a method. A group name with no letters - /// or digits is an error. + /// of the alias the method comes from: a string of group names + /// separated by dots, such as `accounts.members`, or an array with one + /// group name per element, top level first, whose elements are not + /// split. An operation or alias without one, with an empty one, or + /// with `x-forge-ignore: true` is not a method. A group name with no + /// letters or digits is an error. pub fn group(self) -> Group<'f> { self.forge.group(self.data().group) } diff --git a/src/link/openapi.rs b/src/link/openapi.rs index 05b4867ce..dd1b2b093 100644 --- a/src/link/openapi.rs +++ b/src/link/openapi.rs @@ -28,9 +28,7 @@ use super::resolve; use crate::Name; use crate::arena::{Id, List, Span, Str, Strings}; use crate::json::{self, Json}; -use crate::metadata::{ - self, BoolFormat, DefinitionField, DocumentField, GroupFormat, Hit, ParameterField, SchemaField, Tier, -}; +use crate::metadata::{self, BoolFormat, DefinitionField, DocumentField, Hit, ParameterField, SchemaField, Tier}; /// An OpenAPI document: the fields of the OpenAPI Object at its root, and /// the arenas of the objects in it. @@ -896,36 +894,29 @@ impl Read for Types { } } -/// What reads a group path into a `Doc`, in the format it is written in: -/// an array of strings, which are not split, and, if the format says so, a -/// string split on its separator, where the empty string is no group. -struct GroupNames<'a>(&'a mut Doc, GroupFormat); +/// Reads a group path: a string split on dots, or an array of strings that +/// are not split. The empty string is no group. +struct GroupNames; -impl<'de> DeserializeSeed<'de> for GroupNames<'_> { - type Value = Span; +impl Read for GroupNames { + type Out = Span; - fn deserialize>(self, deserializer: D) -> Result, D::Error> { - struct GroupNamesVisitor<'a>(&'a mut Doc, GroupFormat); + fn read<'de, D: Deserializer<'de>>(doc: &mut Doc, deserializer: D) -> Result, D::Error> { + struct GroupNamesVisitor<'a>(&'a mut Doc); impl<'de> Visitor<'de> for GroupNamesVisitor<'_> { type Value = Span; fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.1 { - GroupFormat::Array => f.write_str("an array of strings"), - GroupFormat::StringOrArray { .. } => f.write_str("a string or an array of strings"), - } + f.write_str("a string or an array of strings") } fn visit_str(self, v: &str) -> Result, E> { - let GroupFormat::StringOrArray { separator } = self.1 else { - return Err(E::invalid_type(de::Unexpected::Str(v), &self)); - }; if v.is_empty() { return Ok(Span::default()); } let doc = self.0; - Ok(doc.strings.push_split(v, separator, &mut doc.str_lists)) + Ok(doc.strings.push_split(v, '.', &mut doc.str_lists)) } fn visit_seq>(self, seq: A) -> Result, A::Error> { @@ -934,7 +925,7 @@ impl<'de> DeserializeSeed<'de> for GroupNames<'_> { } } - deserializer.deserialize_any(GroupNamesVisitor(self.0, self.1)) + deserializer.deserialize_any(GroupNamesVisitor(doc)) } } @@ -1312,8 +1303,8 @@ impl Definition { let name = map.next_value_seed(seed::(doc))?; self.method_name.set(&hit, name); } - DefinitionField::Group(format) => { - let names = map.next_value_seed(GroupNames(doc, format))?; + DefinitionField::Group => { + let names = map.next_value_seed(seed::(doc))?; self.group_names.set(&hit, names); } DefinitionField::Ignore(format) => { diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index ae40ba42c..dc59da651 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -124,8 +124,10 @@ pub(crate) fn native_name(names: &[&'static str], slot: u8) -> Option<&'static s pub(crate) enum DefinitionField { /// The name of the method. Method, - /// The group path of the method. - Group(GroupFormat), + /// The group path of the method: an array of group names, top level + /// first, or one string of them separated by dots. The empty string is + /// no group. + Group, /// Whether the definition makes no method. Ignore(BoolFormat), /// The stage of the API the method is in. @@ -163,17 +165,6 @@ pub(crate) enum DocumentField { Commands, } -/// How the value of a group path is written. -#[derive(Clone, Copy)] -pub(crate) enum GroupFormat { - /// An array of group names, top level first. - Array, - /// An array of group names, or one string of them separated by - /// `separator`. The empty string is no group. - #[cfg_attr(not(feature = "compat"), expect(dead_code))] - StringOrArray { separator: char }, -} - /// How the value of a boolean is written. #[derive(Clone, Copy)] pub(crate) enum BoolFormat { @@ -192,7 +183,7 @@ pub(crate) fn definition(key: &str) -> Option> { } Some(match key { METHOD_NAME => Hit::native(DefinitionField::Method, 0), - GROUP => Hit::native(DefinitionField::Group(GroupFormat::Array), 1), + GROUP => Hit::native(DefinitionField::Group, 1), IGNORE => Hit::native(DefinitionField::Ignore(BoolFormat::Bool), 2), AVAILABILITY => Hit::native(DefinitionField::Availability, 3), HIDDEN => Hit::native(DefinitionField::Hidden, 4), diff --git a/tests/compat/fern.rs b/tests/compat/fern.rs index a710822fd..bfd0a41ac 100644 --- a/tests/compat/fern.rs +++ b/tests/compat/fern.rs @@ -29,11 +29,13 @@ fn every_availability_is_read() { } } +/// As `x-forge-group` reads it, which Fern does not: Fern reads the string +/// as one group. #[test] fn a_group_written_as_a_string_is_split_on_dots() { assert_same( &operation_with(r#""x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get","#), - &operation_with(r#""x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get","#), + &operation_with(r#""x-forge-group": "a.b.c", "x-forge-method-name": "get","#), ); } diff --git a/tests/compat/native_first.rs b/tests/compat/native_first.rs index 368968940..9e0db4d6f 100644 --- a/tests/compat/native_first.rs +++ b/tests/compat/native_first.rs @@ -182,12 +182,12 @@ fn a_native_key_written_twice_is_an_error_naming_it() { } #[test] -fn a_native_group_written_as_a_string_is_an_error() { - let err = parse_err(&operation_with( - r#""x-forge-group": "a.b", "x-forge-method-name": "get","#, - )); - - assert!(err.contains("an array of strings"), "{err}"); +fn the_native_group_written_as_a_string_wins() { + native_wins( + r#""x-forge-method-name": "get", "x-forge-group": "native.group","#, + r#""x-fern-sdk-group-name": ["vendor"],"#, + r#""x-forge-method-name": "get", "x-forge-group": ["native", "group"],"#, + ); } #[test] diff --git a/tests/parse/groups.rs b/tests/parse/groups.rs index b22306d41..0e06d3322 100644 --- a/tests/parse/groups.rs +++ b/tests/parse/groups.rs @@ -7,7 +7,7 @@ fn string_group_name_splits_on_dots() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group": "accounts.members", "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -16,6 +16,19 @@ fn string_group_name_splits_on_dots() { assert_eq!(members.parent(), Some(group(&forge, "accounts"))); } +#[test] +fn group_name_that_is_neither_a_string_nor_an_array_is_an_error() { + let err = parse_err( + r#"{ + "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, + "paths": {"/a": {"get": {"x-forge-group": 1, "x-forge-method-name": "list", + "responses": {"204": {"description": "ok"}}}}} + }"#, + ); + + assert!(err.contains("a string or an array of strings"), "{err}"); +} + #[test] fn array_group_name_has_a_group_per_element() { let forge = parse( @@ -99,15 +112,17 @@ fn operation_without_a_group_is_not_a_method() { #[test] fn empty_group_name_is_no_group() { - let forge = parse( - r#"{ - "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": [], "x-forge-method-name": "get", - "responses": {"204": {"description": "ok"}}}}} - }"#, - ); - - assert_eq!(forge.groups().count(), 0); + for group in [r#""""#, "[]"] { + let forge = parse(&format!( + r#"{{ + "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, + "paths": {{"/a": {{"get": {{"x-forge-group": {group}, "x-forge-method-name": "get", + "responses": {{"204": {{"description": "ok"}}}}}}}}}} + }}"# + )); + + assert_eq!(forge.groups().count(), 0, "{group}"); + } } #[test] @@ -156,15 +171,17 @@ fn ignored_operation_is_not_a_method() { #[test] fn group_name_without_letters_is_an_error() { - let err = parse_err( - r#"{ - "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "", "members"], "x-forge-method-name": "list", - "responses": {"204": {"description": "ok"}}}}} - }"#, - ); - - assert!(err.contains("GET /a"), "{err}"); + for group in [r#"["accounts", "", "members"]"#, r#""accounts..members""#] { + let err = parse_err(&format!( + r#"{{ + "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, + "paths": {{"/a": {{"get": {{"x-forge-group": {group}, "x-forge-method-name": "list", + "responses": {{"204": {{"description": "ok"}}}}}}}}}} + }}"# + )); + + assert!(err.contains("GET /a: x-forge-group has a group name"), "{group}: {err}"); + } } #[test] From e84e0e92ddcb34c7adfc727355ebdcd3c50565ff Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 16:42:58 -0400 Subject: [PATCH 17/21] refactor: keep extension tiers local to the reader, and test one key per tier --- src/compat/mod.rs | 27 +++++++++++++++-- src/link/openapi.rs | 72 +++++++++++++++++++++++++++------------------ src/metadata/mod.rs | 33 +++++++++++++++++++++ 3 files changed, 102 insertions(+), 30 deletions(-) diff --git a/src/compat/mod.rs b/src/compat/mod.rs index 48a6a6e42..f4b590ee4 100644 --- a/src/compat/mod.rs +++ b/src/compat/mod.rs @@ -64,8 +64,7 @@ pub(crate) fn schema_name(n: u8) -> &'static str { #[cfg(test)] mod tests { use super::*; - use crate::metadata::COMPAT_SLOTS; - use crate::metadata::Tier; + use crate::metadata::{self, COMPAT_SLOTS, Tier}; /// Asserts that each key in `names` is read by `read` as a key that is /// not native, whose slot `name` names it by. @@ -86,6 +85,30 @@ mod tests { read_as_itself(&stainless::SCHEMA_NAMES, schema, schema_name); } + #[test] + fn no_two_keys_say_the_same_thing_with_the_same_tier() { + // As `link` reads them: native first, then the adapters. + let keys = |native: &[&'static str], adapters: &[&[&'static str]]| -> Vec<&'static str> { + native + .iter() + .chain(adapters.iter().flat_map(|keys| keys.iter())) + .copied() + .collect() + }; + let definitions = keys(&metadata::DEFINITION_NAMES, &[&fern::DEFINITION_NAMES]); + let parameters = keys(&metadata::PARAMETER_NAMES, &[&fern::PARAMETER_NAMES]); + let schemas = keys( + &metadata::SCHEMA_NAMES, + &[&fern::SCHEMA_NAMES, &stainless::SCHEMA_NAMES], + ); + + metadata::assert_one_key_per_tier(&definitions, |key| { + metadata::definition(key).or_else(|| definition(key)) + }); + metadata::assert_one_key_per_tier(¶meters, |key| metadata::parameter(key).or_else(|| parameter(key))); + metadata::assert_one_key_per_tier(&schemas, |key| metadata::schema(key).or_else(|| schema(key))); + } + #[test] fn the_slots_of_the_adapters_do_not_collide_and_fit_in_a_set() { let mut slots: Vec = fern::SCHEMA_NAMES diff --git a/src/link/openapi.rs b/src/link/openapi.rs index dd1b2b093..9041ee621 100644 --- a/src/link/openapi.rs +++ b/src/link/openapi.rs @@ -239,33 +239,42 @@ pub(super) struct Operation { } /// A value an extension gives, and the key it came from, so that an error can -/// name the key the document wrote. The value of the strongest [`Tier`] of -/// key is kept, whatever order the keys are written in. +/// name the key the document wrote. #[derive(Default)] pub(super) struct Val { pub(super) value: T, /// The slot of the key that gave the value, which names it. It means /// nothing if no key gave one. pub(super) slot: u8, - tier: Tier, } impl Val { /// Keeps `value`, which `hit` gave, unless a key of a stronger tier - /// gave the value held. - fn set(&mut self, hit: &Hit, value: T) { - if takes(hit, &mut self.tier) { + /// than `tier`, the tier of the value held, gave it. + fn set(&mut self, hit: &Hit, value: T, tier: &mut Tier) { + if takes(hit, tier) { self.value = value; self.slot = hit.slot; } } } +/// The tier of the key that gave each value of a [`Definition`] so far, while +/// it is read. +#[derive(Default)] +struct DefinitionTiers { + method_name: Tier, + group_names: Tier, + ignore: Tier, + availability: Tier, +} + /// Reports whether a value from the key of `hit` replaces the one read so /// far, which came from a key of tier `tier`, and records the tier of the -/// value kept. Keys of the same tier that say the same thing are different -/// keys of the same object, which no table has, so equal tiers do not -/// happen; were they to, the last written would be kept. +/// value kept. Equal tiers do not happen: a key written twice is an error +/// before it gets here, and no two keys of one tier say the same thing, +/// which the tests of `metadata` and `compat` check. Were they to, the last +/// written would be kept. fn takes(hit: &Hit, tier: &mut Tier) -> bool { if hit.tier >= *tier { *tier = hit.tier; @@ -318,8 +327,6 @@ pub(super) struct Parameter { pub(super) content: Span<(Str, Schema)>, /// The name of the parameter's field, or empty for none. pub(super) field_name: Str, - /// The tier of the key that gave `field_name`. - field_name_tier: Tier, } /// Where a parameter is sent: the `in` of a Parameter Object. @@ -445,12 +452,16 @@ pub(super) struct SchemaObject { /// Whether a property's schema is marked to be left out: it makes no /// field. pub(super) ignore: bool, - /// The tier of the key that gave each of `model_name`, `field_name`, - /// `ignore` and `sensitive`, so that no weaker key replaces it. - model_name_tier: Tier, - field_name_tier: Tier, - ignore_tier: Tier, - sensitive_tier: Tier, +} + +/// The tier of the key that gave each extension value of a [`SchemaObject`] +/// so far, while it is read. +#[derive(Default)] +struct SchemaTiers { + model_name: Tier, + field_name: Tier, + ignore: Tier, + sensitive: Tier, } /// A value of `type` in a Schema Object. @@ -1297,23 +1308,24 @@ impl Definition { doc: &mut Doc, map: &mut A, hit: Hit, + tiers: &mut DefinitionTiers, ) -> Result<(), A::Error> { match hit.field { DefinitionField::Method => { let name = map.next_value_seed(seed::(doc))?; - self.method_name.set(&hit, name); + self.method_name.set(&hit, name, &mut tiers.method_name); } DefinitionField::Group => { let names = map.next_value_seed(seed::(doc))?; - self.group_names.set(&hit, names); + self.group_names.set(&hit, names, &mut tiers.group_names); } DefinitionField::Ignore(format) => { let ignore = read_bool(map, format)?; - self.ignore.set(&hit, ignore); + self.ignore.set(&hit, ignore, &mut tiers.ignore); } DefinitionField::Availability => { let availability = map.next_value_seed(seed::(doc))?; - self.availability.set(&hit, Some(availability)); + self.availability.set(&hit, Some(availability), &mut tiers.availability); } DefinitionField::Hidden => self.hidden = map.next_value()?, DefinitionField::Confirmation => { @@ -1337,13 +1349,14 @@ impl ReadObject for Alias { fn read_object<'de, A: MapAccess<'de>>(doc: &mut Doc, mut map: A) -> Result { let mut definition = Definition::default(); let mut seen = 0; + let mut tiers = DefinitionTiers::default(); // As for an operation. let mut extensions = Vec::new(); while let Some(field) = map.next_key::()? { match field { AliasField::Definition(hit) => { resolve::once(&hit, &mut seen)?; - definition.read_value(doc, &mut map, hit)?; + definition.read_value(doc, &mut map, hit, &mut tiers)?; } AliasField::Extension(name) => json::insert(&mut extensions, name, map.next_value()?), AliasField::Other => skip(&mut map)?, @@ -1502,6 +1515,7 @@ impl ReadObject for Operation { let mut operation = Operation::default(); let mut seen = 0; let mut seen_definition = 0; + let mut tiers = DefinitionTiers::default(); // Kept apart until the operation is read, so that an extension // written again can replace the first. Empty, it allocates nothing. let mut extensions = Vec::new(); @@ -1510,7 +1524,7 @@ impl ReadObject for Operation { OperationField::Key(key) => key, OperationField::Definition(hit) => { resolve::once(&hit, &mut seen_definition)?; - operation.definition.read_value(doc, &mut map, hit)?; + operation.definition.read_value(doc, &mut map, hit, &mut tiers)?; continue; } OperationField::Aliases => { @@ -1612,6 +1626,7 @@ impl ReadObject for Parameter { let mut param = Parameter::default(); let mut seen = 0; let mut seen_extensions = 0; + let mut field_name_tier = Tier::Unset; while let Some(entry) = map.next_key::()? { let key = match entry { ParameterEntry::Extension(hit) => { @@ -1619,7 +1634,7 @@ impl ReadObject for Parameter { match hit.field { ParameterField::Name => { let name = map.next_value_seed(seed::(doc))?; - if takes(&hit, &mut param.field_name_tier) { + if takes(&hit, &mut field_name_tier) { param.field_name = name; } } @@ -1758,6 +1773,7 @@ impl ReadObject for SchemaObject { let mut schema = SchemaObject::default(); let mut seen = 0; let mut seen_extensions = 0; + let mut tiers = SchemaTiers::default(); while let Some(entry) = map.next_key::()? { let key = match entry { SchemaEntry::Extension(hit) => { @@ -1765,25 +1781,25 @@ impl ReadObject for SchemaObject { match hit.field { SchemaField::ModelName => { let name = map.next_value_seed(seed::(doc))?; - if takes(&hit, &mut schema.model_name_tier) { + if takes(&hit, &mut tiers.model_name) { schema.model_name = name; } } SchemaField::PropertyName => { let name = map.next_value_seed(seed::(doc))?; - if takes(&hit, &mut schema.field_name_tier) { + if takes(&hit, &mut tiers.field_name) { schema.field_name = name; } } SchemaField::Ignore(format) => { let ignore = read_bool(&mut map, format)?; - if takes(&hit, &mut schema.ignore_tier) { + if takes(&hit, &mut tiers.ignore) { schema.ignore = ignore; } } SchemaField::Sensitive => { let sensitive = map.next_value()?; - if takes(&hit, &mut schema.sensitive_tier) { + if takes(&hit, &mut tiers.sensitive) { schema.sensitive = sensitive; } } diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index dc59da651..9eba8e7ff 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -275,6 +275,24 @@ pub(crate) fn availability(value: &str) -> Option { } } +/// Asserts that no two of `keys` that `read` reads say the same thing with +/// the same tier. Which key's value is kept is decided by tier alone, so two +/// keys of one tier for one thing would make it depend on the order the +/// keys are written in. +#[cfg(test)] +#[track_caller] +pub(crate) fn assert_one_key_per_tier(keys: &[&str], read: impl Fn(&str) -> Option>) { + let mut said: Vec<(std::mem::Discriminant, Tier, &str)> = Vec::new(); + for &key in keys { + let hit = read(key).unwrap_or_else(|| panic!("{key} is not read")); + let what = std::mem::discriminant(&hit.field); + if let Some(&(_, _, other)) = said.iter().find(|&&(w, tier, _)| w == what && tier == hit.tier) { + panic!("{other} and {key} say the same thing with the same tier"); + } + said.push((what, hit.tier, key)); + } +} + #[cfg(test)] mod tests { use super::*; @@ -323,6 +341,21 @@ mod tests { read_as_itself(documents, &DOCUMENT_NAMES, document); } + #[test] + fn no_two_native_keys_say_the_same_thing_with_the_same_tier() { + let [definitions, parameters, schemas, documents] = native_keys(); + assert_one_key_per_tier(definitions, definition); + assert_one_key_per_tier(parameters, parameter); + assert_one_key_per_tier(schemas, schema); + assert_one_key_per_tier(documents, document); + } + + #[test] + #[should_panic(expected = "x-forge-sensitive and x-forge-sensitive say the same thing with the same tier")] + fn one_key_per_tier_finds_two() { + assert_one_key_per_tier(&["x-forge-sensitive", "x-forge-sensitive"], schema); + } + #[test] fn x_sensitive_is_a_deprecated_name_of_x_forge_sensitive() { let (current, old) = (schema("x-forge-sensitive").unwrap(), schema("x-sensitive").unwrap()); From 471acdf496575b026e58e89800b9a427b91bc92f Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 17:44:11 -0400 Subject: [PATCH 18/21] refactor: address review on RFC 0001 - Rename x-forge-ignore to x-forge-skip, internal names included. - Rename x-forge-group to x-forge-group-name, to match the other -name keys and stay apart from the legacy x-forge-group-info. - Remove benches/compare.sh and its just recipe; the RFC describes the method inline. - RFC: record why the key is model-name, and that CI compiles but does not test the build without compat, on purpose. --- benches/compare.sh | 81 ---------------- justfile | 4 - rfcs/0001-metadata-resolution-layer.md | 24 ++--- src/compat/fern.rs | 6 +- src/compat/stainless.rs | 4 +- src/lib.rs | 12 +-- src/link.rs | 4 +- src/link/openapi.rs | 22 ++--- src/metadata/mod.rs | 24 ++--- src/plugin/ts/tests.rs | 6 +- src/types.rs | 4 +- tests/cli.rs | 2 +- tests/compat/common.rs | 2 +- tests/compat/fern.rs | 24 ++--- tests/compat/native_first.rs | 96 ++++++++++--------- tests/compat/stainless.rs | 31 +++--- tests/parse/aliases.rs | 68 ++++++------- tests/parse/bodies.rs | 28 +++--- tests/parse/common.rs | 4 +- tests/parse/document.rs | 4 +- tests/parse/extensions.rs | 28 +++--- tests/parse/groups.rs | 73 +++++++------- tests/parse/headers.rs | 50 +++++----- tests/parse/methods.rs | 54 +++++------ tests/parse/models.rs | 38 ++++---- tests/parse/requests.rs | 126 ++++++++++++------------- tests/parse/responses.rs | 12 +-- tests/parse/types/arrays.rs | 4 +- tests/parse/types/enums.rs | 2 +- tests/parse/types/intersections.rs | 4 +- tests/parse/types/nulls.rs | 8 +- tests/parse/types/objects.rs | 8 +- tests/parse/types/refs.rs | 18 ++-- tests/parse/types/scalars.rs | 6 +- tests/parse/types/unions.rs | 6 +- tests/wasm.rs | 18 ++-- 36 files changed, 416 insertions(+), 489 deletions(-) delete mode 100755 benches/compare.sh diff --git a/benches/compare.sh b/benches/compare.sh deleted file mode 100755 index d79406d66..000000000 --- a/benches/compare.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env bash -# Compares the parse benchmark of the working tree against a git revision: -# -# FORGE_SPEC=/path/to/openapi.json benches/compare.sh [REV] [PAIRS] -# -# REV defaults to main and PAIRS to 12. The revision is built in a throwaway -# worktree, so the working tree is left as it is. -# -# Each pair runs the two in ABBA order (base, new, new, base) and takes the -# mean of each side's two runs, so a machine that warms up or cools down -# through the session does not bias one side. Three warm-up pairs are -# discarded first. The statistics are paired, on divan's fastest sample of -# each run. A pair whose four runs differ by more than 10% is reported and -# left out: the machine changed speed in the middle of it. -# -# A difference under about twice its standard error is not one this can see. -set -eu - -REV=${1:-main} -PAIRS=${2:-12} -: "${FORGE_SPEC:?set FORGE_SPEC to the document to benchmark}" -export FORGE_SPEC - -ROOT=$(git rev-parse --show-toplevel) -WORK=$(mktemp -d) -trap 'git -C "$ROOT" worktree remove --force "$WORK/base" > /dev/null 2>&1 || true; rm -rf "$WORK"' EXIT - -# Builds the parse benchmark of the tree at $1 into the target folder $2, and -# copies it to $3. -build() { - (cd "$1" && CARGO_TARGET_DIR=$2 cargo bench --locked --bench parse --no-run 2>&1 | tail -1) >&2 - local bin - bin=$(ls -t "$2"/release/deps/parse-* | grep -vE '\.(d|o)$' | head -1) - cp "$bin" "$3" -} - -git -C "$ROOT" worktree add --detach "$WORK/base" "$REV" > /dev/null 2>&1 -build "$WORK/base" "$WORK/target-base" "$WORK/base.bin" -build "$ROOT" "$ROOT/target" "$WORK/new.bin" - -# Writes the fastest sample of a divan run of $1, in ms. -measure() { - "$1" --bench forge > "$WORK/run.out" 2> /dev/null - awk ' - /├─ forge/ {f = 1} - f && /╰─|├─/ && /[0-9] (ms|µs|s) / { - for (i = 1; i <= NF; i++) - if ($i ~ /^[0-9]+(\.[0-9]+)?$/) { - v = $i; u = $(i+1) - print (u == "µs" ? v / 1000 : u == "s" ? v * 1000 : v) - exit - } - }' "$WORK/run.out" -} - -for i in 1 2 3; do - measure "$WORK/base.bin" > /dev/null; measure "$WORK/new.bin" > /dev/null -done -: > "$WORK/pairs" -for i in $(seq "$PAIRS"); do - b1=$(measure "$WORK/base.bin"); n1=$(measure "$WORK/new.bin") - n2=$(measure "$WORK/new.bin"); b2=$(measure "$WORK/base.bin") - echo "$b1 $n1 $n2 $b2" >> "$WORK/pairs" - printf 'pair %2d base %s %s ms new %s %s ms\n' "$i" "$b1" "$b2" "$n1" "$n2" >&2 -done - -awk -v rev="$REV" ' - { - lo = $1; hi = $1 - for (i = 2; i <= 4; i++) { if ($i < lo) lo = $i; if ($i > hi) hi = $i } - if (hi > lo * 1.1) { printf "pair %d left out: the machine changed speed\n", NR; next } - n++; b = ($1 + $4) / 2; d = ($2 + $3) / 2 - b - sb += b; sd += d; sd2 += d * d; if (d > 0) up++ - } - END { - if (n < 2) { print "too few pairs to compare"; exit 1 } - mean = sd / n; se = sqrt((sd2 - n * mean * mean) / (n - 1) / n) - printf "%s: %.2f ms\n", rev, sb / n - printf "working tree - %s: %+.3f ms (%+.2f%%), standard error %.3f ms, t = %.1f, slower in %d of %d pairs\n", - rev, mean, 100 * mean / (sb / n), se, (se > 0 ? mean / se : 0), up, n - }' "$WORK/pairs" diff --git a/justfile b/justfile index ffbadbc88..c3b7d5819 100644 --- a/justfile +++ b/justfile @@ -27,10 +27,6 @@ lint: cargo clippy --locked --all-targets --all-features -- -D warnings cargo clippy --locked --all-targets --no-default-features -- -D warnings -# Compare the parse benchmark against a revision, with FORGE_SPEC set to a document -bench-compare rev="main" pairs="12": - benches/compare.sh {{rev}} {{pairs}} - # Check that no other tool's extension is named outside the compatibility layer boundary: cargo test --locked --test boundary diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 4176308f2..2620cc6a9 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -68,8 +68,8 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… | Native key | Form | Meaning | Compat source (the adapter translates) | |---|---|---|---| | `x-forge-method-name` | string | the method's name | `x-fern-sdk-method-name` | -| `x-forge-group` | **string of names separated by dots**, or **array of strings**, top level first (array elements are not split) | the group path; `""` and `[]` are meant to be the root, but are not yet (see [Known gaps](#known-gaps)) | `x-fern-sdk-group-name` (read the same way as the native key) | -| `x-forge-ignore` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | +| `x-forge-group-name` | **string of names separated by dots**, or **array of strings**, top level first (array elements are not split) | the group path; `""` and `[]` are meant to be the root, but are not yet (see [Known gaps](#known-gaps)) | `x-fern-sdk-group-name` (read the same way as the native key) | +| `x-forge-skip` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | | `x-forge-availability` | `alpha` \| `beta` \| `preview` \| `generally-available` \| `deprecated` | lifecycle stage. The values are Forge's shipped vocabulary (public enum across Rust, WIT, JS); Fern merely coincides | `x-fern-availability` | | `x-forge-model-name` | string | the model's name (components / `$defs` schema) | `x-fern-type-name` | | `x-forge-property-name` | string | the property's field name | `x-fern-property-name` | @@ -81,10 +81,11 @@ Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617… Design notes: - **Explicit position keys over one positional name key.** Fern used three name keys because its reader architecture had one visitor per OpenAPI object kind. We use explicit keys for a different, real reason: tools in the wild mangle `$ref` structure (inlining targets, dropping siblings), and when placement lies, the key name still carries the role — `x-forge-model-name` on a property schema can be ignored or flagged, where a positional `x-forge-name` would silently become a field name. Explicitness here is corruption-detection, not verbosity. -- **One exclusion word, two positions.** "Excluded from generated surfaces" is one concept at two scopes; two words (`ignore` + `skip`) would be a memory tax for no disambiguation, and `skip` is Stainless's word. -- **Groups as a dotted string or an array.** The dotted string is how Cloudflare's specs write a group path today, and Forge CI's lint requires it, so moving a team to `x-forge-group` is a rename of the key, with the value unchanged. The array is JSON's own way to write a path, and the way to write a group name that has a dot in it. Both are read exactly as forge has always read groups. +- **`model-name`, not `type-name` or `schema-name`.** The key sets `Model::name`, and the Rust API, the WIT (`model-info`, `get-model`) and the JS runtime all call the thing a model, so the key uses the word a plugin author sees. `type-name`, Fern's word, would promise more than the key does: a `Type` is any type, scalars, arrays and unions included, of which `Type::Model` is one kind, and only a schema that becomes a model is named by the key. `schema-name` is taken: `Model::schema_name` is the key under `components.schemas`, which is the very name this key replaces. `class-name` and `struct-name` are words of particular target languages, and `title` is OpenAPI's own display string. `method-name` and `model-name` are named after what they set in the model; `property-name` and `parameter-name` both set a field's name, so they are named after their position instead, for the reason above. +- **One exclusion word, two positions.** "Excluded from generated surfaces" is one concept at two scopes; two words would be a memory tax for no disambiguation. The word is `skip` rather than `ignore`: it says what happens (the thing is not generated), where `ignore` reads as though the reader ignores the key; it stands further apart from `x-forge-hidden` (generated, but not listed); and it reads naturally should the key one day take a list of targets. That Stainless uses the same word, and Fern the other, played no part. +- **Groups as a dotted string or an array.** The dotted string is how Cloudflare's specs write a group path today, and Forge CI's lint requires it, so moving a team to `x-forge-group-name` is a rename of the key, with the value unchanged. The array is JSON's own way to write a path, and the way to write a group name that has a dot in it. Both are read exactly as forge has always read groups. - **The dotted string is Cloudflare's, not Fern's.** Fern reads a string `x-fern-sdk-group-name` as *one* group (`"a.b"` is a group named `a.b`) and an array as a path; it never splits on dots. The release pipeline converts Cloudflare's dotted strings to arrays before Fern sees them (the released aggregate has 3,591 arrays and no strings). Forge has always split them, and the adapter reads the Fern key the same way as the native one, so for a string with a dot the adapter and Fern disagree. That is deliberate: the specs forge reads write Fern's key in Cloudflare's convention, and reading the two keys alike keeps a key rename from changing a value's meaning. -- **Every native key begins with `x-forge-`.** The `-name` keys (`method-name`, `model-name`, `property-name`, `parameter-name`) say the same kind of thing and are spelled alike. `x-sensitive` predates the rule; it becomes `x-forge-sensitive`, and the old name stays readable as a deprecated alias (155 production uses), so no spec breaks. A deprecated alias is part of the native vocabulary, not of the compatibility layer: it keeps working with compat off, and deleting compat does not remove it. +- **Every native key begins with `x-forge-`.** The `-name` keys (`method-name`, `group-name`, `model-name`, `property-name`, `parameter-name`) say the same kind of thing and are spelled alike. `x-forge-group-name` holds a path rather than one name, as `x-fern-sdk-group-name` does; keeping the suffix makes moving a team a rename of the key's prefix, and keeps it apart from the legacy `x-forge-group-info`, which Forge CI bans. FORGE-3 expects to rename it to `x-forge-namespace`. `x-sensitive` predates the rule; it becomes `x-forge-sensitive`, and the old name stays readable as a deprecated alias (155 production uses), so no spec breaks. A deprecated alias is part of the native vocabulary, not of the compatibility layer: it keeps working with compat off, and deleting compat does not remove it. - **No misplacement validation in v1.** A known native key in a wrong position is silently ignored, exactly as Fern's keys are today. Adding validation later is a pure tightening that breaks no valid spec. ## Resolution rules @@ -94,7 +95,7 @@ Design notes: 3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). 4. **Empty or punctuation-only values** behave as today, which depends on the key: - `x-forge-property-name`, `x-forge-parameter-name` and `x-forge-model-name`: a value with no letters or digits, empty included, is ignored, and the field or model is named after its wire name (the property, parameter or schema name). - - `x-forge-method-name` and `x-forge-group`: an empty method name, or an empty group path (`""` or `[]`), means the operation or alias is not a method. For the empty group path this is the current behavior, not the intended one: see [Known gaps](#known-gaps). A method name, or any group name in the path, that is not empty but has no letters or digits is an error. + - `x-forge-method-name` and `x-forge-group-name`: an empty method name, or an empty group path (`""` or `[]`), means the operation or alias is not a method. For the empty group path this is the current behavior, not the intended one: see [Known gaps](#known-gaps). A method name, or any group name in the path, that is not empty but has no letters or digits is an error. - Validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. 5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. @@ -102,7 +103,7 @@ Design notes: ### An empty group path -- **Intended:** `x-forge-group: []` (or `""`) attaches the method to the root, in no group. An operation without `x-forge-group` at all is still not a method. +- **Intended:** `x-forge-group-name: []` (or `""`) attaches the method to the root, in no group. An operation without `x-forge-group-name` at all is still not a method. - **Today:** an empty group path makes no method, exactly like a missing key. `add_method` in `src/link.rs` returns before building the method when the path is empty; `Method::group`'s docs in `src/lib.rs` say so; and `tests/parse/groups.rs::empty_group_name_is_no_group` and the empty-group alias case in `tests/parse/aliases.rs` assert it. - **Why it is not fixed here:** the model has no place for a root method. Methods exist only inside groups (`Forge::groups` → `Group::methods`); `Forge` has top-level models but no top-level methods, and neither does the WIT. The fix needs a root method list in the model, a way for plugins to read it (a new WIT function is additive; a new field in an existing record is not), and generators that render root methods. That is beyond FORGE-1, which leaves the model unchanged. - **Impact:** none today. The released aggregate has no empty group path and no method name without a group, so the fix will not change its output. @@ -152,6 +153,7 @@ Properties, all deliberate: - **Structural boundary — compiler-enforced (built-in Rust):** every vendor key literal is private to its adapter; the only things outside `compat/` that can touch vendor knowledge are the aggregator's per-object resolvers and name lookups, which `link/resolve.rs` calls. The name lookups are how a vendor key's name reaches an error message (rule 4's provenance) without `link` holding the literal: it reaches `link` as data, never as code that matches on it. The feature gate makes compat removable, and builds without the `compat` feature keep proving it. - **Textual boundary — `tests/boundary.rs`:** scans `src/`, `tests/`, and `packages/forge/` (including the shipped `plugin/forge.wit`) for `x-fern` / `x-stainless` outside `src/compat/` and `tests/compat/`. Doc comments count — moving the WIT's "from `x-fern-availability`" attribution to `x-forge-availability` is part of the work. The test runs wherever `cargo test` runs; a `just boundary` alias targets it. +- **Compat off is compiled in CI, not tested — on purpose.** The `compat` feature is a tool for organizing the code: it keeps the vendor knowledge in one place that can be deleted, rather than being a build that anyone ships. CI's clippy step already builds the crate without it (`--no-default-features`), so the code can't quietly come to depend on the layer. But CI runs the tests only with `--all-features`. A second test run with compat off would compile the crate and every test binary again, for 30–60 s on each push, to cover a configuration nothing ships. The compat-off run in *Verification* was done locally. - **Criterion mapping:** (1) nothing outside the layer references `x-fern-*` → the two mechanisms above; (2) output unchanged → zero model-shape changes, Fern-keyed specs resolve identically (equivalence tests + the full-aggregate native-vs-wasm byte-equality bench); (3) tests per primitive → below. ## Test plan @@ -172,7 +174,7 @@ The implementation was checked against the unmodified engine on the released agg - **Across the plugin boundary.** `tests/wasm.rs`, including the ignored `bench` on the aggregate, reports identical output and dump, native versus WASM, for 1,317 groups and 3,381 files; `wit_is_current` holds with the regenerated WIT. - **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 445 tests of the native suite, including the deprecated `x-sensitive` alias; with compat on, 498 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. - **The checks can fail.** Breaking the precedence rule (keeping the last value written, whatever its tier) fails 11 compat tests, and 1 `tests/parse` test, the deprecated `x-sensitive` one, with compat on and off; planting a vendor name in a doc comment fails the boundary test, naming the file and line. -- **Performance.** Measured with `benches/compare.sh` (`just bench-compare`): parse and link of the aggregate, paired against the unmodified engine, each pair run base–new–new–base so that drift in the machine's speed cancels, and pairs in which the machine changed speed left out. On the final code (`4e31404`), over 12 pairs, it is 0.8% slower: +0.34 ms of 42.0 ms, standard error 0.18 ms (t = 1.9), slower in 9 of 12 pairs. Earlier runs during the work put it between −0.1% and +1.1%, depending on the machine's speed state. Peak memory is 68.80 MB against 68.75 MB (+0.07%), with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. +- **Performance.** Measured with the divan `parse` bench (parse and link of the aggregate), paired against the unmodified engine: each pair ran base–new–new–base so that drift in the machine's speed cancels, took the fastest sample of each run, and left out pairs whose four runs differed by more than 10%. On the final code, over 12 pairs, it is 0.8% slower: +0.34 ms of 42.0 ms, standard error 0.18 ms (t = 1.9), slower in 9 of 12 pairs. Earlier runs during the work put it between −0.1% and +1.1%, depending on the machine's speed state. Peak memory is 68.80 MB against 68.75 MB (+0.07%), with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. - *Where it went.* Profiling (samply, with line tables, attributing inlined frames) found no hot spot of the layer's own: most of the difference is LLVM inlining parts of serde_json's key loop into `SchemaObject::read_object` and laying the code out differently, which moves with any change. Three things were measured and kept: each table turns away keys outside its prefix (`x-forge-`, `x-fern-`, `x-stainless-`) before matching, and only `x-` keys are asked about, so a skipped key costs one compare; and a `Hit` carries only its field and slot, the key's name looked up by slot when an error needs it, so the reader's per-key result fits in registers (16 bytes, as before, not 24). - *Ruling things out.* Unpaired, sequential runs had suggested +1.5–1.9%; that was the machine warming up through the session, which the ABBA order removes. A single run of either binary differs from the next by about as much as the change measured here, so a smaller difference needs more pairs, not a better single run. @@ -185,8 +187,8 @@ Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensi - **Resolve-after-parse** (keep all `x-` keys as raw JSON, normalize in a second pass): most literal reading of "a resolution step", trivially provenance-aware — but it must retain every schema-level extension on the 27 MB aggregate (5,366 `x-auditable` alone) unless the reader consults a key table anyway, at which point it collapses into the chosen design with extra memory and a reimplementation of duplicate-key errors. Rejected on performance and diff size. - **Vendor-trait machinery** (a `Vendor` trait with Fern/Stainless/Scalar impls): no primitive overlaps across vendors today; the key table grows rows when one does. Rejected as over-engineering for now. - **One positional `x-forge-name`**: mirrors the model's single `Name` concept and is cleaner in the abstract — but when toolchains inline `$ref` targets, the model's name key rides into property positions and silently renames fields. Explicit keys turn that corruption into something ignorable or flaggable. Rejected on robustness. -- **Separate `x-forge-skip` for properties**: two words for one concept, and `skip` is Stainless's word. Rejected. -- **Arrays only for `x-forge-group`**: one form, which every tool reads the same way, and loosening later would break nothing. Rejected: Cloudflare's specs write dotted strings, so every migration would reshape values as well as rename keys, and Forge CI's lint would need an array rule. +- **Separate words for an operation and a property** (`x-forge-ignore` and `x-forge-skip`, as Fern and Stainless split them): two words for one concept. Rejected. +- **Arrays only for `x-forge-group-name`**: one form, which every tool reads the same way, and loosening later would break nothing. Rejected: Cloudflare's specs write dotted strings, so every migration would reshape values as well as rename keys, and Forge CI's lint would need an array rule. - **Reading a string `x-fern-sdk-group-name` as one group, as Fern does**: faithful to Fern, but the native and Fern keys would then read the same value differently, and the specs forge reads use dots. Rejected. - **Error on native/compat disagreement**: the strictest conflict rule, and consistent with the engine's general strictness — deferred as an open question in FORGE-4 in favor of silent native-wins (zero comparison machinery, no cost for correct specs; the drift risk is documented). - **Full crate split now** (a separate `metadata` member crate): delivers "separate library" literally today. The root `Cargo.toml` is already a `[workspace]`, so adding a member does not mean moving the engine; the real cost is that a separate crate cannot depend on the engine, so `Availability` and the other primitive value types would move into it and be re-exported by `forge`. Deferred: the pure contract keeps that move mechanical for when the first standalone consumer exists. @@ -196,7 +198,7 @@ Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensi | Ticket | What | |---|---| -| FORGE-3 | Vocabulary renames in one breaking release: `group` → `namespace`, plus the availability word review; `x-forge-group`/`x-forge-availability` become deprecated aliases (one table row each, the same tier `x-sensitive` uses). | +| FORGE-3 | Vocabulary renames in one breaking release: `group` → `namespace`, plus the availability word review; `x-forge-group-name`/`x-forge-availability` become deprecated aliases (one table row each, the same tier `x-sensitive` uses). | | FORGE-4 | The versioning RFC: the four contracts, the rules this RFC assumes, and open questions (1.0 timing, warning channel, vendor-key EoL policy). | | FORGE-5 | Informational Forge CI lint flagging vendor keys the engine doesn't read, sourced from this layer's key table. | | (FORGE-1 follow-ups) | cf codebase Fern→Forge rename; dotted `operationId` derivation behind an opt-in flag. | diff --git a/src/compat/fern.rs b/src/compat/fern.rs index 925f7e47a..1fbf2fcab 100644 --- a/src/compat/fern.rs +++ b/src/compat/fern.rs @@ -3,7 +3,7 @@ //! | Key | Says | Format | //! |---|---|---| //! | `x-fern-sdk-method-name` | the name of the method | a string | -//! | `x-fern-sdk-group-name` | the group path of the method | as `x-forge-group`: an array of group names, or one string of them separated by dots | +//! | `x-fern-sdk-group-name` | the group path of the method | as `x-forge-group-name`: an array of group names, or one string of them separated by dots | //! | `x-fern-ignore` | the definition makes no method | a boolean | //! | `x-fern-availability` | the stage of the API | a string, one of the native spellings | //! | `x-fern-parameter-name` | the name of a parameter's field | a string | @@ -11,7 +11,7 @@ //! | `x-fern-type-name` | the name of a model | a string | //! //! A group path written as one string is split on dots, as for -//! `x-forge-group`, which Fern itself does not do: Fern reads a string as a +//! `x-forge-group-name`, which Fern itself does not do: Fern reads a string as a //! single group. A document written for Fern uses the array, which means the //! same in both. //! @@ -45,7 +45,7 @@ pub(super) fn definition(key: &str) -> Option> { Some(match key { METHOD_NAME => Hit::compat(DefinitionField::Method, 0), GROUP_NAME => Hit::compat(DefinitionField::Group, 1), - IGNORE => Hit::compat(DefinitionField::Ignore(BoolFormat::Bool), 2), + IGNORE => Hit::compat(DefinitionField::Skip(BoolFormat::Bool), 2), AVAILABILITY => Hit::compat(DefinitionField::Availability, 3), _ => return None, }) diff --git a/src/compat/stainless.rs b/src/compat/stainless.rs index 320957172..caa76ba0c 100644 --- a/src/compat/stainless.rs +++ b/src/compat/stainless.rs @@ -23,7 +23,7 @@ pub(super) fn schema(key: &str) -> Option> { return None; } Some(match key { - SKIP => Hit::compat(SchemaField::Ignore(BoolFormat::BoolOrTargets), 0), + SKIP => Hit::compat(SchemaField::Skip(BoolFormat::BoolOrTargets), 0), _ => return None, }) } @@ -37,7 +37,7 @@ mod tests { fn the_skip_is_read_on_a_schema_as_a_boolean_or_targets_and_not_native() { let hit = schema(SKIP).unwrap(); assert_eq!(hit.tier, Tier::Compat, "{SKIP}"); - assert!(matches!(hit.field, SchemaField::Ignore(BoolFormat::BoolOrTargets))); + assert!(matches!(hit.field, SchemaField::Skip(BoolFormat::BoolOrTargets))); } #[test] diff --git a/src/lib.rs b/src/lib.rs index df76e0b69..1274ce41e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -226,7 +226,7 @@ impl std::fmt::Debug for Group<'_> { /// own group and name, with the `x-forge-aliases` extension: an array of /// objects, each an alias that is a method of the operation. The /// operation's own group and name then make no method, and its own -/// `x-forge-ignore` does not stop its aliases. An empty array makes no +/// `x-forge-skip` does not stop its aliases. An empty array makes no /// method, an element that is not an object is ignored, and a value that /// is not an array is an error. Aliases do not nest: an `x-forge-aliases` /// in an alias is ignored, as are its keys that are not extensions. @@ -236,7 +236,7 @@ impl std::fmt::Debug for Group<'_> { /// [`availability`](Method::availability), whether it is /// [hidden](Method::is_hidden), its [`confirmation`](Method::confirmation) /// and its [`extensions`](Method::extensions), and whether it is ignored -/// with `x-forge-ignore`. None of these come from the operation: an alias +/// with `x-forge-skip`. None of these come from the operation: an alias /// without an extension does not have the operation's. The rest, from the /// HTTP method and path to the responses, is the operation's, and every /// alias has it. Each alias is a method of its own group, so a model one @@ -264,12 +264,12 @@ impl<'f> Method<'f> { /// Returns the group the method is in. /// - /// Corresponds to the `x-forge-group` extension of the operation, or + /// Corresponds to the `x-forge-group-name` extension of the operation, or /// of the alias the method comes from: a string of group names /// separated by dots, such as `accounts.members`, or an array with one /// group name per element, top level first, whose elements are not /// split. An operation or alias without one, with an empty one, or - /// with `x-forge-ignore: true` is not a method. A group name with no + /// with `x-forge-skip: true` is not a method. A group name with no /// letters or digits is an error. pub fn group(self) -> Group<'f> { self.forge.group(self.data().group) @@ -339,7 +339,7 @@ impl<'f> Method<'f> { /// /// Corresponds to the `x-forge-hidden` extension of the operation, a /// boolean, which is false without it. A value that is not a boolean - /// is an error, as for `x-forge-ignore`. Unlike `x-forge-ignore`, a + /// is an error, as for `x-forge-skip`. Unlike `x-forge-skip`, a /// hidden operation is still a method. pub fn is_hidden(self) -> bool { self.data().hidden @@ -499,7 +499,7 @@ impl<'f> Method<'f> { /// An extension is a key of the /// [Operation Object](https://spec.openapis.org/oas/latest.html#operation-object) /// that starts with `x-`. Those forge reads, `x-forge-method-name`, - /// `x-forge-group`, `x-forge-ignore`, `x-forge-availability`, + /// `x-forge-group-name`, `x-forge-skip`, `x-forge-availability`, /// `x-forge-hidden`, `x-forge-require-confirmation` and /// `x-forge-aliases`, are left out, and so are the keys the /// compatibility layer reads in their place, when forge is built with diff --git a/src/link.rs b/src/link.rs index 197ab42da..f78561134 100644 --- a/src/link.rs +++ b/src/link.rs @@ -565,7 +565,7 @@ impl<'d> Builder<'d> { http_method: HttpMethod, ) { let doc = self.doc; - if definition.ignore.value { + if definition.skip.value { return; } if definition.method_name.value.is_empty() { @@ -1595,7 +1595,7 @@ impl<'d> Builder<'d> { Schema::Bool(true) => {} Schema::Object(object) => { let object = doc.get(object); - if object.ignore { + if object.skip { continue; } extension = object.field_name; diff --git a/src/link/openapi.rs b/src/link/openapi.rs index 9041ee621..14925079c 100644 --- a/src/link/openapi.rs +++ b/src/link/openapi.rs @@ -265,7 +265,7 @@ impl Val { struct DefinitionTiers { method_name: Tier, group_names: Tier, - ignore: Tier, + skip: Tier, availability: Tier, } @@ -292,7 +292,7 @@ pub(super) struct Definition { /// The group path, top level first, or empty for none. pub(super) group_names: Val>, /// Whether the definition makes no method. - pub(super) ignore: Val, + pub(super) skip: Val, /// Whether the method is left out of listings. pub(super) hidden: bool, /// The sentence to confirm with, or `None` for none. An empty one is @@ -451,7 +451,7 @@ pub(super) struct SchemaObject { pub(super) field_name: Str, /// Whether a property's schema is marked to be left out: it makes no /// field. - pub(super) ignore: bool, + pub(super) skip: bool, } /// The tier of the key that gave each extension value of a [`SchemaObject`] @@ -460,7 +460,7 @@ pub(super) struct SchemaObject { struct SchemaTiers { model_name: Tier, field_name: Tier, - ignore: Tier, + skip: Tier, sensitive: Tier, } @@ -1319,9 +1319,9 @@ impl Definition { let names = map.next_value_seed(seed::(doc))?; self.group_names.set(&hit, names, &mut tiers.group_names); } - DefinitionField::Ignore(format) => { - let ignore = read_bool(map, format)?; - self.ignore.set(&hit, ignore, &mut tiers.ignore); + DefinitionField::Skip(format) => { + let skip = read_bool(map, format)?; + self.skip.set(&hit, skip, &mut tiers.skip); } DefinitionField::Availability => { let availability = map.next_value_seed(seed::(doc))?; @@ -1791,10 +1791,10 @@ impl ReadObject for SchemaObject { schema.field_name = name; } } - SchemaField::Ignore(format) => { - let ignore = read_bool(&mut map, format)?; - if takes(&hit, &mut tiers.ignore) { - schema.ignore = ignore; + SchemaField::Skip(format) => { + let skip = read_bool(&mut map, format)?; + if takes(&hit, &mut tiers.skip) { + schema.skip = skip; } } SchemaField::Sensitive => { diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index 9eba8e7ff..84b91cf2c 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -129,7 +129,7 @@ pub(crate) enum DefinitionField { /// no group. Group, /// Whether the definition makes no method. - Ignore(BoolFormat), + Skip(BoolFormat), /// The stage of the API the method is in. Availability, /// Whether the method is left out of listings. @@ -153,7 +153,7 @@ pub(crate) enum SchemaField { /// The name of a property's field. PropertyName, /// Whether the property makes no field. - Ignore(BoolFormat), + Skip(BoolFormat), /// Whether the schema's value is a secret. Sensitive, } @@ -183,8 +183,8 @@ pub(crate) fn definition(key: &str) -> Option> { } Some(match key { METHOD_NAME => Hit::native(DefinitionField::Method, 0), - GROUP => Hit::native(DefinitionField::Group, 1), - IGNORE => Hit::native(DefinitionField::Ignore(BoolFormat::Bool), 2), + GROUP_NAME => Hit::native(DefinitionField::Group, 1), + SKIP => Hit::native(DefinitionField::Skip(BoolFormat::Bool), 2), AVAILABILITY => Hit::native(DefinitionField::Availability, 3), HIDDEN => Hit::native(DefinitionField::Hidden, 4), CONFIRMATION => Hit::native(DefinitionField::Confirmation, 5), @@ -193,8 +193,8 @@ pub(crate) fn definition(key: &str) -> Option> { } const METHOD_NAME: &str = "x-forge-method-name"; -const GROUP: &str = "x-forge-group"; -const IGNORE: &str = "x-forge-ignore"; +const GROUP_NAME: &str = "x-forge-group-name"; +const SKIP: &str = "x-forge-skip"; const AVAILABILITY: &str = "x-forge-availability"; const HIDDEN: &str = "x-forge-hidden"; const CONFIRMATION: &str = "x-forge-require-confirmation"; @@ -209,11 +209,11 @@ const DEPRECATED_SENSITIVE: &str = "x-sensitive"; const COMMANDS: &str = "x-forge-commands"; /// The names of the native keys of an operation or an alias, by slot. -pub(crate) const DEFINITION_NAMES: [&str; 6] = [METHOD_NAME, GROUP, IGNORE, AVAILABILITY, HIDDEN, CONFIRMATION]; +pub(crate) const DEFINITION_NAMES: [&str; 6] = [METHOD_NAME, GROUP_NAME, SKIP, AVAILABILITY, HIDDEN, CONFIRMATION]; /// The names of the native keys of a Parameter Object, by slot. pub(crate) const PARAMETER_NAMES: [&str; 1] = [PARAMETER_NAME]; /// The names of the native keys of a Schema Object, by slot. -pub(crate) const SCHEMA_NAMES: [&str; 5] = [MODEL_NAME, PROPERTY_NAME, IGNORE, SENSITIVE, DEPRECATED_SENSITIVE]; +pub(crate) const SCHEMA_NAMES: [&str; 5] = [MODEL_NAME, PROPERTY_NAME, SKIP, SENSITIVE, DEPRECATED_SENSITIVE]; /// The names of the native keys of the document, by slot. pub(crate) const DOCUMENT_NAMES: [&str; 1] = [COMMANDS]; @@ -243,7 +243,7 @@ pub(crate) fn schema(key: &str) -> Option> { Some(match key { MODEL_NAME => Hit::native(SchemaField::ModelName, 0), PROPERTY_NAME => Hit::native(SchemaField::PropertyName, 1), - IGNORE => Hit::native(SchemaField::Ignore(BoolFormat::Bool), 2), + SKIP => Hit::native(SchemaField::Skip(BoolFormat::Bool), 2), SENSITIVE => Hit::native(SchemaField::Sensitive, 3), DEPRECATED_SENSITIVE => Hit::deprecated(SchemaField::Sensitive, 4), _ => return None, @@ -302,8 +302,8 @@ mod tests { [ &[ "x-forge-method-name", - "x-forge-group", - "x-forge-ignore", + "x-forge-group-name", + "x-forge-skip", "x-forge-availability", "x-forge-hidden", "x-forge-require-confirmation", @@ -312,7 +312,7 @@ mod tests { &[ "x-forge-model-name", "x-forge-property-name", - "x-forge-ignore", + "x-forge-skip", "x-forge-sensitive", "x-sensitive", ], diff --git a/src/plugin/ts/tests.rs b/src/plugin/ts/tests.rs index 60dc043b5..58ad0a549 100644 --- a/src/plugin/ts/tests.rs +++ b/src/plugin/ts/tests.rs @@ -370,11 +370,11 @@ fn models() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["pet-store", "list_all"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["pet-store", "list_all"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/pet_owner"}}}}}}}, - "/b": {"get": {"x-forge-group": ["pet-store"], "x-forge-method-name": "get", + "/b": {"get": {"x-forge-group-name": ["pet-store"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/2fa"}}}}}}}, - "/c": {"get": {"x-forge-group": ["other"], "x-forge-method-name": "get", + "/c": {"get": {"x-forge-group-name": ["other"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/2fa"}}}}}}} }, "components": {"schemas": {"pet_owner": {"type": "string"}, "2fa": {"type": "string"}}} diff --git a/src/types.rs b/src/types.rs index 9d5c26b94..06bc6642c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -293,7 +293,7 @@ impl<'f> Object<'f> { /// except in a [`Method::request`](crate::Method::request) and in /// [`Method::headers`](crate::Method::headers). /// - /// A property marked `x-forge-ignore: true`, or whose schema is + /// A property marked `x-forge-skip: true`, or whose schema is /// `false`, has no field. A name in `required` that is not a property is /// ignored. Two fields with equal names are an error. pub fn fields(self) -> impl ExactSizeIterator> { @@ -418,7 +418,7 @@ impl<'f> Field<'f> { /// `readOnly`, an `x-forge-sensitive` next to a `$ref` counts in every /// version of OpenAPI, since tools commonly honour extensions there. A /// value that is not a boolean is an error, as it is for a schema's - /// `x-forge-ignore` and an operation's `x-forge-hidden`. + /// `x-forge-skip` and an operation's `x-forge-hidden`. /// /// A field for a parameter, whether in the request or in /// [`Method::headers`](crate::Method::headers), is sensitive when the diff --git a/tests/cli.rs b/tests/cli.rs index bcb1ea4df..8926f77f0 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -6,7 +6,7 @@ use std::process::{Command, Output, Stdio}; /// A document with one method, `a.get`. const SPEC: &str = r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok"}}}}} }"#; diff --git a/tests/compat/common.rs b/tests/compat/common.rs index 86c6b96c4..7899d1d32 100644 --- a/tests/compat/common.rs +++ b/tests/compat/common.rs @@ -36,7 +36,7 @@ pub fn operation_with(keys: &str) -> String { pub fn responding_with(schema: &str, schemas: &str) -> String { format!( r#"{{"openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}}, "components": {{"schemas": {schemas}}}}}"# ) diff --git a/tests/compat/fern.rs b/tests/compat/fern.rs index bfd0a41ac..7dc3d6998 100644 --- a/tests/compat/fern.rs +++ b/tests/compat/fern.rs @@ -10,7 +10,7 @@ fn method_group_and_availability_are_read_as_native() { r#""x-fern-sdk-group-name": ["accounts"], "x-fern-sdk-method-name": "list", "x-fern-availability": "beta","#, ), &operation_with( - r#""x-forge-group": ["accounts"], "x-forge-method-name": "list", "x-forge-availability": "beta","#, + r#""x-forge-group-name": ["accounts"], "x-forge-method-name": "list", "x-forge-availability": "beta","#, ), ); } @@ -23,19 +23,19 @@ fn every_availability_is_read() { r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "{availability}","# )), &operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "{availability}","# + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "{availability}","# )), ); } } -/// As `x-forge-group` reads it, which Fern does not: Fern reads the string +/// As `x-forge-group-name` reads it, which Fern does not: Fern reads the string /// as one group. #[test] fn a_group_written_as_a_string_is_split_on_dots() { assert_same( &operation_with(r#""x-fern-sdk-group-name": "a.b.c", "x-fern-sdk-method-name": "get","#), - &operation_with(r#""x-forge-group": "a.b.c", "x-forge-method-name": "get","#), + &operation_with(r#""x-forge-group-name": "a.b.c", "x-forge-method-name": "get","#), ); } @@ -43,7 +43,7 @@ fn a_group_written_as_a_string_is_split_on_dots() { fn a_group_written_as_an_array_is_not_split() { assert_same( &operation_with(r#""x-fern-sdk-group-name": ["a.b", "c"], "x-fern-sdk-method-name": "get","#), - &operation_with(r#""x-forge-group": ["a.b", "c"], "x-forge-method-name": "get","#), + &operation_with(r#""x-forge-group-name": ["a.b", "c"], "x-forge-method-name": "get","#), ); } @@ -69,7 +69,7 @@ fn a_group_that_is_neither_a_string_nor_an_array_is_an_error() { fn ignore_makes_no_method() { assert_same( &operation_with(r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": true,"#), - &operation_with(r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": true,"#), + &operation_with(r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-skip": true,"#), ); assert_eq!( parse(&operation_with( @@ -85,7 +85,7 @@ fn ignore_makes_no_method() { fn ignore_set_to_false_keeps_the_method() { assert_same( &operation_with(r#""x-fern-sdk-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-ignore": false,"#), - &operation_with(r#""x-forge-group": ["a"], "x-forge-method-name": "get","#), + &operation_with(r#""x-forge-group-name": ["a"], "x-forge-method-name": "get","#), ); } @@ -93,7 +93,7 @@ fn ignore_set_to_false_keeps_the_method() { fn a_parameter_name_is_read_as_native() { let parameters = |key: &str| { operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method-name": "list", + r#""x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{{"name": "q", "in": "query", "{key}": "query", "schema": {{"type": "string"}}}}],"# )) }; @@ -152,10 +152,10 @@ fn the_keys_of_an_alias_are_read_too() { "x-fern-ignore", ), &alias( - "x-forge-group", + "x-forge-group-name", "x-forge-method-name", "x-forge-availability", - "x-forge-ignore", + "x-forge-skip", ), ); } @@ -182,7 +182,7 @@ fn a_key_that_is_read_is_not_an_extension_of_the_method() { #[test] fn a_key_that_is_not_read_stays_an_extension_of_the_method() { let forge = parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-fern-audiences": ["internal"], "x-fern-pagination": {"offset": "o"},"#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-fern-audiences": ["internal"], "x-fern-pagination": {"offset": "o"},"#, )); let method = forge.groups().next().unwrap().methods().next().unwrap(); @@ -266,7 +266,7 @@ fn a_key_written_twice_is_an_error_naming_it() { fn the_vendor_keys_of_a_kind_of_object_are_read_only_there() { // A name key on an operation, or a method key on a schema, says nothing. let forge = parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-fern-property-name": "p", "x-fern-type-name": "T", + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-fern-property-name": "p", "x-fern-type-name": "T", "x-fern-parameter-name": "q","#, )); let method = forge.groups().next().unwrap().methods().next().unwrap(); diff --git a/tests/compat/native_first.rs b/tests/compat/native_first.rs index 9e0db4d6f..6296e9601 100644 --- a/tests/compat/native_first.rs +++ b/tests/compat/native_first.rs @@ -17,13 +17,13 @@ fn native_wins(native: &str, compat: &str, expected: &str) { #[test] fn the_native_method_wins() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method-name": "native","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "native","#, r#""x-fern-sdk-method-name": "vendor","#, - r#""x-forge-group": ["a"], "x-forge-method-name": "native","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "native","#, ); assert!( describe(&parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method-name": "native", "x-fern-sdk-method-name": "vendor","# + r#""x-forge-group-name": ["a"], "x-forge-method-name": "native", "x-fern-sdk-method-name": "vendor","# ))) .contains("method native") ); @@ -32,36 +32,36 @@ fn the_native_method_wins() { #[test] fn the_native_group_wins() { native_wins( - r#""x-forge-method-name": "get", "x-forge-group": ["native"],"#, + r#""x-forge-method-name": "get", "x-forge-group-name": ["native"],"#, r#""x-fern-sdk-group-name": "vendor.group","#, - r#""x-forge-method-name": "get", "x-forge-group": ["native"],"#, + r#""x-forge-method-name": "get", "x-forge-group-name": ["native"],"#, ); } #[test] fn the_native_availability_wins_and_an_invalid_compat_one_is_not_checked() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, r#""x-fern-availability": "ga","#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, ); } #[test] -fn a_native_ignore_of_false_keeps_the_method_a_compat_one_would_drop() { +fn a_native_skip_of_false_keeps_the_method_a_compat_one_would_drop() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": false,"#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-skip": false,"#, r#""x-fern-ignore": true,"#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get","#, ); } #[test] -fn a_native_ignore_of_true_drops_the_method_a_compat_one_would_keep() { +fn a_native_skip_of_true_drops_the_method_a_compat_one_would_keep() { native_wins( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": true,"#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-skip": true,"#, r#""x-fern-ignore": false,"#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": true,"#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-skip": true,"#, ); } @@ -69,7 +69,7 @@ fn a_native_ignore_of_true_drops_the_method_a_compat_one_would_keep() { fn the_native_parameter_name_wins() { let parameter = |keys: &str| { operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method-name": "list", + r#""x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{{"name": "q", "in": "query", {keys} "schema": {{"type": "string"}}}}],"# )) }; @@ -116,7 +116,7 @@ fn the_native_property_and_model_names_win() { } #[test] -fn the_native_ignore_of_a_property_wins_over_a_skip() { +fn the_native_skip_of_a_property_wins_over_a_stainless_one() { let property = |keys: &str| { responding_with( &format!(r#"{{"type": "object", "properties": {{"a": {{"type": "string", {keys}}}}}}}"#), @@ -124,14 +124,14 @@ fn the_native_ignore_of_a_property_wins_over_a_skip() { ) }; for keys in [ - r#""x-forge-ignore": false, "x-stainless-skip": true"#, - r#""x-stainless-skip": true, "x-forge-ignore": false"#, + r#""x-forge-skip": false, "x-stainless-skip": true"#, + r#""x-stainless-skip": true, "x-forge-skip": false"#, ] { assert!(describe(&parse(&property(keys))).contains("a:a="), "{keys}"); } for keys in [ - r#""x-forge-ignore": true, "x-stainless-skip": false"#, - r#""x-stainless-skip": false, "x-forge-ignore": true"#, + r#""x-forge-skip": true, "x-stainless-skip": false"#, + r#""x-stainless-skip": false, "x-forge-skip": true"#, ] { assert!(!describe(&parse(&property(keys))).contains("a:a="), "{keys}"); } @@ -141,12 +141,12 @@ fn the_native_ignore_of_a_property_wins_over_a_skip() { fn both_keys_with_the_same_value_are_the_same_as_one() { assert_same( &operation_with( - r#""x-forge-group": ["a", "b"], "x-fern-sdk-group-name": "a.b", + r#""x-forge-group-name": ["a", "b"], "x-fern-sdk-group-name": "a.b", "x-forge-method-name": "get", "x-fern-sdk-method-name": "get", "x-forge-availability": "beta", "x-fern-availability": "beta","#, ), &operation_with( - r#""x-forge-group": ["a", "b"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, + r#""x-forge-group-name": ["a", "b"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, ), ); } @@ -155,8 +155,12 @@ fn both_keys_with_the_same_value_are_the_same_as_one() { fn each_primitive_is_resolved_on_its_own() { // The group is native and the method and availability are not. assert_same( - &operation_with(r#""x-forge-group": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "beta","#), - &operation_with(r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#), + &operation_with( + r#""x-forge-group-name": ["a"], "x-fern-sdk-method-name": "get", "x-fern-availability": "beta","#, + ), + &operation_with( + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta","#, + ), ); } @@ -167,7 +171,7 @@ fn a_compat_value_of_the_wrong_type_is_an_error_even_when_a_native_key_wins() { r#""x-fern-availability": 1, "x-forge-availability": "beta","#, ] { let err = parse_err(&operation_with(&format!( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", {keys}"# + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", {keys}"# ))); assert!(err.contains("invalid type"), "{keys}: {err}"); @@ -176,24 +180,24 @@ fn a_compat_value_of_the_wrong_type_is_an_error_even_when_a_native_key_wins() { #[test] fn a_native_key_written_twice_is_an_error_naming_it() { - let err = parse_err(&operation_with(r#""x-forge-ignore": false, "x-forge-ignore": false,"#)); + let err = parse_err(&operation_with(r#""x-forge-skip": false, "x-forge-skip": false,"#)); - assert!(err.contains("duplicate field `x-forge-ignore`"), "{err}"); + assert!(err.contains("duplicate field `x-forge-skip`"), "{err}"); } #[test] fn the_native_group_written_as_a_string_wins() { native_wins( - r#""x-forge-method-name": "get", "x-forge-group": "native.group","#, + r#""x-forge-method-name": "get", "x-forge-group-name": "native.group","#, r#""x-fern-sdk-group-name": ["vendor"],"#, - r#""x-forge-method-name": "get", "x-forge-group": ["native", "group"],"#, + r#""x-forge-method-name": "get", "x-forge-group-name": ["native", "group"],"#, ); } #[test] fn an_error_names_the_native_key_when_the_native_key_gave_the_value() { let err = parse_err(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "ga","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "ga","#, )); assert!(err.contains(r#"GET /a: x-forge-availability "ga" is not"#), "{err}"); @@ -204,14 +208,14 @@ fn only_the_winning_group_and_method_name_are_checked() { // Each compat value is an error on its own, so the document parsing at // all shows it was not checked. native_wins( - r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get","#, r#""x-fern-sdk-group-name": "a..b","#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get","#, ); native_wins( - r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get","#, r#""x-fern-sdk-method-name": "-","#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get","#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get","#, ); assert!( parse_err(&operation_with( @@ -221,7 +225,7 @@ fn only_the_winning_group_and_method_name_are_checked() { ); assert!( parse_err(&operation_with( - r#""x-forge-group": ["a"], "x-fern-sdk-method-name": "-","# + r#""x-forge-group-name": ["a"], "x-fern-sdk-method-name": "-","# )) .contains("x-fern-sdk-method-name") ); @@ -243,41 +247,41 @@ fn native_wins_in_an_alias(native: &str, compat: &str, expected: &str, method: & #[test] fn the_native_keys_of_an_alias_win() { native_wins_in_an_alias( - r#""x-forge-group": ["a"], "x-forge-method-name": "native""#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "native""#, r#""x-fern-sdk-method-name": "vendor""#, - r#""x-forge-group": ["a"], "x-forge-method-name": "native""#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "native""#, "native", ); native_wins_in_an_alias( - r#""x-forge-method-name": "get", "x-forge-group": ["native"]"#, + r#""x-forge-method-name": "get", "x-forge-group-name": ["native"]"#, r#""x-fern-sdk-group-name": "vendor.group""#, - r#""x-forge-method-name": "get", "x-forge-group": ["native"]"#, + r#""x-forge-method-name": "get", "x-forge-group-name": ["native"]"#, "get", ); native_wins_in_an_alias( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta""#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta""#, r#""x-fern-availability": "ga""#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta""#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-availability": "beta""#, "get", ); native_wins_in_an_alias( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-forge-ignore": false"#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-forge-skip": false"#, r#""x-fern-ignore": true"#, - r#""x-forge-group": ["a"], "x-forge-method-name": "get""#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get""#, "get", ); } #[test] -fn a_native_ignore_in_an_alias_drops_the_method_a_compat_one_would_keep() { +fn a_native_skip_in_an_alias_drops_the_method_a_compat_one_would_keep() { let alias = |keys: &str| { operation_with(&format!( - r#""x-forge-aliases": [{{"x-forge-group": ["a"], "x-forge-method-name": "get", {keys}}}],"# + r#""x-forge-aliases": [{{"x-forge-group-name": ["a"], "x-forge-method-name": "get", {keys}}}],"# )) }; for keys in [ - r#""x-forge-ignore": true, "x-fern-ignore": false"#, - r#""x-fern-ignore": false, "x-forge-ignore": true"#, + r#""x-forge-skip": true, "x-fern-ignore": false"#, + r#""x-fern-ignore": false, "x-forge-skip": true"#, ] { assert_eq!(parse(&alias(keys)).groups().count(), 0, "{keys}"); } diff --git a/tests/compat/stainless.rs b/tests/compat/stainless.rs index 7f4cd1a4c..d778ad997 100644 --- a/tests/compat/stainless.rs +++ b/tests/compat/stainless.rs @@ -3,7 +3,7 @@ use super::common::{assert_same, describe, operation_with, parse, parse_err, responding_with}; -fn with_skip(value: &str) -> String { +fn with_stainless_skip(value: &str) -> String { responding_with( &format!( r#"{{"type": "object", "properties": {{"id": {{"type": "string"}}, "old_id": {{"type": "string", "x-stainless-skip": {value}}}}}}}"# @@ -12,44 +12,47 @@ fn with_skip(value: &str) -> String { ) } -fn with_ignore(value: &str) -> String { +fn with_native_skip(value: &str) -> String { responding_with( &format!( - r#"{{"type": "object", "properties": {{"id": {{"type": "string"}}, "old_id": {{"type": "string", "x-forge-ignore": {value}}}}}}}"# + r#"{{"type": "object", "properties": {{"id": {{"type": "string"}}, "old_id": {{"type": "string", "x-forge-skip": {value}}}}}}}"# ), "{}", ) } #[test] -fn a_skipped_property_is_read_as_an_ignored_one() { - assert_same(&with_skip("true"), &with_ignore("true")); - assert!(!describe(&parse(&with_skip("true"))).contains("old_id")); +fn a_stainless_skip_is_read_as_a_native_one() { + assert_same(&with_stainless_skip("true"), &with_native_skip("true")); + assert!(!describe(&parse(&with_stainless_skip("true"))).contains("old_id")); } #[test] fn a_property_skipped_as_false_keeps_its_field() { - assert_same(&with_skip("false"), &with_ignore("false")); - assert!(describe(&parse(&with_skip("false"))).contains("old_id")); + assert_same(&with_stainless_skip("false"), &with_native_skip("false")); + assert!(describe(&parse(&with_stainless_skip("false"))).contains("old_id")); } #[test] fn a_list_of_targets_is_not_a_skip() { - assert_same(&with_skip(r#"["typescript", "go"]"#), &with_ignore("false")); - assert!(describe(&parse(&with_skip(r#"["typescript"]"#))).contains("old_id")); - assert!(describe(&parse(&with_skip("[]"))).contains("old_id")); + assert_same( + &with_stainless_skip(r#"["typescript", "go"]"#), + &with_native_skip("false"), + ); + assert!(describe(&parse(&with_stainless_skip(r#"["typescript"]"#))).contains("old_id")); + assert!(describe(&parse(&with_stainless_skip("[]"))).contains("old_id")); } #[test] fn a_skip_that_is_not_a_boolean_or_a_list_is_an_error() { - let err = parse_err(&with_skip(r#""yes""#)); + let err = parse_err(&with_stainless_skip(r#""yes""#)); assert!(err.contains("a boolean or an array of targets"), "{err}"); } #[test] fn a_list_of_targets_is_an_error_for_the_native_key() { - let err = parse_err(&with_ignore(r#"["typescript"]"#)); + let err = parse_err(&with_native_skip(r#"["typescript"]"#)); assert!(err.contains("invalid type"), "{err}"); } @@ -67,7 +70,7 @@ fn a_skip_written_twice_is_an_error_naming_it() { #[test] fn a_skip_on_an_operation_says_nothing_and_stays_an_extension() { let forge = parse(&operation_with( - r#""x-forge-group": ["a"], "x-forge-method-name": "get", "x-stainless-skip": true,"#, + r#""x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-stainless-skip": true,"#, )); let method = forge.groups().next().unwrap().methods().next().unwrap(); diff --git a/tests/parse/aliases.rs b/tests/parse/aliases.rs index bcb6c580b..8ff74cbb1 100644 --- a/tests/parse/aliases.rs +++ b/tests/parse/aliases.rs @@ -10,7 +10,7 @@ fn aliased(aliases: &str, fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a/{{id}}/status": {{"patch": {{{fields} - "x-forge-group": ["a", "status"], "x-forge-method-name": "edit", + "x-forge-group-name": ["a", "status"], "x-forge-method-name": "edit", "x-forge-aliases": {aliases}, "summary": "Edit status", "description": "Changes the status.", "parameters": [{{"name": "id", "in": "path", "required": true, "schema": {{"type": "string"}}}}], @@ -39,8 +39,8 @@ fn methods(forge: &Forge) -> Vec { } const PAUSE_AND_TERMINATE: &str = r#"[ - {"x-forge-group": ["a"], "x-forge-method-name": "pause"}, - {"x-forge-group": ["a"], "x-forge-method-name": "terminate"} + {"x-forge-group-name": ["a"], "x-forge-method-name": "pause"}, + {"x-forge-group-name": ["a"], "x-forge-method-name": "terminate"} ]"#; #[test] @@ -77,10 +77,10 @@ fn aliases_share_the_rest_of_the_operation() { fn each_alias_has_its_own_availability_hidden_confirmation_and_extensions() { let forge = parse(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method-name": "pause", + {"x-forge-group-name": ["a"], "x-forge-method-name": "pause", "x-forge-availability": "generally-available", "x-forge-hidden": true, "x-forge-params": {"status": {"default": "pause", "hidden": true}}}, - {"x-forge-group": ["a"], "x-forge-method-name": "terminate", + {"x-forge-group-name": ["a"], "x-forge-method-name": "terminate", "x-forge-availability": "beta", "x-forge-require-confirmation": "Sure?", "x-a": 1, "x-b": 2} ]"#, "", @@ -111,7 +111,7 @@ fn each_alias_has_its_own_availability_hidden_confirmation_and_extensions() { #[test] fn alias_does_not_fall_back_to_the_operation() { let forge = parse(&aliased( - r#"[{"x-forge-group": ["a"], "x-forge-method-name": "pause"}]"#, + r#"[{"x-forge-group-name": ["a"], "x-forge-method-name": "pause"}]"#, r#""x-forge-availability": "beta", "x-forge-hidden": true, "x-forge-require-confirmation": "Sure?", "x-forge-params": {"status": {}},"#, )); @@ -128,10 +128,10 @@ fn alias_does_not_fall_back_to_the_operation() { fn alias_without_a_group_or_name_is_not_a_method() { let forge = parse(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method-name": "pause"}, - {"x-forge-group": ["a"]}, + {"x-forge-group-name": ["a"], "x-forge-method-name": "pause"}, + {"x-forge-group-name": ["a"]}, {"x-forge-method-name": "resume"}, - {"x-forge-group": [], "x-forge-method-name": "restart"} + {"x-forge-group-name": [], "x-forge-method-name": "restart"} ]"#, "", )); @@ -142,7 +142,7 @@ fn alias_without_a_group_or_name_is_not_a_method() { #[test] fn element_that_is_not_an_object_is_ignored() { let forge = parse(&aliased( - r#"["pause", null, 1, true, ["a"], {"x-forge-group": ["a"], "x-forge-method-name": "pause"}]"#, + r#"["pause", null, 1, true, ["a"], {"x-forge-group-name": ["a"], "x-forge-method-name": "pause"}]"#, "", )); @@ -159,7 +159,7 @@ fn empty_aliases_make_no_method() { #[test] fn aliases_that_are_not_an_array_are_an_error() { let err = parse_err(&aliased( - r#"{"x-forge-group": ["a"], "x-forge-method-name": "pause"}"#, + r#"{"x-forge-group-name": ["a"], "x-forge-method-name": "pause"}"#, "", )); @@ -172,11 +172,11 @@ fn alias_and_another_method_with_equal_names_are_an_error() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "pause", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "pause", "responses": {"204": {"description": "ok"}}}}, "/b": {"post": {"x-forge-aliases": [ - {"x-forge-group": ["a"], "x-forge-method-name": "resume"}, - {"x-forge-group": ["a"], "x-forge-method-name": "Pause"} + {"x-forge-group-name": ["a"], "x-forge-method-name": "resume"}, + {"x-forge-group-name": ["a"], "x-forge-method-name": "Pause"} ], "responses": {"204": {"description": "ok"}}}} } }"#, @@ -192,8 +192,8 @@ fn alias_and_another_method_with_equal_names_are_an_error() { fn two_aliases_with_equal_names_are_an_error() { let err = parse_err(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method-name": "pause"}, - {"x-forge-group": ["a"], "x-forge-method-name": "pause"} + {"x-forge-group-name": ["a"], "x-forge-method-name": "pause"}, + {"x-forge-group-name": ["a"], "x-forge-method-name": "pause"} ]"#, "", )); @@ -207,12 +207,12 @@ fn two_aliases_with_equal_names_are_an_error() { #[test] fn alias_group_name_without_letters_is_an_error_naming_the_alias() { let err = parse_err(&aliased( - r#"[{"x-forge-group": ["a", "", "b"], "x-forge-method-name": "pause"}]"#, + r#"[{"x-forge-group-name": ["a", "", "b"], "x-forge-method-name": "pause"}]"#, "", )); assert!( - err.contains("PATCH /a/{id}/status: x-forge-aliases[0]: x-forge-group"), + err.contains("PATCH /a/{id}/status: x-forge-aliases[0]: x-forge-group-name"), "{err}" ); } @@ -220,7 +220,7 @@ fn alias_group_name_without_letters_is_an_error_naming_the_alias() { #[test] fn alias_availability_is_checked() { let err = parse_err(&aliased( - r#"[1, {"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-forge-availability": "ga"}]"#, + r#"[1, {"x-forge-group-name": ["a"], "x-forge-method-name": "pause", "x-forge-availability": "ga"}]"#, "", )); @@ -241,18 +241,18 @@ fn repeated_key_forge_reads_in_an_alias_is_an_error() { } #[test] -fn ignored_operation_still_has_its_aliases() { - let forge = parse(&aliased(PAUSE_AND_TERMINATE, r#""x-forge-ignore": true,"#)); +fn skipped_operation_still_has_its_aliases() { + let forge = parse(&aliased(PAUSE_AND_TERMINATE, r#""x-forge-skip": true,"#)); assert_eq!(methods(&forge), ["a.pause", "a.terminate"]); } #[test] -fn ignored_alias_is_not_a_method() { +fn skipped_alias_is_not_a_method() { let forge = parse(&aliased( r#"[ - {"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-forge-ignore": true}, - {"x-forge-group": ["a"], "x-forge-method-name": "terminate", "x-forge-ignore": false} + {"x-forge-group-name": ["a"], "x-forge-method-name": "pause", "x-forge-skip": true}, + {"x-forge-group-name": ["a"], "x-forge-method-name": "terminate", "x-forge-skip": false} ]"#, "", )); @@ -263,8 +263,8 @@ fn ignored_alias_is_not_a_method() { #[test] fn aliases_are_not_extensions() { let forge = parse(&aliased( - r#"[{"x-forge-group": ["a"], "x-forge-method-name": "pause", "x-a": 1, - "x-forge-aliases": [{"x-forge-group": ["b"], "x-forge-method-name": "nested"}]}]"#, + r#"[{"x-forge-group-name": ["a"], "x-forge-method-name": "pause", "x-a": 1, + "x-forge-aliases": [{"x-forge-group-name": ["b"], "x-forge-method-name": "nested"}]}]"#, "", )); @@ -277,7 +277,7 @@ fn aliases_are_not_extensions() { #[test] fn keys_of_an_alias_that_are_not_extensions_are_ignored() { let forge = parse(&aliased( - r#"[{"x-forge-group": ["a"], "x-forge-method-name": "pause", + r#"[{"x-forge-group-name": ["a"], "x-forge-method-name": "pause", "summary": "Pause", "deprecated": false, "path": "/b"}]"#, "", )); @@ -293,7 +293,7 @@ fn operation_without_aliases_keeps_its_own_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -307,10 +307,10 @@ fn model_used_by_aliases_in_two_top_level_groups_is_at_the_top_level() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/m": {"get": { - "x-forge-group": ["a", "b"], "x-forge-method-name": "get", + "x-forge-group-name": ["a", "b"], "x-forge-method-name": "get", "x-forge-aliases": [ - {"x-forge-group": ["a", "b"], "x-forge-method-name": "get"}, - {"x-forge-group": ["x"], "x-forge-method-name": "get"} + {"x-forge-group-name": ["a", "b"], "x-forge-method-name": "get"}, + {"x-forge-group-name": ["x"], "x-forge-method-name": "get"} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}}, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -328,10 +328,10 @@ fn model_used_by_aliases_in_one_group_is_in_that_group() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/m": {"get": { - "x-forge-group": ["x"], "x-forge-method-name": "get", + "x-forge-group-name": ["x"], "x-forge-method-name": "get", "x-forge-aliases": [ - {"x-forge-group": ["a", "b"], "x-forge-method-name": "get"}, - {"x-forge-group": ["a", "c"], "x-forge-method-name": "get"} + {"x-forge-group-name": ["a", "b"], "x-forge-method-name": "get"}, + {"x-forge-group-name": ["a", "c"], "x-forge-method-name": "get"} ], "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}}, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} diff --git a/tests/parse/bodies.rs b/tests/parse/bodies.rs index 76b28f6fc..296d30b5a 100644 --- a/tests/parse/bodies.rs +++ b/tests/parse/bodies.rs @@ -21,7 +21,7 @@ fn body_has_its_required_and_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"required": true, "description": "The pet.", "content": {"application/json": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -38,7 +38,7 @@ fn body_is_optional_by_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -52,7 +52,7 @@ fn contents_are_sorted_by_media_type() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "text/plain": {"schema": {"type": "string"}}, "multipart/form-data": {"schema": {"type": "object"}}, @@ -73,7 +73,7 @@ fn json_is_application_json_before_other_json_types() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "application/geo+json": {"schema": {"type": "object"}}, "application/json": {"schema": {"type": "string"}} @@ -90,7 +90,7 @@ fn json_is_otherwise_the_first_json_type() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"patch": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"patch": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "multipart/form-data": {"schema": {"type": "object"}}, "application/scim+json": {"schema": {"type": "object"}}, @@ -111,7 +111,7 @@ fn json_ignores_case_and_parameters() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"Application/JSON; charset=utf-8": {"schema": {"type": "string"}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -127,7 +127,7 @@ fn multipart_content_is_typed() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "required": ["file"], "properties": { "file": {"type": "string", "format": "binary"}, @@ -151,7 +151,7 @@ fn octet_stream_content_of_a_binary_string_is_binary() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/octet-stream": {"schema": { "type": "string", "format": "binary" }}}}, @@ -169,7 +169,7 @@ fn json_ignores_content_that_is_not_json() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": { "multipart/form-data": {"schema": {"type": "object", "properties": {"name": {"type": "string"}}}}, "text/plain": {"schema": {"type": "string"}} @@ -189,7 +189,7 @@ fn content_that_is_not_json_without_a_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/octet-stream": {}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -204,7 +204,7 @@ fn content_without_a_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -219,7 +219,7 @@ fn body_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"$ref": "#/components/requestBodies/Pet"}, "responses": {"204": {"description": "ok"}}}}}, "components": {"requestBodies": { @@ -239,7 +239,7 @@ fn with_body_schema(version: &str, schema: &str, schemas: &str) -> String { format!( r#"{{ "openapi": "{version}", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"post": {{"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {{"/a": {{"post": {{"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {{"content": {{"application/json": {{"schema": {schema}}}}}}}, "responses": {{"204": {{"description": "ok"}}}}}}}}}}, "components": {{"schemas": {schemas}}} @@ -301,7 +301,7 @@ fn response_content_has_its_schema_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": { "schema": {"type": "string", "description": "The name."}}}}}}}} }"#, diff --git a/tests/parse/common.rs b/tests/parse/common.rs index ddfeccfe9..901cf07bb 100644 --- a/tests/parse/common.rs +++ b/tests/parse/common.rs @@ -19,7 +19,7 @@ pub fn responding_with(schema: &str) -> String { format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}} }}"# ) @@ -31,7 +31,7 @@ pub fn responding_with_schemas(schema: &str, schemas: &str) -> String { format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {{"200": {{"description": "ok", "content": {{"application/json": {{"schema": {schema}}}}}}}}}}}}}}}, "components": {{"schemas": {schemas}}} }}"# diff --git a/tests/parse/document.rs b/tests/parse/document.rs index 934a48ae9..cbb9fc30d 100644 --- a/tests/parse/document.rs +++ b/tests/parse/document.rs @@ -103,7 +103,7 @@ fn every_version_of_3_0_3_1_and_3_2_is_read() { let forge = parse(&format!( r#"{{ "openapi": "{version}", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# )); @@ -118,7 +118,7 @@ fn errors_are_reported_together() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "servers": [{"url": "https://{region}.example.com"}], - "paths": {"/a": {"get": {"x-forge-group": ["a", "", "b"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a", "", "b"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); diff --git a/tests/parse/extensions.rs b/tests/parse/extensions.rs index 58f214836..14fbd9eb0 100644 --- a/tests/parse/extensions.rs +++ b/tests/parse/extensions.rs @@ -9,7 +9,7 @@ fn operation_with(fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a": {{"get": {{{fields} - "x-forge-group": ["a"], "x-forge-method-name": "get", + "x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# ) @@ -85,12 +85,12 @@ fn keys_that_are_not_extensions_are_not_kept() { #[test] fn extensions_forge_reads_are_not_kept() { - let forge = parse(&operation_with(r#""x-forge-ignore": false, "x-a": 1,"#)); + let forge = parse(&operation_with(r#""x-forge-skip": false, "x-a": 1,"#)); let get = method(&forge, "a.get"); assert_eq!(names(&forge, "a.get"), ["x-a"]); - assert_eq!(get.extension("x-forge-group"), None); - assert_eq!(get.extension("x-forge-ignore"), None); + assert_eq!(get.extension("x-forge-group-name"), None); + assert_eq!(get.extension("x-forge-skip"), None); } #[test] @@ -113,9 +113,9 @@ fn extensions_forge_reads_are_still_read() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a", "b"], "x-forge-method-name": "list", "x-a": 1, + "get": {"x-forge-group-name": ["a", "b"], "x-forge-method-name": "list", "x-a": 1, "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "x-forge-ignore": true, + "post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "x-forge-skip": true, "x-a": 1, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -136,9 +136,9 @@ fn repeated_extension_has_the_last_value_in_the_place_of_the_first() { #[test] fn repeated_extension_forge_reads_is_still_an_error() { - let err = parse_err(&operation_with(r#""x-forge-ignore": false, "x-forge-ignore": false,"#)); + let err = parse_err(&operation_with(r#""x-forge-skip": false, "x-forge-skip": false,"#)); - assert!(err.contains("duplicate field `x-forge-ignore`"), "{err}"); + assert!(err.contains("duplicate field `x-forge-skip`"), "{err}"); } #[test] @@ -147,11 +147,11 @@ fn each_method_keeps_its_own_extensions() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "x-a": "get", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-a": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "/b": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}, - "/c": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "x-a": "create", + "/c": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "x-a": "create", "x-b": [], "responses": {"204": {"description": "ok"}}}} } }"#, @@ -170,7 +170,7 @@ fn extensions_outside_the_operation_are_not_kept() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "x-root": 1, - "paths": {"/a": {"x-path-item": 1, "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"x-path-item": 1, "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "q", "in": "query", "x-parameter": 1, "schema": {"type": "string", "x-schema": 1}}], "responses": {"204": {"description": "ok", "x-response": 1}}}}} }"#, @@ -186,11 +186,11 @@ fn operation_of_a_referenced_path_item_keeps_its_extensions() { "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, "paths": { "/a": {"$ref": "#/components/pathItems/A"}, - "/b": {"get": {"x-forge-group": ["b"], "x-forge-method-name": "get", "x-b": 2, + "/b": {"get": {"x-forge-group-name": ["b"], "x-forge-method-name": "get", "x-b": 2, "responses": {"204": {"description": "ok"}}}} }, "components": {"pathItems": { - "A": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "x-a": 1, + "A": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "x-a": 1, "responses": {"204": {"description": "ok"}}}} }} }"##, diff --git a/tests/parse/groups.rs b/tests/parse/groups.rs index 0e06d3322..36a8d4b9b 100644 --- a/tests/parse/groups.rs +++ b/tests/parse/groups.rs @@ -7,7 +7,7 @@ fn string_group_name_splits_on_dots() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": "accounts.members", "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": "accounts.members", "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -21,7 +21,7 @@ fn group_name_that_is_neither_a_string_nor_an_array_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": 1, "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": 1, "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -34,7 +34,7 @@ fn array_group_name_has_a_group_per_element() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["accounts", "members"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -48,7 +48,7 @@ fn array_element_with_a_dot_is_one_group() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["zones.settings"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["zones.settings"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -67,9 +67,9 @@ fn groups_with_equal_names_are_one_group() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["abuse-reports"], "x-forge-method-name": "list", + "/a": {"get": {"x-forge-group-name": ["abuse-reports"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method-name": "get", + "/b": {"get": {"x-forge-group-name": ["abuse_reports"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -85,9 +85,9 @@ fn subgroup_and_method_can_share_a_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"delete": {"x-forge-group": ["members"], "x-forge-method-name": "delete", + "/a": {"delete": {"x-forge-group-name": ["members"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}}, - "/b": {"post": {"x-forge-group": ["members", "delete"], "x-forge-method-name": "bulk", + "/b": {"post": {"x-forge-group-name": ["members", "delete"], "x-forge-method-name": "bulk", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -116,7 +116,7 @@ fn empty_group_name_is_no_group() { let forge = parse(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": {group}, "x-forge-method-name": "get", + "paths": {{"/a": {{"get": {{"x-forge-group-name": {group}, "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# )); @@ -130,7 +130,7 @@ fn operation_without_a_method_name_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -143,7 +143,7 @@ fn empty_method_name_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -152,14 +152,14 @@ fn empty_method_name_is_not_a_method() { } #[test] -fn ignored_operation_is_not_a_method() { +fn skipped_operation_is_not_a_method() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method-name": "create", "x-forge-ignore": true, + "post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "x-forge-skip": true, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -175,12 +175,15 @@ fn group_name_without_letters_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": {group}, "x-forge-method-name": "list", + "paths": {{"/a": {{"get": {{"x-forge-group-name": {group}, "x-forge-method-name": "list", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# )); - assert!(err.contains("GET /a: x-forge-group has a group name"), "{group}: {err}"); + assert!( + err.contains("GET /a: x-forge-group-name has a group name"), + "{group}: {err}" + ); } } @@ -190,9 +193,9 @@ fn duplicate_method_in_a_group_is_an_error() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "/b": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -207,9 +210,9 @@ fn method_names_are_equal_as_names() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list_all", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list_all", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "listAll", + "/b": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "listAll", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -224,11 +227,11 @@ fn groups_are_depth_first() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["a", "b", "c"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["x"], "x-forge-method-name": "get", + "/b": {"get": {"x-forge-group-name": ["x"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/c": {"get": {"x-forge-group": ["a", "d"], "x-forge-method-name": "get", + "/c": {"get": {"x-forge-group-name": ["a", "d"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -258,7 +261,7 @@ fn group_description_comes_from_x_forge_commands() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["accounts"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"accounts": {"description": "Accounts."}} }"#, @@ -272,7 +275,7 @@ fn subgroup_description_is_in_its_parents_command() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["accounts", "members"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"accounts": {"groups": {"members": {"description": "Members."}}}} }"#, @@ -294,7 +297,7 @@ fn with_commands(groups: &[&str], commands: &str) -> String { .collect::>() .join(", "); format!( - r#""/{i}": {{"get": {{"x-forge-group": [{group}], "x-forge-method-name": "list", + r#""/{i}": {{"get": {{"x-forge-group-name": [{group}], "x-forge-method-name": "list", "responses": {{"204": {{"description": "ok"}}}}}}}}"# ) }) @@ -363,7 +366,7 @@ fn command_matches_a_group_with_an_equal_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["abuse_reports"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["abuse_reports"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"abuse-reports": {"description": "Abuse reports."}} }"#, @@ -377,7 +380,7 @@ fn group_without_a_command_has_no_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["accounts"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["accounts"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}}}, "x-forge-commands": {"zones": {"description": "Zones."}} }"#, @@ -406,13 +409,13 @@ fn groups_are_sorted_by_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["zones"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["zones"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/b": {"get": {"x-forge-group": ["accounts", "members"], "x-forge-method-name": "get", + "/b": {"get": {"x-forge-group-name": ["accounts", "members"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/c": {"get": {"x-forge-group": ["dns"], "x-forge-method-name": "get", + "/c": {"get": {"x-forge-group-name": ["dns"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, - "/d": {"get": {"x-forge-group": ["accounts", "billing"], "x-forge-method-name": "get", + "/d": {"get": {"x-forge-group-name": ["accounts", "billing"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} } }"#, @@ -434,11 +437,11 @@ fn methods_are_sorted_by_name() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", + "delete": {"x-forge-group-name": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, diff --git a/tests/parse/headers.rs b/tests/parse/headers.rs index cbba07620..1d45cdb8c 100644 --- a/tests/parse/headers.rs +++ b/tests/parse/headers.rs @@ -17,7 +17,7 @@ fn header_param_is_a_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Request-ID", "in": "header", "required": true, "description": "Traces the request.", "schema": {"type": "integer", "format": "int64"}}, @@ -43,7 +43,7 @@ fn header_field_is_named_by_x_forge_parameter_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "cf-r2-jurisdiction", "in": "header", "x-forge-parameter-name": "jurisdiction", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} @@ -59,7 +59,7 @@ fn header_description_is_the_params_or_else_its_schemas() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Own", "in": "header", "description": "Param.", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "X-Inherited", "in": "header", "schema": {"$ref": "#/components/schemas/Id"}}, @@ -81,7 +81,7 @@ fn deprecated_header_is_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Old", "in": "header", "deprecated": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -95,7 +95,7 @@ fn header_is_sensitive_when_its_schema_is_and_never_read_only() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Api-Key", "in": "header", "schema": {"type": "string", "x-forge-sensitive": true, "readOnly": true}}, {"name": "X-Auth-Token", "in": "header", "schema": {"$ref": "#/components/schemas/Token"}}, @@ -119,7 +119,7 @@ fn header_has_the_default_of_its_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Version", "in": "header", "schema": {"type": "string", "default": "2024-01-01"}}, {"name": "X-Retries", "in": "header", "schema": {"$ref": "#/components/schemas/Retries"}}, @@ -144,7 +144,7 @@ fn header_param_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "parameters": [{"$ref": "#/components/parameters/IdempotencyKey"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"IdempotencyKey": {"name": "Idempotency-Key", "in": "header", @@ -163,8 +163,8 @@ fn path_item_headers_belong_to_each_operation() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Account", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group-name": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -181,7 +181,7 @@ fn operation_header_replaces_the_path_item_header() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Limit", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Limit", "in": "header", "required": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -202,7 +202,7 @@ fn operation_header_replaces_the_path_item_header_ignoring_case() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "X-Request-ID", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "x-request-id", "in": "header", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -221,7 +221,7 @@ fn query_param_does_not_replace_a_header_with_its_name() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "version", "in": "header", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "version", "in": "query", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}} }} @@ -243,7 +243,7 @@ fn headers_are_in_declared_order_the_path_items_first() { {"name": "X-First", "in": "header", "schema": {"type": "string"}}, {"name": "X-Second", "in": "header", "schema": {"type": "string"}} ], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Third", "in": "header", "schema": {"type": "string"}}, {"name": "x-first", "in": "header", "schema": {"type": "string"}} @@ -264,7 +264,7 @@ fn headers_with_equal_names_are_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Rate-Limit", "in": "header", "schema": {"type": "string"}}, {"name": "X_Rate_Limit", "in": "header", "schema": {"type": "string"}} @@ -289,7 +289,7 @@ fn path_item_headers_differing_in_case_are_an_error() { {"name": "X-A", "in": "header", "schema": {"type": "string"}}, {"name": "x-a", "in": "header", "schema": {"type": "string"}} ], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} }} }"#, @@ -303,7 +303,7 @@ fn header_and_param_with_equal_names_are_not_an_error() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{account_id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{account_id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "account_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "Account-Id", "in": "header", "schema": {"type": "string"}} @@ -320,7 +320,7 @@ fn cookie_params_are_not_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "session", "in": "cookie", "schema": {"type": "string"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} @@ -337,7 +337,7 @@ fn method_with_only_cookie_params_has_no_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "session", "in": "cookie", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -351,7 +351,7 @@ fn accept_content_type_and_authorization_headers_are_kept() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "upload", + "paths": {"/a": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "upload", "parameters": [ {"name": "Content-Type", "in": "header", "required": true, "schema": {"type": "string"}}, {"name": "Content-Length", "in": "header", "schema": {"type": "integer"}}, @@ -376,7 +376,7 @@ fn method_without_header_params_has_no_headers() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -391,7 +391,7 @@ fn headers_are_not_in_the_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "parameters": [ {"name": "page", "in": "query", "schema": {"type": "integer"}}, {"name": "X-Trace", "in": "header", "schema": {"type": "string"}} @@ -411,7 +411,7 @@ fn method_with_only_headers_has_no_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Trace", "in": "header", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -427,7 +427,7 @@ fn model_used_only_by_a_header_is_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a", "b"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a", "b"], "x-forge-method-name": "get", "parameters": [{"name": "cf-r2-storage-class", "in": "header", "schema": {"$ref": "#/components/schemas/StorageClass"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": {"StorageClass": {"type": "string", "enum": ["Standard", "InfrequentAccess"]}}} @@ -446,7 +446,7 @@ fn header_with_content_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Filter", "in": "header", "content": {"application/json": {"schema": { "type": "object", "properties": {"status": {"type": "string"}} }}}}], @@ -465,7 +465,7 @@ fn header_style_other_than_simple_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Ids", "in": "header", "style": "form", "schema": {"type": "array", "items": {"type": "string"}}}], "responses": {"204": {"description": "ok"}}}}} diff --git a/tests/parse/methods.rs b/tests/parse/methods.rs index c03f128e5..029470219 100644 --- a/tests/parse/methods.rs +++ b/tests/parse/methods.rs @@ -9,7 +9,7 @@ fn operation_with(fields: &str) -> String { r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, "paths": {{"/a": {{"get": {{{fields} - "x-forge-group": ["a"], "x-forge-method-name": "get", + "x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# ) @@ -21,14 +21,14 @@ fn each_operation_field_is_its_http_method() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "put": {"x-forge-group": ["a"], "x-forge-method-name": "put", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method-name": "post", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}, - "options": {"x-forge-group": ["a"], "x-forge-method-name": "options", "responses": {"204": {"description": "ok"}}}, - "head": {"x-forge-group": ["a"], "x-forge-method-name": "head", "responses": {"204": {"description": "ok"}}}, - "patch": {"x-forge-group": ["a"], "x-forge-method-name": "patch", "responses": {"204": {"description": "ok"}}}, - "trace": {"x-forge-group": ["a"], "x-forge-method-name": "trace", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "put": {"x-forge-group-name": ["a"], "x-forge-method-name": "put", "responses": {"204": {"description": "ok"}}}, + "post": {"x-forge-group-name": ["a"], "x-forge-method-name": "post", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group-name": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}, + "options": {"x-forge-group-name": ["a"], "x-forge-method-name": "options", "responses": {"204": {"description": "ok"}}}, + "head": {"x-forge-group-name": ["a"], "x-forge-method-name": "head", "responses": {"204": {"description": "ok"}}}, + "patch": {"x-forge-group-name": ["a"], "x-forge-method-name": "patch", "responses": {"204": {"description": "ok"}}}, + "trace": {"x-forge-group-name": ["a"], "x-forge-method-name": "trace", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -54,7 +54,7 @@ fn query_operation_is_query() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"query": {"x-forge-group": ["a"], "x-forge-method-name": "search", + "paths": {"/a": {"query": {"x-forge-group-name": ["a"], "x-forge-method-name": "search", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -68,7 +68,7 @@ fn additional_operation_is_its_method_as_written() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "COPY": {"x-forge-group": ["a"], "x-forge-method-name": "copy", + "COPY": {"x-forge-group-name": ["a"], "x-forge-method-name": "copy", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -86,7 +86,7 @@ fn additional_operation_with_the_method_of_a_field_is_that_variant() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "GET": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "GET": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -101,7 +101,7 @@ fn additional_operation_methods_are_case_sensitive() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"additionalOperations": { - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} }}} }"#, @@ -118,7 +118,7 @@ fn method_has_the_summary_description_and_deprecation_of_its_operation() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "summary": "Get an a.", "description": "Gets an a.", "deprecated": true, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -135,7 +135,7 @@ fn method_without_docs_is_empty_and_not_deprecated() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -153,7 +153,7 @@ fn path_item_ref_is_followed() { "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": {"$ref": "#/components/pathItems/A"}}, "components": {"pathItems": { - "A": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "A": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}} }} }"##, @@ -168,11 +168,11 @@ fn extensions_in_paths_and_path_items_are_not_operations() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "x-paths-extension": {"get": {"x-forge-group": ["x"], "x-forge-method-name": "get", + "x-paths-extension": {"get": {"x-forge-group-name": ["x"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}, "/a": { "x-forge-commands": {"a": {"description": "A."}}, - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}} } } @@ -189,9 +189,9 @@ fn additional_operation_with_the_method_of_a_present_field_is_skipped() { r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "additionalOperations": {"GET": {"x-forge-group": ["a"], "x-forge-method-name": "shadowed", + "additionalOperations": {"GET": {"x-forge-group-name": ["a"], "x-forge-method-name": "shadowed", "responses": {"204": {"description": "ok"}}}} }} }"#, @@ -206,7 +206,7 @@ fn webhooks_are_not_methods() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "webhooks": {"newPet": {"post": {"x-forge-group": ["pets"], "x-forge-method-name": "created", + "webhooks": {"newPet": {"post": {"x-forge-group-name": ["pets"], "x-forge-method-name": "created", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -219,9 +219,9 @@ fn callbacks_are_not_methods() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/subscribe": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "subscribe", + "paths": {"/subscribe": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "subscribe", "callbacks": {"event": {"{$request.query.url}": {"post": { - "x-forge-group": ["a"], "x-forge-method-name": "event", + "x-forge-group-name": ["a"], "x-forge-method-name": "event", "responses": {"204": {"description": "ok"}} }}}}, "responses": {"204": {"description": "ok"}}}}} @@ -331,13 +331,13 @@ fn availability_and_deprecation_are_apart() { r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "deprecated": true, "x-forge-availability": "generally-available", "responses": {"204": {"description": "ok"}}}, - "put": {"x-forge-group": ["a"], "x-forge-method-name": "put", + "put": {"x-forge-group-name": ["a"], "x-forge-method-name": "put", "x-forge-availability": "deprecated", "responses": {"204": {"description": "ok"}}}, - "post": {"x-forge-group": ["a"], "x-forge-method-name": "post", + "post": {"x-forge-group-name": ["a"], "x-forge-method-name": "post", "deprecated": true, "responses": {"204": {"description": "ok"}}} }} }"#, @@ -359,7 +359,7 @@ fn x_forge_method_without_name_is_not_a_method_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); diff --git a/tests/parse/models.rs b/tests/parse/models.rs index dcb7af171..f4bfe3b36 100644 --- a/tests/parse/models.rs +++ b/tests/parse/models.rs @@ -13,7 +13,7 @@ fn response_model_is_placed_in_its_group() { "paths": { "/zones": { "get": { - "x-forge-group": ["zones"], + "x-forge-group-name": ["zones"], "x-forge-method-name": "list", "responses": { "200": { @@ -43,9 +43,9 @@ fn model_used_in_sibling_groups_is_in_their_parent() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get", + "/c": {"get": {"x-forge-group-name": ["a", "b", "c"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/d": {"get": {"x-forge-group": ["a", "b", "d"], "x-forge-method-name": "get", + "/d": {"get": {"x-forge-group-name": ["a", "b", "d"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -61,9 +61,9 @@ fn model_used_in_a_group_and_its_subgroup_is_in_the_group() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/c": {"get": {"x-forge-group": ["a", "b", "c"], "x-forge-method-name": "get", + "/c": {"get": {"x-forge-group-name": ["a", "b", "c"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -79,9 +79,9 @@ fn model_used_in_top_level_groups_is_at_the_top_level() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/x": {"get": {"x-forge-group": ["x"], "x-forge-method-name": "get", + "/x": {"get": {"x-forge-group-name": ["x"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}} }, "components": {"schemas": {"M": {"type": "object", "properties": {"id": {"type": "string"}}}}} @@ -99,9 +99,9 @@ fn model_used_through_another_model_is_placed_by_every_use() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/b": {"get": {"x-forge-group": ["a", "b"], "x-forge-method-name": "get", + "/b": {"get": {"x-forge-group-name": ["a", "b"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Outer"}}}}}}}, - "/c": {"get": {"x-forge-group": ["a", "c"], "x-forge-method-name": "get", + "/c": {"get": {"x-forge-group-name": ["a", "c"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Inner"}}}}}}} }, "components": {"schemas": { @@ -120,7 +120,7 @@ fn params_bodies_and_errors_use_models() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "parameters": [{"name": "filter", "in": "query", "schema": {"$ref": "#/components/schemas/Filter"}}], "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Input"}}}}, "responses": {"400": {"description": "no", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Failure"}}}}}}}}, @@ -144,16 +144,16 @@ fn schema_no_method_uses_is_not_a_model() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Used"}}}}}}}, - "/ignored": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "ignored", "x-forge-ignore": true, - "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ignored"}}}}}}}, + "/skipped": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "skipped", "x-forge-skip": true, + "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Skipped"}}}}}}}, "/ungrouped": {"get": {"x-forge-method-name": "ungrouped", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ungrouped"}}}}}}} }, "components": {"schemas": { "Used": {"type": "string"}, - "Ignored": {"type": "string"}, + "Skipped": {"type": "string"}, "Ungrouped": {"type": "string"}, "Unused": {"type": "string"} }} @@ -224,7 +224,7 @@ fn schema_in_defs_is_a_model() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Tree/$defs/Node"}}}}}}}}, "components": {"schemas": { "Tree": {"type": "object", "$defs": {"Node": {"type": "string"}}} @@ -256,7 +256,7 @@ fn schema_used_only_by_content_that_is_not_json_is_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a", "files"], "x-forge-method-name": "upload", + "paths": {"/a": {"post": {"x-forge-group-name": ["a", "files"], "x-forge-method-name": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": {"$ref": "#/components/schemas/Upload"}}}}, "responses": {"200": {"description": "ok", "content": {"text/csv": {"schema": {"$ref": "#/components/schemas/Report"}}}}}}}}, "components": {"schemas": { @@ -287,9 +287,9 @@ fn use_by_content_that_is_not_json_places_a_model() { r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": { - "/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/M"}}}}}}}, - "/b": {"post": {"x-forge-group": ["b"], "x-forge-method-name": "upload", + "/b": {"post": {"x-forge-group-name": ["b"], "x-forge-method-name": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"meta": {"$ref": "#/components/schemas/M"}} }}}}, @@ -307,7 +307,7 @@ fn schema_used_only_in_a_response_header_is_not_a_model() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "X-Trace", "in": "header", "schema": {"$ref": "#/components/schemas/Trace"}}], "responses": {"204": {"description": "ok", "headers": {"X-Rate-Limit": {"schema": {"$ref": "#/components/schemas/RateLimit"}}}}}}}}, diff --git a/tests/parse/requests.rs b/tests/parse/requests.rs index e87904898..b0e9eaaae 100644 --- a/tests/parse/requests.rs +++ b/tests/parse/requests.rs @@ -13,7 +13,7 @@ fn path_param_is_a_required_request_field() { "paths": { "/zones/{zone_id}": { "get": { - "x-forge-group": ["zones"], + "x-forge-group-name": ["zones"], "x-forge-method-name": "get", "parameters": [ { "name": "zone_id", "in": "path", "required": true, "schema": { "type": "string" } } @@ -44,7 +44,7 @@ fn query_param_is_optional_and_exploded_by_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -61,7 +61,7 @@ fn query_param_can_be_required() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "required": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -76,7 +76,7 @@ fn query_param_with_explode_false_is_not_exploded() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "ids", "in": "query", "style": "form", "explode": false, "schema": {"type": "array", "items": {"type": "string"}}}], "responses": {"204": {"description": "ok"}}}}} @@ -93,7 +93,7 @@ fn header_and_cookie_params_are_not_fields() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "X-Trace", "in": "header", "schema": {"type": "string"}}, {"name": "session", "in": "cookie", "schema": {"type": "string"}} @@ -111,7 +111,7 @@ fn param_field_is_named_by_x_forge_parameter_name() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "q", "in": "query", "x-forge-parameter-name": "query", "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -126,7 +126,7 @@ fn param_description_falls_back_to_an_inline_schema() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "own", "in": "query", "description": "Param.", "schema": {"type": "string", "description": "Schema."}}, {"name": "inherited", "in": "query", "schema": {"type": "string", "description": "Schema."}} @@ -145,7 +145,7 @@ fn param_description_comes_from_a_ref_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "own", "in": "query", "description": "Param.", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id"}} @@ -165,7 +165,7 @@ fn param_description_follows_a_chain_of_refs() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"$ref": "#/components/schemas/Id"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": { @@ -184,7 +184,7 @@ fn param_description_is_never_a_schema_title() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id"}}, {"name": "inline", "in": "query", "schema": {"type": "string", "title": "Inline"}} @@ -204,7 +204,7 @@ fn description_next_to_a_param_schema_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "id", "in": "query", "schema": {"$ref": "#/components/schemas/Id", "description": "The ID to find."}}], "responses": {"204": {"description": "ok"}}}}}, @@ -221,7 +221,7 @@ fn param_description_comes_from_an_all_of_member_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "region", "in": "query", "schema": {"allOf": [{"$ref": "#/components/schemas/Region"}, {"default": "us"}]}}], "responses": {"204": {"description": "ok"}}}}}, @@ -238,7 +238,7 @@ fn param_description_from_an_all_of_member_is_ignored_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "region", "in": "query", "schema": {"allOf": [{"$ref": "#/components/schemas/Region"}, {"default": "us"}]}}], "responses": {"204": {"description": "ok"}}}}}, @@ -255,7 +255,7 @@ fn param_ref_description_overrides_the_params_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page", "description": "The page of pets."}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -272,7 +272,7 @@ fn param_ref_description_is_ignored_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page", "description": "The page of pets."}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -289,7 +289,7 @@ fn param_ref_without_a_description_has_the_params() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "description": "A page.", @@ -306,7 +306,7 @@ fn param_field_is_never_read_only() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "id", "in": "path", "required": true, "schema": {"type": "string", "readOnly": true}}, {"name": "since", "in": "query", "schema": {"$ref": "#/components/schemas/Since", "readOnly": true}}, @@ -331,7 +331,7 @@ fn query_string_property_is_never_read_only() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": { "type": "object", "properties": {"status": {"type": "string", "readOnly": true, "x-forge-sensitive": true}} }}}}], @@ -349,7 +349,7 @@ fn param_field_is_sensitive_when_its_schema_is() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "token", "in": "query", "schema": {"type": "string", "x-forge-sensitive": true}}, {"name": "page", "in": "query", "schema": {"type": "integer"}} @@ -368,7 +368,7 @@ fn param_field_is_sensitive_when_its_ref_schema_is() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "token", "in": "query", "schema": {"$ref": "#/components/schemas/Token"}}], "responses": {"204": {"description": "ok"}}}}}, "components": {"schemas": { @@ -386,7 +386,7 @@ fn sensitive_next_to_a_param_schema_ref_counts_in_3_0() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "token", "in": "query", "schema": {"$ref": "#/components/schemas/Token", "x-forge-sensitive": true}}], "responses": {"204": {"description": "ok"}}}}}, @@ -402,7 +402,7 @@ fn sensitive_on_the_param_itself_is_ignored() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "token", "in": "query", "x-forge-sensitive": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -416,7 +416,7 @@ fn param_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"$ref": "#/components/parameters/Page"}], "responses": {"204": {"description": "ok"}}}}}, "components": {"parameters": {"Page": {"name": "page", "in": "query", "schema": {"type": "integer"}}}} @@ -435,8 +435,8 @@ fn path_item_params_belong_to_each_operation() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group-name": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -455,7 +455,7 @@ fn operation_param_replaces_the_path_item_param() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "page", "in": "query", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}} }} @@ -472,7 +472,7 @@ fn undeclared_path_placeholder_is_a_required_string() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -491,7 +491,7 @@ fn params_are_in_path_template_then_declared_order() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{second}/{first}": { "parameters": [{"name": "item_query", "in": "query", "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "op_query", "in": "query", "schema": {"type": "string"}}, {"name": "first", "in": "path", "required": true, "schema": {"type": "string"}}, @@ -511,7 +511,7 @@ fn query_string_object_is_query_fields() { let forge = parse( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": { "type": "object", "properties": {"status": {"type": "string"}, "limit": {"type": "integer"}} }}}}], @@ -532,7 +532,7 @@ fn no_params_and_no_body_is_no_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -545,7 +545,7 @@ fn body_without_params_is_the_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}}} }"#, @@ -559,7 +559,7 @@ fn object_body_is_intersected_with_the_params() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "properties": {"name": {"type": "string"}} @@ -582,7 +582,7 @@ fn model_body_is_intersected_with_the_params() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, "responses": {"204": {"description": "ok"}}}}}, @@ -604,7 +604,7 @@ fn union_body_is_intersected_with_the_params() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "oneOf": [{"$ref": "#/components/schemas/Cat"}, {"$ref": "#/components/schemas/Dog"}] @@ -631,7 +631,7 @@ fn array_body_is_the_last_field_of_the_params() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -651,7 +651,7 @@ fn body_field_is_neither_read_only_nor_sensitive() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "readOnly": true, "x-forge-sensitive": true @@ -670,7 +670,7 @@ fn read_only_field_of_a_body_model_is_kept() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}}}}}, "components": {"schemas": {"Pet": {"type": "object", "properties": { @@ -690,7 +690,7 @@ fn map_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "additionalProperties": {"type": "string"} @@ -708,7 +708,7 @@ fn unknown_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {}}}}, "responses": {"204": {"description": "ok"}}}}} @@ -724,7 +724,7 @@ fn nullable_body_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "nullable": true, "properties": {"name": {"type": "string"}} @@ -742,7 +742,7 @@ fn body_with_the_name_of_a_param_is_a_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{zone_id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{zone_id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "zone_id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "type": "object", "properties": {"zoneId": {"type": "string"}, "name": {"type": "string"}} @@ -762,8 +762,8 @@ fn field_of_another_method_has_no_location() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, - "delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"204": {"description": "ok"}}}, + "delete": {"x-forge-group-name": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}} }} }"#, ); @@ -779,7 +779,7 @@ fn body_that_is_not_json_is_an_unknown_body_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "upload", + "paths": {"/a/{id}": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "upload", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"file": {"type": "string", "format": "binary"}} @@ -798,7 +798,7 @@ fn body_that_is_only_multipart_is_an_unknown_request() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "upload", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "upload", "requestBody": {"content": {"multipart/form-data": {"schema": { "type": "object", "properties": {"file": {"type": "string", "format": "binary"}} }}}}, @@ -816,7 +816,7 @@ fn path_param_missing_from_the_template_is_dropped() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "account_id", "in": "path", "required": true, "schema": {"type": "string"}} @@ -833,7 +833,7 @@ fn deprecated_query_param_is_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "page", "in": "query", "deprecated": true, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -847,7 +847,7 @@ fn deprecated_path_param_is_not_a_deprecated_field() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{"name": "id", "in": "path", "required": true, "deprecated": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -861,7 +861,7 @@ fn all_of_body_is_one_member_of_the_intersection() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}] @@ -888,7 +888,7 @@ fn param_with_content_is_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "query", "content": {"application/json": {"schema": { "type": "object", "properties": {"status": {"type": "string"}} }}}}], @@ -912,7 +912,7 @@ fn query_style_other_than_form_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {{"/a": {{"get": {{"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{{"name": "filter", "in": "query", "style": "{style}", "schema": {schema}}}], "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# @@ -927,7 +927,7 @@ fn two_query_string_params_are_an_error() { let err = parse_err( r#"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "one", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}}, {"name": "two", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}} @@ -946,7 +946,7 @@ fn query_and_query_string_params_are_an_error() { "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, "paths": {"/a": { "parameters": [{"name": "page", "in": "query", "schema": {"type": "integer"}}], - "get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "filter", "in": "querystring", "content": {"application/x-www-form-urlencoded": {"schema": {"type": "object"}}}}], "responses": {"204": {"description": "ok"}}} }} @@ -963,10 +963,10 @@ fn body_field_is_required_when_the_body_is() { "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, "paths": {"/a/{id}": { "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], - "put": {"x-forge-group": ["a"], "x-forge-method-name": "replace", + "put": {"x-forge-group-name": ["a"], "x-forge-method-name": "replace", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}}, - "patch": {"x-forge-group": ["a"], "x-forge-method-name": "append", + "patch": {"x-forge-group-name": ["a"], "x-forge-method-name": "append", "requestBody": {"content": {"application/json": {"schema": {"type": "array", "items": {"type": "string"}}}}}, "responses": {"204": {"description": "ok"}}} }} @@ -983,7 +983,7 @@ fn params_with_equal_names_are_an_error() { let err = parse_err( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{zone_id}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a/{zone_id}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [ {"name": "zone_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "zoneId", "in": "query", "schema": {"type": "string"}} @@ -1001,7 +1001,7 @@ fn path_style_other_than_simple_is_an_error() { let err = parse_err(&format!( r#"{{ "openapi": "3.0.3", "info": {{"title": "t", "version": "1"}}, - "paths": {{"/a/{{id}}": {{"get": {{"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {{"/a/{{id}}": {{"get": {{"x-forge-group-name": ["a"], "x-forge-method-name": "get", "parameters": [{{"name": "id", "in": "path", "required": true, "style": "{style}", "schema": {{"type": "string"}}}}], "responses": {{"204": {{"description": "ok"}}}}}}}}}} }}"# @@ -1016,7 +1016,7 @@ fn param_field_has_the_default_of_its_schema() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "per_page", "in": "query", "schema": {"type": "integer", "default": 20}}, {"name": "page", "in": "query", "schema": {"type": "integer"}} @@ -1035,7 +1035,7 @@ fn param_field_has_the_default_of_its_ref_schema() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{order}": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a/{order}": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [ {"name": "order", "in": "path", "required": true, "schema": {"$ref": "#/components/schemas/Order"}}, {"$ref": "#/components/parameters/Direction"} @@ -1062,7 +1062,7 @@ fn default_next_to_a_param_schema_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "per_page", "in": "query", "schema": {"$ref": "#/components/schemas/PerPage", "default": 50}}], "responses": {"204": {"description": "ok"}}}}}, @@ -1079,7 +1079,7 @@ fn default_on_the_param_itself_is_ignored() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "list", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "list", "parameters": [{"name": "per_page", "in": "query", "default": 20, "schema": {"type": "integer"}}], "responses": {"204": {"description": "ok"}}}}} }"#, @@ -1096,7 +1096,7 @@ fn body_field_and_undeclared_placeholder_have_no_default() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a/{id}": {"put": {"x-forge-group": ["a"], "x-forge-method-name": "update", + "paths": {"/a/{id}": {"put": {"x-forge-group-name": ["a"], "x-forge-method-name": "update", "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "default": ["x"] }}}}, @@ -1114,7 +1114,7 @@ fn array_body_keeps_its_max_items() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "requestBody": {"content": {"application/json": {"schema": { "type": "array", "items": {"type": "string"}, "maxItems": 100 }}}}, diff --git a/tests/parse/responses.rs b/tests/parse/responses.rs index 7ac12e940..6555d6935 100644 --- a/tests/parse/responses.rs +++ b/tests/parse/responses.rs @@ -7,7 +7,7 @@ fn responses_are_the_2xx_sorted_by_status() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"post": {"x-forge-group": ["a"], "x-forge-method-name": "create", + "paths": {"/a": {"post": {"x-forge-group-name": ["a"], "x-forge-method-name": "create", "responses": { "2XX": {"description": "ok"}, "201": {"description": "ok"}, @@ -29,7 +29,7 @@ fn errors_are_the_rest_sorted_with_default_last() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": { "default": {"description": "no"}, "500": {"description": "no"}, @@ -54,7 +54,7 @@ fn response_has_its_description() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "The pet."}}}}} }"#, ); @@ -68,7 +68,7 @@ fn response_without_content_has_none() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"delete": {"x-forge-group": ["a"], "x-forge-method-name": "delete", + "paths": {"/a": {"delete": {"x-forge-group-name": ["a"], "x-forge-method-name": "delete", "responses": {"204": {"description": "ok"}}}}} }"#, ); @@ -83,7 +83,7 @@ fn response_ref_is_followed() { let forge = parse( r##"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"4XX": {"$ref": "#/components/responses/Failure"}}}}}, "components": {"responses": { "Failure": {"description": "Failed.", "content": {"application/json": {"schema": {"type": "string"}}}} @@ -102,7 +102,7 @@ fn response_content_that_is_not_json_is_typed() { let forge = parse( r#"{ "openapi": "3.0.3", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "download", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "download", "responses": {"200": {"description": "ok", "content": { "application/octet-stream": {"schema": {"type": "string", "format": "binary"}}, "text/csv": {"schema": {"type": "string"}} diff --git a/tests/parse/types/arrays.rs b/tests/parse/types/arrays.rs index 3af14fdf8..88caa3184 100644 --- a/tests/parse/types/arrays.rs +++ b/tests/parse/types/arrays.rs @@ -92,7 +92,7 @@ fn array_without_items_has_unknown_elements() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "array" }}}}}}}} @@ -107,7 +107,7 @@ fn tuple_is_unknown() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "array", "prefixItems": [{"type": "string"}, {"type": "integer"}], "items": false }}}}}}}} diff --git a/tests/parse/types/enums.rs b/tests/parse/types/enums.rs index a1511c847..1e331ab35 100644 --- a/tests/parse/types/enums.rs +++ b/tests/parse/types/enums.rs @@ -59,7 +59,7 @@ fn const_is_an_enum_of_one_value() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "const": "a" }}}}}}}} diff --git a/tests/parse/types/intersections.rs b/tests/parse/types/intersections.rs index 26c7b8ae3..0794b2739 100644 --- a/tests/parse/types/intersections.rs +++ b/tests/parse/types/intersections.rs @@ -49,7 +49,7 @@ fn true_member_is_dropped() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}, true, {"$ref": "#/components/schemas/B"}] }}}}}}}}, @@ -141,7 +141,7 @@ fn unevaluated_properties_is_an_object_member() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "allOf": [{"$ref": "#/components/schemas/A"}], "unevaluatedProperties": {"type": "string"} diff --git a/tests/parse/types/nulls.rs b/tests/parse/types/nulls.rs index ecf06e087..79ee061b7 100644 --- a/tests/parse/types/nulls.rs +++ b/tests/parse/types/nulls.rs @@ -95,7 +95,7 @@ fn nullable_is_read_in_3_1() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "nullable": true }}}}}}}} @@ -110,7 +110,7 @@ fn null_in_a_type_array_is_a_union_with_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "null"] }}}}}}}} @@ -125,7 +125,7 @@ fn null_type_is_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "null" }}}}}}}} @@ -140,7 +140,7 @@ fn const_null_is_null() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "const": null }}}}}}}} diff --git a/tests/parse/types/objects.rs b/tests/parse/types/objects.rs index 7135a1f19..7ade16797 100644 --- a/tests/parse/types/objects.rs +++ b/tests/parse/types/objects.rs @@ -195,7 +195,7 @@ fn pattern_properties_are_ignored() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"type": "string"}}, "patternProperties": {"^x-": {"type": "string"}} }}}}}}}} @@ -212,7 +212,7 @@ fn false_property_is_no_field() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"type": "string"}, "gone": false} }}}}}}}} @@ -223,9 +223,9 @@ fn false_property_is_no_field() { } #[test] -fn property_ignored_by_x_forge_ignore_is_no_field() { +fn property_skipped_by_x_forge_skip_is_no_field() { let forge = parse(&responding_with( - r#"{"type": "object", "properties": {"id": {"type": "string"}, "old_id": {"type": "string", "x-forge-ignore": true}}}"#, + r#"{"type": "object", "properties": {"id": {"type": "string"}, "old_id": {"type": "string", "x-forge-skip": true}}}"#, )); assert_eq!(field_names(object(response_type(&forge, "a.get"))), ["id"]); diff --git a/tests/parse/types/refs.rs b/tests/parse/types/refs.rs index c736bf622..6c6429a6d 100644 --- a/tests/parse/types/refs.rs +++ b/tests/parse/types/refs.rs @@ -65,7 +65,7 @@ fn annotations_next_to_a_ref_keep_the_model_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "description": "The zone.", "deprecated": true }}}}}}}}, @@ -81,7 +81,7 @@ fn shape_next_to_a_ref_is_intersected_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "properties": {"extra": {"type": "string"}} }}}}}}}}, @@ -97,7 +97,7 @@ fn nullable_next_to_a_ref_is_a_union_with_null_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "$ref": "#/components/schemas/Zone", "nullable": true }}}}}}}}, @@ -153,7 +153,7 @@ fn description_next_to_a_property_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"home": {"$ref": "#/components/schemas/Zone", "description": "The home zone."}} }}}}}}}}, @@ -324,7 +324,7 @@ fn read_only_next_to_a_property_ref_counts_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"$ref": "#/components/schemas/Id", "readOnly": true}} }}}}}}}}, @@ -350,7 +350,7 @@ fn read_only_false_next_to_a_ref_does_not_undo_its_schemas_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"id": {"$ref": "#/components/schemas/Id", "readOnly": false}} }}}}}}}}, @@ -386,7 +386,7 @@ fn sensitive_next_to_a_property_ref_counts_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"token": {"$ref": "#/components/schemas/Token", "x-forge-sensitive": true}} }}}}}}}}, @@ -424,7 +424,7 @@ fn property_default_is_the_first_along_a_chain_of_refs_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": {"size": {"$ref": "#/components/schemas/Size"}} }}}}}}}}, @@ -454,7 +454,7 @@ fn default_next_to_a_property_ref_is_its_own_in_3_1() { let forge = parse( r##"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": { "size": {"$ref": "#/components/schemas/Size", "default": 5}, diff --git a/tests/parse/types/scalars.rs b/tests/parse/types/scalars.rs index 65b9e455c..3ec41e305 100644 --- a/tests/parse/types/scalars.rs +++ b/tests/parse/types/scalars.rs @@ -140,7 +140,7 @@ fn base64_content_encoding_is_bytes() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "contentEncoding": "base64" }}}}}}}} @@ -155,7 +155,7 @@ fn binary_format_is_binary_even_with_base64_content_encoding() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "string", "format": "binary", "contentEncoding": "base64" }}}}}}}} @@ -198,7 +198,7 @@ fn true_schema_is_unknown() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": true}}}}}}} }"#, ); diff --git a/tests/parse/types/unions.rs b/tests/parse/types/unions.rs index f8349fe71..8f26b6e38 100644 --- a/tests/parse/types/unions.rs +++ b/tests/parse/types/unions.rs @@ -76,7 +76,7 @@ fn type_array_is_exclusive() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "integer"] }}}}}}}} @@ -138,7 +138,7 @@ fn types_in_a_type_array_are_a_union() { let forge = parse( r#"{ "openapi": "3.1.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": ["string", "integer"] }}}}}}}} @@ -329,7 +329,7 @@ fn discriminator_default_mapping_is_the_default() { let forge = parse( r##"{ "openapi": "3.2.0", "info": {"title": "t", "version": "1"}, - "paths": {"/a": {"get": {"x-forge-group": ["a"], "x-forge-method-name": "get", + "paths": {"/a": {"get": {"x-forge-group-name": ["a"], "x-forge-method-name": "get", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "oneOf": [{"$ref": "#/components/schemas/A"}, {"$ref": "#/components/schemas/B"}], "discriminator": {"propertyName": "kind", "mapping": {"a": "#/components/schemas/A"}, "defaultMapping": "#/components/schemas/B"} diff --git a/tests/wasm.rs b/tests/wasm.rs index 95b4730cd..18bedd8b9 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -41,7 +41,7 @@ const SPEC: &str = r##"{ "paths": { "/pets": { "get": { - "x-forge-group": ["pets"], "x-forge-method-name": "list", "summary": "Lists pets.", + "x-forge-group-name": ["pets"], "x-forge-method-name": "list", "summary": "Lists pets.", "parameters": [ {"name": "limit", "in": "query", "schema": {"type": "integer", "format": "int32"}}, {"name": "tags", "in": "query", "explode": false, "schema": {"type": "array", "items": {"type": "string"}}} @@ -52,14 +52,14 @@ const SPEC: &str = r##"{ } }, "post": { - "x-forge-group": ["pets"], "x-forge-method-name": "create", "deprecated": true, + "x-forge-group-name": ["pets"], "x-forge-method-name": "create", "deprecated": true, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/NewPet"}}}}, "responses": {"201": {"description": "created", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}} } }, "/pets/{pet_id}": { "get": { - "x-forge-group": ["pets"], "x-forge-method-name": "get", + "x-forge-group-name": ["pets"], "x-forge-method-name": "get", "parameters": [{"name": "pet_id", "in": "path", "required": true, "schema": {"type": "string", "format": "uuid"}}], "responses": { "200": {"description": "ok", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Pet"}}}}, @@ -69,7 +69,7 @@ const SPEC: &str = r##"{ }, "/pets/{pet_id}/photos": { "put": { - "x-forge-group": ["pets", "photos"], "x-forge-method-name": "upload", + "x-forge-group-name": ["pets", "photos"], "x-forge-method-name": "upload", "parameters": [{"name": "pet_id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/octet-stream": {"schema": {"type": "string", "format": "binary"}}}}, "responses": {"204": {"description": "done"}} @@ -77,7 +77,7 @@ const SPEC: &str = r##"{ }, "/owners": { "get": { - "x-forge-group": ["owners"], "x-forge-method-name": "list", + "x-forge-group-name": ["owners"], "x-forge-method-name": "list", "responses": {"200": {"description": "ok", "content": {"application/json": {"schema": { "type": "object", "properties": { @@ -138,7 +138,7 @@ const FEATURES: &str = r##"{ "/pets/{id}": { "parameters": [{"name": "X-Trace", "in": "header", "schema": {"type": "string"}}], "get": { - "x-forge-group": ["pets"], "x-forge-method-name": "get", + "x-forge-group-name": ["pets"], "x-forge-method-name": "get", "x-forge-availability": "beta", "x-forge-hidden": true, "x-custom": {"b": 1, "a": [1.5, "two \"quoted\"\n", null, true, {}], "b": 2}, "x-flag": false, "x-count": 9007199254740993, "x-text": "é 😀", @@ -152,9 +152,9 @@ const FEATURES: &str = r##"{ }, "delete": { "x-forge-aliases": [ - {"x-forge-group": ["pets"], "x-forge-method-name": "remove", "x-forge-availability": "deprecated", + {"x-forge-group-name": ["pets"], "x-forge-method-name": "remove", "x-forge-availability": "deprecated", "x-forge-require-confirmation": "This deletes the pet.", "x-alias": [1]}, - {"x-forge-group": ["admin", "pets"], "x-forge-method-name": "delete", "x-forge-require-confirmation": ""} + {"x-forge-group-name": ["admin", "pets"], "x-forge-method-name": "delete", "x-forge-require-confirmation": ""} ], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "gone"}} @@ -162,7 +162,7 @@ const FEATURES: &str = r##"{ }, "/pets/{id}/photo": { "put": { - "x-forge-group": ["pets", "photos"], "x-forge-method-name": "upload", + "x-forge-group-name": ["pets", "photos"], "x-forge-method-name": "upload", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"required": true, "content": { "application/octet-stream": {"schema": {"type": "string", "format": "binary", "description": "The photo."}}, From 19b3577a81cce3554b2231e256cd9a04a7716d32 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 23:22:47 -0400 Subject: [PATCH 19/21] docs: say where vendor compatibility lives, and how to add or remove it AGENTS.md gets a short section: only src/compat/ names vendor extensions, it sits behind the compat feature, native keys win, and tests/boundary.rs enforces it. src/compat/README.md holds the longer how-to, next to the code it describes and deleted along with it. --- AGENTS.md | 10 ++++++++++ src/compat/README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/compat/README.md diff --git a/AGENTS.md b/AGENTS.md index c43a3f71d..39e758679 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,6 +8,16 @@ API documentation site for Forge OpenAPI specs, built on Astro. - **`packages/fern-forge`**: `astro-fern` extension that validates and adapts Forge OpenAPI metadata. - **`packages/docs-site`**: API documentation website consuming `astro-fern` and `fern-forge`. The OpenAPI spec is fetched from the `openapi.forge.json` GitHub release asset (or a local file via `FORGE_OPENAPI_SPEC`). - **`packages/cloudflare-terraform-docs`**: Generator for the site's Terraform documentation data, derived from the released Cloudflare Terraform provider. Temporary: removed once Forge supports Terraform natively (see the site's README). +- **`src/`**: The Rust engine: OpenAPI to linked model to plugin host. It reads only native `x-forge-*` extensions (`src/metadata/`); other tools' extensions are translated in `src/compat/`. + +## Vendor compatibility + +Only `src/compat/` knows vendor extensions (`x-fern-*`, `x-stainless-*`). It is sectioned off so it can be deleted as a whole. See [`src/compat/README.md`](src/compat/README.md). + +- Never name a vendor extension outside `src/compat/` and `tests/compat/`, comments and docs included. `tests/boundary.rs` enforces this (`just boundary`). +- Compat is behind the default-on `compat` feature and is only a fallback: native `x-forge-*` keys always win. +- Support for a new vendor key means mapping it onto an existing native primitive in an adapter. Add the native key first if there is none. +- The docs packages (`astro-fern`, `fern-forge`, `cloudflare-api-site`) read vendor keys themselves and are not covered by the boundary. ## Conventions diff --git a/src/compat/README.md b/src/compat/README.md new file mode 100644 index 000000000..6ebaee086 --- /dev/null +++ b/src/compat/README.md @@ -0,0 +1,47 @@ +# The compatibility layer + +The engine understands one vocabulary: the native `x-forge-*` extensions in +[`src/metadata/`](../metadata/mod.rs). This folder is the only place that +knows any other tool's extensions (Fern's `x-fern-*`, Stainless's +`x-stainless-*`). Each adapter maps its tool's keys onto native primitives. + +The layer is meant to be deleted as a whole once nobody writes those keys. +Everything below follows from that. + +## Rules + +- **Only this folder names a vendor extension.** That includes the readers, + the linker, the plugin host, the WIT, the `packages/forge` npm package, and + their comments and docs. `tests/boundary.rs` fails, with file and line, if + one appears elsewhere (`just boundary`; it also runs with `cargo test`). + Vendor tests live in `tests/compat/`. +- **Native wins.** A vendor key is read only for a primitive the document + has no native key for. When both are written, the native value is used and + the vendor value is not even validated, whatever order they appear in. +- **Behind the `compat` feature** (on by default). Native keys must mean the + same with it off. CI compiles that configuration (clippy with + `--no-default-features`) but does not run its tests. +- **Mapping, not semantics.** An adapter says which native primitive a key + stands for and how its value is written, as data. Anything structural, such + as how aliases become methods, belongs to the builder, not here. +- **No vendor knowledge leaks out.** Keys are private to their adapter. + `mod.rs` is the only way in: one resolver per kind of object, and one name + lookup per kind so errors can name the key the author wrote. + +## Adding a vendor key + +1. Find the native primitive it stands for in `src/metadata/`. If there is + none, add a native `x-forge-*` key first: a vendor key never introduces a + primitive. +2. Map it in the adapter for its tool, or add an adapter next to `fern.rs` + and `stainless.rs` and register it in `mod.rs`. +3. Add a test in `tests/compat/` showing that the vendor-keyed document + parses to the same `Forge` as the native-keyed one. + +## Removing the layer + +Delete this folder and `tests/compat/`, `mod compat` in `src/lib.rs`, the +`compat` arms in `src/link/resolve.rs`, and the `compat` feature and its +`[[test]]` entry in `Cargo.toml`. No native extension changes. A few +native-side items exist only for the layer and are left unused; removing them +is a mechanical follow-up. From a852e335439422e63c4d3b50ed06436998c142b0 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Mon, 26 Oct 2026 23:22:47 -0400 Subject: [PATCH 20/21] refactor: group extension keys by the level they apply to Each level (operation or alias, parameter, schema, document) now has its own module holding its key constants, its table of names and its reader, in the native vocabulary and in each adapter. A key constant is no longer in scope at a level it does not belong to. Tests check that every key is read at exactly the levels that list it. Also drop the key tables from the adapters' module docs: the code is the source of truth for the keys. --- src/compat/fern.rs | 167 +++++++++++++++------------- src/compat/mod.rs | 66 ++++++++---- src/compat/stainless.rs | 43 ++++---- src/link/resolve.rs | 16 +-- src/metadata/mod.rs | 234 ++++++++++++++++++++++++---------------- 5 files changed, 315 insertions(+), 211 deletions(-) diff --git a/src/compat/fern.rs b/src/compat/fern.rs index 1fbf2fcab..771c76f45 100644 --- a/src/compat/fern.rs +++ b/src/compat/fern.rs @@ -1,15 +1,5 @@ //! The adapter for Fern's `x-fern-*` extensions. //! -//! | Key | Says | Format | -//! |---|---|---| -//! | `x-fern-sdk-method-name` | the name of the method | a string | -//! | `x-fern-sdk-group-name` | the group path of the method | as `x-forge-group-name`: an array of group names, or one string of them separated by dots | -//! | `x-fern-ignore` | the definition makes no method | a boolean | -//! | `x-fern-availability` | the stage of the API | a string, one of the native spellings | -//! | `x-fern-parameter-name` | the name of a parameter's field | a string | -//! | `x-fern-property-name` | the name of a property's field | a string | -//! | `x-fern-type-name` | the name of a model | a string | -//! //! A group path written as one string is split on dots, as for //! `x-forge-group-name`, which Fern itself does not do: Fern reads a string as a //! single group. A document written for Fern uses the array, which means the @@ -18,103 +8,136 @@ //! Its other extensions, such as `x-fern-enum` and `x-fern-audiences`, are //! not read: they say things forge has no primitive for. -use crate::metadata::{BoolFormat, DefinitionField, Hit, ParameterField, SchemaField}; - /// What every key of the adapter begins with. A key without it is turned /// away before it is matched against the table. const PREFIX: &str = "x-fern-"; -const METHOD_NAME: &str = "x-fern-sdk-method-name"; -const GROUP_NAME: &str = "x-fern-sdk-group-name"; -const IGNORE: &str = "x-fern-ignore"; -const AVAILABILITY: &str = "x-fern-availability"; -const PARAMETER_NAME: &str = "x-fern-parameter-name"; -const PROPERTY_NAME: &str = "x-fern-property-name"; -const TYPE_NAME: &str = "x-fern-type-name"; - -/// The names of the adapter's keys of an operation or an alias, by slot. -pub(super) const DEFINITION_NAMES: [&str; 4] = [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY]; -/// The names of the adapter's keys of a Parameter Object, by slot. -pub(super) const PARAMETER_NAMES: [&str; 1] = [PARAMETER_NAME]; -/// The names of the adapter's keys of a Schema Object, by slot. -pub(super) const SCHEMA_NAMES: [&str; 2] = [TYPE_NAME, PROPERTY_NAME]; - -pub(super) fn definition(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; + +/// The keys of an operation or an alias. +pub(super) mod definition { + use super::PREFIX; + use crate::metadata::{BoolFormat, DefinitionField, Hit}; + + const METHOD_NAME: &str = "x-fern-sdk-method-name"; + const GROUP_NAME: &str = "x-fern-sdk-group-name"; + const IGNORE: &str = "x-fern-ignore"; + const AVAILABILITY: &str = "x-fern-availability"; + + /// The names of the adapter's keys of an operation or an alias, by slot. + pub(crate) const NAMES: [&str; 4] = [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY]; + + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + METHOD_NAME => Hit::compat(DefinitionField::Method, 0), + GROUP_NAME => Hit::compat(DefinitionField::Group, 1), + IGNORE => Hit::compat(DefinitionField::Skip(BoolFormat::Bool), 2), + AVAILABILITY => Hit::compat(DefinitionField::Availability, 3), + _ => return None, + }) } - Some(match key { - METHOD_NAME => Hit::compat(DefinitionField::Method, 0), - GROUP_NAME => Hit::compat(DefinitionField::Group, 1), - IGNORE => Hit::compat(DefinitionField::Skip(BoolFormat::Bool), 2), - AVAILABILITY => Hit::compat(DefinitionField::Availability, 3), - _ => return None, - }) } -pub(super) fn parameter(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; +/// The keys of a Parameter Object. +pub(super) mod parameter { + use super::PREFIX; + use crate::metadata::{Hit, ParameterField}; + + const NAME: &str = "x-fern-parameter-name"; + + /// The names of the adapter's keys of a Parameter Object, by slot. + pub(crate) const NAMES: [&str; 1] = [NAME]; + + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + NAME => Hit::compat(ParameterField::Name, 0), + _ => return None, + }) } - Some(match key { - PARAMETER_NAME => Hit::compat(ParameterField::Name, 0), - _ => return None, - }) } -pub(super) fn schema(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; +/// The keys of a Schema Object. +pub(super) mod schema { + use super::PREFIX; + use crate::metadata::{Hit, SchemaField}; + + const TYPE_NAME: &str = "x-fern-type-name"; + const PROPERTY_NAME: &str = "x-fern-property-name"; + + /// The names of the adapter's keys of a Schema Object, by slot. + pub(crate) const NAMES: [&str; 2] = [TYPE_NAME, PROPERTY_NAME]; + + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + TYPE_NAME => Hit::compat(SchemaField::ModelName, 0), + PROPERTY_NAME => Hit::compat(SchemaField::PropertyName, 1), + _ => return None, + }) } - Some(match key { - TYPE_NAME => Hit::compat(SchemaField::ModelName, 0), - PROPERTY_NAME => Hit::compat(SchemaField::PropertyName, 1), - _ => return None, - }) } #[cfg(test)] mod tests { use super::*; - use crate::metadata::Tier; + + /// The names of the keys of a level, and whether the level reads a key. + type Level<'a> = (&'a [&'a str], fn(&str) -> bool); + use crate::metadata::{DefinitionField, Tier}; #[test] fn each_key_is_read_as_itself_and_as_not_native() { - for key in [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY] { - let hit = definition(key).unwrap_or_else(|| panic!("{key} is not a definition key")); + for key in definition::NAMES { + let hit = definition::read(key).unwrap_or_else(|| panic!("{key} is not a definition key")); + assert_eq!(hit.tier, Tier::Compat, "{key}"); + } + for key in parameter::NAMES { + let hit = parameter::read(key).unwrap_or_else(|| panic!("{key} is not a parameter key")); assert_eq!(hit.tier, Tier::Compat, "{key}"); } - let hit = parameter(PARAMETER_NAME).unwrap(); - assert_eq!(hit.tier, Tier::Compat, "{PARAMETER_NAME}"); - for key in [TYPE_NAME, PROPERTY_NAME] { - let hit = schema(key).unwrap_or_else(|| panic!("{key} is not a schema key")); + for key in schema::NAMES { + let hit = schema::read(key).unwrap_or_else(|| panic!("{key} is not a schema key")); assert_eq!(hit.tier, Tier::Compat, "{key}"); } } #[test] - fn a_key_is_read_only_where_it_says_something() { - assert!(definition(PARAMETER_NAME).is_none()); - assert!(definition(PROPERTY_NAME).is_none()); - assert!(parameter(METHOD_NAME).is_none()); - assert!(schema(IGNORE).is_none()); - assert!(schema(METHOD_NAME).is_none()); + fn a_key_is_read_only_at_its_level() { + let levels: [Level; 3] = [ + (&definition::NAMES, |key| definition::read(key).is_some()), + (¶meter::NAMES, |key| parameter::read(key).is_some()), + (&schema::NAMES, |key| schema::read(key).is_some()), + ]; + for (own, _) in levels { + for &key in own { + for (names, reads) in levels { + assert_eq!(reads(key), names.contains(&key), "{key}"); + } + } + } } #[test] fn slots_are_unique_among_the_keys_of_an_object() { - let mut slots: Vec = [METHOD_NAME, GROUP_NAME, IGNORE, AVAILABILITY] + let mut slots: Vec = definition::NAMES .iter() - .map(|key| definition(key).unwrap().slot) + .map(|key| definition::read(key).unwrap().slot) .collect(); slots.sort_unstable(); slots.dedup(); - assert_eq!(slots.len(), 4); + assert_eq!(slots.len(), definition::NAMES.len()); assert!(slots.iter().all(|&slot| slot >= 32), "slots of other keys start at 32"); } #[test] fn the_group_is_read_as_the_native_group() { - let hit = definition(GROUP_NAME).unwrap(); + let hit = definition::read("x-fern-sdk-group-name").unwrap(); assert!(matches!(hit.field, DefinitionField::Group)); } @@ -126,9 +149,9 @@ mod tests { "x-fern-pagination", "x-fern-sdk-variables", ] { - assert!(definition(key).is_none(), "{key}"); - assert!(parameter(key).is_none(), "{key}"); - assert!(schema(key).is_none(), "{key}"); + assert!(definition::read(key).is_none(), "{key}"); + assert!(parameter::read(key).is_none(), "{key}"); + assert!(schema::read(key).is_none(), "{key}"); } } } diff --git a/src/compat/mod.rs b/src/compat/mod.rs index f4b590ee4..46c87e2f8 100644 --- a/src/compat/mod.rs +++ b/src/compat/mod.rs @@ -21,49 +21,52 @@ use crate::metadata::{DefinitionField, Hit, ParameterField, SchemaField}; /// Returns what `key` says on an operation or an alias, if an adapter reads /// it there. pub(crate) fn definition(key: &str) -> Option> { - fern::definition(key) + fern::definition::read(key) } /// Returns what `key` says on a Parameter Object, if an adapter reads it /// there. pub(crate) fn parameter(key: &str) -> Option> { - fern::parameter(key) + fern::parameter::read(key) } /// Returns what `key` says on a Schema Object, if an adapter reads it there. /// Each adapter counts its keys from zero, so Stainless's come after Fern's. pub(crate) fn schema(key: &str) -> Option> { - fern::schema(key).or_else(|| stainless::schema(key).map(|hit| hit.after(FERN_SCHEMA_KEYS))) + fern::schema::read(key).or_else(|| stainless::schema::read(key).map(|hit| hit.after(FERN_SCHEMA_KEYS))) } /// How many keys of a Schema Object Fern has, which is where Stainless's /// start. -const FERN_SCHEMA_KEYS: u8 = fern::SCHEMA_NAMES.len() as u8; +const FERN_SCHEMA_KEYS: u8 = fern::schema::NAMES.len() as u8; /// Returns the name of the key of an operation or an alias that is `n`th /// among the keys of the adapters. pub(crate) fn definition_name(n: u8) -> &'static str { - fern::DEFINITION_NAMES[usize::from(n)] + fern::definition::NAMES[usize::from(n)] } /// Returns the name of the key of a Parameter Object that is `n`th among the /// keys of the adapters. pub(crate) fn parameter_name(n: u8) -> &'static str { - fern::PARAMETER_NAMES[usize::from(n)] + fern::parameter::NAMES[usize::from(n)] } /// Returns the name of the key of a Schema Object that is `n`th among the /// keys of the adapters. pub(crate) fn schema_name(n: u8) -> &'static str { match n.checked_sub(FERN_SCHEMA_KEYS) { - None => fern::SCHEMA_NAMES[usize::from(n)], - Some(n) => stainless::SCHEMA_NAMES[usize::from(n)], + None => fern::schema::NAMES[usize::from(n)], + Some(n) => stainless::schema::NAMES[usize::from(n)], } } #[cfg(test)] mod tests { use super::*; + + /// The names of the keys of a level, and whether the level reads a key. + type Level<'a> = (&'a [&'a str], fn(&str) -> bool); use crate::metadata::{self, COMPAT_SLOTS, Tier}; /// Asserts that each key in `names` is read by `read` as a key that is @@ -79,10 +82,29 @@ mod tests { #[test] fn each_key_of_each_adapter_is_named_by_its_slot() { - read_as_itself(&fern::DEFINITION_NAMES, definition, definition_name); - read_as_itself(&fern::PARAMETER_NAMES, parameter, parameter_name); - read_as_itself(&fern::SCHEMA_NAMES, schema, schema_name); - read_as_itself(&stainless::SCHEMA_NAMES, schema, schema_name); + read_as_itself(&fern::definition::NAMES, definition, definition_name); + read_as_itself(&fern::parameter::NAMES, parameter, parameter_name); + read_as_itself(&fern::schema::NAMES, schema, schema_name); + read_as_itself(&stainless::schema::NAMES, schema, schema_name); + } + + #[test] + fn a_key_of_an_adapter_is_read_only_at_its_level() { + let definitions = fern::definition::NAMES.to_vec(); + let parameters = fern::parameter::NAMES.to_vec(); + let schemas = [&fern::schema::NAMES[..], &stainless::schema::NAMES[..]].concat(); + let levels: [Level; 3] = [ + (&definitions, |key| definition(key).is_some()), + (¶meters, |key| parameter(key).is_some()), + (&schemas, |key| schema(key).is_some()), + ]; + for (own, _) in levels { + for &key in own { + for (names, reads) in levels { + assert_eq!(reads(key), names.contains(&key), "{key}"); + } + } + } } #[test] @@ -95,25 +117,27 @@ mod tests { .copied() .collect() }; - let definitions = keys(&metadata::DEFINITION_NAMES, &[&fern::DEFINITION_NAMES]); - let parameters = keys(&metadata::PARAMETER_NAMES, &[&fern::PARAMETER_NAMES]); + let definitions = keys(&metadata::definition::NAMES, &[&fern::definition::NAMES]); + let parameters = keys(&metadata::parameter::NAMES, &[&fern::parameter::NAMES]); let schemas = keys( - &metadata::SCHEMA_NAMES, - &[&fern::SCHEMA_NAMES, &stainless::SCHEMA_NAMES], + &metadata::schema::NAMES, + &[&fern::schema::NAMES, &stainless::schema::NAMES], ); metadata::assert_one_key_per_tier(&definitions, |key| { - metadata::definition(key).or_else(|| definition(key)) + metadata::definition::read(key).or_else(|| definition(key)) + }); + metadata::assert_one_key_per_tier(¶meters, |key| { + metadata::parameter::read(key).or_else(|| parameter(key)) }); - metadata::assert_one_key_per_tier(¶meters, |key| metadata::parameter(key).or_else(|| parameter(key))); - metadata::assert_one_key_per_tier(&schemas, |key| metadata::schema(key).or_else(|| schema(key))); + metadata::assert_one_key_per_tier(&schemas, |key| metadata::schema::read(key).or_else(|| schema(key))); } #[test] fn the_slots_of_the_adapters_do_not_collide_and_fit_in_a_set() { - let mut slots: Vec = fern::SCHEMA_NAMES + let mut slots: Vec = fern::schema::NAMES .iter() - .chain(&stainless::SCHEMA_NAMES) + .chain(&stainless::schema::NAMES) .map(|key| schema(key).unwrap().slot) .collect(); let len = slots.len(); diff --git a/src/compat/stainless.rs b/src/compat/stainless.rs index caa76ba0c..275ed5b8b 100644 --- a/src/compat/stainless.rs +++ b/src/compat/stainless.rs @@ -1,42 +1,47 @@ //! The adapter for Stainless's `x-stainless-*` extensions. //! -//! | Key | Says | Format | -//! |---|---|---| -//! | `x-stainless-skip` | the property makes no field | a boolean, or an array of the targets to skip it for, which counts as `false` | +//! `x-stainless-skip` may be a list of the targets to skip a property for, +//! which counts as `false`. //! //! Its other extensions, such as `x-stainless-terraform-configurability` and //! `x-stainless-deprecation-message`, are not read: they say things forge has //! no primitive for. -use crate::metadata::{BoolFormat, Hit, SchemaField}; - /// What every key of the adapter begins with. A key without it is turned /// away before it is matched against the table. const PREFIX: &str = "x-stainless-"; -const SKIP: &str = "x-stainless-skip"; -/// The names of the adapter's keys of a Schema Object, by slot. -pub(super) const SCHEMA_NAMES: [&str; 1] = [SKIP]; +/// The keys of a Schema Object. +pub(super) mod schema { + use super::PREFIX; + use crate::metadata::{BoolFormat, Hit, SchemaField}; + + const SKIP: &str = "x-stainless-skip"; -pub(super) fn schema(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; + /// The names of the adapter's keys of a Schema Object, by slot. + pub(crate) const NAMES: [&str; 1] = [SKIP]; + + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + SKIP => Hit::compat(SchemaField::Skip(BoolFormat::BoolOrTargets), 0), + _ => return None, + }) } - Some(match key { - SKIP => Hit::compat(SchemaField::Skip(BoolFormat::BoolOrTargets), 0), - _ => return None, - }) } #[cfg(test)] mod tests { use super::*; - use crate::metadata::Tier; + use crate::metadata::{BoolFormat, SchemaField, Tier}; #[test] fn the_skip_is_read_on_a_schema_as_a_boolean_or_targets_and_not_native() { - let hit = schema(SKIP).unwrap(); - assert_eq!(hit.tier, Tier::Compat, "{SKIP}"); + let key = "x-stainless-skip"; + let hit = schema::read(key).unwrap(); + assert_eq!(hit.tier, Tier::Compat, "{key}"); assert!(matches!(hit.field, SchemaField::Skip(BoolFormat::BoolOrTargets))); } @@ -47,7 +52,7 @@ mod tests { "x-stainless-deprecation-message", "x-fern-ignore", ] { - assert!(schema(key).is_none(), "{key}"); + assert!(schema::read(key).is_none(), "{key}"); } } } diff --git a/src/link/resolve.rs b/src/link/resolve.rs index 956351c13..2a2fae2bd 100644 --- a/src/link/resolve.rs +++ b/src/link/resolve.rs @@ -16,23 +16,23 @@ use crate::metadata::{self, DefinitionField, DocumentField, Hit, ParameterField, /// Returns what `key` says on an operation or an alias, if it is a key of /// one. pub(super) fn definition(key: &str) -> Option> { - metadata::definition(key).or_else(|| compat_definition(key)) + metadata::definition::read(key).or_else(|| compat_definition(key)) } /// Returns what `key` says on a Parameter Object, if it is a key of one. pub(super) fn parameter(key: &str) -> Option> { - metadata::parameter(key).or_else(|| compat_parameter(key)) + metadata::parameter::read(key).or_else(|| compat_parameter(key)) } /// Returns what `key` says on a Schema Object, if it is a key of one. pub(super) fn schema(key: &str) -> Option> { - metadata::schema(key).or_else(|| compat_schema(key)) + metadata::schema::read(key).or_else(|| compat_schema(key)) } /// Returns what `key` says at the root of the document, if it is a key of /// it. No compatibility key says anything there. pub(super) fn document(key: &str) -> Option> { - metadata::document(key) + metadata::document::read(key) } /// A kind of object with extensions, which can name its keys by slot. @@ -43,25 +43,25 @@ pub(super) trait Kind { impl Kind for DefinitionField { fn name(slot: u8) -> &'static str { - metadata::native_name(&metadata::DEFINITION_NAMES, slot).unwrap_or_else(|| compat_definition_name(slot)) + metadata::native_name(&metadata::definition::NAMES, slot).unwrap_or_else(|| compat_definition_name(slot)) } } impl Kind for ParameterField { fn name(slot: u8) -> &'static str { - metadata::native_name(&metadata::PARAMETER_NAMES, slot).unwrap_or_else(|| compat_parameter_name(slot)) + metadata::native_name(&metadata::parameter::NAMES, slot).unwrap_or_else(|| compat_parameter_name(slot)) } } impl Kind for SchemaField { fn name(slot: u8) -> &'static str { - metadata::native_name(&metadata::SCHEMA_NAMES, slot).unwrap_or_else(|| compat_schema_name(slot)) + metadata::native_name(&metadata::schema::NAMES, slot).unwrap_or_else(|| compat_schema_name(slot)) } } impl Kind for DocumentField { fn name(slot: u8) -> &'static str { - metadata::native_name(&metadata::DOCUMENT_NAMES, slot).unwrap_or_default() + metadata::native_name(&metadata::document::NAMES, slot).unwrap_or_default() } } diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index 84b91cf2c..89b680973 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -175,91 +175,118 @@ pub(crate) enum BoolFormat { BoolOrTargets, } -/// Returns what `key` says on an operation or an alias, if it is a native -/// key of one. -pub(crate) fn definition(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; - } - Some(match key { - METHOD_NAME => Hit::native(DefinitionField::Method, 0), - GROUP_NAME => Hit::native(DefinitionField::Group, 1), - SKIP => Hit::native(DefinitionField::Skip(BoolFormat::Bool), 2), - AVAILABILITY => Hit::native(DefinitionField::Availability, 3), - HIDDEN => Hit::native(DefinitionField::Hidden, 4), - CONFIRMATION => Hit::native(DefinitionField::Confirmation, 5), - _ => return None, - }) -} - -const METHOD_NAME: &str = "x-forge-method-name"; -const GROUP_NAME: &str = "x-forge-group-name"; -const SKIP: &str = "x-forge-skip"; -const AVAILABILITY: &str = "x-forge-availability"; -const HIDDEN: &str = "x-forge-hidden"; -const CONFIRMATION: &str = "x-forge-require-confirmation"; -const PARAMETER_NAME: &str = "x-forge-parameter-name"; -const MODEL_NAME: &str = "x-forge-model-name"; -const PROPERTY_NAME: &str = "x-forge-property-name"; -const SENSITIVE: &str = "x-forge-sensitive"; -/// The old name of `x-forge-sensitive`, from before every native key began -/// with `x-forge-`. Deprecated: it is read only where `x-forge-sensitive` is -/// not written. -const DEPRECATED_SENSITIVE: &str = "x-sensitive"; -const COMMANDS: &str = "x-forge-commands"; - -/// The names of the native keys of an operation or an alias, by slot. -pub(crate) const DEFINITION_NAMES: [&str; 6] = [METHOD_NAME, GROUP_NAME, SKIP, AVAILABILITY, HIDDEN, CONFIRMATION]; -/// The names of the native keys of a Parameter Object, by slot. -pub(crate) const PARAMETER_NAMES: [&str; 1] = [PARAMETER_NAME]; -/// The names of the native keys of a Schema Object, by slot. -pub(crate) const SCHEMA_NAMES: [&str; 5] = [MODEL_NAME, PROPERTY_NAME, SKIP, SENSITIVE, DEPRECATED_SENSITIVE]; -/// The names of the native keys of the document, by slot. -pub(crate) const DOCUMENT_NAMES: [&str; 1] = [COMMANDS]; - /// Returns whether `key` is the `x-forge-aliases` of an operation. pub(crate) fn is_aliases(key: &str) -> bool { key == ALIASES } -/// Returns what `key` says on a Parameter Object, if it is a native key of -/// one. -pub(crate) fn parameter(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; +/// The native keys of an operation, or of an alias in its `x-forge-aliases`. +pub(crate) mod definition { + use super::{BoolFormat, DefinitionField, Hit, PREFIX}; + + const METHOD_NAME: &str = "x-forge-method-name"; + const GROUP_NAME: &str = "x-forge-group-name"; + const SKIP: &str = "x-forge-skip"; + const AVAILABILITY: &str = "x-forge-availability"; + const HIDDEN: &str = "x-forge-hidden"; + const CONFIRMATION: &str = "x-forge-require-confirmation"; + + /// The names of the native keys of an operation or an alias, by slot. + pub(crate) const NAMES: [&str; 6] = [METHOD_NAME, GROUP_NAME, SKIP, AVAILABILITY, HIDDEN, CONFIRMATION]; + + /// Returns what `key` says on an operation or an alias, if it is a native + /// key of one. + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + METHOD_NAME => Hit::native(DefinitionField::Method, 0), + GROUP_NAME => Hit::native(DefinitionField::Group, 1), + SKIP => Hit::native(DefinitionField::Skip(BoolFormat::Bool), 2), + AVAILABILITY => Hit::native(DefinitionField::Availability, 3), + HIDDEN => Hit::native(DefinitionField::Hidden, 4), + CONFIRMATION => Hit::native(DefinitionField::Confirmation, 5), + _ => return None, + }) + } +} + +/// The native keys of a Parameter Object. +pub(crate) mod parameter { + use super::{Hit, PREFIX, ParameterField}; + + const NAME: &str = "x-forge-parameter-name"; + + /// The names of the native keys of a Parameter Object, by slot. + pub(crate) const NAMES: [&str; 1] = [NAME]; + + /// Returns what `key` says on a Parameter Object, if it is a native key of + /// one. + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + NAME => Hit::native(ParameterField::Name, 0), + _ => return None, + }) } - Some(match key { - PARAMETER_NAME => Hit::native(ParameterField::Name, 0), - _ => return None, - }) } -/// Returns what `key` says on a Schema Object, if it is a native key of one. -pub(crate) fn schema(key: &str) -> Option> { - // `x-sensitive` is the one native key outside the prefix. - if !key.starts_with(PREFIX) && key != DEPRECATED_SENSITIVE { - return None; +/// The native keys of a Schema Object. +pub(crate) mod schema { + use super::{BoolFormat, Hit, PREFIX, SchemaField}; + + const MODEL_NAME: &str = "x-forge-model-name"; + const PROPERTY_NAME: &str = "x-forge-property-name"; + const SKIP: &str = "x-forge-skip"; + const SENSITIVE: &str = "x-forge-sensitive"; + /// The old name of `x-forge-sensitive`, from before every native key began + /// with `x-forge-`. Deprecated: it is read only where `x-forge-sensitive` is + /// not written. + const DEPRECATED_SENSITIVE: &str = "x-sensitive"; + + /// The names of the native keys of a Schema Object, by slot. + pub(crate) const NAMES: [&str; 5] = [MODEL_NAME, PROPERTY_NAME, SKIP, SENSITIVE, DEPRECATED_SENSITIVE]; + + /// Returns what `key` says on a Schema Object, if it is a native key of one. + pub(crate) fn read(key: &str) -> Option> { + // `x-sensitive` is the one native key outside the prefix. + if !key.starts_with(PREFIX) && key != DEPRECATED_SENSITIVE { + return None; + } + Some(match key { + MODEL_NAME => Hit::native(SchemaField::ModelName, 0), + PROPERTY_NAME => Hit::native(SchemaField::PropertyName, 1), + SKIP => Hit::native(SchemaField::Skip(BoolFormat::Bool), 2), + SENSITIVE => Hit::native(SchemaField::Sensitive, 3), + DEPRECATED_SENSITIVE => Hit::deprecated(SchemaField::Sensitive, 4), + _ => return None, + }) } - Some(match key { - MODEL_NAME => Hit::native(SchemaField::ModelName, 0), - PROPERTY_NAME => Hit::native(SchemaField::PropertyName, 1), - SKIP => Hit::native(SchemaField::Skip(BoolFormat::Bool), 2), - SENSITIVE => Hit::native(SchemaField::Sensitive, 3), - DEPRECATED_SENSITIVE => Hit::deprecated(SchemaField::Sensitive, 4), - _ => return None, - }) } -/// Returns what `key` says at the root of the document, if it is a native -/// key of it. -pub(crate) fn document(key: &str) -> Option> { - if !key.starts_with(PREFIX) { - return None; +/// The native keys at the root of the document. +pub(crate) mod document { + use super::{DocumentField, Hit, PREFIX}; + + const COMMANDS: &str = "x-forge-commands"; + + /// The names of the native keys of the document, by slot. + pub(crate) const NAMES: [&str; 1] = [COMMANDS]; + + /// Returns what `key` says at the root of the document, if it is a native + /// key of it. + pub(crate) fn read(key: &str) -> Option> { + if !key.starts_with(PREFIX) { + return None; + } + Some(match key { + COMMANDS => Hit::native(DocumentField::Commands, 0), + _ => return None, + }) } - Some(match key { - COMMANDS => Hit::native(DocumentField::Commands, 0), - _ => return None, - }) } /// Returns the availability `value` is, such as `beta`, or `None` if it is @@ -297,6 +324,9 @@ pub(crate) fn assert_one_key_per_tier(keys: &[&str], read: impl Fn(&str) -> O mod tests { use super::*; + /// The names of the keys of a level, and whether the level reads a key. + type Level<'a> = (&'a [&'a str], fn(&str) -> bool); + /// Every native key of each kind of object, in slot order. fn native_keys() -> [&'static [&'static str]; 4] { [ @@ -335,30 +365,50 @@ mod tests { #[test] fn each_native_key_is_read_as_itself_and_as_native() { let [definitions, parameters, schemas, documents] = native_keys(); - read_as_itself(definitions, &DEFINITION_NAMES, definition); - read_as_itself(parameters, &PARAMETER_NAMES, parameter); - read_as_itself(schemas, &SCHEMA_NAMES, schema); - read_as_itself(documents, &DOCUMENT_NAMES, document); + read_as_itself(definitions, &definition::NAMES, definition::read); + read_as_itself(parameters, ¶meter::NAMES, parameter::read); + read_as_itself(schemas, &schema::NAMES, schema::read); + read_as_itself(documents, &document::NAMES, document::read); } #[test] fn no_two_native_keys_say_the_same_thing_with_the_same_tier() { let [definitions, parameters, schemas, documents] = native_keys(); - assert_one_key_per_tier(definitions, definition); - assert_one_key_per_tier(parameters, parameter); - assert_one_key_per_tier(schemas, schema); - assert_one_key_per_tier(documents, document); + assert_one_key_per_tier(definitions, definition::read); + assert_one_key_per_tier(parameters, parameter::read); + assert_one_key_per_tier(schemas, schema::read); + assert_one_key_per_tier(documents, document::read); + } + + #[test] + fn a_native_key_is_read_only_at_its_level() { + let levels: [Level; 4] = [ + (&definition::NAMES, |key| definition::read(key).is_some()), + (¶meter::NAMES, |key| parameter::read(key).is_some()), + (&schema::NAMES, |key| schema::read(key).is_some()), + (&document::NAMES, |key| document::read(key).is_some()), + ]; + for (own, _) in levels { + for &key in own { + for (names, reads) in levels { + assert_eq!(reads(key), names.contains(&key), "{key}"); + } + } + } } #[test] #[should_panic(expected = "x-forge-sensitive and x-forge-sensitive say the same thing with the same tier")] fn one_key_per_tier_finds_two() { - assert_one_key_per_tier(&["x-forge-sensitive", "x-forge-sensitive"], schema); + assert_one_key_per_tier(&["x-forge-sensitive", "x-forge-sensitive"], schema::read); } #[test] fn x_sensitive_is_a_deprecated_name_of_x_forge_sensitive() { - let (current, old) = (schema("x-forge-sensitive").unwrap(), schema("x-sensitive").unwrap()); + let (current, old) = ( + schema::read("x-forge-sensitive").unwrap(), + schema::read("x-sensitive").unwrap(), + ); assert!(matches!( (current.field, old.field), @@ -370,7 +420,7 @@ mod tests { #[test] fn a_slot_past_the_native_ones_has_no_native_name() { - assert_eq!(native_name(&DEFINITION_NAMES, COMPAT_SLOTS), None); + assert_eq!(native_name(&definition::NAMES, COMPAT_SLOTS), None); } #[test] @@ -384,8 +434,10 @@ mod tests { assert_eq!(slots.len(), len, "duplicate slot among {keys:?}"); assert!(slots.iter().all(|&slot| slot < 32), "native slots are under 32"); }; - slots(definitions, &|key| definition(key).map_or(u8::MAX, |hit| hit.slot)); - slots(schemas, &|key| schema(key).map_or(u8::MAX, |hit| hit.slot)); + slots(definitions, &|key| { + definition::read(key).map_or(u8::MAX, |hit| hit.slot) + }); + slots(schemas, &|key| schema::read(key).map_or(u8::MAX, |hit| hit.slot)); } #[test] @@ -398,17 +450,17 @@ mod tests { "x-forge-nope", "x-forge-method", ] { - assert!(definition(key).is_none(), "{key}"); - assert!(parameter(key).is_none(), "{key}"); - assert!(schema(key).is_none(), "{key}"); - assert!(document(key).is_none(), "{key}"); + assert!(definition::read(key).is_none(), "{key}"); + assert!(parameter::read(key).is_none(), "{key}"); + assert!(schema::read(key).is_none(), "{key}"); + assert!(document::read(key).is_none(), "{key}"); } } #[test] fn aliases_are_not_a_definition_key() { assert!(is_aliases("x-forge-aliases")); - assert!(definition("x-forge-aliases").is_none()); + assert!(definition::read("x-forge-aliases").is_none()); } #[test] From 34a123cfaba12f13b009d3147a6f067d83e6be47 Mon Sep 17 00:00:00 2001 From: Niels Swimberghe Date: Tue, 27 Oct 2026 11:51:38 -0400 Subject: [PATCH 21/21] docs: trim RFC 0001 to the essentials Drop the status header, the known gaps and follow-ups sections, the test plan and the release shape, and shorten the rest. The vocabulary, the resolution rules, the architecture and the alternatives considered stay. --- rfcs/0001-metadata-resolution-layer.md | 217 +++++++------------------ 1 file changed, 58 insertions(+), 159 deletions(-) diff --git a/rfcs/0001-metadata-resolution-layer.md b/rfcs/0001-metadata-resolution-layer.md index 2620cc6a9..d68ac7806 100644 --- a/rfcs/0001-metadata-resolution-layer.md +++ b/rfcs/0001-metadata-resolution-layer.md @@ -1,204 +1,103 @@ # RFC 0001: The metadata resolution layer -- **Status:** Draft -- **Date:** 2026-10-23 -- **Ticket:** FORGE-1 — *section off the fern stuff into a compatibility layer* -- **Related:** FORGE-3 (vocabulary renames) · FORGE-4 (versioning RFC) · FORGE-5 (unread vendor key lint) - ## Summary -Forge's engine reads vendor metadata extensions (`x-fern-*`, `x-stainless-skip`) directly, so everything downstream of the linked model inherits the vendors' vocabulary, formats, and limitations. This RFC adds a **metadata resolution layer** with three parts: - -1. a native `x-forge-*` vocabulary, designed on Forge's own terms rather than mirroring any vendor's; -2. a pure library that resolves keys to primitives — native first, vendor adapters as fallback; -3. a quarantined, feature-gated **compatibility layer** that is the only code holding vendor knowledge, and whose designed end state is wholesale deletion. +The engine reads vendor metadata extensions (`x-fern-*`, `x-stainless-skip`) directly, so everything downstream of the linked model inherits the vendors' vocabulary and formats. This RFC gives the engine a native `x-forge-*` vocabulary and moves all vendor knowledge into one quarantined, feature-gated **compatibility layer** (`src/compat/`) that maps vendor keys onto native primitives. The layer is designed to be deleted as a whole. -After the boundary, the engine — reader, builder, linked model, plugin host, npm runtime — acts only on Forge primitives. Output for existing specs is unchanged, and the release is non-breaking. +Output for existing specs is unchanged, and the release is non-breaking. ## Motivation -Today the engine couples to vendors in five places: +Vendor names are hardcoded in the serde key enums in `src/link/openapi.rs`, in value formats (Fern's availability words, Stainless's skip list), in validation messages, in the list of keys kept from plugins, and in the public docs, the WIT and the JS runtime. Anything downstream, including the cf codebase, depends on a vendor's extension format, and adding another vendor means touching all of it again. -1. **Wire keys** — vendor names are hardcoded in the serde key enums (`DefinitionKey`, `ParameterKey::FieldName`, `SchemaKey::{ModelName, FieldName, Skip}` in `src/link/openapi.rs`). -2. **Vendor value formats** — Fern's five-value availability vocabulary, Stainless's `x-stainless-skip` (where a list of target names means *false*). -3. **Error strings** — validation messages name vendor keys ("`x-fern-availability "ga" is not …`"). -4. **The consumed-key set** — the seven names excluded from the plugin passthrough are hand-listed in the deserializers and re-documented in the model docs. -5. **Documentation** — the public model, the WIT, and the JS runtime attribute primitives to vendor keys; the WIT's doc comments ship in the npm package. +The released aggregate uses the keys forge reads about 11,400 times (`x-fern-sdk-*` 3,638 each, `x-fern-availability` 3,444, `x-fern-ignore` 449, `x-stainless-skip` 114, and about 150 name keys). It also carries keys forge does not read, such as `x-fern-enum` (3,652) and `x-stainless-terraform-configurability` (407). -Anything downstream — including the cf codebase — therefore depends on a vendor's extension format. Adding another vendor (Stainless, Scalar) means touching the parser, the linker, the docs, and the filter again. +## Scope -### What the production specs actually use +Goals: -Audit of the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617…`): +- Nothing in the engine (`src/`, `tests/`, `packages/forge`) outside `src/compat/` and `tests/compat/` names a vendor extension, enforced by a test. +- Output for existing specs is byte-identical; no meaningful parse-time regression. +- Native keys are applied first; the compatibility layer is only a fallback, and can be removed without changing what any `x-forge-*` key means. -| Read by forge today | Uses | Present, **not** read | Uses | -|---|---|---|---| -| `x-fern-sdk-method-name` | 3,638 | `x-fern-enum` | 3,652 | -| `x-fern-sdk-group-name` | 3,638 | `x-stainless-terraform-configurability` | 407 | -| `x-fern-availability` | 3,444 | `x-stainless-deprecation-message` | 281 | -| `x-fern-ignore` | 449 | `x-stability` | 240 | -| `x-fern-parameter-name` | 108 | `x-stainless-collection-type` | 110 | -| `x-fern-property-name` | 38 | `x-fern-audiences` | 80 | -| `x-fern-type-name` | 2 | ~10 further Stainless / Fern keys | ~30 | -| `x-stainless-skip` | 114 | `x-fern-sdk-variables` | 0 | - -## Goals - -- Nothing in the engine outside the resolution layer references `x-fern-*` or `x-stainless-*` — enforced mechanically. The engine is `src/`, `tests/` and the `packages/forge` npm package; the docs packages in this repository (`astro-fern`, `fern-forge`, `cloudflare-api-site`) read vendor keys themselves and are outside this RFC (see Non-goals). -- Output for existing specs is unchanged, proven by byte-equality tests on the real aggregate. -- Tests cover each supported primitive, from each accepted key. -- No meaningful performance regression; parse throughput is benchmarked before and after. -- All Fern (and Stainless) compat code and tests live in one folder, imported only through an aggregating library. -- Native metadata is applied first; the compatibility layer is a fallback. -- The compatibility layer can be completely deleted or turned off without affecting any `x-forge-*` extension. -- The native vocabulary is not constrained by vendor naming, structure, or limitations — native keys are designed for Forge's model, and adapters do the translating. - -## Non-goals (this ticket) - -- Fern's structural behavior (allOf/anyOf handling, inline request types) — unchanged. -- Operation ID prefixing. -- Renaming Fern→Forge across the cf codebase (existing follow-up). -- Dotted `operationId` derivation (`a.b.c.d` → group `[a,b,c]` + method `d`) — a follow-up that will land *in this layer* behind an opt-in flag. -- Audiences. The ticket lists audiences as a lower-priority primitive; this RFC deliberately leaves `x-fern-audiences` unread (it needs a visibility concept Forge has not designed), flagged by FORGE-5. This is a scope deviation from the ticket text and needs the reviewers' agreement. -- New primitives for `x-fern-enum` (enum-value names — needs a model primitive that does not exist yet), `x-stability`, `x-forge-sunset`, `x-stainless-deprecation-message`. These are flagged (FORGE-5) and stay unread; each would be a one-row additive addition later. -- The docs packages' own `x-fern-*` reading (`fern-forge`, `astro-fern`, `cloudflare-api-site`: downstream consumers, like cf) — follow-up. +Non-goals: Fern's structural behavior (allOf/anyOf, inline request types), operation ID prefixing, the cf codebase's own Fern-to-Forge rename, dotted `operationId` derivation, and the docs packages in this repository, which read vendor keys themselves. Vendor keys with no Forge primitive (`x-fern-enum`, `x-fern-audiences`, `x-stability` and others) stay unread. ## The native vocabulary -| Native key | Form | Meaning | Compat source (the adapter translates) | +| Native key | Value | Meaning | Compat source | |---|---|---|---| | `x-forge-method-name` | string | the method's name | `x-fern-sdk-method-name` | -| `x-forge-group-name` | **string of names separated by dots**, or **array of strings**, top level first (array elements are not split) | the group path; `""` and `[]` are meant to be the root, but are not yet (see [Known gaps](#known-gaps)) | `x-fern-sdk-group-name` (read the same way as the native key) | -| `x-forge-skip` | bool, positional | operation/alias → no method; property schema → no field | `x-fern-ignore` (operation) · `x-stainless-skip` (property; a list of targets counts as `false` — inside the adapter) | -| `x-forge-availability` | `alpha` \| `beta` \| `preview` \| `generally-available` \| `deprecated` | lifecycle stage. The values are Forge's shipped vocabulary (public enum across Rust, WIT, JS); Fern merely coincides | `x-fern-availability` | -| `x-forge-model-name` | string | the model's name (components / `$defs` schema) | `x-fern-type-name` | +| `x-forge-group-name` | dotted string, or array of strings, top level first | the group path; an empty path makes no method, as today | `x-fern-sdk-group-name`, read the same way | +| `x-forge-skip` | bool | operation or alias: no method; property schema: no field | `x-fern-ignore` (operation), `x-stainless-skip` (property; a list of targets counts as `false`) | +| `x-forge-availability` | `alpha`, `beta`, `preview`, `generally-available`, `deprecated` | lifecycle stage | `x-fern-availability` | +| `x-forge-model-name` | string | the model's name | `x-fern-type-name` | | `x-forge-property-name` | string | the property's field name | `x-fern-property-name` | | `x-forge-parameter-name` | string | the parameter's field name | `x-fern-parameter-name` | -| `x-forge-sensitive` | bool | the schema's value is a secret, to mask | — (replaces `x-sensitive`, below) | -| `x-sensitive` | bool | **deprecated** name of `x-forge-sensitive`, read only where `x-forge-sensitive` is not written | — (a native key, not a vendor one) | -| `x-forge-hidden`, `x-forge-require-confirmation`, `x-forge-aliases`, `x-forge-commands` | *(existing, unchanged)* | | — no vendor source; now owned by the native table | +| `x-forge-sensitive` | bool | the value is a secret, to mask | none; replaces `x-sensitive` | +| `x-sensitive` | bool | deprecated name of `x-forge-sensitive`, read only where that is not written | none | + +`x-forge-hidden`, `x-forge-require-confirmation`, `x-forge-aliases` and `x-forge-commands` are unchanged. Design notes: -- **Explicit position keys over one positional name key.** Fern used three name keys because its reader architecture had one visitor per OpenAPI object kind. We use explicit keys for a different, real reason: tools in the wild mangle `$ref` structure (inlining targets, dropping siblings), and when placement lies, the key name still carries the role — `x-forge-model-name` on a property schema can be ignored or flagged, where a positional `x-forge-name` would silently become a field name. Explicitness here is corruption-detection, not verbosity. -- **`model-name`, not `type-name` or `schema-name`.** The key sets `Model::name`, and the Rust API, the WIT (`model-info`, `get-model`) and the JS runtime all call the thing a model, so the key uses the word a plugin author sees. `type-name`, Fern's word, would promise more than the key does: a `Type` is any type, scalars, arrays and unions included, of which `Type::Model` is one kind, and only a schema that becomes a model is named by the key. `schema-name` is taken: `Model::schema_name` is the key under `components.schemas`, which is the very name this key replaces. `class-name` and `struct-name` are words of particular target languages, and `title` is OpenAPI's own display string. `method-name` and `model-name` are named after what they set in the model; `property-name` and `parameter-name` both set a field's name, so they are named after their position instead, for the reason above. -- **One exclusion word, two positions.** "Excluded from generated surfaces" is one concept at two scopes; two words would be a memory tax for no disambiguation. The word is `skip` rather than `ignore`: it says what happens (the thing is not generated), where `ignore` reads as though the reader ignores the key; it stands further apart from `x-forge-hidden` (generated, but not listed); and it reads naturally should the key one day take a list of targets. That Stainless uses the same word, and Fern the other, played no part. -- **Groups as a dotted string or an array.** The dotted string is how Cloudflare's specs write a group path today, and Forge CI's lint requires it, so moving a team to `x-forge-group-name` is a rename of the key, with the value unchanged. The array is JSON's own way to write a path, and the way to write a group name that has a dot in it. Both are read exactly as forge has always read groups. -- **The dotted string is Cloudflare's, not Fern's.** Fern reads a string `x-fern-sdk-group-name` as *one* group (`"a.b"` is a group named `a.b`) and an array as a path; it never splits on dots. The release pipeline converts Cloudflare's dotted strings to arrays before Fern sees them (the released aggregate has 3,591 arrays and no strings). Forge has always split them, and the adapter reads the Fern key the same way as the native one, so for a string with a dot the adapter and Fern disagree. That is deliberate: the specs forge reads write Fern's key in Cloudflare's convention, and reading the two keys alike keeps a key rename from changing a value's meaning. -- **Every native key begins with `x-forge-`.** The `-name` keys (`method-name`, `group-name`, `model-name`, `property-name`, `parameter-name`) say the same kind of thing and are spelled alike. `x-forge-group-name` holds a path rather than one name, as `x-fern-sdk-group-name` does; keeping the suffix makes moving a team a rename of the key's prefix, and keeps it apart from the legacy `x-forge-group-info`, which Forge CI bans. FORGE-3 expects to rename it to `x-forge-namespace`. `x-sensitive` predates the rule; it becomes `x-forge-sensitive`, and the old name stays readable as a deprecated alias (155 production uses), so no spec breaks. A deprecated alias is part of the native vocabulary, not of the compatibility layer: it keeps working with compat off, and deleting compat does not remove it. -- **No misplacement validation in v1.** A known native key in a wrong position is silently ignored, exactly as Fern's keys are today. Adding validation later is a pure tightening that breaks no valid spec. +- **Explicit keys, not one positional name key.** Tools that inline `$ref` targets would make a positional `x-forge-name` silently rename fields. A misplaced explicit key can be ignored or flagged instead. +- **`model-name`** sets `Model::name`, the word the Rust API, the WIT and the JS runtime use. `type-name` would promise more than it does, `schema-name` clashes with `Model::schema_name`, and `class-name` and `title` are a language's word and OpenAPI's display string. +- **`skip`**, not `ignore`: it says what happens, and stands apart from `x-forge-hidden` (generated, but not listed). One word covers operations and properties. +- **Groups as a dotted string or an array.** Cloudflare's specs write dotted strings, so moving to the native key is a rename with the value unchanged. Fern reads a string as one group and never splits on dots, so for a string with a dot the adapter and Fern disagree. That is deliberate. FORGE-3 expects to rename the key to `x-forge-namespace`. +- **Every native key begins with `x-forge-`.** `x-sensitive` predates that rule: it stays readable (155 production uses) as a deprecated alias, which is part of the native vocabulary and keeps working with compat off. +- **No misplacement validation.** A native key at the wrong level is silently ignored, as Fern's keys are today. Validating later only tightens. ## Resolution rules -1. **Native applied, compat fallback** — per primitive, independently (a spec mid-migration may take the group from native and availability from Fern). Keys rank in three tiers: a native key under its current name, then a deprecated native alias (`x-sensitive`), then a compat key. The strongest tier present wins. -2. **Silent native-wins** — when keys of two tiers are present (a native key and a deprecated alias or compat key), the weaker value is ignored without comparison machinery. Only the winning value is validated: an invalid compat `availability` does not error when a native one wins. A value of the wrong JSON type (a number where a string is expected) is still a document-shape error at read time, whichever key it is on and in whatever order the keys are written, so errors never depend on key order. Consequence, to be documented in the metadata docs: a stale compat key silently diverges, and editing the compat key when a native key is present appears to do nothing. -3. **Same key twice** → error (today's `duplicate field` behavior, unchanged). -4. **Empty or punctuation-only values** behave as today, which depends on the key: - - `x-forge-property-name`, `x-forge-parameter-name` and `x-forge-model-name`: a value with no letters or digits, empty included, is ignored, and the field or model is named after its wire name (the property, parameter or schema name). - - `x-forge-method-name` and `x-forge-group-name`: an empty method name, or an empty group path (`""` or `[]`), means the operation or alias is not a method. For the empty group path this is the current behavior, not the intended one: see [Known gaps](#known-gaps). A method name, or any group name in the path, that is not empty but has no letters or digits is an error. - - Validation errors name the key the author actually wrote (provenance), so existing Fern-keyed error expectations hold. -5. **Dual-writing** (native and compat keys carrying the same value) is the supported pattern for keeping specs portable across engine versions during the transition: old engines read the compat key, new engines apply native. - -## Known gaps - -### An empty group path +1. Keys rank in three tiers: native, then deprecated native alias, then compat. The strongest tier present wins, per primitive and whatever order the keys are written in. Only the winning value is validated. +2. The same key written twice is an error. A value of the wrong JSON type is an error whichever key it is on. +3. Names with no letters or digits behave as they always have: a property, parameter or model name is ignored, a method name or group path that is empty makes no method, and a non-empty one that has none is an error. +4. Errors name the key the author actually wrote. +5. Writing native and compat keys with the same value is the supported way to stay portable across engine versions during the transition. -- **Intended:** `x-forge-group-name: []` (or `""`) attaches the method to the root, in no group. An operation without `x-forge-group-name` at all is still not a method. -- **Today:** an empty group path makes no method, exactly like a missing key. `add_method` in `src/link.rs` returns before building the method when the path is empty; `Method::group`'s docs in `src/lib.rs` say so; and `tests/parse/groups.rs::empty_group_name_is_no_group` and the empty-group alias case in `tests/parse/aliases.rs` assert it. -- **Why it is not fixed here:** the model has no place for a root method. Methods exist only inside groups (`Forge::groups` → `Group::methods`); `Forge` has top-level models but no top-level methods, and neither does the WIT. The fix needs a root method list in the model, a way for plugins to read it (a new WIT function is additive; a new field in an existing record is not), and generators that render root methods. That is beyond FORGE-1, which leaves the model unchanged. -- **Impact:** none today. The released aggregate has no empty group path and no method name without a group, so the fix will not change its output. -- **To decide with the fix:** whether an empty `x-fern-sdk-group-name` (`""` or `[]`) should also mean the root, or keep meaning "not a method" in the compatibility layer. Fern itself puts a method with no group, or an empty array, at the root of the client, so meaning the root would bring the adapter closer to Fern. +A consequence of rule 1: a stale compat key silently diverges from a native key written beside it. ## Architecture ``` src/ -├─ metadata/ THE NATIVE LIBRARY — pure -│ │ The x-forge-* table (per kind of object: definition, -│ │ parameter, schema, document), deprecated native aliases, -│ │ the primitives and format descriptors, the availability -│ │ vocabulary, the consumed-key set. Imports neither compat nor link. No serde, no arena -│ │ coupling: its inputs are &str keys, its outputs small -│ │ pure values. -├─ compat/ THE COMPATIBILITY LAYER — feature "compat" (default on) -│ ├─ mod.rs the aggregator: one resolver per kind of object, trying -│ │ each vendor in turn, and one name lookup per kind, for -│ │ errors. The only things link imports from here. -│ │ The designed end state: delete this folder + the feature. -│ ├─ fern.rs every x-fern-* literal, mapped onto metadata's primitives; -│ │ the value formats of those keys, as data; Fern unit -│ │ tests. -│ └─ stainless.rs the x-stainless-skip mapping and its format-as-data -│ (a list of targets counts as false); unit tests. +├─ metadata/ the native table, per kind of object (definition, parameter, +│ schema, document): keys, values, formats. Pure: `&str` in, +│ small values out. Imports neither compat nor link. +├─ compat/ the adapters (fern, stainless) and their aggregator. The only +│ code holding vendor keys. Behind the default-on `compat` feature. └─ link/ - ├─ resolve.rs the orchestrator: native first, then compat behind - │ #[cfg(feature = "compat")] — the only place link calls - │ compat. (The feature's other cfg points: `mod compat` in - │ lib.rs, and the compat-only items in metadata.) - ├─ openapi.rs OpenAPI's own keys only; every x- key asks resolve.rs. - └─ read.rs serde helpers, as today. + ├─ resolve.rs native first, then compat; the only place link calls compat + └─ openapi.rs OpenAPI's own keys; every `x-` key asks resolve.rs ``` -Properties, all deliberate: - -- **Dependencies**: `link → metadata` and `link → compat` (behind the feature), and `compat → metadata` (an adapter produces metadata's primitives). `metadata` imports neither of the others, so compat sits *beside* the native table rather than under it. `link/resolve.rs` asks native first, compat second — that fallback arm *is* resolution rule 2. -- **Purity**: the library's contract is `&str` keys in and small values out: primitives, key names, and *format descriptors as data* (for example "a string splits on `.`" or "a list of targets counts as `false`"). The serde reading and the arena writes stay in `link` and are generic, driven by those descriptors. This is what makes the library pluggable, standalone-consumable (a future `forge-ci validate` needs the key table, not the engine), and mechanically liftable into a real separate crate when the first standalone consumer appears (FORGE-5's work). -- **The availability vocabulary is native.** The five values live in the native table (they are shipped public API); `fern.rs` only maps `x-fern-availability` onto that primitive. -- **Deletion is the designed end state.** `cargo build --no-default-features --features cli` proves the native vocabulary stands alone. When vendor keys reach end-of-life, deleting the layer means removing `src/compat/` and `tests/compat/`, `mod compat` in `src/lib.rs`, the `compat` cfg arms in `link/resolve.rs` (a resolver and a name lookup for each kind of object the layer reads: operations and aliases, parameters, schemas), and the `compat` feature and its `[[test]]` entry in `Cargo.toml`. No `x-forge-*` extension changes, in behavior, docs, or WIT. - - *What a deletion leaves behind.* Some native-side code exists only for the layer and compiles, unused, without it: `Hit::compat` and `Hit::after`, `Tier::Compat`, `COMPAT_SLOTS`, the value format only a vendor uses (`BoolFormat::BoolOrTargets`) and its reader in `link/openapi.rs`, and the sentence in `Method::extensions`'s docs about the keys the compatibility layer reads. Removing them is a mechanical follow-on step, not a prerequisite. -- **With compat off, vendor keys are ordinary extensions.** Built without the feature, the engine does not drop `x-fern-*` and `x-stainless-*` keys: like any other `x-` key it does not read, an operation's vendor keys are kept and given to plugins by `Method::extensions`. Native behavior is the same either way; what plugins see in `extensions()` is not. -- **Dispatch, not semantics**: the layer maps keys to primitives and normalizes simple values. Structural behavior — `x-forge-aliases` becoming methods, `x-forge-commands` describing groups — stays in the builder. +- Dependencies: `link` uses `metadata` and, behind the feature, `compat`; `compat` uses `metadata`. +- The layer maps keys to primitives and normalizes simple values. Structural behavior, such as aliases becoming methods, stays in the builder. +- Without the `compat` feature, vendor keys are ordinary extensions and are passed to plugins. +- Deleting the layer means removing `src/compat/`, `tests/compat/`, `mod compat` in `src/lib.rs`, the compat arms in `link/resolve.rs`, and the feature in `Cargo.toml`. No native key changes. A little native-side code that only the layer used is left over and can be removed afterwards. ## Enforcement -- **Structural boundary — compiler-enforced (built-in Rust):** every vendor key literal is private to its adapter; the only things outside `compat/` that can touch vendor knowledge are the aggregator's per-object resolvers and name lookups, which `link/resolve.rs` calls. The name lookups are how a vendor key's name reaches an error message (rule 4's provenance) without `link` holding the literal: it reaches `link` as data, never as code that matches on it. The feature gate makes compat removable, and builds without the `compat` feature keep proving it. -- **Textual boundary — `tests/boundary.rs`:** scans `src/`, `tests/`, and `packages/forge/` (including the shipped `plugin/forge.wit`) for `x-fern` / `x-stainless` outside `src/compat/` and `tests/compat/`. Doc comments count — moving the WIT's "from `x-fern-availability`" attribution to `x-forge-availability` is part of the work. The test runs wherever `cargo test` runs; a `just boundary` alias targets it. -- **Compat off is compiled in CI, not tested — on purpose.** The `compat` feature is a tool for organizing the code: it keeps the vendor knowledge in one place that can be deleted, rather than being a build that anyone ships. CI's clippy step already builds the crate without it (`--no-default-features`), so the code can't quietly come to depend on the layer. But CI runs the tests only with `--all-features`. A second test run with compat off would compile the crate and every test binary again, for 30–60 s on each push, to cover a configuration nothing ships. The compat-off run in *Verification* was done locally. -- **Criterion mapping:** (1) nothing outside the layer references `x-fern-*` → the two mechanisms above; (2) output unchanged → zero model-shape changes, Fern-keyed specs resolve identically (equivalence tests + the full-aggregate native-vs-wasm byte-equality bench); (3) tests per primitive → below. - -## Test plan - -- `tests/parse/` — every fixture rewrites to native keys. Not find-and-replace: group values `"a.b"` become `["a","b"]`; the three Fern name keys become their explicit native keys; error assertions naming Fern keys move out. -- `tests/compat/` — the vendor suite, mirroring `tests/parse`'s harness: for each primitive, parse(Fern-keyed fixture) == parse(native-keyed fixture); format specifics (dotted vs array groups, duplicate-key errors, provenance error strings, Stainless's skip-list semantics). -- `tests/boundary.rs` — the guard. -- Existing tripwires keep working: `wit_is_current` (WIT regeneration is mechanical via `wit.mjs`), the wasm dump equality, native-vs-wasm generated-output byte equality. -- Performance: divan parse benches before/after on the real aggregate (`FORGE_SPEC`); `tests/wasm.rs::bench` re-run; forge-bench re-pinned upstream after merge. +- Every vendor key literal is private to its adapter, and the compiler enforces that. +- `tests/boundary.rs` searches `src/`, `tests/` and `packages/forge/` (docs and WIT included) for `x-fern` and `x-stainless` outside the layer. +- CI compiles the crate without `compat` through clippy, but runs tests only with all features, to avoid a second full compile for a configuration nothing ships. ## Verification -The implementation was checked against the unmodified engine on the released aggregate (`openapi.forge.json`, 27.6 MB, sha `99544617…`): - -- **Fern-keyed behavior.** The original, untouched suite — 379 parse tests written with Fern keys — passed against the new engine before any fixture was migrated. -- **Generated output.** `forge --target ts` on the aggregate writes the same 3,381 files, byte for byte (`diff -r`). The aggregate's 155 `x-sensitive` keys are read through the deprecated alias; the dump's 210 sensitive fields are unchanged. -- **The model.** The full model dump (the repo's own `tests/wasm/dump.rs`: every group, method, availability, hidden flag, confirmation, extension and field name) is identical between the old and new engines: 197,702 lines, covering 3,021 availability values, 1,259 hidden flags, 217 confirmations and 4,695 extension entries. The generated TypeScript consumes none of those four, which is why the dump, not the output diff, is what proves them. -- **Across the plugin boundary.** `tests/wasm.rs`, including the ignored `bench` on the aggregate, reports identical output and dump, native versus WASM, for 1,317 groups and 3,381 files; `wit_is_current` holds with the regenerated WIT. -- **Independence.** `cargo test --no-default-features --features cli` (compat off) passes all 445 tests of the native suite, including the deprecated `x-sensitive` alias; with compat on, 498 pass. Clippy is clean in the library-alone, compat-off and all-features configurations. -- **The checks can fail.** Breaking the precedence rule (keeping the last value written, whatever its tier) fails 11 compat tests, and 1 `tests/parse` test, the deprecated `x-sensitive` one, with compat on and off; planting a vendor name in a doc comment fails the boundary test, naming the file and line. -- **Performance.** Measured with the divan `parse` bench (parse and link of the aggregate), paired against the unmodified engine: each pair ran base–new–new–base so that drift in the machine's speed cancels, took the fastest sample of each run, and left out pairs whose four runs differed by more than 10%. On the final code, over 12 pairs, it is 0.8% slower: +0.34 ms of 42.0 ms, standard error 0.18 ms (t = 1.9), slower in 9 of 12 pairs. Earlier runs during the work put it between −0.1% and +1.1%, depending on the machine's speed state. Peak memory is 68.80 MB against 68.75 MB (+0.07%), with the same peak allocation count. Parsing is under a tenth of a whole `forge` run on the aggregate (about 0.5 s), so the end-to-end change is under 0.1%. - - *Where it went.* Profiling (samply, with line tables, attributing inlined frames) found no hot spot of the layer's own: most of the difference is LLVM inlining parts of serde_json's key loop into `SchemaObject::read_object` and laying the code out differently, which moves with any change. Three things were measured and kept: each table turns away keys outside its prefix (`x-forge-`, `x-fern-`, `x-stainless-`) before matching, and only `x-` keys are asked about, so a skipped key costs one compare; and a `Hit` carries only its field and slot, the key's name looked up by slot when an error needs it, so the reader's per-key result fits in registers (16 bytes, as before, not 24). - - *Ruling things out.* Unpaired, sequential runs had suggested +1.5–1.9%; that was the machine warming up through the session, which the ABBA order removes. A single run of either binary differs from the next by about as much as the change measured here, so a smaller difference needs more pairs, not a better single run. - -## Release shape +Checked against the unmodified engine on the released aggregate (27.6 MB): -Non-breaking. `x-sensitive` keeps working, deprecated in favor of `x-forge-sensitive`; when it stops being read is FORGE-4's policy question. The WIT changes are doc comments only — `forge:plugin@0.3.0` stays, bindings regenerate identically, no plugin rebuilds anywhere; npm gets an additive release: the engine binary it ships accepts the new native keys and, built with the default `compat` feature, still reads the vendor keys, and the JS runtime changes only in doc comments; the spec surface grows append-only; generated output is byte-identical. Vocabulary renames that *are* breaking (group→namespace, the availability word) are deliberately deferred to FORGE-3 so one breaking release absorbs all of them; the versioning policy that governs this is FORGE-4's RFC. +- The original 379 Fern-keyed parse tests passed before any fixture was migrated. +- `forge --target ts` writes the same 3,381 files byte for byte, and the full model dump (197,702 lines) is identical, natively and through the WASM plugin boundary. +- `cargo test` passes with compat on, and with it off when run locally; clippy is clean in the library-only, compat-off and all-features configurations. +- Parse time (divan `parse` bench, paired base-new-new-base runs) is 0.8% slower (+0.34 ms of 42.0 ms, t = 1.9). Peak memory is +0.07%, with the same allocation count. ## Alternatives considered -- **Resolve-after-parse** (keep all `x-` keys as raw JSON, normalize in a second pass): most literal reading of "a resolution step", trivially provenance-aware — but it must retain every schema-level extension on the 27 MB aggregate (5,366 `x-auditable` alone) unless the reader consults a key table anyway, at which point it collapses into the chosen design with extra memory and a reimplementation of duplicate-key errors. Rejected on performance and diff size. -- **Vendor-trait machinery** (a `Vendor` trait with Fern/Stainless/Scalar impls): no primitive overlaps across vendors today; the key table grows rows when one does. Rejected as over-engineering for now. -- **One positional `x-forge-name`**: mirrors the model's single `Name` concept and is cleaner in the abstract — but when toolchains inline `$ref` targets, the model's name key rides into property positions and silently renames fields. Explicit keys turn that corruption into something ignorable or flaggable. Rejected on robustness. -- **Separate words for an operation and a property** (`x-forge-ignore` and `x-forge-skip`, as Fern and Stainless split them): two words for one concept. Rejected. -- **Arrays only for `x-forge-group-name`**: one form, which every tool reads the same way, and loosening later would break nothing. Rejected: Cloudflare's specs write dotted strings, so every migration would reshape values as well as rename keys, and Forge CI's lint would need an array rule. -- **Reading a string `x-fern-sdk-group-name` as one group, as Fern does**: faithful to Fern, but the native and Fern keys would then read the same value differently, and the specs forge reads use dots. Rejected. -- **Error on native/compat disagreement**: the strictest conflict rule, and consistent with the engine's general strictness — deferred as an open question in FORGE-4 in favor of silent native-wins (zero comparison machinery, no cost for correct specs; the drift risk is documented). -- **Full crate split now** (a separate `metadata` member crate): delivers "separate library" literally today. The root `Cargo.toml` is already a `[workspace]`, so adding a member does not mean moving the engine; the real cost is that a separate crate cannot depend on the engine, so `Availability` and the other primitive value types would move into it and be re-exported by `forge`. Deferred: the pure contract keeps that move mechanical for when the first standalone consumer exists. -- **Renaming `Group`/`Availability` now**: both are Fern-inherited words, but both renames break the plugin contract. Deferred to FORGE-3's single breaking wave. - -## Follow-ups - -| Ticket | What | -|---|---| -| FORGE-3 | Vocabulary renames in one breaking release: `group` → `namespace`, plus the availability word review; `x-forge-group-name`/`x-forge-availability` become deprecated aliases (one table row each, the same tier `x-sensitive` uses). | -| FORGE-4 | The versioning RFC: the four contracts, the rules this RFC assumes, and open questions (1.0 timing, warning channel, vendor-key EoL policy). | -| FORGE-5 | Informational Forge CI lint flagging vendor keys the engine doesn't read, sourced from this layer's key table. | -| (FORGE-1 follow-ups) | cf codebase Fern→Forge rename; dotted `operationId` derivation behind an opt-in flag. | +- **Resolve after parse** (keep every `x-` key as raw JSON, normalize in a second pass): it must retain every extension on the 27 MB aggregate unless the reader consults a key table anyway, which collapses into this design. Rejected on memory and diff size. +- **A `Vendor` trait** with an implementation per tool: no primitive overlaps across vendors today, so the table just grows rows. Over-engineering for now. +- **Separate words for operations and properties** (`ignore` and `skip`): two words for one concept. +- **Arrays only for `x-forge-group-name`**: every migration would reshape values as well as rename keys. +- **Reading a string group as one group, as Fern does**: the native and Fern keys would read the same value differently. +- **Erroring when native and compat keys disagree**: stricter, but costs comparison machinery for no gain on correct specs. Silent native-wins was chosen. +- **A separate `metadata` crate now**: it would pull `Availability` and the other primitive types out of the engine. Deferred until a standalone consumer exists; the pure contract keeps that move mechanical. +- **Renaming `Group` and `Availability` now**: both break the plugin contract, so both wait for FORGE-3's single breaking release.