Class OpenApiSpecVersions

java.lang.Object
io.wcm.siteapi.openapi.validator.OpenApiSpecVersions

public final class OpenApiSpecVersions extends Object
Get available versions of Site API specification.

By default, spec files are expected in the classpath at /site-api-spec with filenames named following this pattern:

 site-api.yaml
 site-api-v1.yaml
 site-api-v2.yaml
 ...
 

But you can also specify a custom path and file name pattern.

The spec versions are derived from the file names. If no version is detected in the filename (e.g. site-api.yaml an empty string is used as versions. Otherwise the version from the file name is returned (e.g. site-api-v1.yaml -> v1). This versions reflects the "major version" of the spec with expected full backward compatibility within this version.

  • Field Details

    • DEFAULT_RESOURCE_PATH

      public static final String DEFAULT_RESOURCE_PATH
      Default classpath path to look for Site API spec files.
      See Also:
    • DEFAULT_FILENAME_PATTERN

      public static final Pattern DEFAULT_FILENAME_PATTERN
      Default pattern for Site API spec files. Last group is expected to return the actual version.
  • Constructor Details

    • OpenApiSpecVersions

      public OpenApiSpecVersions()
      Get all Site API Specs detected in classpath matching the default path and pattern.
    • OpenApiSpecVersions

      public OpenApiSpecVersions(@NotNull @NotNull String path, @NotNull @NotNull Pattern filenamePattern, @Nullable @Nullable Comparator<String> versionComparator)
      Get all Site API Specs detected in classpath matching given path and filename pattern.
      Parameters:
      path - Directory in classpath
      filenamePattern - File name pattern (last group is expected to return the actual version).
      versionComparator - Comparator for versions ("highest" version is last version) - or null to use standard string sorting
  • Method Details

    • getAllVersions

      @NotNull public @NotNull Collection<String> getAllVersions()
      Get all Site API versions.
      Returns:
      Versions
    • getLatestVersion

      @NotNull public @NotNull String getLatestVersion()
      Get latest version.
      Returns:
      Version
    • getLatest

      @NotNull public @NotNull OpenApiSpec getLatest()
      Returns Site API specification for highest version number.
      Returns:
      Site API specification.
    • get

      @NotNull public @NotNull OpenApiSpec get(@NotNull @NotNull String version)
      Returns Site API specification.
      Parameters:
      version - Requested spec version
      Returns:
      Site API specification.