Skip to content

Commit f642ade

Browse files
committed
Regenerate readme.azureresourceschema.md before autorest
1 parent 80cc085 commit f642ade

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

generator/autogenlist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ const autoGenList: AutoGenConfig[] = [
671671
{
672672
basePath: 'keyvault/resource-manager',
673673
namespace: 'Microsoft.KeyVault',
674-
overrideApiVersion: {
674+
readmeTag: {
675675
'2016-10-01': [
676676
'Microsoft.KeyVault/stable/2016-10-01/keyvault.json',
677677
'Microsoft.KeyVault/stable/2016-10-01/providers.json',

generator/generate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export async function getApiVersionsByNamespace(readme: string): Promise<Diction
4747

4848
export async function generateSchemas(readme: string, autoGenConfig?: AutoGenConfig): Promise<SchemaConfiguration[]> {
4949
await prepareReadme(readme, autoGenConfig);
50+
5051
const apiVersionsByNamespace = pickBy(
5152
await getApiVersionsByNamespace(readme),
5253
(_, key) => !autoGenConfig || lowerCaseEquals(key, autoGenConfig.namespace));

generator/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export interface AutoGenConfig {
1212
basePath: string,
1313
namespace: string,
1414
readmeFile?: string,
15-
overrideApiVersion?: ApiVersionFile,
15+
readmeTag?: ReadmeTag,
1616
suffix?: string,
1717
resourceConfig?: AutoGenResourceConfig[],
1818
postProcessor?: SchemaPostProcessor,
1919
}
2020

21-
export interface ApiVersionFile {
21+
export interface ReadmeTag {
2222
[apiVersion: string]: string[]
2323
}
2424

generator/package-lock.json

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator/specs.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs';
33
import { promisify } from 'util';
44
import { cloneGitRepo } from './git';
55
import { findRecursive, lowerCaseEquals } from './utils';
6-
import { ApiVersionFile, AutoGenConfig, CodeBlock } from './models';
6+
import { ReadmeTag, AutoGenConfig, CodeBlock } from './models';
77
import * as constants from './constants'
88
import * as cm from '@ts-common/commonmark-to-markdown'
99
import * as yaml from 'js-yaml'
@@ -90,19 +90,52 @@ export async function prepareReadme(readme: string, autoGenConfig?: AutoGenConfi
9090
}
9191
}
9292

93-
const result = {} as ApiVersionFile;
93+
let readmeTag = {} as ReadmeTag;
9494
fileSet.forEach(inputFile => {
9595
const match = constants.pathRegex.exec(inputFile);
9696
if (!!match) {
9797
const mNamespace = match[1];
9898
const mApiVersion = match[2];
9999
if (!autoGenConfig || lowerCaseEquals(mNamespace, autoGenConfig.namespace)) {
100-
if (!result[mApiVersion]) {
101-
result[mApiVersion] = [];
100+
if (!readmeTag[mApiVersion]) {
101+
readmeTag[mApiVersion] = [];
102102
}
103-
result[mApiVersion].push(inputFile);
103+
readmeTag[mApiVersion].push(inputFile);
104104
}
105105
}
106106
});
107107

108+
if (!!autoGenConfig?.readmeTag) {
109+
readmeTag = {...readmeTag, ...autoGenConfig.readmeTag };
110+
}
111+
112+
const schemaReadmeContent = compositeSchemaReadme(readmeTag);
113+
114+
const schemaReadme = readme.replace(/\.md$/i, '.azureresourceschema.md');
115+
116+
fs.writeFileSync(schemaReadme, schemaReadmeContent);
117+
}
118+
119+
function compositeSchemaReadme(readmeTag: ReadmeTag): string {
120+
let content =
121+
`## AzureResourceSchema
122+
123+
### AzureResourceSchema multi-api
124+
125+
\`\`\` yaml $(azureresourceschema) && $(multiapi)
126+
${yaml.dump({ 'batch': Object.keys(readmeTag).map(apiVersion => ({ 'tag': `schema-${apiVersion}`})) }, { lineWidth: 1000 })}
127+
\`\`\`
128+
129+
`
130+
for (const apiVersion of Object.keys(readmeTag)) {
131+
content +=
132+
`
133+
### Tag: schema-${apiVersion} and azureresourceschema
134+
135+
\`\`\` yaml $(tag) == 'schema-${apiVersion}' && $(azureresourceschema)
136+
${yaml.dump({ 'input-file': readmeTag[apiVersion] }, { lineWidth: 1000})}
137+
\`\`\`
138+
`
139+
}
140+
return content;
108141
}

0 commit comments

Comments
 (0)