OapiCodemode.Proxy.Matcher (oapi_codemode v0.5.0)

Copy Markdown View Source

Matches an intercepted (method, path) against the operation index. On failure, suggests the nearest operations so the model can self-correct without another search round-trip.

Summary

Types

What matching reads: id, method and segments.

Functions

The ids of the 5 operations whose ids are nearest op_id by Jaro distance, nearest first.

Types

candidate()

What matching reads: id, method and segments.

A stored %OapiCodemode.Operation{} has them, a resolved operation has them, and so does the registry's cached index entry — and the index is what the proxy matches against, the operation itself being read from the store only once one has been matched.

Functions

match(operations, method, path)

@spec match([candidate()], String.t(), String.t()) ::
  {:ok, candidate(), %{required(String.t()) => String.t()}}
  | {:error, {:no_match, [String.t()]}}

nearest_ids(operations, op_id)

@spec nearest_ids([candidate()], String.t()) :: [String.t()]

The ids of the 5 operations whose ids are nearest op_id by Jaro distance, nearest first.

search_apis' describe names these when handed an id the index does not hold: an unknown id is usually a near miss (a typo, a _ for a -, the wrong casing) the model can fix without another search round trip. Ties keep index order, so the suggestions are deterministic for a given index.