Skip to content

Commit 0413410

Browse files
authored
Merge pull request #3244 from swagger-api/feature/small-tweaks
Some small tweaks
2 parents e594392 + 49333df commit 0413410

File tree

6 files changed

+52
-45
lines changed

6 files changed

+52
-45
lines changed

.agignore

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

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,

src/core/plugins/spec/selectors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ export const allowTryItOutFor = () => {
256256

257257
// Get the parameter value by parameter name
258258
export function getParameter(state, pathMethod, name, inType) {
259+
pathMethod = pathMethod || []
259260
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
260-
return params.filter( (p) => {
261+
return params.find( (p) => {
261262
return Map.isMap(p) && p.get("name") === name && p.get("in") === inType
262-
}).first()
263+
}) || Map() // Always return a map
263264
}
264265

265266
export const hasHost = createSelector(
@@ -272,6 +273,7 @@ export const hasHost = createSelector(
272273

273274
// Get the parameter values, that the user filled out
274275
export function parameterValues(state, pathMethod, isXml) {
276+
pathMethod = pathMethod || []
275277
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
276278
return params.reduce( (hash, p) => {
277279
let value = isXml && p.get("in") === "body" ? p.get("value_xml") : p.get("value")
@@ -295,6 +297,7 @@ export function parametersIncludeType(parameters, typeValue="") {
295297

296298
// Get the consumes/produces value that the user selected
297299
export function contentTypeValues(state, pathMethod) {
300+
pathMethod = pathMethod || []
298301
let op = spec(state).getIn(["paths", ...pathMethod], fromJS({}))
299302
const parameters = op.get("parameters") || new List()
300303

@@ -313,6 +316,7 @@ export function contentTypeValues(state, pathMethod) {
313316

314317
// Get the consumes/produces by path
315318
export function operationConsumes(state, pathMethod) {
319+
pathMethod = pathMethod || []
316320
return spec(state).getIn(["paths", ...pathMethod, "consumes"], fromJS({}))
317321
}
318322

@@ -329,6 +333,7 @@ export const canExecuteScheme = ( state, path, method ) => {
329333
}
330334

331335
export const validateBeforeExecute = ( state, pathMethod ) => {
336+
pathMethod = pathMethod || []
332337
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
333338
let isValid = true
334339

0 commit comments

Comments
 (0)