@@ -36,8 +36,8 @@ type DiffTarget = {
3636const SPEC_DIR_URL = ( commit : string ) =>
3737 `https://api.github.com/repos/oxidecomputer/omicron/contents/openapi/nexus?ref=${ commit } `
3838
39- const SPEC_RAW_URL = ( commit : string , filename : string ) =>
40- `https://raw.githubusercontent.com/oxidecomputer/omicron/${ commit } /openapi/nexus/ ${ filename } `
39+ const SPEC_RAW_URL = ( ref : string , path : string ) =>
40+ `https://raw.githubusercontent.com/oxidecomputer/omicron/${ ref } / ${ path } `
4141
4242async function resolveCommit ( ref ?: string | number ) : Promise < string > {
4343 if ( ref === undefined ) return resolveCommit ( await pickPr ( ) )
@@ -60,20 +60,23 @@ async function resolveCommit(ref?: string | number): Promise<string> {
6060const normalizeRef = ( ref ?: string | number ) =>
6161 typeof ref === 'string' && / ^ \d { 1 , 5 } $ / . test ( ref ) ? parseInt ( ref , 10 ) : ref
6262
63+ const LEGACY_SPEC_PATH = 'openapi/nexus.json'
64+
6365async function listSchemaDir ( ref : string ) {
6466 console . error ( `Fetching schema list for ${ ref } ...` )
6567 try {
6668 return await $ `gh api ${ SPEC_DIR_URL ( ref ) } ` . stderr ( 'null' ) . json ( )
6769 } catch {
68- throw new Error (
69- `Could not list openapi/nexus/ at ref '${ ref } '. ` +
70- `This ref may predate the versioned schema directory.`
71- )
70+ return null
7271 }
7372}
7473
7574async function getLatestSchema ( ref : string ) {
7675 const contents = await listSchemaDir ( ref )
76+ if ( ! contents ) {
77+ console . error ( `No openapi/nexus/ dir at ${ ref } , falling back to ${ LEGACY_SPEC_PATH } ` )
78+ return LEGACY_SPEC_PATH
79+ }
7780 const schemaFiles = contents
7881 . map ( ( f : { name : string } ) => f . name )
7982 . filter ( ( n : string ) => n . startsWith ( 'nexus-' ) )
@@ -85,12 +88,19 @@ async function getLatestSchema(ref: string) {
8588 `Available schemas: ${ schemaFiles . join ( ', ' ) || '(none)' } `
8689 )
8790 }
88- return ( await fetch ( latestLink . download_url ) . then ( ( r ) => r . text ( ) ) ) . trim ( )
91+ const latest = ( await fetch ( latestLink . download_url ) . then ( ( r ) => r . text ( ) ) ) . trim ( )
92+ return `openapi/nexus/${ latest } `
8993}
9094
9195/** When diffing a single ref, we diff its latest schema against the previous one */
9296async function getLatestAndPreviousSchema ( ref : string ) {
9397 const contents = await listSchemaDir ( ref )
98+ if ( ! contents ) {
99+ throw new Error (
100+ `No openapi/nexus/ dir at ref '${ ref } '. ` +
101+ `Single-ref mode requires the versioned schema directory.`
102+ )
103+ }
94104
95105 const latestLink = contents . find ( ( f : { name : string } ) => f . name === 'nexus-latest.json' )
96106 const schemaFiles = contents
@@ -113,7 +123,10 @@ async function getLatestAndPreviousSchema(ref: string) {
113123 throw new Error ( `Latest schema ${ latest } not found in dir at ref '${ ref } '` )
114124 if ( latestIndex === 0 ) throw new Error ( `No previous schema version found at ref '${ ref } '` )
115125
116- return { previous : schemaFiles [ latestIndex - 1 ] , latest }
126+ return {
127+ previous : `openapi/nexus/${ schemaFiles [ latestIndex - 1 ] } ` ,
128+ latest : `openapi/nexus/${ latest } ` ,
129+ }
117130}
118131
119132async function resolveTarget ( ref1 ?: string | number , ref2 ?: string ) : Promise < DiffTarget > {
0 commit comments