Skip to content

Commit 0edf264

Browse files
committed
fix: Filter resourceSamples on endpoints like on route
1 parent c644115 commit 0edf264

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/lib/layout/api-endpoint.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
mapResourceSample,
1919
normalizePropertyFormatForDocs,
2020
type ResourceSampleContext,
21+
resourceSampleFilter,
2122
} from './api-route.js'
2223

2324
const supportedSdks: SdkName[] = [
@@ -185,11 +186,14 @@ export function setEndpointLayoutContext(
185186
}
186187
}
187188

188-
file.resourceSamples = getResourceSamples(
189-
endpoint,
190-
resources,
191-
actionAttempts,
192-
).map(mapResourceSample)
189+
file.resourceSamples = getResourceSamples(endpoint, resources, actionAttempts)
190+
.filter(
191+
resourceSampleFilter({
192+
include: metadata.include_groups,
193+
exclude: metadata.exclude_groups,
194+
}),
195+
)
196+
.map(mapResourceSample)
193197

194198
const [primaryCodeSample, ...additionalCodeSamples] = endpoint.codeSamples
195199
file.primaryCodeSample =

src/lib/layout/api-route.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ export const setApiRouteLayoutContext = (
182182
? groupProperties(
183183
legacyProperty.properties,
184184
legacyProperty.propertyGroups,
185-
{
186-
include: metadata.include_groups,
187-
exclude: metadata.exclude_groups,
188-
},
185+
groupOptions,
189186
)
190187
: null
191188

@@ -199,24 +196,31 @@ export const setApiRouteLayoutContext = (
199196
hidePreamble: route.path !== resource.routePath,
200197
events: eventsByRoutePath.get(resource.routePath) ?? [],
201198
resourceSamples: resource.resourceSamples
202-
.filter(({ title }) => {
203-
if (groupOptions.include != null) {
204-
return groupOptions.include.some((x) =>
205-
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
206-
)
207-
}
208-
if (groupOptions.exclude != null) {
209-
return !groupOptions.exclude.some((x) =>
210-
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
211-
)
212-
}
213-
return true
214-
})
199+
.filter(resourceSampleFilter(groupOptions))
215200
.map(mapResourceSample),
216201
})
217202
}
218203
}
219204

205+
export const resourceSampleFilter =
206+
(groupOptions: {
207+
include: string[] | undefined
208+
exclude?: string[] | undefined
209+
}) =>
210+
({ title }: ResourceSample): boolean => {
211+
if (groupOptions.include != null) {
212+
return groupOptions.include.some((x) =>
213+
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
214+
)
215+
}
216+
if (groupOptions.exclude != null) {
217+
return !groupOptions.exclude.some((x) =>
218+
title.toLowerCase().includes(x.split('_')[0]?.slice(0, -1) ?? ''),
219+
)
220+
}
221+
return true
222+
}
223+
220224
const groupVariants = (
221225
property: Property | null,
222226
{

0 commit comments

Comments
 (0)