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:
@@ -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