Skip to content

Commit 15dbc20

Browse files
authored
Merge branch 'master' into master
2 parents 6ba6039 + 5e72f68 commit 15dbc20

File tree

14 files changed

+126
-64
lines changed

14 files changed

+126
-64
lines changed

.agignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

docs/customization/plugin-api.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const MyWrapSelectorsPlugin = function(system) {
293293

294294
Wrap Components allow you to override a component registered within the system.
295295

296-
Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`.
296+
Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`. If you'd prefer to provide a React component class, `(OriginalComponent, system) => ReactClass` works as well.
297297

298298
```javascript
299299
const MyWrapBuiltinComponentPlugin = function(system) {
@@ -310,9 +310,12 @@ const MyWrapBuiltinComponentPlugin = function(system) {
310310
}
311311
```
312312

313+
Here's another example that includes a code sample of a component that will be wrapped:
314+
313315
```javascript
314-
// Overriding a component from a plugin
316+
///// Overriding a component from a plugin
315317

318+
// Here's our normal, unmodified component.
316319
const MyNumberDisplayPlugin = function(system) {
317320
return {
318321
components: {
@@ -321,13 +324,15 @@ const MyNumberDisplayPlugin = function(system) {
321324
}
322325
}
323326

327+
// Here's a component wrapper defined as a function.
324328
const MyWrapComponentPlugin = function(system) {
325329
return {
326330
wrapComponents: {
327331
NumberDisplay: (Original, system) => (props) => {
328332
if(props.number > 10) {
329333
return <div>
330334
<h3>Warning! Big number ahead.</h3>
335+
<OriginalComponent {...props} />
331336
</div>
332337
} else {
333338
return <Original {...props} />
@@ -336,8 +341,30 @@ const MyWrapComponentPlugin = function(system) {
336341
}
337342
}
338343
}
344+
345+
// Alternatively, here's the same component wrapper defined as a class.
346+
const MyWrapComponentPlugin = function(system) {
347+
return {
348+
wrapComponents: {
349+
NumberDisplay: (Original, system) => class WrappedNumberDisplay extends React.component {
350+
render() {
351+
if(props.number > 10) {
352+
return <div>
353+
<h3>Warning! Big number ahead.</h3>
354+
<OriginalComponent {...props} />
355+
</div>
356+
} else {
357+
return <Original {...props} />
358+
}
359+
}
360+
}
361+
}
362+
}
363+
}
339364
```
340365

366+
367+
341368
##### fn
342369

343370
The fn interface allows you to add helper functions to the system for use elsewhere.

docs/usage/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const ui = SwaggerUIBundle({
4949
presets: [
5050
SwaggerUIBundle.presets.apis,
5151
SwaggerUIBundle.SwaggerUIStandalonePreset
52-
]
52+
],
5353
layout: "StandaloneLayout"
5454
})
5555
```
@@ -86,7 +86,7 @@ This will serve Swagger UI at `/swagger` instead of `/`.
8686
You can embed Swagger-UI's code directly in your HTML by using unkpg's interface:
8787

8888
```html
89-
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js">
89+
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
9090
<!-- `SwaggerUIBundle` is now available on the page -->
9191
```
9292

src/core/components/deep-link.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
4+
export const DeepLink = ({ enabled, path, text }) => {
5+
return (
6+
<a className="nostyle"
7+
onClick={enabled ? (e) => e.preventDefault() : null}
8+
href={enabled ? `#/${path}` : null}>
9+
<span>{text}</span>
10+
</a>
11+
)
12+
}
13+
DeepLink.propTypes = {
14+
enabled: PropTypes.bool,
15+
isShown: PropTypes.bool,
16+
path: PropTypes.string,
17+
text: PropTypes.string
18+
}
19+
20+
export default DeepLink

