@@ -2,8 +2,9 @@ import path from 'path';
22import os from 'os' ;
33import { findRecursive , findDirRecursive , executeCmd , rmdirRecursive , lowerCaseCompare , lowerCaseCompareLists , lowerCaseStartsWith , readJsonFile , writeJsonFile , safeMkdir , safeUnlink , fileExists , lowerCaseEquals , lowerCaseContains } from './utils' ;
44import * as constants from './constants' ;
5+ import { prepareReadme } from './specs' ;
56import chalk from 'chalk' ;
6- import { ScopeType , AutogenlistConfig } from './models' ;
7+ import { ScopeType , AutoGenConfig } from './models' ;
78import { get , set , flatten , uniq , concat , Dictionary , groupBy , keys , difference , pickBy } from 'lodash' ;
89
910const autorestBinary = os . platform ( ) === 'win32' ? 'autorest.cmd' : 'autorest' ;
@@ -44,10 +45,12 @@ export async function getApiVersionsByNamespace(readme: string): Promise<Diction
4445 return output ;
4546}
4647
47- export async function generateSchemas ( readme : string , autogenlistConfig ?: AutogenlistConfig ) : Promise < SchemaConfiguration [ ] > {
48+ export async function generateSchemas ( readme : string , autoGenConfig ?: AutoGenConfig ) : Promise < SchemaConfiguration [ ] > {
49+ await prepareReadme ( readme , autoGenConfig ) ;
50+
4851 const apiVersionsByNamespace = pickBy (
4952 await getApiVersionsByNamespace ( readme ) ,
50- ( _ , key ) => ! autogenlistConfig || lowerCaseEquals ( key , autogenlistConfig . namespace ) ) ;
53+ ( _ , key ) => ! autoGenConfig || lowerCaseEquals ( key , autoGenConfig . namespace ) ) ;
5154
5255 const namespaces = keys ( apiVersionsByNamespace ) ;
5356
@@ -63,7 +66,7 @@ export async function generateSchemas(readme: string, autogenlistConfig?: Autoge
6366 continue ;
6467 }
6568
66- const generatedSchemaConfig = await handleGeneratedSchema ( readme , schemaPath , autogenlistConfig ) ;
69+ const generatedSchemaConfig = await handleGeneratedSchema ( readme , schemaPath , autoGenConfig ) ;
6770
6871 schemaConfigs . push ( generatedSchemaConfig ) ;
6972 }
@@ -75,19 +78,19 @@ export async function generateSchemas(readme: string, autogenlistConfig?: Autoge
7578 return schemaConfigs ;
7679}
7780
78- async function handleGeneratedSchema ( readme : string , schemaPath : string , autogenlistConfig ?: AutogenlistConfig ) {
81+ async function handleGeneratedSchema ( readme : string , schemaPath : string , autoGenConfig ?: AutoGenConfig ) {
7982 const namespace = path . basename ( schemaPath . substring ( 0 , schemaPath . lastIndexOf ( path . extname ( schemaPath ) ) ) ) ;
8083
81- if ( autogenlistConfig && autogenlistConfig . namespace . toLowerCase ( ) !== namespace . toLowerCase ( ) ) {
84+ if ( autoGenConfig && autoGenConfig . namespace . toLowerCase ( ) !== namespace . toLowerCase ( ) ) {
8285 throw new Error ( `Encountered unexpected namespace ${ namespace } in readme ${ readme } ` ) ;
8386 }
8487
8588 const apiVersion = path . basename ( path . resolve ( `${ schemaPath } /..` ) ) ;
8689
87- const schemaConfig = await generateSchemaConfig ( schemaPath , namespace , apiVersion , autogenlistConfig ) ;
90+ const schemaConfig = await generateSchemaConfig ( schemaPath , namespace , apiVersion , autoGenConfig ) ;
8891
8992 const unknownScopeResources = schemaConfig . references . filter ( x => x . scope & ScopeType . Unknown ) ;
90- if ( autogenlistConfig && unknownScopeResources . length > 0 ) {
93+ if ( autoGenConfig && unknownScopeResources . length > 0 ) {
9194 throw new Error ( `Unable to determine scope for resource types ${ unknownScopeResources . map ( x => x . type ) . join ( ', ' ) } in readme ${ readme } ` ) ;
9295 }
9396
@@ -111,8 +114,7 @@ async function generateSchema(readme: string, tmpFolder: string) {
111114 `--use=@autorest/azureresourceschema@${ constants . azureresourceschemaVersion } ` ,
112115 '--azureresourceschema' ,
113116 `--output-folder=${ tmpFolder } ` ,
114- `--multiapi` ,
115- '--title=none' ,
117+ '--multiapi' ,
116118 '--pass-thru:subset-reducer' ,
117119 readme ,
118120 ] ;
@@ -144,8 +146,8 @@ function getFilePathFromRef(schemaRef: string) {
144146 return path . resolve ( path . join ( constants . schemasBasePath , schemaUri . substring ( constants . schemasBaseUri . length + 1 ) ) ) ;
145147}
146148
147- function assignScopesToUnknownReferences ( knownReferences : SchemaReference [ ] , unknownReferences : SchemaReference [ ] , autogenlistConfig ?: AutogenlistConfig ) {
148- const resourceConfig = ( autogenlistConfig || { } ) . resourceConfig || [ ] ;
149+ function assignScopesToUnknownReferences ( knownReferences : SchemaReference [ ] , unknownReferences : SchemaReference [ ] , autoGenConfig ?: AutoGenConfig ) {
150+ const resourceConfig = ( autoGenConfig || { } ) . resourceConfig || [ ] ;
149151
150152 for ( const schemaRef of unknownReferences ) {
151153 const config = resourceConfig . find ( c => lowerCaseCompare ( c . type , schemaRef . type ) === 0 ) ;
@@ -169,14 +171,14 @@ function getSchemaFileName(namespace: string, suffix: string | undefined) {
169171 return `${ namespace } .${ suffix } .json` ;
170172}
171173
172- async function generateSchemaConfig ( outputFile : string , namespace : string , apiVersion : string , autogenlistConfig ?: AutogenlistConfig ) : Promise < SchemaConfiguration > {
173- namespace = autogenlistConfig ?. namespace ?? namespace ;
174- const suffix = autogenlistConfig ?. suffix ;
174+ async function generateSchemaConfig ( outputFile : string , namespace : string , apiVersion : string , autoGenConfig ?: AutoGenConfig ) : Promise < SchemaConfiguration > {
175+ namespace = autoGenConfig ?. namespace ?? namespace ;
176+ const suffix = autoGenConfig ?. suffix ;
175177 const relativePath = `${ apiVersion } /${ getSchemaFileName ( namespace , suffix ) } ` ;
176178
177179 let output = await readJsonFile ( outputFile ) ;
178- if ( autogenlistConfig ?. postProcessor ) {
179- autogenlistConfig ?. postProcessor ( namespace , apiVersion , output ) ;
180+ if ( autoGenConfig ?. postProcessor ) {
181+ autoGenConfig ?. postProcessor ( namespace , apiVersion , output ) ;
180182
181183 await writeJsonFile ( outputFile , output ) ;
182184 }
@@ -190,7 +192,7 @@ async function generateSchemaConfig(outputFile: string, namespace: string, apiVe
190192 ] ;
191193
192194 const unknownReferences = getSchemaRefs ( output , ScopeType . Unknown , 'unknown_resourceDefinitions' ) ;
193- assignScopesToUnknownReferences ( knownReferences , unknownReferences , autogenlistConfig ) ;
195+ assignScopesToUnknownReferences ( knownReferences , unknownReferences , autoGenConfig ) ;
194196
195197 const references = [
196198 ...knownReferences ,
@@ -290,10 +292,10 @@ async function getCurrentTemplateRefs(scopeType: ScopeType, rootSchemaConfig: Ro
290292 return currentRefsOneOf . map ( v => v [ '$ref' ] ) ;
291293}
292294
293- export async function clearAutogeneratedSchemaRefs ( autogenlist : AutogenlistConfig [ ] ) {
295+ export async function clearAutoGeneratedSchemaRefs ( autoGenList : AutoGenConfig [ ] ) {
294296 RootSchemaConfigs . forEach ( async ( rootSchemaConfig , scopeType ) => {
295297 const currentRefs = await getCurrentTemplateRefs ( scopeType , rootSchemaConfig ) ;
296- const autogenlistedFiles = new Set ( autogenlist . map ( x => getSchemaFileName ( x . namespace , x . suffix ) . toLowerCase ( ) ) ) ;
298+ const autogenlistedFiles = new Set ( autoGenList . map ( x => getSchemaFileName ( x . namespace , x . suffix ) . toLowerCase ( ) ) ) ;
297299 const schemasToRemove = [ ] ;
298300 const schemasByFilePath = groupBy ( currentRefs , getFilePathFromRef ) ;
299301 // clean up existing schemas to detect deletions
@@ -311,7 +313,7 @@ export async function clearAutogeneratedSchemaRefs(autogenlist: AutogenlistConfi
311313 } ) ;
312314}
313315
314- export async function saveAutogeneratedSchemaRefs ( schemaConfigs : SchemaConfiguration [ ] ) {
316+ export async function saveAutoGeneratedSchemaRefs ( schemaConfigs : SchemaConfiguration [ ] ) {
315317 RootSchemaConfigs . forEach ( async ( rootSchemaConfig , scopeType ) => {
316318 const refs = flatten ( schemaConfigs
317319 . map ( c => c . references
0 commit comments