Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Commit f89dfd8

Browse files
authored
Merge pull request #25 from Virtual-Finland-Development/feat/automatic-openapi-specs
Feat/automatic openapi specs
2 parents 0fea7af + d2ce466 commit f89dfd8

File tree

43 files changed

+1222
-941
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1222
-941
lines changed

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,29 @@ name = "testbed_api"
33
version = "1.0.0"
44
edition = "2021"
55

6+
[workspace]
7+
8+
[workspace.dependencies]
9+
serde_json = "^1.0.87"
10+
serde = { version = "^1.0.147", features = ["derive"] }
11+
log = "^0.4.17"
12+
http = "^0.2.8"
13+
reqwest = { version = "^0.11.12", features = ["json"] }
14+
simple_logger = "^4.0.0"
15+
lambda_http = "^0.7.1"
16+
futures = "^0.3.18"
17+
itertools = "^0.10.5"
18+
libmath = "^0.2.1"
19+
stopwatch = "^0.0.7"
20+
utoipa = "3"
21+
622
[dependencies]
723
hot-lib-reloader = { version = "^0.6", optional = true }
824
tokio = { version = "^1.21.2", features = ["full"] }
925
dotenv = "^0.15.0"
26+
log = { workspace = true }
27+
simple_logger = { workspace = true }
28+
lambda_http = { workspace = true }
1029
api_app = { path = "./src/lib/api_app" }
1130
http_server = { path = "./src/lib/http_server" }
1231
lambda_service = { path = "./src/lib/lambda_service" }

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ make run-sam
8383
### Docker
8484

8585
- https://hub.docker.com/_/rust/
86+
87+
### OpenAPI
88+
89+
- Automatic generation of OpenAPI spec: https://github.com/juhaku/utoipa

openapi/index.html

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="description" content="SwaggerUI" />
88
<title>SwaggerUI</title>
9-
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" />
9+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.15.5/swagger-ui.css" />
1010
</head>
1111

1212
<body>
1313
<div id="swagger-ui"></div>
14-
<script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" crossorigin></script>
14+
<script src="https://unpkg.com/swagger-ui-dist@4.15.5/swagger-ui-bundle.js" crossorigin></script>
1515
<script>
1616
// @see: https://stackoverflow.com/a/68871496
1717
// Examples map
@@ -46,7 +46,7 @@
4646
}
4747

4848
// Custom plugin for the logic that happens before the response element is created
49-
const CustomPlugin = () => {
49+
const ExtrenalSchemaPopulatePlugin = () => {
5050
return {
5151
wrapComponents: {
5252
RequestBody: (Original, { React, oas3Actions, oas3Selectors }) => (props) => {
@@ -62,7 +62,8 @@
6262
} else {
6363
const resolveData = (data) => {
6464
// Dirtly parse content
65-
const ref = data.paths[Object.keys(data.paths)[0]].post.requestBody.content[contentType].schema["$ref"];
65+
const method = "post";
66+
const ref = data.paths[Object.keys(data.paths)[0]][method].requestBody.content[contentType].schema["$ref"];
6667
const component = ref.split("/").pop();
6768
// Put downloaded file content into the examples map
6869
examples[externalValueUrlKey] = {
@@ -100,7 +101,11 @@
100101
props.response = parseSchemaObject(props.response, examples[externalValueUrlKey].schema, contentType)
101102
} else {
102103
const resolveData = (data) => {
103-
const ref = data.paths[Object.keys(data.paths)[0]][props.method].responses[Number(props.code)].content[contentType].schema["$ref"];
104+
let method = props.method;
105+
if (method === "get" && props.path.startsWith("/testbed/productizer")) {
106+
method = "post";
107+
}
108+
const ref = data.paths[Object.keys(data.paths)[0]][method].responses[Number(props.code)].content[contentType].schema["$ref"];
104109
const component = ref.split("/").pop();
105110
// Put downloaded file content into the examples map
106111
examples[externalValueUrlKey] = {
@@ -145,12 +150,18 @@
145150

146151
window.onload = () => {
147152
window.ui = SwaggerUIBundle({
148-
url: '/openapi.yml',
153+
url: '/openapi.json',
149154
dom_id: '#swagger-ui',
150155
plugins: [
151156
SwaggerUIBundle.plugins.DownloadUrl,
152157
// Add custom plugin
153-
CustomPlugin
158+
ExtrenalSchemaPopulatePlugin
159+
],
160+
layout: "BaseLayout",
161+
deepLinking: true,
162+
presets: [
163+
SwaggerUIBundle.presets.apis,
164+
SwaggerUIBundle.SwaggerUIStandalonePreset
154165
],
155166
});
156167
};

0 commit comments

Comments
 (0)