88import { mkdirSync , rmSync , writeFileSync , existsSync , readFileSync } from "fs" ;
99import { join } from "path" ;
1010
11- import { manifest , cases , type TestCase } from "@oxa/conformance" ;
12-
1311import { loadMergedSchema } from "./schema.js" ;
1412
1513const OUTPUT_DIR = join ( import . meta. dirname , "../../docs/schema" ) ;
1614const INDEX_FILE = join ( OUTPUT_DIR , "index.md" ) ;
15+ const CONFORMANCE_DIR = join (
16+ import . meta. dirname ,
17+ "../../packages/oxa-conformance" ,
18+ ) ;
19+ const MANIFEST_FILE = join ( CONFORMANCE_DIR , "manifest.json" ) ;
1720
1821interface SchemaProperty {
1922 type ?: string ;
@@ -36,6 +39,21 @@ interface SchemaDefinition {
3639 required ?: string [ ] ;
3740}
3841
42+ interface TestCase {
43+ formats : Record < string , unknown > ;
44+ }
45+
46+ interface ManifestCase {
47+ id : string ;
48+ path : string ;
49+ nodeTypes : string [ ] ;
50+ }
51+
52+ interface Manifest {
53+ formats : string [ ] ;
54+ cases : ManifestCase [ ] ;
55+ }
56+
3957export async function generateDocs ( ) : Promise < void > {
4058 // Preserve index.md if it exists
4159 let indexContent : string | null = null ;
@@ -56,12 +74,13 @@ export async function generateDocs(): Promise<void> {
5674
5775 const schema = loadMergedSchema ( ) ;
5876 const definitions = schema . definitions as Record < string , SchemaDefinition > ;
59- const testCases = loadTestCases ( ) ;
77+ const { manifest, cases } = loadConformanceData ( ) ;
78+ const testCases = loadTestCases ( manifest , cases ) ;
6079
6180 // Generate documentation for object types (non-union types)
6281 for ( const [ name , def ] of Object . entries ( definitions ) ) {
6382 if ( ! def . anyOf && def . type === "object" ) {
64- const content = generateDocContent ( name , def , testCases ) ;
83+ const content = generateDocContent ( name , def , testCases , manifest ) ;
6584 const filePath = join ( OUTPUT_DIR , `${ name . toLowerCase ( ) } .md` ) ;
6685 writeFileSync ( filePath , content ) ;
6786 console . log ( `Generated ${ filePath } ` ) ;
@@ -83,6 +102,7 @@ function generateDocContent(
83102 name : string ,
84103 def : SchemaDefinition ,
85104 testCases : Map < string , TestCase > ,
105+ manifest : Manifest ,
86106) : string {
87107 const lines : string [ ] = [ ] ;
88108
@@ -111,6 +131,10 @@ function generateDocContent(
111131 } else if ( prop . enum && prop . enum . length === 1 ) {
112132 // Single-element enum (same as const)
113133 lines . push ( `__${ propName } __: _string_, ("${ prop . enum [ 0 ] } ")` ) ;
134+ } else if ( prop . enum && prop . enum . length > 1 ) {
135+ lines . push (
136+ `__${ propName } __: _string_, (${ prop . enum . map ( ( value ) => `"${ value } "` ) . join ( " | " ) } )` ,
137+ ) ;
114138 } else if ( prop . type === "array" && prop . items ) {
115139 const arrayType = getArrayItemType ( prop . items ) ;
116140 lines . push ( `__${ propName } __: __array__ ("${ arrayType } ")` ) ;
@@ -137,7 +161,7 @@ function generateDocContent(
137161 // Add test case example if available
138162 const testCase = testCases . get ( name . toLowerCase ( ) ) ;
139163 if ( testCase ) {
140- lines . push ( generateTestCaseSection ( testCase ) ) ;
164+ lines . push ( generateTestCaseSection ( testCase , manifest ) ) ;
141165 }
142166
143167 return lines . join ( "\n" ) ;
@@ -213,7 +237,27 @@ function getArrayItemType(items: { $ref?: string; type?: string }): string {
213237 return "unknown" ;
214238}
215239
216- function loadTestCases ( ) : Map < string , TestCase > {
240+ function loadConformanceData ( ) : {
241+ manifest : Manifest ;
242+ cases : Record < string , TestCase > ;
243+ } {
244+ const manifest = JSON . parse ( readFileSync ( MANIFEST_FILE , "utf-8" ) ) as Manifest ;
245+ const cases = Object . fromEntries (
246+ manifest . cases . map ( ( caseInfo ) => [
247+ caseInfo . id ,
248+ JSON . parse (
249+ readFileSync ( join ( CONFORMANCE_DIR , caseInfo . path ) , "utf-8" ) ,
250+ ) as TestCase ,
251+ ] ) ,
252+ ) ;
253+
254+ return { manifest, cases } ;
255+ }
256+
257+ function loadTestCases (
258+ manifest : Manifest ,
259+ cases : Record < string , TestCase > ,
260+ ) : Map < string , TestCase > {
217261 const testCases = new Map < string , TestCase > ( ) ;
218262
219263 // Filter for *-basic test cases
@@ -257,7 +301,10 @@ const FORMAT_LANGUAGES: Record<string, string> = {
257301 jats : "xml" ,
258302} ;
259303
260- function generateTestCaseSection ( testCase : TestCase ) : string {
304+ function generateTestCaseSection (
305+ testCase : TestCase ,
306+ manifest : Manifest ,
307+ ) : string {
261308 const lines : string [ ] = [ ] ;
262309
263310 lines . push ( "### Example" ) ;
0 commit comments