feature: Docker OAuth block support (via #4987)
* add `onFound` callback to schemas * add warning to method docs (for #4957) * implement Docker OAuth2 init block support * update docs * add OAUTH_SCOPE_SEPARATOR * drop OAuth env from Dockerfile and run script * don't indent the first oauth block line * drop unused `dedent` import * touch up warning message * add more test cases * return an empty block if no OAuth content is generated * fix broken doc line
This commit is contained in:
@@ -3,18 +3,43 @@ const translator = require("../../docker/configurator/translator")
|
||||
const dedent = require("dedent")
|
||||
|
||||
describe("docker: env translator", function() {
|
||||
it("should generate an empty baseline config", function() {
|
||||
const input = {}
|
||||
describe("fundamentals", function() {
|
||||
it("should generate an empty baseline config", function () {
|
||||
const input = {}
|
||||
|
||||
expect(translator(input)).toEqual(``)
|
||||
expect(translator(input)).toEqual(``)
|
||||
})
|
||||
|
||||
it("should call an onFound callback", function () {
|
||||
const input = {
|
||||
MY_THING: "hey"
|
||||
}
|
||||
|
||||
const onFoundSpy = expect.createSpy()
|
||||
|
||||
const schema = {
|
||||
MY_THING: {
|
||||
type: "string",
|
||||
name: "myThing",
|
||||
onFound: onFoundSpy
|
||||
}
|
||||
}
|
||||
|
||||
const res = translator(input, {
|
||||
schema
|
||||
})
|
||||
expect(res).toEqual(`myThing: "hey",`)
|
||||
expect(onFoundSpy.calls.length).toEqual(1)
|
||||
|
||||
})
|
||||
})
|
||||
describe("Swagger UI configuration", function() {
|
||||
it("should generate a base config including the base content", function () {
|
||||
const input = {}
|
||||
|
||||
it("should generate a base config including the base content", function() {
|
||||
const input = {}
|
||||
|
||||
expect(translator(input, {
|
||||
injectBaseConfig: true
|
||||
})).toEqual(dedent(`
|
||||
expect(translator(input, {
|
||||
injectBaseConfig: true
|
||||
})).toEqual(dedent(`
|
||||
url: "https://petstore.swagger.io/v2/swagger.json",
|
||||
"dom_id": "#swagger-ui",
|
||||
deepLinking: true,
|
||||
@@ -27,121 +52,121 @@ describe("docker: env translator", function() {
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
`))
|
||||
})
|
||||
})
|
||||
|
||||
it("should ignore an unknown config", function() {
|
||||
const input = {
|
||||
ASDF1234: "wow hello"
|
||||
}
|
||||
it("should ignore an unknown config", function () {
|
||||
const input = {
|
||||
ASDF1234: "wow hello"
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(``))
|
||||
})
|
||||
expect(translator(input)).toEqual(dedent(``))
|
||||
})
|
||||
|
||||
it("should generate a string config", function() {
|
||||
const input = {
|
||||
URL: "http://petstore.swagger.io/v2/swagger.json",
|
||||
FILTER: ""
|
||||
}
|
||||
it("should generate a string config", function () {
|
||||
const input = {
|
||||
URL: "http://petstore.swagger.io/v2/swagger.json",
|
||||
FILTER: ""
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
url: "http://petstore.swagger.io/v2/swagger.json",
|
||||
filter: "",`
|
||||
).trim())
|
||||
})
|
||||
).trim())
|
||||
})
|
||||
|
||||
it("should generate a boolean config", function() {
|
||||
const input = {
|
||||
DEEP_LINKING: "true",
|
||||
SHOW_EXTENSIONS: "false",
|
||||
SHOW_COMMON_EXTENSIONS: ""
|
||||
}
|
||||
it("should generate a boolean config", function () {
|
||||
const input = {
|
||||
DEEP_LINKING: "true",
|
||||
SHOW_EXTENSIONS: "false",
|
||||
SHOW_COMMON_EXTENSIONS: ""
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
deepLinking: true,
|
||||
showExtensions: false,
|
||||
showCommonExtensions: undefined,`
|
||||
))
|
||||
})
|
||||
))
|
||||
})
|
||||
|
||||
it("should generate an object config", function() {
|
||||
const input = {
|
||||
SPEC: `{ swagger: "2.0" }`
|
||||
}
|
||||
it("should generate an object config", function () {
|
||||
const input = {
|
||||
SPEC: `{ swagger: "2.0" }`
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
spec: { swagger: "2.0" },`
|
||||
).trim())
|
||||
})
|
||||
})
|
||||
|
||||
it("should generate an array config", function() {
|
||||
const input = {
|
||||
URLS: `["/one", "/two"]`,
|
||||
SUPPORTED_SUBMIT_METHODS: ""
|
||||
}
|
||||
it("should generate an array config", function () {
|
||||
const input = {
|
||||
URLS: `["/one", "/two"]`,
|
||||
SUPPORTED_SUBMIT_METHODS: ""
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
urls: ["/one", "/two"],
|
||||
supportedSubmitMethods: undefined,`
|
||||
).trim())
|
||||
})
|
||||
})
|
||||
|
||||
it("should properly escape key names when necessary", function () {
|
||||
const input = {
|
||||
URLS: `["/one", "/two"]`,
|
||||
URLS_PRIMARY_NAME: "one",
|
||||
}
|
||||
it("should properly escape key names when necessary", function () {
|
||||
const input = {
|
||||
URLS: `["/one", "/two"]`,
|
||||
URLS_PRIMARY_NAME: "one",
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
urls: ["/one", "/two"],
|
||||
"urls.primaryName": "one",`
|
||||
).trim())
|
||||
})
|
||||
})
|
||||
|
||||
it("should disregard a legacy variable in favor of a regular one", function() {
|
||||
const input = {
|
||||
// Order is important to this test... legacy vars should be
|
||||
// superseded regardless of what is fed in first.
|
||||
API_URL: "/old.json",
|
||||
URL: "/swagger.json",
|
||||
URLS: `["/one", "/two"]`,
|
||||
API_URLS: `["/three", "/four"]`,
|
||||
}
|
||||
it("should disregard a legacy variable in favor of a regular one", function () {
|
||||
const input = {
|
||||
// Order is important to this test... legacy vars should be
|
||||
// superseded regardless of what is fed in first.
|
||||
API_URL: "/old.json",
|
||||
URL: "/swagger.json",
|
||||
URLS: `["/one", "/two"]`,
|
||||
API_URLS: `["/three", "/four"]`,
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
url: "/swagger.json",
|
||||
urls: ["/one", "/two"],`
|
||||
).trim())
|
||||
})
|
||||
})
|
||||
|
||||
it("should generate a full config k:v string", function() {
|
||||
const input = {
|
||||
API_URL: "/old.yaml",
|
||||
API_URLS: `["/old", "/older"]`,
|
||||
CONFIG_URL: "/wow",
|
||||
DOM_ID: "#swagger_ui",
|
||||
SPEC: `{ swagger: "2.0" }`,
|
||||
URL: "/swagger.json",
|
||||
URLS: `["/one", "/two"]`,
|
||||
URLS_PRIMARY_NAME: "one",
|
||||
LAYOUT: "BaseLayout",
|
||||
DEEP_LINKING: "false",
|
||||
DISPLAY_OPERATION_ID: "true",
|
||||
DEFAULT_MODELS_EXPAND_DEPTH: "0",
|
||||
DEFAULT_MODEL_EXPAND_DEPTH: "1",
|
||||
DEFAULT_MODEL_RENDERING: "example",
|
||||
DISPLAY_REQUEST_DURATION: "true",
|
||||
DOC_EXPANSION: "full",
|
||||
FILTER: "wowee",
|
||||
MAX_DISPLAYED_TAGS: "4",
|
||||
SHOW_EXTENSIONS: "true",
|
||||
SHOW_COMMON_EXTENSIONS: "false",
|
||||
OAUTH2_REDIRECT_URL: "http://google.com/",
|
||||
SHOW_MUTATED_REQUEST: "true",
|
||||
SUPPORTED_SUBMIT_METHODS: `["get", "post"]`,
|
||||
VALIDATOR_URL: "http://smartbear.com/"
|
||||
}
|
||||
it("should generate a full config k:v string", function () {
|
||||
const input = {
|
||||
API_URL: "/old.yaml",
|
||||
API_URLS: `["/old", "/older"]`,
|
||||
CONFIG_URL: "/wow",
|
||||
DOM_ID: "#swagger_ui",
|
||||
SPEC: `{ swagger: "2.0" }`,
|
||||
URL: "/swagger.json",
|
||||
URLS: `["/one", "/two"]`,
|
||||
URLS_PRIMARY_NAME: "one",
|
||||
LAYOUT: "BaseLayout",
|
||||
DEEP_LINKING: "false",
|
||||
DISPLAY_OPERATION_ID: "true",
|
||||
DEFAULT_MODELS_EXPAND_DEPTH: "0",
|
||||
DEFAULT_MODEL_EXPAND_DEPTH: "1",
|
||||
DEFAULT_MODEL_RENDERING: "example",
|
||||
DISPLAY_REQUEST_DURATION: "true",
|
||||
DOC_EXPANSION: "full",
|
||||
FILTER: "wowee",
|
||||
MAX_DISPLAYED_TAGS: "4",
|
||||
SHOW_EXTENSIONS: "true",
|
||||
SHOW_COMMON_EXTENSIONS: "false",
|
||||
OAUTH2_REDIRECT_URL: "http://google.com/",
|
||||
SHOW_MUTATED_REQUEST: "true",
|
||||
SUPPORTED_SUBMIT_METHODS: `["get", "post"]`,
|
||||
VALIDATOR_URL: "http://smartbear.com/"
|
||||
}
|
||||
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
expect(translator(input)).toEqual(dedent(`
|
||||
configUrl: "/wow",
|
||||
"dom_id": "#swagger_ui",
|
||||
spec: { swagger: "2.0" },
|
||||
@@ -165,37 +190,37 @@ describe("docker: env translator", function() {
|
||||
supportedSubmitMethods: ["get", "post"],
|
||||
validatorUrl: "http://smartbear.com/",`
|
||||
).trim())
|
||||
})
|
||||
})
|
||||
|
||||
it("should generate a full config k:v string including base config", function() {
|
||||
const input = {
|
||||
API_URL: "/old.yaml",
|
||||
API_URLS: `["/old", "/older"]`,
|
||||
CONFIG_URL: "/wow",
|
||||
DOM_ID: "#swagger_ui",
|
||||
SPEC: `{ swagger: "2.0" }`,
|
||||
URL: "/swagger.json",
|
||||
URLS: `["/one", "/two"]`,
|
||||
URLS_PRIMARY_NAME: "one",
|
||||
LAYOUT: "BaseLayout",
|
||||
DEEP_LINKING: "false",
|
||||
DISPLAY_OPERATION_ID: "true",
|
||||
DEFAULT_MODELS_EXPAND_DEPTH: "0",
|
||||
DEFAULT_MODEL_EXPAND_DEPTH: "1",
|
||||
DEFAULT_MODEL_RENDERING: "example",
|
||||
DISPLAY_REQUEST_DURATION: "true",
|
||||
DOC_EXPANSION: "full",
|
||||
FILTER: "wowee",
|
||||
MAX_DISPLAYED_TAGS: "4",
|
||||
SHOW_EXTENSIONS: "true",
|
||||
SHOW_COMMON_EXTENSIONS: "false",
|
||||
OAUTH2_REDIRECT_URL: "http://google.com/",
|
||||
SHOW_MUTATED_REQUEST: "true",
|
||||
SUPPORTED_SUBMIT_METHODS: `["get", "post"]`,
|
||||
VALIDATOR_URL: "http://smartbear.com/"
|
||||
}
|
||||
it("should generate a full config k:v string including base config", function () {
|
||||
const input = {
|
||||
API_URL: "/old.yaml",
|
||||
API_URLS: `["/old", "/older"]`,
|
||||
CONFIG_URL: "/wow",
|
||||
DOM_ID: "#swagger_ui",
|
||||
SPEC: `{ swagger: "2.0" }`,
|
||||
URL: "/swagger.json",
|
||||
URLS: `["/one", "/two"]`,
|
||||
URLS_PRIMARY_NAME: "one",
|
||||
LAYOUT: "BaseLayout",
|
||||
DEEP_LINKING: "false",
|
||||
DISPLAY_OPERATION_ID: "true",
|
||||
DEFAULT_MODELS_EXPAND_DEPTH: "0",
|
||||
DEFAULT_MODEL_EXPAND_DEPTH: "1",
|
||||
DEFAULT_MODEL_RENDERING: "example",
|
||||
DISPLAY_REQUEST_DURATION: "true",
|
||||
DOC_EXPANSION: "full",
|
||||
FILTER: "wowee",
|
||||
MAX_DISPLAYED_TAGS: "4",
|
||||
SHOW_EXTENSIONS: "true",
|
||||
SHOW_COMMON_EXTENSIONS: "false",
|
||||
OAUTH2_REDIRECT_URL: "http://google.com/",
|
||||
SHOW_MUTATED_REQUEST: "true",
|
||||
SUPPORTED_SUBMIT_METHODS: `["get", "post"]`,
|
||||
VALIDATOR_URL: "http://smartbear.com/"
|
||||
}
|
||||
|
||||
expect(translator(input, { injectBaseConfig: true })).toEqual(dedent(`
|
||||
expect(translator(input, { injectBaseConfig: true })).toEqual(dedent(`
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
@@ -226,5 +251,6 @@ describe("docker: env translator", function() {
|
||||
supportedSubmitMethods: ["get", "post"],
|
||||
validatorUrl: "http://smartbear.com/",`
|
||||
).trim())
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user