Improvement: Hash-keyed Try-It-Out parameter value storage (#4670)
* allow param update by identity + hashed value storage * add specActions.changeParamByIdentity * add identity-based lookup support in spec selectors * migrate `changeParam` usage to `changeParamByIdentity` * migrate usage of `parameterWithMeta` to `parameterWithMetaByIdentity` * update invocations of `changeParamByIdentity` to match fn signature * use OrderedMap throughout hash-based selectors for consistency * normalize usage of ParameterRow `onChange` * migrate bug 4557 tests to reflect new ParameterRow interface * remove exclusive test blocks * linter fixes * copy Parameters changes into OAS3 wrapper * use rawParam for meta lookups in ParameterRow
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { execute, executeRequest } from "corePlugins/spec/actions"
|
||||
import { execute, executeRequest, changeParamByIdentity } from "corePlugins/spec/actions"
|
||||
|
||||
describe("spec plugin - actions", function(){
|
||||
|
||||
@@ -184,4 +184,27 @@ describe("spec plugin - actions", function(){
|
||||
it.skip("should call errActions.newErr, if the fn.execute rejects", function(){
|
||||
})
|
||||
|
||||
describe("changeParamByIdentity", function () {
|
||||
it("should map its arguments to a payload", function () {
|
||||
const pathMethod = ["/one", "get"]
|
||||
const param = fromJS({
|
||||
name: "body",
|
||||
in: "body"
|
||||
})
|
||||
const value = "my value"
|
||||
const isXml = false
|
||||
|
||||
const result = changeParamByIdentity(pathMethod, param, value, isXml)
|
||||
|
||||
expect(result).toEqual({
|
||||
type: "spec_update_param",
|
||||
payload: {
|
||||
path: pathMethod,
|
||||
param,
|
||||
value,
|
||||
isXml
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -129,4 +129,53 @@ describe("spec plugin - reducer", function(){
|
||||
expect(response).toEqual(expectedResult)
|
||||
})
|
||||
})
|
||||
describe("SPEC_UPDATE_PARAM", function() {
|
||||
it("should store parameter values by name+in", () => {
|
||||
const updateParam = reducer["spec_update_param"]
|
||||
|
||||
const path = "/pet/post"
|
||||
const method = "POST"
|
||||
|
||||
const state = fromJS({})
|
||||
const result = updateParam(state, {
|
||||
payload: {
|
||||
path: [path, method],
|
||||
paramName: "body",
|
||||
paramIn: "body",
|
||||
value: `{ "a": 123 }`,
|
||||
isXml: false
|
||||
}
|
||||
})
|
||||
|
||||
const response = result.getIn(["meta", "paths", path, method, "parameters", "body.body", "value"])
|
||||
expect(response).toEqual(`{ "a": 123 }`)
|
||||
})
|
||||
it("should store parameter values by identity", () => {
|
||||
const updateParam = reducer["spec_update_param"]
|
||||
|
||||
const path = "/pet/post"
|
||||
const method = "POST"
|
||||
|
||||
const param = fromJS({
|
||||
name: "body",
|
||||
in: "body",
|
||||
schema: {
|
||||
type: "string"
|
||||
}
|
||||
})
|
||||
|
||||
const state = fromJS({})
|
||||
const result = updateParam(state, {
|
||||
payload: {
|
||||
param,
|
||||
path: [path, method],
|
||||
value: `{ "a": 123 }`,
|
||||
isXml: false
|
||||
}
|
||||
})
|
||||
|
||||
const value = result.getIn(["meta", "paths", path, method, "parameters", `body.body.hash-${param.hashCode()}`, "value"])
|
||||
expect(value).toEqual(`{ "a": 123 }`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,6 +11,11 @@ import {
|
||||
} from "corePlugins/spec/selectors"
|
||||
|
||||
import Petstore from "./assets/petstore.json"
|
||||
import {
|
||||
operationWithMeta,
|
||||
parameterWithMeta,
|
||||
parameterWithMetaByIdentity
|
||||
} from "../../../../src/core/plugins/spec/selectors"
|
||||
|
||||
describe("spec plugin - selectors", function(){
|
||||
|
||||
@@ -451,4 +456,260 @@ describe("spec plugin - selectors", function(){
|
||||
expect(result.getIn(["paths"]).keySeq().toJS()).toEqual(correctOrder)
|
||||
})
|
||||
})
|
||||
|
||||
describe("operationWithMeta", function() {
|
||||
it("should support merging in name+in keyed param metadata", function () {
|
||||
const state = fromJS({
|
||||
json: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: [
|
||||
{
|
||||
name: "body",
|
||||
in: "body"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: {
|
||||
"body.body": {
|
||||
value: "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = operationWithMeta(state, "/", "get")
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
parameters: [
|
||||
{
|
||||
name: "body",
|
||||
in: "body",
|
||||
value: "abc123"
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
it("should support merging in hash-keyed param metadata", function () {
|
||||
const bodyParam = fromJS({
|
||||
name: "body",
|
||||
in: "body"
|
||||
})
|
||||
|
||||
const state = fromJS({
|
||||
json: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: [
|
||||
bodyParam
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: {
|
||||
[`body.body.hash-${bodyParam.hashCode()}`]: {
|
||||
value: "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = operationWithMeta(state, "/", "get")
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
parameters: [
|
||||
{
|
||||
name: "body",
|
||||
in: "body",
|
||||
value: "abc123"
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
describe("parameterWithMeta", function() {
|
||||
it("should support merging in name+in keyed param metadata", function () {
|
||||
const state = fromJS({
|
||||
json: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: [
|
||||
{
|
||||
name: "body",
|
||||
in: "body"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: {
|
||||
"body.body": {
|
||||
value: "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = parameterWithMeta(state, ["/", "get"], "body", "body")
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
name: "body",
|
||||
in: "body",
|
||||
value: "abc123"
|
||||
})
|
||||
})
|
||||
it("should give best-effort when encountering hash-keyed param metadata", function () {
|
||||
const bodyParam = fromJS({
|
||||
name: "body",
|
||||
in: "body"
|
||||
})
|
||||
|
||||
const state = fromJS({
|
||||
json: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: [
|
||||
bodyParam
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: {
|
||||
[`body.body.hash-${bodyParam.hashCode()}`]: {
|
||||
value: "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = parameterWithMeta(state, ["/", "get"], "body", "body")
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
name: "body",
|
||||
in: "body",
|
||||
value: "abc123"
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
describe("parameterWithMetaByIdentity", function() {
|
||||
it("should support merging in name+in keyed param metadata", function () {
|
||||
const bodyParam = fromJS({
|
||||
name: "body",
|
||||
in: "body"
|
||||
})
|
||||
|
||||
const state = fromJS({
|
||||
json: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: [bodyParam]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: {
|
||||
"body.body": {
|
||||
value: "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = parameterWithMetaByIdentity(state, ["/", "get"], bodyParam)
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
name: "body",
|
||||
in: "body",
|
||||
value: "abc123"
|
||||
})
|
||||
})
|
||||
it("should support merging in hash-keyed param metadata", function () {
|
||||
const bodyParam = fromJS({
|
||||
name: "body",
|
||||
in: "body"
|
||||
})
|
||||
|
||||
const state = fromJS({
|
||||
json: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: [
|
||||
bodyParam
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
parameters: {
|
||||
[`body.body.hash-${bodyParam.hashCode()}`]: {
|
||||
value: "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = parameterWithMetaByIdentity(state, ["/", "get"], bodyParam)
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
name: "body",
|
||||
in: "body",
|
||||
value: "abc123"
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user