Class OpenApiSyncPlanner

java.lang.Object
org.mockserver.openapi.OpenApiSyncPlanner

public final class OpenApiSyncPlanner extends Object
Pure-function helper for incremental OpenAPI sync: given the set of existing expectation ids, the set of newly-generated ids, and the namespace prefixes that the new generation covers, determines which existing ids should be pruned.

An existing id is pruned iff it starts with one of the namespace prefixes AND is not in the new id set. This ensures that re-importing a spec updates expectations in place and removes operations no longer present, without affecting expectations from other specs or manually created expectations.

  • Field Details

    • OPENAPI_ID_PREFIX

      public static final String OPENAPI_ID_PREFIX
      Prefix used for all OpenAPI-generated expectation ids.
      See Also:
  • Method Details

    • idsToPrune

      public static Set<String> idsToPrune(Collection<String> existingIds, Collection<String> newIds, Collection<String> namespacePrefixes)
      Computes the set of existing expectation ids that should be removed (pruned) during an incremental OpenAPI sync.
      Parameters:
      existingIds - all currently active expectation ids
      newIds - ids generated from the newly-imported spec(s)
      namespacePrefixes - the "openapi:<specKey>:" prefixes covered by this import batch
      Returns:
      the ids to remove — a subset of existingIds
    • specKeyFromTitle

      public static String specKeyFromTitle(String title)
      Derives a stable spec key from an OpenAPI title. The title is lowercased and every non-alphanumeric character is replaced with '_'.
      Parameters:
      title - the parsed openAPI.getInfo().getTitle(), may be null/blank
      Returns:
      sanitized key, or null if the title is blank
    • specKeyFromHash

      public static String specKeyFromHash(String specUrlOrPayload)
      Derives a stable spec key by hashing the spec payload/URL. Returns a short (8-char) hex hash suitable for use as a namespace token.
      Parameters:
      specUrlOrPayload - the raw spec URL or inline payload
      Returns:
      an 8-character lowercase hex string
    • namespacePrefix

      public static String namespacePrefix(String specKey)
      Builds the namespace prefix for a given spec key, i.e. "openapi:<specKey>:".
      Parameters:
      specKey - the sanitized spec key (from title or hash)
      Returns:
      the namespace prefix string