Pure functions for API versioning logic.
This namespace provides pure functional implementations for API version management, following the Functional Core pattern. All functions are deterministic and side-effect free.
Supports:
Pure: All functions return data, no side effects.
Pure functions for API versioning logic. This namespace provides pure functional implementations for API version management, following the Functional Core pattern. All functions are deterministic and side-effect free. Supports: - Version parsing and comparison - Version lifecycle management (experimental → stable → deprecated → sunset) - Version validation - Migration path tracking Pure: All functions return data, no side effects.
(compare-versions v1 v2)Compare two version strings.
Args: v1 - First version string v2 - Second version string
Returns: -1 (v1 < v2), 0 (equal), 1 (v1 > v2), or nil (invalid version)
Examples: (compare-versions "v1" "v2") => -1 (compare-versions "v2" "v1") => 1 (compare-versions "v1" "v1") => 0 (compare-versions "v1.2" "v1.3") => -1
Pure: true
Compare two version strings. Args: v1 - First version string v2 - Second version string Returns: -1 (v1 < v2), 0 (equal), 1 (v1 > v2), or nil (invalid version) Examples: (compare-versions "v1" "v2") => -1 (compare-versions "v2" "v1") => 1 (compare-versions "v1" "v1") => 0 (compare-versions "v1.2" "v1.3") => -1 Pure: true
(create-version-metadata version config)Create version metadata for response headers.
Args: version - Current version config - Configuration
Returns: Map of version metadata
Pure: true
Create version metadata for response headers. Args: version - Current version config - Configuration Returns: Map of version metadata Pure: true
(extract-version-from-header headers header-name)Extract version from custom header.
Args: headers - Request headers map header-name - Header name (default: "x-api-version")
Returns: Version keyword or nil
Pure: true
Extract version from custom header. Args: headers - Request headers map header-name - Header name (default: "x-api-version") Returns: Version keyword or nil Pure: true
(extract-version-from-path path)Extract version from request path.
Args: path - Request path (e.g., "/api/v1/users", "/api/users")
Returns: Version keyword or nil
Examples: (extract-version-from-path "/api/v1/users") => :v1 (extract-version-from-path "/api/v2/items") => :v2 (extract-version-from-path "/api/users") => nil
Pure: true
Extract version from request path. Args: path - Request path (e.g., "/api/v1/users", "/api/users") Returns: Version keyword or nil Examples: (extract-version-from-path "/api/v1/users") => :v1 (extract-version-from-path "/api/v2/items") => :v2 (extract-version-from-path "/api/users") => nil Pure: true
(get-migration-path from-version to-version config)Get migration path from old version to new version.
Args: from-version - Starting version to-version - Target version config - Configuration with :migration-paths
Returns: Vector of intermediate versions, or nil if no path
Pure: true
Get migration path from old version to new version. Args: from-version - Starting version to-version - Target version config - Configuration with :migration-paths Returns: Vector of intermediate versions, or nil if no path Pure: true
(get-sunset-date version config)Get sunset date for version.
Args: version - Version string or keyword config - Configuration with :sunset-dates map
Returns: Date string or nil
Pure: true
Get sunset date for version. Args: version - Version string or keyword config - Configuration with :sunset-dates map Returns: Date string or nil Pure: true
(is-deprecated? version config)Check if version is deprecated.
Args: version - Version string or keyword config - Configuration with :deprecated-versions set
Returns: Boolean
Pure: true
Check if version is deprecated. Args: version - Version string or keyword config - Configuration with :deprecated-versions set Returns: Boolean Pure: true
(is-experimental? version)Check if version is experimental (v0).
Args: version - Version string or keyword
Returns: Boolean
Pure: true
Check if version is experimental (v0). Args: version - Version string or keyword Returns: Boolean Pure: true
(is-stable? version config)Check if version is stable (v1+, not deprecated).
Args: version - Version string or keyword config - Configuration with :deprecated-versions set
Returns: Boolean
Pure: true
Check if version is stable (v1+, not deprecated). Args: version - Version string or keyword config - Configuration with :deprecated-versions set Returns: Boolean Pure: true
(is-sunset? version config current-date)Check if version has passed sunset date.
Args: version - Version string or keyword config - Configuration with :sunset-dates map current-date - ISO 8601 date string (e.g., "2024-01-04")
Returns: Boolean
Pure: true
Check if version has passed sunset date. Args: version - Version string or keyword config - Configuration with :sunset-dates map current-date - ISO 8601 date string (e.g., "2024-01-04") Returns: Boolean Pure: true
(is-supported-version? version config)Check if version is supported.
Args: version - Version string or keyword config - Configuration with :supported-versions set
Returns: Boolean
Pure: true
Check if version is supported. Args: version - Version string or keyword config - Configuration with :supported-versions set Returns: Boolean Pure: true
(is-valid-version? version)Check if version string is valid and parseable.
Args: version - Version string
Returns: Boolean
Pure: true
Check if version string is valid and parseable. Args: version - Version string Returns: Boolean Pure: true
(parse-version version)Parse version string to structured map.
Args: version - Version string (e.g., 'v1', 'v2.1', 'v1.2.3')
Returns: {:major int :minor int :patch int :original string}
Examples: (parse-version "v1") => {:major 1 :minor 0 :patch 0 :original "v1"} (parse-version "v2.1") => {:major 2 :minor 1 :patch 0 :original "v2.1"} (parse-version "v1.2.3") => {:major 1 :minor 2 :patch 3 :original "v1.2.3"} (parse-version "v0") => {:major 0 :minor 0 :patch 0 :original "v0"}
Pure: true
Parse version string to structured map.
Args:
version - Version string (e.g., 'v1', 'v2.1', 'v1.2.3')
Returns:
{:major int :minor int :patch int :original string}
Examples:
(parse-version "v1") => {:major 1 :minor 0 :patch 0 :original "v1"}
(parse-version "v2.1") => {:major 2 :minor 1 :patch 0 :original "v2.1"}
(parse-version "v1.2.3") => {:major 1 :minor 2 :patch 3 :original "v1.2.3"}
(parse-version "v0") => {:major 0 :minor 0 :patch 0 :original "v0"}
Pure: true(requires-migration? from-version to-version config)Check if migrating between versions requires data migration.
Args: from-version - Starting version to-version - Target version config - Configuration
Returns: Boolean
Pure: true
Check if migrating between versions requires data migration. Args: from-version - Starting version to-version - Target version config - Configuration Returns: Boolean Pure: true
(resolve-default-version config)Resolve default version when none specified.
Args: config - Configuration with :default-version
Returns: Version keyword (e.g., :v1)
Pure: true
Resolve default version when none specified. Args: config - Configuration with :default-version Returns: Version keyword (e.g., :v1) Pure: true
(resolve-latest-version config)Resolve latest stable version.
Args: config - Configuration with :latest-stable
Returns: Version keyword (e.g., :v2)
Pure: true
Resolve latest stable version. Args: config - Configuration with :latest-stable Returns: Version keyword (e.g., :v2) Pure: true
(resolve-version request config)Resolve API version from request.
Priority:
Args: request - Request map with :uri and :headers config - Configuration
Returns: Resolved version keyword
Pure: true
Resolve API version from request. Priority: 1. URL path (/api/v1/...) 2. Custom header (X-API-Version) 3. Default version from config Args: request - Request map with :uri and :headers config - Configuration Returns: Resolved version keyword Pure: true
(validate-version* version config current-date)Validate version against configuration using an explicit current date.
Args: version - Version string or keyword config - Configuration with version settings current-date - ISO 8601 date string or comparable date value
Returns: {:valid? bool :version string :errors vector of error messages}
Examples: (validate-version "v1" {:supported-versions #{:v1 :v2}}) => {:valid? true :version "v1" :errors []}
(validate-version "v3" {:supported-versions #{:v1 :v2}}) => {:valid? false :version "v3" :errors ["Version v3 is not supported"]}
Pure: true
Validate version against configuration using an explicit current date.
Args:
version - Version string or keyword
config - Configuration with version settings
current-date - ISO 8601 date string or comparable date value
Returns:
{:valid? bool
:version string
:errors vector of error messages}
Examples:
(validate-version "v1" {:supported-versions #{:v1 :v2}})
=> {:valid? true :version "v1" :errors []}
(validate-version "v3" {:supported-versions #{:v1 :v2}})
=> {:valid? false :version "v3" :errors ["Version v3 is not supported"]}
Pure: true(version-equal? v1 v2)Check if v1 == v2.
Pure: true
Check if v1 == v2. Pure: true
(version-greater-than? v1 v2)Check if v1 > v2.
Pure: true
Check if v1 > v2. Pure: true
(version-headers version config)Generate version-related HTTP headers.
Args: version - Current version config - Configuration
Returns: Map of header name to value
Pure: true
Generate version-related HTTP headers. Args: version - Current version config - Configuration Returns: Map of header name to value Pure: true
(version-less-than? v1 v2)Check if v1 < v2.
Pure: true
Check if v1 < v2. Pure: true
(version-string version)Convert parsed version back to string.
Args: version - Parsed version map
Returns: Version string (e.g., "v1", "v2.1")
Pure: true
Convert parsed version back to string. Args: version - Parsed version map Returns: Version string (e.g., "v1", "v2.1") Pure: true
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |