Skip to content

Commit

Permalink
EA-3669 added info endpoint and swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
SrishtiSingh-eu committed Feb 26, 2024
1 parent 0ef68a3 commit f254655
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 16 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<!-- Spring Boot 3 is based on Spring Framework 6.0 and Jakarta EE 9. A-->
<spring-boot.version>3.1.2</spring-boot.version>
<spring-framework.version>6.0.11</spring-framework.version>
<springdoc.version>2.3.0</springdoc.version>

<surefire.version>3.1.2</surefire.version>
<swagger.version>3.0.0</swagger.version>
Expand Down Expand Up @@ -129,6 +130,7 @@
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>git.branch</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
Expand Down
8 changes: 8 additions & 0 deletions record-api-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

<!-- spring doc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>


<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package eu.europeana.api.record.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* Makes build information and the application name and description from the project's pom.xml available.
* While generating a war file this data is written automatically to the build.properties file which is read here.
* Note that the same information is also available in the Spring-Boot /actuator/info endpoint
*/
@Configuration
@PropertySource("classpath:build.properties")
public class BuildInfo {

@Value("${info.app.name}")
private String appName;

@Value("${info.app.version}")
private String appVersion;

@Value("${info.app.description}")
private String appDescription;

@Value("${info.build.number}")
private String buildNumber;

public String getAppName() {
return appName;
}

public String getAppDescription() {
return appDescription;
}

public String getAppVersion() {
return appVersion;
}

public String getBuildNumber() {
return buildNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.europeana.api.record.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringDocConfig {

private final BuildInfo buildInfo;

/**
* Initialize SpringDoc with API build information
* @param buildInfo object for retrieving build information
*/
public SpringDocConfig(BuildInfo buildInfo) {
this.buildInfo = buildInfo;
}

@Bean
public OpenAPI userServiceOpenAPI() {
return new OpenAPI().info(new Info().title(buildInfo.getAppName())
.description(buildInfo.getAppDescription())
.version(buildInfo.getAppVersion() + " (build " + buildInfo.getBuildNumber() + ")")
.contact(new Contact().name("API team").url("https://api.europeana.eu").email("[email protected]"))
.termsOfService("https://www.europeana.eu/en/rights/api-terms-of-use")
.license(new License().name("EUPL 1.2").url("https://www.eupl.eu")))
.externalDocs(new ExternalDocumentation()
.description("Documentation")
.url("https://pro.europeana.eu/page/intro#general"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import eu.europeana.api.record.model.RecordRequest;
import eu.europeana.api.record.service.RecordService;
import eu.europeana.api.record.utils.RecordUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -20,12 +21,19 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;


import java.io.*;
import java.util.Optional;

import static eu.europeana.api.record.utils.RecordConstants.*;

@Tag(
name = "Record API rest endpoints"
// description = "Record API retrieval in different formats"

)
@RestController
@Validated
public class RecordController {
Expand All @@ -43,10 +51,14 @@ public RecordController(RecordService recordService, FormatHandlerRegistry forma
}


@ApiOperation(
value = "Retrieve a record",
nickname = "retrieveRecord",
response = java.lang.Void.class)
@Operation(
summary = "retrieveRecord",
description = "Retrieve record in json/json-ld, XML, Turtle, N3, NT "
)
@ApiResponse(
responseCode = "200",
description = "HTTP Status 200 OK"
)
@GetMapping(
value = {
"/record/v3/{datasetId}/{localId}",
Expand Down
37 changes: 37 additions & 0 deletions record-api-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#debug=true

#Spring configs
spring.application.name=Record API
spring.main.allow-bean-definition-overriding=false
info.app.name=${spring.application.name}
info.app.version=${project.version}
info.app.description=Europeana Record API retrieves record in different formats.

#switch Spring boot logging to log4j (see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.logging)
org.springframework.boot.logging.LoggingSystem= org.springframework.boot.logging.log4j2.Log4J2LoggingSystem

## management / actuator / swagger
#springfox.documentation.swagger-ui.enabled=true
management.security.enabled=false

management.endpoints.web.exposure.include=health,info
# for debugging conditioonal annotations locally the following configuration can be used
management.info.build.enabled=true
management.info.git.enabled=true
management.health.probes.enabled=true

### Configurations for swagger console
#springdoc.paths-to-exclude=/error
#springdoc.show-actuator=true

## server configurations
server.port = 8080
server.error.include-message=always
server.error.include-stacktrace=on_param
server.error.include-exception=false
server.error.see-also=https://pro.europeana.eu/page/apis

# compression:
# enabled: true
# min-response-size: 4096
# mime-types: application/json, application/ld+json, application/xml, text/html, text/xml, text/plain
11 changes: 0 additions & 11 deletions record-api-web/src/main/resources/application.yml

This file was deleted.

21 changes: 21 additions & 0 deletions record-api-web/src/main/resources/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Template for application build and version information. If you use the Europeana Parent POM then all Maven properties
# will be filled during a build by the Maven War plugin.
# Properties that start with 'info.' will be displayed by Spring Actuator in the /actuator/info endpoint and can be
# reused in the BuildInfo class

info.app.name = ${project.name}
info.app.version = ${project.version}
info.app.description = ${project.description}

info.build.branch = ${scmBranch}
info.build.number = ${buildNumber}
info.build.date = ${timestamp}


## Default values for local testing. Will be ignored in war builds
project.name = MyApi
project.version = n/a
project.description = No description available
scmBranch = n/a
buildNumber = local-build
timestamp = n/a
12 changes: 12 additions & 0 deletions record-api-web/src/main/resources/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Europeana Record API</title>
<meta http-equiv="refresh" content="0; url=/swagger-ui/index.html">
</head>
<body>
<h1>Europeana API</h1>
<!--<li><a href="/actuator/info">Build information</a></li>-->
<!--<li><a href="/swagger-ui/index.html">Swagger UI</a></li>-->
</body>
</html>

0 comments on commit f254655

Please sign in to comment.