Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ Parameter name | Docker variable | Description
duration (in milliseconds) for "Try it out" requests.
</td>
</tr>
<tr>
<td><a name="user-content-disablevirtualization"></a><code>disableVirtualization</code>
</td>
<td><code>DISABLE_VIRTUALIZATION</code></td>
<td><code>Boolean=false</code>. Disables virtualization of the
operations and schemas lists. By default, specs with a large
number of operations or schemas are rendered using
virtualization so that only the items currently in view are
present in the DOM, for performance. This also means the
browser's native find-in-page (Cmd/Ctrl+F) cannot match items
that have not been scrolled into view. Set this to
<code>true</code> to always render the full list, at the cost of
performance on very large specs.
</td>
</tr>
<tr>
<td><a name="user-content-docexpansion"></a><code>docExpansion</code>
</td>
Expand Down
6 changes: 4 additions & 2 deletions src/core/components/operations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Operations = ({
}) => {
const taggedOps = specSelectors.taggedOperations()
const validOperationMethods = specSelectors.validOperationMethods()
const { docExpansion } = getConfigs()
const { docExpansion, disableVirtualization } = getConfigs()

const tagDefaultOpen = docExpansion === "full" || docExpansion === "list"

Expand Down Expand Up @@ -94,7 +94,9 @@ const Operations = ({
return items
}, [taggedOps, validOperationMethods, tagDefaultOpen, expandedTagsState])

const isVirtualized = flatItems.length >= VIRTUALIZE_OPERATIONS_THRESHOLD
const isVirtualized =
!disableVirtualization &&
flatItems.length >= VIRTUALIZE_OPERATIONS_THRESHOLD

const [containerEl, setContainerEl] = useState(null)
const [scrollMargin, setScrollMargin] = useState(0)
Expand Down
1 change: 1 addition & 0 deletions src/core/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const defaultOptions = Object.freeze({
layout: "BaseLayout",
docExpansion: "list",
maxDisplayedTags: -1,
disableVirtualization: false,
filter: false,
validatorUrl: "https://validator.swagger.io/validator",
oauth2RedirectUrl: undefined,
Expand Down
7 changes: 5 additions & 2 deletions src/core/plugins/json-schema-5/components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const Models = ({
getConfigs,
}) => {
const definitions = specSelectors.definitions()
const { docExpansion, defaultModelsExpandDepth } = getConfigs()
const { docExpansion, defaultModelsExpandDepth, disableVirtualization } =
getConfigs()

const isOAS3 = specSelectors.isOAS3()
const specPathBase = useMemo(
Expand Down Expand Up @@ -80,7 +81,9 @@ const Models = ({
},
})

const isVirtualized = definitionEntries.length >= VIRTUALIZE_MODELS_THRESHOLD
const isVirtualized =
!disableVirtualization &&
definitionEntries.length >= VIRTUALIZE_MODELS_THRESHOLD
const pendingVirtualizedSchemaScroll =
layoutSelectors.getScrollToVirtualizedSchema()

Expand Down
7 changes: 5 additions & 2 deletions src/core/plugins/oas31/components/models/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const Models = ({
fn,
}) => {
const schemas = specSelectors.selectSchemas()
const { docExpansion, defaultModelsExpandDepth } = getConfigs()
const { docExpansion, defaultModelsExpandDepth, disableVirtualization } =
getConfigs()
const isOpenDefault = defaultModelsExpandDepth > 0 && docExpansion !== "none"
const isOpen = layoutSelectors.isShown(SCHEMAS_PATH, isOpenDefault)
const Collapse = getComponent("Collapse")
Expand All @@ -49,7 +50,9 @@ const Models = ({
},
})

const isVirtualized = schemaEntries.length >= VIRTUALIZE_MODELS_THRESHOLD
const isVirtualized =
!disableVirtualization &&
schemaEntries.length >= VIRTUALIZE_MODELS_THRESHOLD

/**
* Effects.
Expand Down
23 changes: 23 additions & 0 deletions test/unit/components/operations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,29 @@ describe("<Operations/>", function () {
expect(wrapper.find(".operations-virtual__list").length).toBeGreaterThan(0)
})

it("does not virtualize when disableVirtualization config is true", function () {
const ops = Array.from({ length: 149 }, (_, i) => [
`/p${i}`,
"get",
`op${i}`,
])
const props = makeProps({
specSelectors: {
taggedOperations: () => makeTaggedOps([["tag0", ops]]),
validOperationMethods: () => ["get"],
url: () => "",
},
getConfigs: () => ({
docExpansion: "list",
disableVirtualization: true,
}),
})

const wrapper = mount(<Operations {...props} />)

expect(wrapper.find(".operations-virtual__list").length).toEqual(0)
})

it("renders OperationTag for each tag in the non-virtualized path", function () {
const TagSpy = jest.fn(({ children }) => <div>{children}</div>)
const props = makeProps({
Expand Down
27 changes: 27 additions & 0 deletions test/unit/core/plugins/json-schema-5/components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,31 @@ describe("<Models/>", function () {
// virtualizer mock returns no items, so no .model-container should be in DOM
expect(wrapper.find(".model-container").length).toEqual(0)
})

it("does not virtualize when disableVirtualization config is true", function () {
const defs = {}

for (let i = 0; i < 100; i++) {
defs[`Schema${i}`] = {}
}

const props = makeProps({
specSelectors: {
isOAS3: () => false,
specJson: () => Map(),
definitions: () => fromJS(defs),
specResolvedSubtree: () => undefined,
},
getConfigs: () => ({
docExpansion: "list",
defaultModelsExpandDepth: 1,
disableVirtualization: true,
}),
})

const wrapper = mount(<Models {...props} />)

expect(wrapper.find(".models-scroll").length).toEqual(0)
expect(wrapper.find(".model-container").length).toEqual(100)
})
})
23 changes: 23 additions & 0 deletions test/unit/core/plugins/oas31/components/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,27 @@ describe("<Models/> (oas31)", function () {
// virtualizer mock returns no items, so no schema-item should be rendered
expect(wrapper.find(".schema-item").length).toEqual(0)
})

it("does not virtualize when disableVirtualization config is true", function () {
const schemas: Record<string, object> = {}
for (let i = 0; i < 100; i++) {
schemas[`Schema${i}`] = {}
}
const props = makeProps({
specSelectors: {
selectSchemas: () => schemas,
specResolvedSubtree: () => undefined,
},
getConfigs: () => ({
docExpansion: "list",
defaultModelsExpandDepth: 1,
disableVirtualization: true,
}),
})

const wrapper = mount(<Models {...props} />)

expect(wrapper.find(".models-scroll").length).toEqual(0)
expect(wrapper.find(".schema-item").length).toEqual(100)
})
})