diff --git a/rushScripts/regeneration.js b/rushScripts/regeneration.js index 79785de94..c8443913a 100644 --- a/rushScripts/regeneration.js +++ b/rushScripts/regeneration.js @@ -50,7 +50,7 @@ for (namespace in goMappings) { } const blobStorage = 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/storage-dataplane-preview/specification/storage/data-plane/Microsoft.BlobStorage/preview/2019-07-07/blob.json'; -generate(blobStorage, 'test/storage/2019-07-07/azblob', '--credential-scope="https://storage.azure.com/.default" --module="azstorage" --export-client="false"'); +generate(blobStorage, 'test/storage/2019-07-07/azblob', '--credential-scope="https://storage.azure.com/.default" --module="azstorage" --export-client="false" --file-prefix="zz_generated_"'); // helper to log the package being generated before invocation function generate(inputFile, outputDir, additionalArgs) { diff --git a/src/generator/generator.ts b/src/generator/generator.ts index 8ff57c248..92ef8647b 100644 --- a/src/generator/generator.ts +++ b/src/generator/generator.ts @@ -22,48 +22,52 @@ export async function protocolGen(host: Host) { const debug = await host.GetValue('debug') || false; try { - // get the code model from the core const session = await startSession(host, codeModelSchema); const operations = await generateOperations(session); + let filePrefix = await session.getValue('file-prefix', ''); + // if a file prefix was specified, ensure it's properly snaked + if (filePrefix.length > 0 && filePrefix[filePrefix.length - 1] !== '_') { + filePrefix += '_'; + } // output the model to the pipeline. this must happen after all model // updates are complete and before any source files are written. host.WriteFile('code-model-v4.yaml', serialize(session.model), undefined, 'code-model-v4'); for (const op of values(operations)) { - host.WriteFile(`${op.name.toLowerCase()}.go`, op.content, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}${op.name.toLowerCase()}.go`, op.content, undefined, 'source-file-go'); } const enums = await generateEnums(session); if (enums.length > 0) { - host.WriteFile('enums.go', enums, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}enums.go`, enums, undefined, 'source-file-go'); } const models = await generateModels(session); - host.WriteFile('models.go', models, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}models.go`, models, undefined, 'source-file-go'); const client = await generateClient(session); - host.WriteFile('client.go', client, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}client.go`, client, undefined, 'source-file-go'); const timeHelpers = await generateTimeHelpers(session); for (const helper of values(timeHelpers)) { - host.WriteFile(`${helper.name.toLowerCase()}.go`, helper.content, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}${helper.name.toLowerCase()}.go`, helper.content, undefined, 'source-file-go'); } const pagers = await generatePagers(session); if (pagers.length > 0) { - host.WriteFile('pagers.go', pagers, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}pagers.go`, pagers, undefined, 'source-file-go'); } const pollers = await generatePollers(session); if (pollers.length > 0) { const pollingHelper = await generatePollersHelper(session); - host.WriteFile('pollers_helper.go', pollingHelper, undefined, 'source-file-go'); - host.WriteFile('pollers.go', pollers, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}pollers_helper.go`, pollingHelper, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}pollers.go`, pollers, undefined, 'source-file-go'); } const polymorphics = await generatePolymorphicHelpers(session); if (polymorphics.length > 0) { - host.WriteFile('polymorphic_helpers.go', polymorphics, undefined, 'source-file-go'); + host.WriteFile(`${filePrefix}polymorphic_helpers.go`, polymorphics, undefined, 'source-file-go'); } const gomod = await generateGoModFile(session); if (gomod.length > 0) { diff --git a/src/generator/gomod.ts b/src/generator/gomod.ts index c36c5b8cd..ec6947c6a 100644 --- a/src/generator/gomod.ts +++ b/src/generator/gomod.ts @@ -16,6 +16,6 @@ export async function generateGoModFile(session: Session): Promise