Skip to content

Commit b2c41e1

Browse files
authored
Merge branch 'master' into feature/validation_tooltips
2 parents 61a9fa0 + 0432828 commit b2c41e1

File tree

9 files changed

+67
-48
lines changed

9 files changed

+67
-48
lines changed

src/core/components/errors.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const SpecErrorItem = ( { error, jumpToLine } ) => {
113113
}
114114

115115
function toTitleCase(str) {
116-
return str
116+
return (str || "")
117117
.split(" ")
118118
.map(substr => substr[0].toUpperCase() + substr.slice(1))
119119
.join(" ")

src/core/components/object-model.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export default class ObjectModel extends Component {
2121
let { specSelectors } = otherProps
2222
let { isOAS3 } = specSelectors
2323

24+
if(!schema) {
25+
return null
26+
}
27+
2428
let description = schema.get("description")
2529
let properties = schema.get("properties")
2630
let additionalProperties = schema.get("additionalProperties")

src/core/components/operation.jsx

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export default class Operation extends PureComponent {
1212
method: PropTypes.string.isRequired,
1313
operation: PropTypes.object.isRequired,
1414
showSummary: PropTypes.bool,
15+
isShown: PropTypes.bool.isRequired,
1516

16-
isShownKey: CustomPropTypes.arrayOrString.isRequired,
17+
tagKey: PropTypes.string,
18+
operationKey: PropTypes.string,
1719
jumpToKey: CustomPropTypes.arrayOrString.isRequired,
1820

1921
allowTryItOut: PropTypes.bool,
@@ -52,38 +54,16 @@ export default class Operation extends PureComponent {
5254
}
5355

5456
componentWillReceiveProps(nextProps) {
55-
const defaultContentType = "application/json"
56-
let { specActions, path, method, operation } = nextProps
57-
let producesValue = operation.get("produces_value")
58-
let produces = operation.get("produces")
59-
let consumes = operation.get("consumes")
60-
let consumesValue = operation.get("consumes_value")
61-
6257
if(nextProps.response !== this.props.response) {
6358
this.setState({ executeInProgress: false })
6459
}
65-
66-
if (producesValue === undefined) {
67-
producesValue = produces && produces.size ? produces.first() : defaultContentType
68-
specActions.changeProducesValue([path, method], producesValue)
69-
}
70-
71-
if (consumesValue === undefined) {
72-
consumesValue = consumes && consumes.size ? consumes.first() : defaultContentType
73-
specActions.changeConsumesValue([path, method], consumesValue)
74-
}
7560
}
7661

7762
toggleShown =() => {
78-
let { layoutActions, isShownKey } = this.props
79-
layoutActions.show(isShownKey, !this.isShown())
80-
}
81-
82-
isShown =() => {
83-
let { layoutSelectors, isShownKey, getConfigs } = this.props
84-
let { docExpansion } = getConfigs()
63+
let { layoutActions, tagKey, operationKey, isShown } = this.props
64+
const isShownKey = ["operations", tagKey, operationKey]
8565

86-
return layoutSelectors.isShown(isShownKey, docExpansion === "full" ) // Here is where we set the default
66+
layoutActions.show(isShownKey, !isShown)
8767
}
8868

8969
onTryoutClick =() => {
@@ -102,7 +82,9 @@ export default class Operation extends PureComponent {
10282

10383
render() {
10484
let {
105-
isShownKey,
85+
operationKey,
86+
tagKey,
87+
isShown,
10688
jumpToKey,
10789
path,
10890
method,
@@ -156,18 +138,17 @@ export default class Operation extends PureComponent {
156138
}
157139

158140
let { tryItOutEnabled } = this.state
159-
let shown = this.isShown()
160141
let onChangeKey = [ path, method ] // Used to add values to _this_ operation ( indexed by path and method )
161142

162143
return (
163-
<div className={deprecated ? "opblock opblock-deprecated" : shown ? `opblock opblock-${method} is-open` : `opblock opblock-${method}`} id={isShownKey.join("-")} >
144+
<div className={deprecated ? "opblock opblock-deprecated" : isShown ? `opblock opblock-${method} is-open` : `opblock opblock-${method}`} id={`operations-${tagKey}-${operationKey}`} >
164145
<div className={`opblock-summary opblock-summary-${method}`} onClick={this.toggleShown} >
165146
<span className="opblock-summary-method">{method.toUpperCase()}</span>
166147
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" } >
167148
<a
168149
className="nostyle"
169150
onClick={isDeepLinkingEnabled ? (e) => e.preventDefault() : null}
170-
href={isDeepLinkingEnabled ? `#/${isShownKey[1]}/${isShownKey[2]}` : null}>
151+
href={isDeepLinkingEnabled ? `#/${tagKey}/${operationKey}` : null}>
171152
<span>{path}</span>
172153
</a>
173154
<JumpToPath path={jumpToKey} />
@@ -193,7 +174,7 @@ export default class Operation extends PureComponent {
193174
}
194175
</div>
195176

196-
<Collapse isOpened={shown}>
177+
<Collapse isOpened={isShown}>
197178
<div className="opblock-body">
198179
{ deprecated && <h4 className="opblock-title_normal"> Warning: Deprecated</h4>}
199180
{ description &&

src/core/components/operations.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,21 @@ export default class Operations extends React.Component {
127127

128128
const operationId =
129129
op.getIn(["operation", "operationId"]) || op.getIn(["operation", "__originalOperationId"]) || opId(op.get("operation"), path, method) || op.get("id")
130-
const isShownKey = ["operations", createDeepLinkPath(tag), createDeepLinkPath(operationId)]
130+
const tagKey = createDeepLinkPath(tag)
131+
const operationKey = createDeepLinkPath(operationId)
131132

132133
const allowTryItOut = specSelectors.allowTryItOutFor(op.get("path"), op.get("method"))
133134
const response = specSelectors.responseFor(op.get("path"), op.get("method"))
134135
const request = specSelectors.requestFor(op.get("path"), op.get("method"))
135136

136137
return <Operation
137138
{...op.toObject()}
138-
139-
isShownKey={isShownKey}
139+
tagKey={tagKey}
140+
operationKey={operationKey}
141+
isShown={layoutSelectors.isShown(["operations", tagKey, operationKey])}
140142
jumpToKey={jumpToKey}
141143
showSummary={showSummary}
142-
key={isShownKey}
144+
key={tagKey + operationKey}
143145
response={ response }
144146
request={ request }
145147
allowTryItOut={allowTryItOut}

src/core/plugins/err/actions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import serializeError from "serialize-error"
33
export const NEW_THROWN_ERR = "err_new_thrown_err"
44
export const NEW_THROWN_ERR_BATCH = "err_new_thrown_err_batch"
55
export const NEW_SPEC_ERR = "err_new_spec_err"
6+
export const NEW_SPEC_ERR_BATCH = "err_new_spec_err_batch"
67
export const NEW_AUTH_ERR = "err_new_auth_err"
78
export const CLEAR = "err_clear"
89

@@ -27,6 +28,13 @@ export function newSpecErr(err) {
2728
}
2829
}
2930

31+
export function newSpecErrBatch(errArray) {
32+
return {
33+
type: NEW_SPEC_ERR_BATCH,
34+
payload: errArray
35+
}
36+
}
37+
3038
export function newAuthErr(err) {
3139
return {
3240
type: NEW_AUTH_ERR,

src/core/plugins/err/reducers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
NEW_THROWN_ERR,
33
NEW_THROWN_ERR_BATCH,
44
NEW_SPEC_ERR,
5+
NEW_SPEC_ERR_BATCH,
56
NEW_AUTH_ERR,
67
CLEAR
78
} from "./actions"
@@ -45,6 +46,15 @@ export default function(system) {
4546
.update("errors", errors => transformErrors(errors, system.getSystem()))
4647
},
4748

49+
[NEW_SPEC_ERR_BATCH]: (state, { payload }) => {
50+
payload = payload.map(err => {
51+
return fromJS(Object.assign(DEFAULT_ERROR_STRUCTURE, err, { type: "spec" }))
52+
})
53+
return state
54+
.update("errors", errors => (errors || List()).concat( fromJS( payload )) )
55+
.update("errors", errors => transformErrors(errors, system.getSystem()))
56+
},
57+
4858
[NEW_AUTH_ERR]: (state, { payload }) => {
4959
let error = fromJS(Object.assign({}, payload))
5060

src/core/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
494494
let listCheck = type === "array" && Im.List.isList(value) && value.count()
495495
let fileCheck = type === "file" && value instanceof win.File
496496
let booleanCheck = type === "boolean" && (value || value === false)
497-
let numberCheck = type === "number" && value
498-
let integerCheck = type === "integer" && value
497+
let numberCheck = type === "number" && (value || value === 0)
498+
let integerCheck = type === "integer" && (value || value === 0)
499499

500500
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
501501
errors.push("Required field is not provided")

src/style/_models.scss

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
font-size: 12px;
44
font-weight: 300;
55

6+
@include text_code();
7+
68
.deprecated
79
{
8-
span, td {
9-
color: $model-deprecated-font-color !important;
10-
}
10+
span,
11+
td
12+
{
13+
color: $model-deprecated-font-color !important;
14+
}
1115
}
12-
13-
@include text_code();
1416
&-toggle
1517
{
1618
font-size: 10px;
@@ -87,7 +89,8 @@
8789
background: rgba($model-hint-background-color,.7);
8890
}
8991

90-
p {
92+
p
93+
{
9194
margin: 0 0 1em 0;
9295
}
9396
}
@@ -106,6 +109,7 @@ section.models
106109
h4
107110
{
108111
margin: 0 0 5px 0;
112+
109113
border-bottom: 1px solid rgba($section-models-isopen-h4-border-bottom-color, .3);
110114
}
111115
}
@@ -114,6 +118,7 @@ section.models
114118
font-size: 16px;
115119

116120
display: flex;
121+
align-items: center;
117122

118123
margin: 0;
119124
padding: 10px 20px 10px 10px;
@@ -122,7 +127,6 @@ section.models
122127
transition: all .2s;
123128

124129
@include text_headline($section-models-h4-font-color);
125-
align-items: center;
126130

127131
svg
128132
{
@@ -202,7 +206,7 @@ section.models
202206

203207
&.deprecated
204208
{
205-
opacity: .5;
209+
opacity: .5;
206210
}
207211
}
208212

@@ -218,14 +222,16 @@ section.models
218222
{
219223
font-size: 16px;
220224
font-weight: 600;
225+
221226
margin-right: 1em;
227+
222228
@include text_headline($_color-delete);
223229
}
224230

225231

226232
span
227233
{
228-
> span.model
234+
> span.model
229235
{
230236
.brace-close
231237
{
@@ -237,8 +243,8 @@ span
237243
.prop-name
238244
{
239245
display: inline-block;
246+
240247
margin-right: 1em;
241-
width: 8em;
242248
}
243249

244250
.prop-type

test/core/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,14 @@ describe("utils", function() {
700700
}
701701
assertValidateParam(param, ["Required field is not provided"])
702702

703+
// valid integer, but 0 is falsy in JS
704+
param = {
705+
required: true,
706+
type: "integer",
707+
value: 0
708+
}
709+
assertValidateParam(param, [])
710+
703711
// valid integer
704712
param = {
705713
required: true,

0 commit comments

Comments
 (0)