src/core/components/operation.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ export default class Operation extends PureComponent {
102102
const Schemes = getComponent( "schemes" )
103103
const OperationServers = getComponent( "OperationServers" )
104104
const OperationExt = getComponent( "OperationExt" )
105+
const DeepLink = getComponent( "DeepLink" )
105106

106107
const { showExtensions } = getConfigs()
107108

108109
// Merge in Live Response
109110
if(responses && response && response.size > 0) {
110-
let notDocumented = !responses.get(String(response.get("status")))
111+
let notDocumented = !responses.get(String(response.get("status"))) && !responses.get("default")
111112
response = response.set("notDocumented", notDocumented)
112113
}
113114

@@ -120,12 +121,11 @@ export default class Operation extends PureComponent {
120121
and pulled in with getComponent */}
121122
<span className="opblock-summary-method">{method.toUpperCase()}</span>
122123
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" } >
123-
<a
124-
className="nostyle"
125-
onClick={isDeepLinkingEnabled ? (e) => e.preventDefault() : null}
126-
href={isDeepLinkingEnabled ? `#/${isShownKey.join("/")}` : null}>
127-
<span>{path}</span>
128-
</a>
124+
<DeepLink
125+
enabled={isDeepLinkingEnabled}
126+
isShown={isShown}
127+
path={`${isShownKey.join("/")}`}
128+
text={path} />
129129
<JumpToPath path={specPath} /> {/*TODO: use wrapComponents here, swagger-ui doesn't care about jumpToPath */}
130130
</span>
131131

src/core/components/operations.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class Operations extends React.Component {
3737
const OperationContainer = getComponent("OperationContainer", true)
3838
const Collapse = getComponent("Collapse")
3939
const Markdown = getComponent("Markdown")
40+
const DeepLink = getComponent("DeepLink")
4041

4142
let {
4243
docExpansion,
@@ -79,12 +80,11 @@ export default class Operations extends React.Component {
7980
onClick={() => layoutActions.show(isShownKey, !showTag)}
8081
className={!tagDescription ? "opblock-tag no-desc" : "opblock-tag" }
8182
id={isShownKey.join("-")}>
82-
<a
83-
className="nostyle"
84-
onClick={isDeepLinkingEnabled ? (e) => e.preventDefault() : null}
85-
href= {isDeepLinkingEnabled ? `#/${tag}` : null}>
86-
<span>{tag}</span>
87-
</a>
83+
<DeepLink
84+
enabled={isDeepLinkingEnabled}
85+
isShown={showTag}
86+
path={tag}
87+
text={tag} />
8888
{ !tagDescription ? null :
8989
<small>
9090
<Markdown source={tagDescription} />

src/core/components/param-body.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class ParamBody extends PureComponent {
4747

4848
updateValues = (props) => {
4949
let { specSelectors, pathMethod, param, isExecute, consumesValue="" } = props
50-
let parameter = specSelectors ? specSelectors.getParameter(pathMethod, param.get("name"), param.get("in")) : {}
50+
let parameter = specSelectors ? specSelectors.getParameter(pathMethod, param.get("name"), param.get("in")) : fromJS({})
5151
let isXml = /xml/i.test(consumesValue)
5252
let isJson = /json/i.test(consumesValue)
5353
let paramValue = isXml ? parameter.get("value_xml") : parameter.get("value")

src/core/components/response-body.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export default class ResponseBody extends React.Component {
4343

4444
// Image
4545
} else if (/^image\//i.test(contentType)) {
46-
bodyEl = <img style={{ maxWidth: "100%" }} src={ window.URL.createObjectURL(content) } />
46+
if(contentType.includes("svg")) {
47+
bodyEl = <div> { content } </div>
48+
} else {
49+
bodyEl = <img style={{ maxWidth: "100%" }} src={ window.URL.createObjectURL(content) } />
50+
}
4751

4852
// Audio
4953
} else if (/^audio\//i.test(contentType)) {

src/core/oauth2-authorize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function authorize ( { auth, authActions, errActions, configs, au
4646
authId: name,
4747
source: "validation",
4848
level: "error",
49-
message: "oauth2RedirectUri configuration is not passed. Oauth2 authorization cannot be performed."
49+
message: "oauth2RedirectUrl configuration is not passed. Oauth2 authorization cannot be performed."
5050
})
5151
return
5252
}

src/core/plugins/ast/ast.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,30 @@ export function positionRangeForPath(yaml, path) {
103103

104104
let ast = cachedCompose(yaml)
105105

106-
// simply walks the tree using current path recursively to the point that
106+
// simply walks the tree using astValue path recursively to the point that
107107
// path is empty.
108108
return find(ast)
109109

110-
function find(current) {
111-
if (current.tag === MAP_TAG) {
112-
for (i = 0; i < current.value.length; i++) {
113-
var pair = current.value[i]
110+
function find(astValue, astKeyValue) {
111+
if (astValue.tag === MAP_TAG) {
112+
for (i = 0; i < astValue.value.length; i++) {
113+
var pair = astValue.value[i]
114114
var key = pair[0]
115115
var value = pair[1]
116116

117117
if (key.value === path[0]) {
118118
path.shift()
119-
return find(value)
119+
return find(value, key)
120120
}
121121
}
122122
}
123123

124-
if (current.tag === SEQ_TAG) {
125-
var item = current.value[path[0]]
124+
if (astValue.tag === SEQ_TAG) {
125+
var item = astValue.value[path[0]]
126126

127127
if (item && item.tag) {
128128
path.shift()
129-
return find(item)
129+
return find(item, astKeyValue)
130130
}
131131
}
132132

@@ -135,17 +135,35 @@ export function positionRangeForPath(yaml, path) {
135135
return invalidRange
136136
}
137137

138-
return {
139-
/* jshint camelcase: false */
138+
const range = {
140139
start: {
141-
line: current.start_mark.line,
142-
column: current.start_mark.column
140+
line: astValue.start_mark.line,
141+
column: astValue.start_mark.column,
142+
pointer: astValue.start_mark.pointer,
143143
},
144144
end: {
145-
line: current.end_mark.line,
146-
column: current.end_mark.column
145+
line: astValue.end_mark.line,
146+
column: astValue.end_mark.column,
147+
pointer: astValue.end_mark.pointer,
147148
}
148149
}
150+
151+
if(astKeyValue) {
152+
// eslint-disable-next-line camelcase
153+
range.key_start = {
154+
line: astKeyValue.start_mark.line,
155+
column: astKeyValue.start_mark.column,
156+
pointer: astKeyValue.start_mark.pointer,
157+
}
158+
// eslint-disable-next-line camelcase
159+
range.key_end = {
160+
line: astKeyValue.end_mark.line,
161+
column: astKeyValue.end_mark.column,
162+
pointer: astKeyValue.end_mark.pointer,
163+
}
164+
}
165+
166+
return range
149167
}
150168
}
151169

0 commit comments

Comments
 (0)