Package org.mockserver.openapi
Class OpenApiSyncPlanner
java.lang.Object
org.mockserver.openapi.OpenApiSyncPlanner
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPrefix used for all OpenAPI-generated expectation ids. -
Method Summary
Modifier and TypeMethodDescriptionidsToPrune(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.static StringnamespacePrefix(String specKey) Builds the namespace prefix for a given spec key, i.e.static StringspecKeyFromHash(String specUrlOrPayload) Derives a stable spec key by hashing the spec payload/URL.static StringspecKeyFromTitle(String title) Derives a stable spec key from an OpenAPI title.
-
Field Details
-
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 idsnewIds- 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
Derives a stable spec key from an OpenAPI title. The title is lowercased and every non-alphanumeric character is replaced with'_'.- Parameters:
title- the parsedopenAPI.getInfo().getTitle(), may be null/blank- Returns:
- sanitized key, or
nullif the title is blank
-
specKeyFromHash
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
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
-