Skip to content

Commit 2b3a590

Browse files
authored
Merge branch 'master' into patch-1
2 parents f3cb0d7 + 0413410 commit 2b3a590

File tree

13 files changed

+121
-63
lines changed

13 files changed

+121
-63
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/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

src/core/plugins/spec/actions.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import YAML from "js-yaml"
22
import parseUrl from "url-parse"
33
import serializeError from "serialize-error"
4+
import isString from "lodash/isString"
45
import { isJSONObject } from "core/utils"
56

67
// Actions conform to FSA (flux-standard-actions)
@@ -22,22 +23,16 @@ export const UPDATE_OPERATION_VALUE = "spec_update_operation_value"
2223
export const UPDATE_RESOLVED = "spec_update_resolved"
2324
export const SET_SCHEME = "set_scheme"
2425

25-
export function updateSpec(spec) {
26-
if(spec instanceof Error) {
27-
return {type: UPDATE_SPEC, error: true, payload: spec}
28-
}
26+
const toStr = (str) => isString(str) ? str : ""
2927

28+
export function updateSpec(spec) {
29+
const cleanSpec = (toStr(spec)).replace(/\t/g, " ")
3030
if(typeof spec === "string") {
3131
return {
3232
type: UPDATE_SPEC,
33-
payload: spec.replace(/\t/g, " ") || ""
33+
payload: cleanSpec
3434
}
3535
}
36-
37-
return {
38-
type: UPDATE_SPEC,
39-
payload: ""
40-
}
4136
}
4237

4338
export function updateResolved(spec) {
@@ -52,9 +47,6 @@ export function updateUrl(url) {
5247
}
5348

5449
export function updateJsonSpec(json) {
55-
if(!json || typeof json !== "object") {
56-
throw new Error("updateJson must only accept a simple JSON object")
57-
}
5850
return {type: UPDATE_JSON, payload: json}
5951
}
6052

@@ -76,7 +68,10 @@ export const parseToJson = (str) => ({specActions, specSelectors, errActions}) =
7668
line: e.mark && e.mark.line ? e.mark.line + 1 : undefined
7769
})
7870
}
79-
return specActions.updateJsonSpec(json)
71+
if(json) {
72+
return specActions.updateJsonSpec(json)
73+
}
74+
return {}
8075
}
8176

8277
export const resolveSpec = (json, url) => ({specActions, specSelectors, errActions, fn: { fetch, resolve, AST }, getConfigs}) => {
@@ -130,18 +125,6 @@ export const resolveSpec = (json, url) => ({specActions, specSelectors, errActio
130125
})
131126
}
132127

133-
export const formatIntoYaml = () => ({specActions, specSelectors}) => {
134-
let { specStr } = specSelectors
135-
let { updateSpec } = specActions
136-
137-
try {
138-
let yaml = YAML.safeDump(YAML.safeLoad(specStr()), {indent: 2})
139-
updateSpec(yaml)
140-
} catch(e) {
141-
updateSpec(e)
142-
}
143-
}
144-
145128
export function changeParam( path, paramName, paramIn, value, isXml ){
146129
return {
147130
type: UPDATE_PARAM,

0 commit comments

Comments
 (0)