class

EndpointOptimizer

Inherits Reference < Object

Endpoint optimization module that handles endpoint deduplication, URL combination, and path parameter extraction

Constants

ABSOLUTE_URL_RE = /\A[a-zA-Z][a-zA-Z0-9+.\-]*:\/\//

A URL that already carries its own scheme + authority (e.g. https://host/path). The HAR / OAS detectors emit these, so the optimizer must not prepend a target, collapse the // after the scheme, or treat the leading segment as a path.

COLLECTION_NOISE_HEADERS = Set {"user-agent", "accept", "content-type", "host", "origin", "referer", "x-requested-with"}

Generic request headers a browser/HTTP client always sends; they carry no endpoint-specific signal, so collection imports that surface them as params are treated as noise during dedup.

PROJECT_MANIFEST_FILES = {"pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts", "shard.yml", "package.json", "go.mod", "Cargo.toml", "pyproject.toml", "mix.exs"}

Constructors

new(logger : NoirLogger, options : Hash(String, YAML::Any))
Source

Instance methods

add_path_parameters(endpoints : Array(Endpoint)) : Array(Endpoint)

Add path parameters by parsing URL patterns

Source
apply_pvalue(param_type, param_name, param_value) : String

Apply parameter values based on configuration

Source
combine_url_and_endpoints(endpoints : Array(Endpoint)) : Array(Endpoint)

Combine target URL with endpoints

Source
normalize_url_shapes(endpoints : Array(Endpoint)) : Array(Endpoint)

Normalize cross-framework URL shapes the analyzers can't always resolve without language context. Rewrites a small set of well- known leaky forms into the canonical {name} placeholder so the downstream add_path_parameters pass picks them up as path params instead of literal noise.

Covered shapes:

  • (?P<name>pattern) — Python re_path-style named groups. Bleeds through Django's re_path route table; rewrite to {name} and drop the regex body.
  • ${name} / ${obj.field} — JS/TS template literals that analyzers can't statically resolve (handler files reference captured variables, not literal paths). Rewrite to {name} (or {field} for ${obj.field}) so the AI/output payload surfaces it as a path placeholder rather than as a literal ${...} segment.
  • Python regex anchors ^ (leading) and $/\Z (trailing) — re_path patterns commonly include these.
  • Python regex backslash-escaped dots \. — rewrite to plain . for the visible URL.
  • Spring {name:regex} — strip the inline regex constraint so the placeholder is {name} regardless of framework dialect.
  • Postman / Express-style :name path segments — rewrite to {name} so collections merge with framework analyzers that already emit the canonical placeholder shape.
Source
optimize(endpoints : Array(Endpoint)) : Array(Endpoint)

Main optimization workflow - calls all optimization steps

Source
optimize_endpoints(endpoints : Array(Endpoint)) : Array(Endpoint)

Remove duplicated endpoints and parameters, validate HTTP methods, clean URLs

Source