Skip to content

Commit d003df2

Browse files
authored
Merge branch 'master' into base-url
2 parents 8223710 + 5015348 commit d003df2

File tree

5 files changed

+172
-16
lines changed

5 files changed

+172
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ displayRequestDuration | Controls the display of the request duration (in millis
170170
maxDisplayedTags | If set, limits the number of tagged operations displayed to at most this many. The default is to show all operations.
171171
filter | If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. Can be true/false to enable or disable, or an explicit filter string in which case filtering will be enabled using that string as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag.
172172
deepLinking | If set to `true`, enables dynamic deep linking for tags and operations. [Docs](https://github.com/swagger-api/swagger-ui/blob/master/docs/deep-linking.md)
173-
requestInterceptor | MUST be a function. Function to intercept try-it-out requests. Accepts one argument requestInterceptor(request) and must return the potentially modified request.
174-
responseInterceptor | MUST be a function. Function to intercept try-it-out responses. Accepts one argument responseInterceptor(response) and must return the potentially modified response.
173+
requestInterceptor | MUST be a function. Function to intercept remote definition, Try-It-Out, and OAuth2 requests. Accepts one argument requestInterceptor(request) and must return the potentially modified request.
174+
responseInterceptor | MUST be a function. Function to intercept remote definition, Try-It-Out, and OAuth2 responses. Accepts one argument responseInterceptor(response) and must return the potentially modified response.
175175
showMutatedRequest | If set to `true` (the default), uses the mutated request returned from a rquestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
176176
showExtensions | Controls the display of vendor extension (`x-`) fields and values for Operations, Parameters, and Schema. The default is `false`.
177177

src/core/components/layout-utils.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class Select extends React.Component {
183183
{ allowEmptyValue ? <option value="">--</option> : null }
184184
{
185185
allowedValues.map(function (item, key) {
186-
return <option key={ key } value={ String(item) }>{ item }</option>
186+
return <option key={ key } value={ String(item) }>{ String(item) }</option>
187187
})
188188
}
189189
</select>

src/core/json-schema-components.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class JsonSchemaForm extends Component {
3636

3737
let { type, format="" } = schema
3838

39-
let Comp = getComponent(`JsonSchema_${type}_${format}`) || getComponent(`JsonSchema_${type}`) || getComponent("JsonSchema_string")
39+
let Comp = (format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`)) || getComponent("JsonSchema_string")
4040
return <Comp { ...this.props } fn={fn} getComponent={getComponent} value={value} onChange={onChange} schema={schema}/>
4141
}
4242

@@ -68,19 +68,19 @@ export class JsonSchema_string extends Component {
6868
const isDisabled = schema["in"] === "formData" && !("FormData" in window)
6969
const Input = getComponent("Input")
7070
if (schema["type"] === "file") {
71-
return (<Input type="file"
72-
className={ errors.length ? "invalid" : ""}
71+
return (<Input type="file"
72+
className={ errors.length ? "invalid" : ""}
7373
title={ errors.length ? errors : ""}
74-
onChange={ this.onChange }
74+
onChange={ this.onChange }
7575
disabled={isDisabled}/>)
7676
}
7777
else {
78-
return (<Input type={ schema.format === "password" ? "password" : "text" }
79-
className={ errors.length ? "invalid" : ""}
78+
return (<Input type={ schema.format === "password" ? "password" : "text" }
79+
className={ errors.length ? "invalid" : ""}
8080
title={ errors.length ? errors : ""}
81-
value={value}
82-
placeholder={description}
83-
onChange={ this.onChange }
81+
value={value}
82+
placeholder={description}
83+
onChange={ this.onChange }
8484
disabled={isDisabled}/>)
8585
}
8686
}
@@ -189,8 +189,8 @@ export class JsonSchema_boolean extends Component {
189189
return (<Select className={ errors.length ? "invalid" : ""}
190190
title={ errors.length ? errors : ""}
191191
value={ String(value) }
192-
allowedValues={ fromJS(["true", "false"]) }
193-
allowEmptyValue={ true }
192+
allowedValues={ fromJS(schema.enum || ["true", "false"]) }
193+
allowEmptyValue={ !this.props.required }
194194
onChange={ this.onEnumChange }/>)
195195
}
196196
}

src/core/plugins/auth/actions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const authorizeAccessCodeWithBasicAuthentication = ( { auth, redirectUrl
139139
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth, headers})
140140
}
141141

142-
export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, authSelectors } ) => {
142+
export const authorizeRequest = ( data ) => ( { fn, getConfigs, authActions, errActions, authSelectors } ) => {
143143
let { body, query={}, headers={}, name, url, auth } = data
144144
let { additionalQueryStringParams } = authSelectors.getConfigs() || {}
145145
let fetchUrl = url
@@ -158,7 +158,9 @@ export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, aut
158158
method: "post",
159159
headers: _headers,
160160
query: query,
161-
body: body
161+
body: body,
162+
requestInterceptor: getConfigs().requestInterceptor,
163+
responseInterceptor: getConfigs().responseInterceptor
162164
})
163165
.then(function (response) {
164166
let token = JSON.parse(response.data)
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/* eslint-env mocha */
2+
import React from "react"
3+
import expect, { createSpy } from "expect"
4+
import { Select, Input } from "components/layout-utils"
5+
import { render } from "enzyme"
6+
import * as JsonSchemaComponents from "core/json-schema-components"
7+
import { JsonSchemaForm } from "core/json-schema-components"
8+
9+
const components = {...JsonSchemaComponents, Select, Input}
10+
11+
const getComponentStub = (name) => {
12+
if(components[name]) return components[name]
13+
14+
return null
15+
}
16+
17+
describe("<JsonSchemaForm/>", function(){
18+
describe("strings", function() {
19+
it("should render the correct options for a string enum parameter", function(){
20+
21+
let props = {
22+
getComponent: getComponentStub,
23+
value: "",
24+
onChange: () => {},
25+
keyName: "",
26+
fn: {},
27+
schema: {
28+
type: "string",
29+
enum: ["one", "two"]
30+
}
31+
}
32+
33+
let wrapper = render(<JsonSchemaForm {...props}/>)
34+
35+
expect(wrapper.find("select").length).toEqual(1)
36+
expect(wrapper.find("select option").length).toEqual(3)
37+
expect(wrapper.find("select option").eq(0).text()).toEqual("--")
38+
expect(wrapper.find("select option").eq(1).text()).toEqual("one")
39+
expect(wrapper.find("select option").eq(2).text()).toEqual("two")
40+
})
41+
42+
it("should render the correct options for a required string enum parameter", function(){
43+
44+
let props = {
45+
getComponent: getComponentStub,
46+
value: "",
47+
onChange: () => {},
48+
keyName: "",
49+
fn: {},
50+
required: true,
51+
schema: {
52+
type: "string",
53+
enum: ["one", "two"]
54+
}
55+
}
56+
57+
let wrapper = render(<JsonSchemaForm {...props}/>)
58+
59+
expect(wrapper.find("select").length).toEqual(1)
60+
expect(wrapper.find("select option").length).toEqual(2)
61+
expect(wrapper.find("select option").eq(0).text()).toEqual("one")
62+
expect(wrapper.find("select option").eq(1).text()).toEqual("two")
63+
})
64+
})
65+
describe("booleans", function() {
66+
it("should render the correct options for a boolean parameter", function(){
67+
68+
let props = {
69+
getComponent: getComponentStub,
70+
value: "",
71+
onChange: () => {},
72+
keyName: "",
73+
fn: {},
74+
schema: {
75+
type: "boolean"
76+
}
77+
}
78+
79+
let wrapper = render(<JsonSchemaForm {...props}/>)
80+
81+
expect(wrapper.find("select").length).toEqual(1)
82+
expect(wrapper.find("select option").length).toEqual(3)
83+
expect(wrapper.find("select option").eq(0).text()).toEqual("--")
84+
expect(wrapper.find("select option").eq(1).text()).toEqual("true")
85+
expect(wrapper.find("select option").eq(2).text()).toEqual("false")
86+
})
87+
88+
it("should render the correct options for a required enum boolean parameter", function(){
89+
90+
let props = {
91+
getComponent: getComponentStub,
92+
value: "",
93+
onChange: () => {},
94+
keyName: "",
95+
fn: {},
96+
required: true,
97+
schema: {
98+
type: "boolean",
99+
enum: ["true"]
100+
}
101+
}
102+
103+
let wrapper = render(<JsonSchemaForm {...props}/>)
104+
105+
expect(wrapper.find("select").length).toEqual(1)
106+
expect(wrapper.find("select option").length).toEqual(1)
107+
expect(wrapper.find("select option").first().text()).toEqual("true")
108+
})
109+
})
110+
describe("unknown types", function() {
111+
it("should render unknown types as strings", function(){
112+
113+
let props = {
114+
getComponent: getComponentStub,
115+
value: "yo",
116+
onChange: () => {},
117+
keyName: "",
118+
fn: {},
119+
schema: {
120+
type: "NotARealType"
121+
}
122+
}
123+
124+
125+
let wrapper = render(<JsonSchemaForm {...props}/>)
126+
127+
expect(wrapper.find("input").length).toEqual(1)
128+
// expect(wrapper.find("select input").length).toEqual(1)
129+
// expect(wrapper.find("select option").first().text()).toEqual("true")
130+
})
131+
132+
it("should render unknown types as strings when a format is passed", function(){
133+
134+
let props = {
135+
getComponent: getComponentStub,
136+
value: "yo",
137+
onChange: () => {},
138+
keyName: "",
139+
fn: {},
140+
schema: {
141+
type: "NotARealType",
142+
format: "NotARealFormat"
143+
}
144+
}
145+
146+
147+
let wrapper = render(<JsonSchemaForm {...props}/>)
148+
149+
expect(wrapper.find("input").length).toEqual(1)
150+
// expect(wrapper.find("select input").length).toEqual(1)
151+
// expect(wrapper.find("select option").first().text()).toEqual("true")
152+
})
153+
})
154+
})

0 commit comments

Comments
 (0)