Skip to content

Commit 0432828

Browse files
authored
Merge pull request #3885 from swagger-api/ft/big-spec-performance
Improve performance of big API definitions
2 parents 9020ee1 + 82a2ee9 commit 0432828

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
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

0 commit comments

Comments
 (0)