Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI definition endpoint #10328

Merged
merged 51 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
e64bc66
Plugin initial config
jp-tosca Feb 15, 2024
d717ad1
Initial changes to provide OpenAPI definition
jp-tosca Feb 16, 2024
63df178
Added integration test
jp-tosca Feb 16, 2024
77f9c61
Imports fix
jp-tosca Feb 16, 2024
2da5b05
Add patchnotes
jp-tosca Feb 16, 2024
9f528d8
Update the changelog
jp-tosca Feb 16, 2024
a8c4c06
Update src/main/java/edu/harvard/iq/dataverse/api/Info.java
jp-tosca Feb 16, 2024
a859a50
Update doc/release-notes/10236-openapi-definition-endpoint.md
jp-tosca Feb 16, 2024
8d41917
Update doc/release-notes/10236-openapi-definition-endpoint.md
jp-tosca Feb 16, 2024
9405d54
Add native API docs
jp-tosca Feb 16, 2024
468672e
Remove generated definitions
jp-tosca Feb 16, 2024
3a0daa6
Add to gitignore generated openapi files
jp-tosca Feb 16, 2024
3a699a8
Updates to docs
jp-tosca Feb 16, 2024
4b6a9fd
Ignore files correction
jp-tosca Feb 20, 2024
c5bfc83
Branch update
jp-tosca Mar 11, 2024
3f3145e
Remove files created by the plugin
jp-tosca Mar 11, 2024
094105d
Changes to move the definition files to META-INF
jp-tosca Mar 13, 2024
9d563eb
Changes to move the definitions to WEB-INF
jp-tosca Mar 14, 2024
f2f815c
Changes to get the files from META-INF
jp-tosca Mar 15, 2024
058a4e5
Changed the phase of execution of the smallrye plugin
jp-tosca Mar 22, 2024
df9a680
Changes of names to improve the generation of the spec
jp-tosca Mar 22, 2024
2873d07
Add support for OpenAPI annotations and documents the version endpoint
jp-tosca Mar 24, 2024
25bebdc
Merge remote-tracking branch 'origin/develop' into openapi-definition…
jp-tosca Mar 26, 2024
fdb85c6
Multipart Annotations
jp-tosca Mar 27, 2024
e5c60f3
Merge remote-tracking branch 'origin/develop' into openapi-definition…
jp-tosca Mar 27, 2024
80ebbf7
Typos correction
jp-tosca Mar 27, 2024
e1e19d7
Merge remote-tracking branch 'origin/develop' into openapi-definition…
jp-tosca Apr 2, 2024
b181899
Changes for tags
jp-tosca Apr 2, 2024
f8fa32b
Renaming of methods
jp-tosca Apr 2, 2024
7d45759
Changes to the endpoint
jp-tosca Apr 17, 2024
c009cc7
Added test
jp-tosca Apr 17, 2024
779897e
Add test
jp-tosca Apr 17, 2024
a0141cd
Deleted extra import
jp-tosca Apr 17, 2024
9cdd9dc
Merge branch 'develop' into openapi-definition-endpoint
jp-tosca Apr 17, 2024
9ca4111
Merge remote-tracking branch 'origin/develop' into openapi-definition…
jp-tosca May 14, 2024
b7ba865
Merge remote-tracking branch 'origin/develop' into openapi-definition…
jp-tosca May 29, 2024
59fc8ce
Docs updated
jp-tosca May 29, 2024
5ad07f7
openapi doc tweaks #9981 #10236
pdurbin May 29, 2024
b99b194
improve release note #9981 #10236
pdurbin May 29, 2024
f265744
Remove old test and changes response to JSON
jp-tosca May 29, 2024
4ea444a
stub out guidance on openapi validation #9981 #10236
pdurbin May 29, 2024
6fe471f
add InfoIT to list of tests
pdurbin May 29, 2024
31a65a7
use description of Dataverse from website
pdurbin May 29, 2024
5cbad6d
mention status codes in openapi doc
pdurbin May 29, 2024
0d656a1
update api faq about changelog, link to breaking changes doc
pdurbin May 29, 2024
eb9cf7c
typo
pdurbin May 29, 2024
678865d
Change to OpenApi
jp-tosca May 29, 2024
d23d78c
Changes to docs
jp-tosca May 29, 2024
942d473
Name fix
jp-tosca May 29, 2024
683ea85
Removing the multipart from unirest
jp-tosca May 30, 2024
ef267d0
Merge remote-tracking branch 'origin/develop' into openapi-definition…
jp-tosca Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/release-notes/10236-openapi-definition-endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
On Dataverse 6.0 Payara was updated and this caused the url `/openapi/` to stop working and caused an exception on the server.
jp-tosca marked this conversation as resolved.
Show resolved Hide resolved

- https://github.com/IQSS/dataverse/issues/9981
- https://github.com/payara/Payara/issues/6369

