Skip to main content

patch

Function patch 

Source
pub fn patch(input_yaml: &str, config: &PatchConfig<'_>) -> Result<String>
Expand description

Apply the configured transform pipeline to an OpenAPI YAML spec.

Parses the input YAML, applies all enabled transforms in the correct order, and returns the patched YAML string.

§Phase Ordering

The 12-phase pipeline has ordering dependencies:

  • Phases 1–3 (structural, streaming, responses): run first to establish the base spec structure; later phases depend on correct response entries.
  • Phase 4 (enum rewrites): must run before inlining (phase 11) so that inlined schemas contain the rewritten enum values.
  • Phase 5 (unimplemented markers): must run after response fixes (phase 3) so that 501 responses are added to specs with correct error schema refs.
  • Phase 6 (security): must run after operation ID resolution; independent of validation.
  • Phase 7 (cleanup): removes empty bodies before constraint injection to avoid injecting constraints into schemas about to be removed.
  • Phase 8 (UUID flattening): must run before validation (phase 9) so that flattened UUID fields get correct format/pattern constraints.
  • Phase 9 (validation): injects constraints into component schemas.
  • Phase 10 (path field stripping): must run after constraint injection (phase 9) since it clones schemas before removing path fields.
  • Phase 11 (inlining): must run after path stripping (phase 10) to correctly detect emptied bodies; runs last among content transforms.
  • Phase 12 (normalization): always runs last as a final cleanup pass.

§Errors

Returns an error if the input YAML cannot be parsed, processing fails, or any deferred method name (from PatchConfig::unimplemented_methods or PatchConfig::public_methods) cannot be resolved against proto metadata.