Skip to content

Commit

Permalink
Add file-prefix switch (#431)
Browse files Browse the repository at this point in the history
To add optional prefix to file names (uses snake-casing).
Bumped azcore version in go.mod file.
  • Loading branch information
jhendrixMSFT authored Jun 30, 2020
1 parent 7f7a951 commit 3ec17cd
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rushScripts/regeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 14 additions & 10 deletions src/generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeModel>(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) {
Expand Down
2 changes: 1 addition & 1 deletion src/generator/gomod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export async function generateGoModFile(session: Session<CodeModel>): Promise<st
text += 'go 1.13\n\n';
// here we specify the minimum version of azcore as required by the code generator
// TODO: come up with a way to get the latest minor/patch version.
text += 'require github.com/Azure/azure-sdk-for-go/sdk/azcore v0.8.0\n';
text += 'require github.com/Azure/azure-sdk-for-go/sdk/azcore v0.8.2\n';
return text;
}
2 changes: 1 addition & 1 deletion test/storage/2019-07-07/azblob/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module azstorage

go 1.13

require github.com/Azure/azure-sdk-for-go/sdk/azcore v0.8.0
require github.com/Azure/azure-sdk-for-go/sdk/azcore v0.8.2
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3ec17cd

Please sign in to comment.