From 3ec17cdcbf5b3996b55de221fa66804d7da67c9d Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Tue, 30 Jun 2020 13:01:12 -0700 Subject: [PATCH] Add file-prefix switch (#431) To add optional prefix to file names (uses snake-casing). Bumped azcore version in go.mod file. --- rushScripts/regeneration.js | 2 +- src/generator/generator.ts | 24 +++++++++++-------- src/generator/gomod.ts | 2 +- test/storage/2019-07-07/azblob/go.mod | 2 +- ...pendblob.go => zz_generated_appendblob.go} | 0 .../azblob/{blob.go => zz_generated_blob.go} | 0 ...blockblob.go => zz_generated_blockblob.go} | 0 .../{client.go => zz_generated_client.go} | 0 ...container.go => zz_generated_container.go} | 0 ...directory.go => zz_generated_directory.go} | 0 .../{enums.go => zz_generated_enums.go} | 0 .../{models.go => zz_generated_models.go} | 0 .../{pageblob.go => zz_generated_pageblob.go} | 0 .../{pagers.go => zz_generated_pagers.go} | 0 .../{service.go => zz_generated_service.go} | 0 ...fc1123.go => zz_generated_time_rfc1123.go} | 0 ...fc3339.go => zz_generated_time_rfc3339.go} | 0 17 files changed, 17 insertions(+), 13 deletions(-) rename test/storage/2019-07-07/azblob/{appendblob.go => zz_generated_appendblob.go} (100%) rename test/storage/2019-07-07/azblob/{blob.go => zz_generated_blob.go} (100%) rename test/storage/2019-07-07/azblob/{blockblob.go => zz_generated_blockblob.go} (100%) rename test/storage/2019-07-07/azblob/{client.go => zz_generated_client.go} (100%) rename test/storage/2019-07-07/azblob/{container.go => zz_generated_container.go} (100%) rename test/storage/2019-07-07/azblob/{directory.go => zz_generated_directory.go} (100%) rename test/storage/2019-07-07/azblob/{enums.go => zz_generated_enums.go} (100%) rename test/storage/2019-07-07/azblob/{models.go => zz_generated_models.go} (100%) rename test/storage/2019-07-07/azblob/{pageblob.go => zz_generated_pageblob.go} (100%) rename test/storage/2019-07-07/azblob/{pagers.go => zz_generated_pagers.go} (100%) rename test/storage/2019-07-07/azblob/{service.go => zz_generated_service.go} (100%) rename test/storage/2019-07-07/azblob/{time_rfc1123.go => zz_generated_time_rfc1123.go} (100%) rename test/storage/2019-07-07/azblob/{time_rfc3339.go => zz_generated_time_rfc3339.go} (100%) 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