Merge pull request #3244 from swagger-api/feature/small-tweaks
Some small tweaks
This commit is contained in:
@@ -47,7 +47,7 @@ export default class ParamBody extends PureComponent {
|
|||||||
|
|
||||||
updateValues = (props) => {
|
updateValues = (props) => {
|
||||||
let { specSelectors, pathMethod, param, isExecute, consumesValue="" } = props
|
let { specSelectors, pathMethod, param, isExecute, consumesValue="" } = props
|
||||||
let parameter = specSelectors ? specSelectors.getParameter(pathMethod, param.get("name"), param.get("in")) : {}
|
let parameter = specSelectors ? specSelectors.getParameter(pathMethod, param.get("name"), param.get("in")) : fromJS({})
|
||||||
let isXml = /xml/i.test(consumesValue)
|
let isXml = /xml/i.test(consumesValue)
|
||||||
let isJson = /json/i.test(consumesValue)
|
let isJson = /json/i.test(consumesValue)
|
||||||
let paramValue = isXml ? parameter.get("value_xml") : parameter.get("value")
|
let paramValue = isXml ? parameter.get("value_xml") : parameter.get("value")
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function authorize ( { auth, authActions, errActions, configs, au
|
|||||||
authId: name,
|
authId: name,
|
||||||
source: "validation",
|
source: "validation",
|
||||||
level: "error",
|
level: "error",
|
||||||
message: "oauth2RedirectUri configuration is not passed. Oauth2 authorization cannot be performed."
|
message: "oauth2RedirectUrl configuration is not passed. Oauth2 authorization cannot be performed."
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,30 +103,30 @@ export function positionRangeForPath(yaml, path) {
|
|||||||
|
|
||||||
let ast = cachedCompose(yaml)
|
let ast = cachedCompose(yaml)
|
||||||
|
|
||||||
// simply walks the tree using current path recursively to the point that
|
// simply walks the tree using astValue path recursively to the point that
|
||||||
// path is empty.
|
// path is empty.
|
||||||
return find(ast)
|
return find(ast)
|
||||||
|
|
||||||
function find(current) {
|
function find(astValue, astKeyValue) {
|
||||||
if (current.tag === MAP_TAG) {
|
if (astValue.tag === MAP_TAG) {
|
||||||
for (i = 0; i < current.value.length; i++) {
|
for (i = 0; i < astValue.value.length; i++) {
|
||||||
var pair = current.value[i]
|
var pair = astValue.value[i]
|
||||||
var key = pair[0]
|
var key = pair[0]
|
||||||
var value = pair[1]
|
var value = pair[1]
|
||||||
|
|
||||||
if (key.value === path[0]) {
|
if (key.value === path[0]) {
|
||||||
path.shift()
|
path.shift()
|
||||||
return find(value)
|
return find(value, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current.tag === SEQ_TAG) {
|
if (astValue.tag === SEQ_TAG) {
|
||||||
var item = current.value[path[0]]
|
var item = astValue.value[path[0]]
|
||||||
|
|
||||||
if (item && item.tag) {
|
if (item && item.tag) {
|
||||||
path.shift()
|
path.shift()
|
||||||
return find(item)
|
return find(item, astKeyValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,17 +135,35 @@ export function positionRangeForPath(yaml, path) {
|
|||||||
return invalidRange
|
return invalidRange
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const range = {
|
||||||
/* jshint camelcase: false */
|
|
||||||
start: {
|
start: {
|
||||||
line: current.start_mark.line,
|
line: astValue.start_mark.line,
|
||||||
column: current.start_mark.column
|
column: astValue.start_mark.column,
|
||||||
|
pointer: astValue.start_mark.pointer,
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
line: current.end_mark.line,
|
line: astValue.end_mark.line,
|
||||||
column: current.end_mark.column
|
column: astValue.end_mark.column,
|
||||||
|
pointer: astValue.end_mark.pointer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(astKeyValue) {
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
range.key_start = {
|
||||||
|
line: astKeyValue.start_mark.line,
|
||||||
|
column: astKeyValue.start_mark.column,
|
||||||
|
pointer: astKeyValue.start_mark.pointer,
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
range.key_end = {
|
||||||
|
line: astKeyValue.end_mark.line,
|
||||||
|
column: astKeyValue.end_mark.column,
|
||||||
|
pointer: astKeyValue.end_mark.pointer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return range
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import YAML from "js-yaml"
|
import YAML from "js-yaml"
|
||||||
import parseUrl from "url-parse"
|
import parseUrl from "url-parse"
|
||||||
import serializeError from "serialize-error"
|
import serializeError from "serialize-error"
|
||||||
|
import isString from "lodash/isString"
|
||||||
import { isJSONObject } from "core/utils"
|
import { isJSONObject } from "core/utils"
|
||||||
|
|
||||||
// Actions conform to FSA (flux-standard-actions)
|
// Actions conform to FSA (flux-standard-actions)
|
||||||
@@ -22,22 +23,16 @@ export const UPDATE_OPERATION_VALUE = "spec_update_operation_value"
|
|||||||
export const UPDATE_RESOLVED = "spec_update_resolved"
|
export const UPDATE_RESOLVED = "spec_update_resolved"
|
||||||
export const SET_SCHEME = "set_scheme"
|
export const SET_SCHEME = "set_scheme"
|
||||||
|
|
||||||
export function updateSpec(spec) {
|
const toStr = (str) => isString(str) ? str : ""
|
||||||
if(spec instanceof Error) {
|
|
||||||
return {type: UPDATE_SPEC, error: true, payload: spec}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export function updateSpec(spec) {
|
||||||
|
const cleanSpec = (toStr(spec)).replace(/\t/g, " ")
|
||||||
if(typeof spec === "string") {
|
if(typeof spec === "string") {
|
||||||
return {
|
return {
|
||||||
type: UPDATE_SPEC,
|
type: UPDATE_SPEC,
|
||||||
payload: spec.replace(/\t/g, " ") || ""
|
payload: cleanSpec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
type: UPDATE_SPEC,
|
|
||||||
payload: ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateResolved(spec) {
|
export function updateResolved(spec) {
|
||||||
@@ -52,9 +47,6 @@ export function updateUrl(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function updateJsonSpec(json) {
|
export function updateJsonSpec(json) {
|
||||||
if(!json || typeof json !== "object") {
|
|
||||||
throw new Error("updateJson must only accept a simple JSON object")
|
|
||||||
}
|
|
||||||
return {type: UPDATE_JSON, payload: json}
|
return {type: UPDATE_JSON, payload: json}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +68,10 @@ export const parseToJson = (str) => ({specActions, specSelectors, errActions}) =
|
|||||||
line: e.mark && e.mark.line ? e.mark.line + 1 : undefined
|
line: e.mark && e.mark.line ? e.mark.line + 1 : undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return specActions.updateJsonSpec(json)
|
if(json) {
|
||||||
|
return specActions.updateJsonSpec(json)
|
||||||
|
}
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const resolveSpec = (json, url) => ({specActions, specSelectors, errActions, fn: { fetch, resolve, AST }, getConfigs}) => {
|
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
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const formatIntoYaml = () => ({specActions, specSelectors}) => {
|
|
||||||
let { specStr } = specSelectors
|
|
||||||
let { updateSpec } = specActions
|
|
||||||
|
|
||||||
try {
|
|
||||||
let yaml = YAML.safeDump(YAML.safeLoad(specStr()), {indent: 2})
|
|
||||||
updateSpec(yaml)
|
|
||||||
} catch(e) {
|
|
||||||
updateSpec(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeParam( path, paramName, paramIn, value, isXml ){
|
export function changeParam( path, paramName, paramIn, value, isXml ){
|
||||||
return {
|
return {
|
||||||
type: UPDATE_PARAM,
|
type: UPDATE_PARAM,
|
||||||
|
|||||||
@@ -256,10 +256,11 @@ export const allowTryItOutFor = () => {
|
|||||||
|
|
||||||
// Get the parameter value by parameter name
|
// Get the parameter value by parameter name
|
||||||
export function getParameter(state, pathMethod, name, inType) {
|
export function getParameter(state, pathMethod, name, inType) {
|
||||||
|
pathMethod = pathMethod || []
|
||||||
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
|
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
|
||||||
return params.filter( (p) => {
|
return params.find( (p) => {
|
||||||
return Map.isMap(p) && p.get("name") === name && p.get("in") === inType
|
return Map.isMap(p) && p.get("name") === name && p.get("in") === inType
|
||||||
}).first()
|
}) || Map() // Always return a map
|
||||||
}
|
}
|
||||||
|
|
||||||
export const hasHost = createSelector(
|
export const hasHost = createSelector(
|
||||||
@@ -272,6 +273,7 @@ export const hasHost = createSelector(
|
|||||||
|
|
||||||
// Get the parameter values, that the user filled out
|
// Get the parameter values, that the user filled out
|
||||||
export function parameterValues(state, pathMethod, isXml) {
|
export function parameterValues(state, pathMethod, isXml) {
|
||||||
|
pathMethod = pathMethod || []
|
||||||
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
|
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
|
||||||
return params.reduce( (hash, p) => {
|
return params.reduce( (hash, p) => {
|
||||||
let value = isXml && p.get("in") === "body" ? p.get("value_xml") : p.get("value")
|
let value = isXml && p.get("in") === "body" ? p.get("value_xml") : p.get("value")
|
||||||
@@ -295,6 +297,7 @@ export function parametersIncludeType(parameters, typeValue="") {
|
|||||||
|
|
||||||
// Get the consumes/produces value that the user selected
|
// Get the consumes/produces value that the user selected
|
||||||
export function contentTypeValues(state, pathMethod) {
|
export function contentTypeValues(state, pathMethod) {
|
||||||
|
pathMethod = pathMethod || []
|
||||||
let op = spec(state).getIn(["paths", ...pathMethod], fromJS({}))
|
let op = spec(state).getIn(["paths", ...pathMethod], fromJS({}))
|
||||||
const parameters = op.get("parameters") || new List()
|
const parameters = op.get("parameters") || new List()
|
||||||
|
|
||||||
@@ -313,6 +316,7 @@ export function contentTypeValues(state, pathMethod) {
|
|||||||
|
|
||||||
// Get the consumes/produces by path
|
// Get the consumes/produces by path
|
||||||
export function operationConsumes(state, pathMethod) {
|
export function operationConsumes(state, pathMethod) {
|
||||||
|
pathMethod = pathMethod || []
|
||||||
return spec(state).getIn(["paths", ...pathMethod, "consumes"], fromJS({}))
|
return spec(state).getIn(["paths", ...pathMethod, "consumes"], fromJS({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,6 +333,7 @@ export const canExecuteScheme = ( state, path, method ) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const validateBeforeExecute = ( state, pathMethod ) => {
|
export const validateBeforeExecute = ( state, pathMethod ) => {
|
||||||
|
pathMethod = pathMethod || []
|
||||||
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
|
let params = spec(state).getIn(["paths", ...pathMethod, "parameters"], fromJS([]))
|
||||||
let isValid = true
|
let isValid = true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user