forked from vloschiavo/powerwall2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (78 loc) · 3.87 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<html>
<head>
<!-- Load the latest Swagger UI code and style from npm using unpkg.com -->
<script src="https://unpkg.com/[email protected]/swagger-ui-bundle.js"></script>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/swagger-ui.css"/>
<title>Tesla Powerwall 2 API</title>
</head>
<body>
<div id="swagger-ui"></div> <!-- Div to hold the UI component -->
<script>
// Add in workaround for externalValue not populating from https://github.com/swagger-api/swagger-ui/issues/5433
// Examples map
const examples = {};
// Custom plugin for logic that happens before the response element is created
const CustomPlugin = () => {
return {
wrapComponents: {
response: (Original, { React, oas3Actions, oas3Selectors }) => (props) => {
const contentType = oas3Selectors.responseContentType(props.path, props.method)
const externalValue = props.response.getIn(['content', contentType, 'examples', props.activeExamplesKey, 'externalValue'])
// Check if externalValue field exists
if (externalValue) {
// Check if examples map already contains externalValue key
if (examples[externalValue]) {
// Set example value directly from examples map
props.response = props.response.setIn(['content', contentType, 'examples', props.activeExamplesKey, 'value'], examples[externalValue])
} else {
fetch(externalValue)
.then(res => res.text())
.then(data => {
// Put downloaded file content into the examples map
examples[externalValue] = data
// Simulate select another example action
oas3Actions.setActiveExamplesMember({
"name": 'fake',
"pathMethod": [props.path, props.method],
"contextType": "responses",
"contextName": props.code
})
// Reselect this example
oas3Actions.setActiveExamplesMember({
"name": props.activeExamplesKey,
"pathMethod": [props.path, props.method],
"contextType": "responses",
"contextName": props.code
})
})
.catch(e => console.error(e))
}
}
return React.createElement(Original, props)
}
}
}
}
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "spec.yaml", //Location of Open API spec in the repo
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
CustomPlugin
],
supportedSubmitMethods: [
"get", "put", "post", "options", "head", "patch", "trace"
]
})
window.ui = ui
}
</script>
</body>
</html>