We incorporated the SmallRye OpenAPI plugin on our POM (https://github.com/smallrye/smallrye-open-api/tree/main/tools/maven-plugin) which will generate files for YAML and JSON formats and deposit them on `edu/harvard/iq/dataverse/openapi/ `these files will be provided by this endpoint depending on the format requested.
jp-tosca marked this conversation as resolved.
Show resolved Hide resolved

The API endpoint was added `/api/info/openapi/{format}` accepting the "json" and "yaml" as formats.
jp-tosca marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<poi.version>5.2.1</poi.version>
<tika.version>2.4.1</tika.version>
<netcdf.version>5.5.3</netcdf.version>

<smallrye.schemaFilename>dataverse_openapi</smallrye.schemaFilename>
<smallrye.infoTitle>Dataverse API</smallrye.infoTitle>
<smallrye.outputDirectory>src/main/resources/edu/harvard/iq/dataverse/openapi</smallrye.outputDirectory>
</properties>

<!-- Versions of dependencies used both directly and transitive are managed here.
Expand Down Expand Up @@ -682,6 +686,7 @@
<include>**/firstNames/*.*</include>
<include>**/*.xsl</include>
<include>**/services/*</include>
<include>**/openapi/*</include>
</includes>
</resource>
<resource>
Expand All @@ -694,6 +699,22 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>smallrye-open-api-maven-plugin</artifactId>
<groupId>io.smallrye</groupId>
<executions>
<execution>
<goals>
<goal>generate-schema</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaFilename>${smallrye.schemaFilename}</schemaFilename>
<infoTitle>${smallrye.infoTitle}</infoTitle>
<outputDirectory>${smallrye.outputDirectory}</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Info.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package edu.harvard.iq.dataverse.api;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.io.IOUtils;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.FileUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import jakarta.ejb.EJB;
import jakarta.json.Json;
import jakarta.json.JsonValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

@Path("info")
Expand All @@ -19,6 +32,8 @@ public class Info extends AbstractApiBean {
@EJB
SystemConfig systemConfig;

private static final Logger logger = Logger.getLogger(Info.class.getCanonicalName());

@GET
@Path("settings/:DatasetPublishPopupCustomText")
public Response getDatasetPublishPopupCustomText() {
Expand Down Expand Up @@ -55,6 +70,52 @@ public Response getTermsOfUse() {
return ok(systemConfig.getApiTermsOfUse());
}

/*
* On Dataverse 6.0 Payara was updated and the openapi endpoint stopped working: https://github.com/payara/Payara/issues/6369
*
* This caused the url /openapi/ to stop working and caused an exception on the server: https://github.com/IQSS/dataverse/issues/9981
*
* We incorporated the SmallRye OpenAPI plugin on our POM (https://github.com/smallrye/smallrye-open-api/tree/main/tools/maven-plugin)
* which will generate files for YAML and JSON formats and deposit them on edu/harvard/iq/dataverse/openapi/
* these files will be provided by this endpoint depending on the format requested.
*
*/
@GET
@Path("openapi/{format}")
public Response getOpenapiSpec(@PathParam("format") String format) {

//We use the lowercase of the specified format to define the mediatype and will be used as the file extension.
String requestedFormat = format.toLowerCase();
MediaType mediaType = null;

if (requestedFormat.equals("json")){
mediaType = MediaType.APPLICATION_JSON_TYPE;
} else if (requestedFormat.equals("yaml")){
mediaType = MediaType.TEXT_PLAIN_TYPE;
} else {
//If the format is not supported we will return a 400 Bad Request
List<String> args = Arrays.asList(format);
String bundleResponse = BundleUtil.getStringFromBundle("info.api.exception.invalid.format", args);
return error(Response.Status.BAD_REQUEST, bundleResponse);
}

try {
//We create an input stream based on the requested format and will return the content of the file as a response.
String baseFileName = "edu/harvard/iq/dataverse/openapi/dataverse_openapi." + requestedFormat;
InputStream openapiDefinitionStream = Info.class.getClassLoader().getResourceAsStream(baseFileName);
return Response.ok().entity(IOUtils.toString(openapiDefinitionStream, StandardCharsets.UTF_8))
.type(mediaType).build();
} catch (Exception ex) {
//If a supported file is not found we will return a 400 Bad Request with an exception.
logger.log(Level.SEVERE, "OpenApi Definition format not found " + format + ":" + ex.getMessage(), ex);
jp-tosca marked this conversation as resolved.
Show resolved Hide resolved
List<String> args = Arrays.asList(format);
String bundleResponse = BundleUtil.getStringFromBundle("info.api.exception", args);
return error(Response.Status.BAD_REQUEST, bundleResponse);
}
}



@GET
@Path("settings/incompleteMetadataViaApi")
public Response getAllowsIncompleteMetadata() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2948,3 +2948,7 @@ publishDatasetCommand.pidNotReserved=Cannot publish dataset because its persiste
api.errors.invalidApiToken=Invalid API token.
api.ldninbox.citation.alert={0},<br><br> The {1} has just been notified that the {2}, <a href=''{3}''>{3}</a>, cites "<a href=''{4}/dataset.xhtml?persistentId={5}''>{6}</a>" in this repository.
api.ldninbox.citation.subject={0}: A Dataset Citation has been reported!

#Info.java
info.api.exception.invalid.format=Invalid format {0}, currently supported formats are YAML and JSON.
info.api.exception=Supported format definition not found.
jp-tosca marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading