File tree Expand file tree Collapse file tree 4 files changed +70
-2
lines changed
.vitepress/theme/components Expand file tree Collapse file tree 4 files changed +70
-2
lines changed Original file line number Diff line number Diff line change 124124import MarkdownIt from ' markdown-it' ;
125125import type { Route } from ' ../types' ;
126126import CopyButton from ' ./CopyButton.vue' ;
127+ import { parseJsonSchema } from ' ./parse-json-schema' ;
127128
128129const props = defineProps <{
129130 namespace: string ,
@@ -134,7 +135,11 @@ const props = defineProps<{
134135 description: string | null ,
135136 siteUrl: string | null ,
136137 image: string | null ,
137- }[] },
138+ }[],
139+ param? : any ,
140+ query? : any ,
141+ location? : string ,
142+ },
138143 test? : {
139144 code: number ,
140145 message? : string ,
@@ -143,9 +148,10 @@ const props = defineProps<{
143148
144149const demoUrl = props .data .example ? (' https://rsshub.app' + props .data .example ) : null ;
145150const path = typeof props .data .path === " string" ? props .data .path : props .data .path [0 ];
151+ const param = parseJsonSchema (props .data .param );
146152const paramMatch = path .match ?.(/ (?<=:). *? (?=\/ | $ )/ g )?.map ((item ) => {
147153 const name = item .replace (/ :| \? | \+ | \* / g , ' ' );
148- let parameter = props .data .parameters ?.[name ];
154+ let parameter = param ?.[ name ] || props .data .parameters ?.[name ];
149155 if (typeof parameter === " string" ) {
150156 parameter = {
151157 description: parameter ,
Original file line number Diff line number Diff line change 1+ import type { JSONSchema4 } from "json-schema" ;
2+
3+ export type ParamDesc = {
4+ description ?: string ;
5+ default ?: string ;
6+ options ?: {
7+ value : string ;
8+ label : string ;
9+ } [ ] ;
10+ optional ?: boolean ;
11+ } ;
12+
13+ export function parseJsonSchema (
14+ schema ?: JSONSchema4
15+ ) : Record < string , ParamDesc > {
16+ if ( schema ?. type !== "object" ) {
17+ return { } ;
18+ }
19+ const properties = schema . properties || { } ;
20+ const required = Array . isArray ( schema . required ) ? schema . required : [ ] ;
21+ const result : Record < string , ParamDesc > = { } ;
22+
23+ for ( const [ key , value ] of Object . entries ( properties ) ) {
24+ if ( typeof value === "boolean" ) continue ;
25+
26+ const propertySchema = value as JSONSchema4 ;
27+ const isOptional = ! required . includes ( key ) ;
28+
29+ // Extract default value
30+ const defaultValue =
31+ propertySchema . default !== undefined
32+ ? String ( propertySchema . default )
33+ : undefined ;
34+
35+ // Extract options from enum
36+ const options = propertySchema . anyOf
37+ ? propertySchema . anyOf
38+ . filter ( ( val ) => "const" in val && "description" in val )
39+ . map ( ( val ) => ( {
40+ label : String ( val . description ) ,
41+ value : String ( val . const ) ,
42+ } ) )
43+ : undefined ;
44+
45+ result [ key ] = {
46+ optional : isOptional ,
47+ default : defaultValue ,
48+ description : propertySchema . description ,
49+ ...( options && { options } ) ,
50+ } ;
51+ }
52+ return result ;
53+ }
Original file line number Diff line number Diff line change 66 "docs:preview" : " vitepress preview"
77 },
88 "devDependencies" : {
9+ "@types/json-schema" : " 7.0.15" ,
910 "markdown-it" : " 14.1.0" ,
1011 "vitepress" : " 1.6.4" ,
1112 "vue" : " 3.5.25"
You can’t perform that action at this time.
0 commit comments