JsonVersionResource.java
/*
* Copyright © 2024-2025 The CTAN Team and individual authors
*
* This file is distributed under the 3-clause BSD license.
* See file LICENSE for details.
*/
package org.ctan.site.resources.catalogue.api;
import java.util.List;
import java.util.Map;
import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response.Status;
import lombok.NonNull;
/**
* The class <code>VersionResource</code> contains the controller for the
* version resource.
*
* @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
*/
@Path("/")
@Produces({MediaType.APPLICATION_JSON})
public class JsonVersionResource {
/**
* The constant <code>values</code> contains the acceptable values.
*/
static List<String> values =
List.of("1.1", "1.2", "1.3", "2.0", "3.0");
/**
* The method <code>getVersion</code> provides means to retrieve the version
* number of the API in use.
*
* @param vers the version
* @return the version number
*/
@GET
@Path("/json/{vers}/version")
@PermitAll
public Map<String, String> getVersion(
@NonNull @PathParam("vers") String vers) {
if (!values.contains(vers)) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return Map.of("version", vers);
}
}