This is an automated email from the ASF dual-hosted git repository.
iuliana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new b08cec4 Add info and security definition to the swagger doc
new c12f52c Merge pull request #1196 from
jcabrerizo/feature/improve-swagger
b08cec4 is described below
commit b08cec4e6bd0b8c143fb95fac424970f6686d4f9
Author: Juan Cabrerizo <[email protected]>
AuthorDate: Wed Jul 7 15:52:36 2021 +0100
Add info and security definition to the swagger doc
---
.../org/apache/brooklyn/rest/api/ServerApi.java | 2 ++
.../rest/apidoc/RestApiResourceScanner.java | 27 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git
a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ServerApi.java
b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ServerApi.java
index 766dcca..d70510c 100644
--- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ServerApi.java
+++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ServerApi.java
@@ -135,6 +135,7 @@ public interface ServerApi {
@POST
@Path("/ha/state")
@ApiOperation(value = "Changes the HA state of this management node")
+ @Produces({MediaType.APPLICATION_FORM_URLENCODED})
public ManagementNodeState setHighAvailabilityNodeState(
@ApiParam(name = "mode", value = "The state to change to")
@FormParam("mode") HighAvailabilityMode mode);
@@ -158,6 +159,7 @@ public interface ServerApi {
@POST
@Path("/ha/priority")
@ApiOperation(value = "Sets the HA node priority for MASTER failover")
+ @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
public long setHighAvailabilityPriority(
@ApiParam(name = "priority", value = "The priority to be set")
@FormParam("priority") long priority);
diff --git
a/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
b/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
index 83e56e0..21f92d3 100644
---
a/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
+++
b/utils/rest-swagger/src/main/java/org/apache/brooklyn/rest/apidoc/RestApiResourceScanner.java
@@ -27,7 +27,12 @@ import io.swagger.annotations.Api;
import io.swagger.config.SwaggerConfig;
import io.swagger.jaxrs.config.AbstractScanner;
import io.swagger.jaxrs.config.JaxrsScanner;
+import io.swagger.models.Info;
+import io.swagger.models.Scheme;
import io.swagger.models.Swagger;
+import io.swagger.models.auth.ApiKeyAuthDefinition;
+import io.swagger.models.auth.BasicAuthDefinition;
+import io.swagger.models.auth.In;
/**
@@ -109,9 +114,31 @@ public class RestApiResourceScanner extends
AbstractScanner implements JaxrsScan
@Override
public Swagger configure(Swagger swagger) {
swagger.setBasePath("/v1");
+ swagger.setSchemes(Arrays.asList(new Scheme[]{Scheme.HTTPS,
Scheme.HTTP}));
+
+ swagger.info(getSwaggerInfo());
+
+ ApiKeyAuthDefinition security = new ApiKeyAuthDefinition();
+ String apiKeyName = "JWT";
+ security.setName(apiKeyName);
+ security.setIn(In.HEADER);
+ security.setType("apiKey");
+ swagger.addSecurityDefinition(apiKeyName, security);
+
+ BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
+ swagger.addSecurityDefinition("Basic authentication",
basicAuthDefinition);
+
return swagger;
}
+ private Info getSwaggerInfo() {
+ Info info = new Info();
+ info.setTitle("Apache Brooklyn API");
+
info.setVersion(this.getClass().getPackage()!=null?this.getClass().getPackage().getImplementationVersion():"");
+ info.setDescription("API specification for Apache Brooklyn");
+ return info;
+ }
+
@Override
public String getFilterClass() {
return null;