Skip to content

Commit 092f401

Browse files
committed
refactor: common reference should not use uid
1 parent 6b92dab commit 092f401

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/runtime/components/OpenAPIPath.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export const OpenAPIPath = ({
298298
key={ref}
299299
schema={ref}
300300
openapiPath={openapiPath}
301+
isCommonRef={false}
301302
collectRefs={false}
302303
/>
303304
)

src/runtime/components/OpenAPIRef.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ export interface OpenAPIRefProps {
2020
* The specific path to the OpenAPI schema, otherwise the first matched will be used.
2121
*/
2222
openapiPath?: string
23+
/**
24+
* Whether is a common reference, no `uid` will be generated.
25+
*
26+
* @default true
27+
*/
28+
isCommonRef?: boolean
29+
/**
30+
* Whether to collect references from the schema.
31+
*
32+
* @default true
33+
*/
2334
collectRefs?: boolean
2435
}
2536

@@ -150,6 +161,7 @@ const getRefsForSchema = (
150161
export const OpenAPIRef = ({
151162
schema,
152163
openapiPath: openapiPath_,
164+
isCommonRef = true,
153165
collectRefs = true,
154166
}: OpenAPIRefProps) => {
155167
const { page } = usePageData()
@@ -158,7 +170,9 @@ export const OpenAPIRef = ({
158170

159171
const innerUid = useId()
160172

161-
if (!uid) {
173+
if (isCommonRef) {
174+
uid = '' // common references do not need a unique ID
175+
} else if (!uid) {
162176
uid = innerUid
163177
}
164178

@@ -207,6 +221,7 @@ export const OpenAPIRef = ({
207221
key={schema}
208222
schema={schema}
209223
openapiPath={openapiPath}
224+
isCommonRef={isCommonRef}
210225
collectRefs={false}
211226
/>
212227
))}

src/runtime/components/_RefLink.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ export const RefLink = ({ $ref }: RefLinkProps) => {
1414
return null
1515
}
1616

17-
const ref = $ref.replace('/components/schemas/', '').slice(1)
18-
const refName = modelName(ref)
19-
return <X.a href={COMMON_REFS[ref] || `#${uid}-${ref}`}>{refName}</X.a>
17+
const ref = $ref.replace('/components/schemas/', '')
18+
const plainRef = ref.slice(1)
19+
const refName = modelName(plainRef)
20+
return (
21+
<X.a href={COMMON_REFS[plainRef] || (uid ? `#${uid}-${plainRef}` : ref)}>
22+
{refName}
23+
</X.a>
24+
)
2025
}

0 commit comments

Comments
 (0)