-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manual swagger documentation generation
- Loading branch information
Bernard Labno
committed
Jul 24, 2019
1 parent
d9a6085
commit 9c505cb
Showing
10 changed files
with
444 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "Bisq HTTP API", | ||
"version": "0.0.1" | ||
}, | ||
"security": [ | ||
{ | ||
"authorization": [] | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"name": "user" | ||
}, | ||
{ | ||
"name": "version" | ||
} | ||
], | ||
"paths": { | ||
"/api/v1/user/authenticate": { | ||
"post": { | ||
"tags": [ | ||
"user" | ||
], | ||
"summary": "Exchange password for access token", | ||
"operationId": "authenticate", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/AuthForm" | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"default": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/AuthResult" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v1/user/password": { | ||
"post": { | ||
"tags": [ | ||
"user" | ||
], | ||
"summary": "Change password", | ||
"operationId": "changePassword", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/ChangePassword" | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"default": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/AuthResult" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v1/version": { | ||
"get": { | ||
"tags": [ | ||
"version" | ||
], | ||
"summary": "Get version details", | ||
"operationId": "getVersionDetails", | ||
"responses": { | ||
"default": { | ||
"description": "default response", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/VersionDetails" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"AuthResult": { | ||
"type": "object", | ||
"properties": { | ||
"token": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"AuthForm": { | ||
"type": "object", | ||
"properties": { | ||
"password": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"ChangePassword": { | ||
"type": "object", | ||
"properties": { | ||
"newPassword": { | ||
"type": "string" | ||
}, | ||
"oldPassword": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"VersionDetails": { | ||
"type": "object", | ||
"properties": { | ||
"application": { | ||
"type": "string" | ||
}, | ||
"network": { | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"p2PMessage": { | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"localDB": { | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"tradeProtocol": { | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
} | ||
} | ||
}, | ||
"securitySchemes": { | ||
"authorization": { | ||
"type": "apiKey", | ||
"name": "authorization", | ||
"in": "header" | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!-- HTML for static distribution bundle build --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Swagger UI</title> | ||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" > | ||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> | ||
<style> | ||
html | ||
{ | ||
box-sizing: border-box; | ||
overflow: -moz-scrollbars-vertical; | ||
overflow-y: scroll; | ||
} | ||
|
||
*, | ||
*:before, | ||
*:after | ||
{ | ||
box-sizing: inherit; | ||
} | ||
|
||
body | ||
{ | ||
margin:0; | ||
background: #fafafa; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="swagger-ui"></div> | ||
|
||
<script src="./swagger-ui-bundle.js"> </script> | ||
<script> | ||
window.onload = function() { | ||
// Begin Swagger UI call region | ||
const ui = SwaggerUIBundle({ | ||
url: "/openapi.json", | ||
dom_id: '#swagger-ui', | ||
deepLinking: true, | ||
presets: [ | ||
SwaggerUIBundle.presets.apis | ||
], | ||
plugins: [ | ||
SwaggerUIBundle.plugins.DownloadUrl | ||
], | ||
layout: "BaseLayout" | ||
}); | ||
// End Swagger UI call region | ||
|
||
window.ui = ui | ||
} | ||
</script> | ||
</body> | ||
</html> |
98 changes: 98 additions & 0 deletions
98
api/src/main/resources/META-INF/swagger/ui/swagger-ui-bundle.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
api/src/test/java/bisq/api/http/service/auth/SwaggerGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package bisq.api.http.service.auth; | ||
|
||
import bisq.api.http.service.HttpApiInterfaceV1; | ||
|
||
|
||
|
||
import io.swagger.v3.core.util.Json; | ||
import io.swagger.v3.jaxrs2.Reader; | ||
import io.swagger.v3.oas.integration.SwaggerConfiguration; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
|
||
public class SwaggerGenerator { | ||
|
||
public static void main(String[] args) { | ||
Reader reader = new Reader(new SwaggerConfiguration()); | ||
OpenAPI openAPI = reader.read(HttpApiInterfaceV1.class); | ||
System.out.println(Json.pretty(openAPI)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package bisq.api.http; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
|
||
|
||
import org.arquillian.cube.docker.impl.client.containerobject.dsl.Container; | ||
import org.arquillian.cube.docker.impl.client.containerobject.dsl.DockerContainer; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.junit.InSequence; | ||
|
||
@RunWith(Arquillian.class) | ||
public class SwaggerIT { | ||
|
||
@DockerContainer | ||
private Container alice = ContainerFactory.createApiContainer("alice", "8081->8080", 3333, false, false); | ||
|
||
@InSequence(1) | ||
@Test | ||
public void getDocs_always_returns200() { | ||
int alicePort = getAlicePort(); | ||
|
||
given(). | ||
port(alicePort). | ||
// | ||
when(). | ||
get("/docs"). | ||
// | ||
then(). | ||
statusCode(200). | ||
and().body(containsString("Swagger UI")) | ||
; | ||
} | ||
|
||
@InSequence(1) | ||
@Test | ||
public void getOpenApiJson_always_returns200() { | ||
int alicePort = getAlicePort(); | ||
|
||
given(). | ||
port(alicePort). | ||
// | ||
when(). | ||
get("/openapi.json"). | ||
// | ||
then(). | ||
statusCode(200). | ||
and().body("info.title", equalTo("Bisq HTTP API")) | ||
; | ||
} | ||
|
||
private int getAlicePort() { | ||
return alice.getBindPort(8080); | ||
} | ||
|
||
} |
Oops, something went wrong.