Skip to content

Commit

Permalink
Update all azureresourceschema.md files (Azure#10657)
Browse files Browse the repository at this point in the history
* Revert "Update all readme.azureresourceschema.md (Azure#10647)"

This reverts commit a615f5c.

* Update script to output schema input files to readme.azureresourceschema.md

* Update script to create apiVersion specific tags for schema generation

* Regenerating all readme.azureresourceschema.md

* Run npm run multiapi to update all-api-versions blocks
  • Loading branch information
leni-msft authored Sep 1, 2020
1 parent 51a9390 commit e773233
Show file tree
Hide file tree
Showing 161 changed files with 8,333 additions and 1,117 deletions.
70 changes: 47 additions & 23 deletions scripts/multiapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import * as yaml from "js-yaml"
type Code = {
readonly "input-file"?: ReadonlyArray<string>|string
}
const yamlBegin = `yaml $(tag) == 'all-api-versions' /* autogenerated */`;
const magic = `yaml $(tag) == 'all-api-versions' /* autogenerated */`;
const pathRegex = /microsoft\.(\w+)\/\S*\/(\d{4}-\d{2}-\d{2}(|-preview))\//i;

const main = async (specificationDir: string, profilesDir: string) => {
const main = async (specificationDir: string) => {
try {
const list = fs.recursiveReaddir(specificationDir)
for await (const file of list) {
const f = path.parse(file)
if (f.base === "readme.md") {
if (f.base === "readme.md" && f.dir.endsWith('/resource-manager')) {
const original_content = (await fs.readFile(file)).toString()
let content = original_content;
const readMe = cm.parse(content)
Expand All @@ -27,7 +28,7 @@ const main = async (specificationDir: string, profilesDir: string) => {
if (
c.type === "code_block" &&
c.info !== null &&
(c.info.startsWith("yaml") && !c.info.startsWith(yamlBegin)) &&
(c.info.startsWith("yaml") && !c.info.startsWith(magic)) &&
c.literal !== null
) {
const DOC = (yaml.load(c.literal) as Code);
Expand All @@ -41,38 +42,61 @@ const main = async (specificationDir: string, profilesDir: string) => {
}
}
}

}
}
const block =
let map = new Map<string, string[]>();
for (let input of set) {
let match = pathRegex.exec(input);
if (!!match) {
let tagName = `schema-${match[1].toLowerCase()}-${match[2]}`;
if (!map.has(tagName)) {
map.set(tagName, []);
}
let array = map.get(tagName);
if (!!array) {
array.push(input);
}
}
}
map = new Map(Array.from(map.entries()).sort().reverse());
let schemaReadmeContent =
`## AzureResourceSchema
These settings apply only when \`--azureresourceschema\` is specified on the command line.
### AzureResourceSchema multi-api
\`\`\` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ${path.relative(f.dir, profilesDir).replace(/\\/g, '/')}/readme.md
${yaml.dump({ 'batch': it.toArray(it.map(map.keys(), (tagName) => ({'tag': tagName})))}, { lineWidth: 1000})}
\`\`\`
Please also specify \`--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>\`.
`
map.forEach((inputList, tagName) => {
schemaReadmeContent +=
`
### Tag: ${tagName} and azureresourceschema
\`\`\` yaml $(tag) == '${tagName}' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas
# all the input files across all versions
${yaml.dump({ 'input-file': it.toArray(set) },{ lineWidth: 1000 } )}
\`\`\``
content = content.replace( /``` yaml \$\(tag\) == 'all-api-versions' \/\* autogenerated \*\/[\S\s]*?```/g, '')
content = content.replace( /``` yaml \$\(tag\) == 'all-api-versions'[\S\s]*?```/g, '')
content = content.replace( /## Multi-API\/Profile support for AutoRest v3 generators[\S\s]*/g, '')
# all the input files in this apiVersion
${yaml.dump({ 'input-file': it.toArray(inputList)}, { lineWidth: 1000})}
\`\`\`
`
});

if(original_content !== content ){
console.log(`Updating: ${file}`);
fs.writeFile(path.join(f.dir, "readme.md"), content)
}
// content = content.replace( /``` yaml \$\(tag\) == 'all-api-versions' \/\* autogenerated \*\/[\S\s]*?```/g, '')
// content = content.replace( /``` yaml \$\(tag\) == 'all-api-versions'[\S\s]*?```/g, '')
// content = content.replace( /## Multi-API\/Profile support for AutoRest v3 generators[\S\s]*/g, '')

if (f.dir.endsWith('/resource-manager')) {
console.log(`Rewriting: ${f.dir}/readme.azureresourceschema.md`);
fs.writeFile(path.join(f.dir, "readme.azureresourceschema.md"), block);
}
// if(original_content !== content ){
// console.log(`Updating: ${file}`);
// fs.writeFile(path.join(f.dir, "readme.md"), content)
// }

console.log(`Rewriting: ${f.dir}/readme.azureresourceschema.md`);
fs.writeFile(path.join(f.dir, "readme.azureresourceschema.md"), schemaReadmeContent);

}
}
Expand All @@ -81,4 +105,4 @@ ${yaml.dump({ 'input-file': it.toArray(set) },{ lineWidth: 1000 } )}
}
}

main(path.join(process.cwd(), "specification"), path.join(process.cwd(), "profiles"))
main(path.join(process.cwd(), "specification"))
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ These settings apply only when `--azureresourceschema` is specified on the comma
### AzureResourceSchema multi-api

``` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ../../../profiles/readme.md
batch:
- tag: schema-enterpriseknowledgegraph-2018-12-03

```

Please also specify `--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>`.

### Tag: schema-enterpriseknowledgegraph-2018-12-03 and azureresourceschema

``` yaml $(tag) == 'schema-enterpriseknowledgegraph-2018-12-03' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files across all versions
# all the input files in this apiVersion
input-file:
- Microsoft.EnterpriseKnowledgeGraph/preview/2018-12-03/EnterpriseKnowledgeGraphSwagger.json

```
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,32 @@ These settings apply only when `--azureresourceschema` is specified on the comma
### AzureResourceSchema multi-api

``` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ../../../profiles/readme.md
batch:
- tag: schema-addons-2018-03-01
- tag: schema-addons-2017-05-15

```

Please also specify `--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>`.

### Tag: schema-addons-2018-03-01 and azureresourceschema

``` yaml $(tag) == 'schema-addons-2018-03-01' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files across all versions
# all the input files in this apiVersion
input-file:
- Microsoft.Addons/preview/2018-03-01/addons-swagger.json

```

### Tag: schema-addons-2017-05-15 and azureresourceschema

``` yaml $(tag) == 'schema-addons-2017-05-15' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.Addons/preview/2017-05-15/Addons.json

```
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ These settings apply only when `--azureresourceschema` is specified on the comma
### AzureResourceSchema multi-api

``` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ../../../profiles/readme.md
batch: []

output-folder: $(azureresourceschema-folder)/schemas
```
# all the input files across all versions
input-file:
- Microsoft.ADHybridHealthService\stable\2014-01-01\ADHybridHealthService.json

```
Please also specify `--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>`.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,68 @@ These settings apply only when `--azureresourceschema` is specified on the comma
### AzureResourceSchema multi-api

``` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ../../../profiles/readme.md
batch:
- tag: schema-advisor-2020-07-01-preview
- tag: schema-advisor-2020-01-01
- tag: schema-advisor-2017-04-19
- tag: schema-advisor-2017-03-31
- tag: schema-advisor-2016-07-12-preview

```

Please also specify `--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>`.

### Tag: schema-advisor-2020-07-01-preview and azureresourceschema

``` yaml $(tag) == 'schema-advisor-2020-07-01-preview' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files across all versions
# all the input files in this apiVersion
input-file:
- Microsoft.Advisor/preview/2020-07-01-preview/advisor.json

```

### Tag: schema-advisor-2020-01-01 and azureresourceschema

``` yaml $(tag) == 'schema-advisor-2020-01-01' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.Advisor/stable/2020-01-01/advisor.json

```

### Tag: schema-advisor-2017-04-19 and azureresourceschema

``` yaml $(tag) == 'schema-advisor-2017-04-19' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.Advisor/stable/2017-04-19/advisor.json

```

### Tag: schema-advisor-2017-03-31 and azureresourceschema

``` yaml $(tag) == 'schema-advisor-2017-03-31' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.Advisor/stable/2017-03-31/advisor.json

```

### Tag: schema-advisor-2016-07-12-preview and azureresourceschema

``` yaml $(tag) == 'schema-advisor-2016-07-12-preview' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.Advisor/preview/2016-07-12-preview/advisor.json

```
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,71 @@ These settings apply only when `--azureresourceschema` is specified on the comma
### AzureResourceSchema multi-api

``` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ../../../profiles/readme.md
batch:
- tag: schema-alertsmanagement-2019-06-01
- tag: schema-alertsmanagement-2019-05-05-preview
- tag: schema-alertsmanagement-2019-03-01
- tag: schema-alertsmanagement-2018-05-05-preview
- tag: schema-alertsmanagement-2018-05-05

```

Please also specify `--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>`.

### Tag: schema-alertsmanagement-2019-06-01 and azureresourceschema

``` yaml $(tag) == 'schema-alertsmanagement-2019-06-01' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.AlertsManagement/stable/2019-06-01/SmartDetectorAlertRulesApi.json

```

### Tag: schema-alertsmanagement-2019-05-05-preview and azureresourceschema

``` yaml $(tag) == 'schema-alertsmanagement-2019-05-05-preview' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files across all versions
# all the input files in this apiVersion
input-file:
- Microsoft.AlertsManagement/preview/2019-05-05-preview/ActionRules.json
- Microsoft.AlertsManagement/preview/2019-05-05-preview/AlertsManagement.json
- Microsoft.AlertsManagement/preview/2019-05-05-preview/SmartGroups.json
- Microsoft.AlertsManagement/stable/2019-06-01/SmartDetectorAlertRulesApi.json

```

### Tag: schema-alertsmanagement-2019-03-01 and azureresourceschema

``` yaml $(tag) == 'schema-alertsmanagement-2019-03-01' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.AlertsManagement/stable/2019-03-01/AlertsManagement.json
- Microsoft.AlertsManagement/stable/2019-03-01/SmartDetectorAlertRulesApi.json
- Microsoft.AlertsManagement/stable/2018-05-05/AlertsManagement.json

```

### Tag: schema-alertsmanagement-2018-05-05-preview and azureresourceschema

``` yaml $(tag) == 'schema-alertsmanagement-2018-05-05-preview' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.AlertsManagement/preview/2018-05-05-preview/AlertsManagement.json

```
```

### Tag: schema-alertsmanagement-2018-05-05 and azureresourceschema

``` yaml $(tag) == 'schema-alertsmanagement-2018-05-05' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.AlertsManagement/stable/2018-05-05/AlertsManagement.json

```
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,44 @@ These settings apply only when `--azureresourceschema` is specified on the comma
### AzureResourceSchema multi-api

``` yaml $(azureresourceschema) && $(multiapi)
# include the azure profile definitions from the standard location
require: ../../../profiles/readme.md
batch:
- tag: schema-analysisservices-2017-08-01
- tag: schema-analysisservices-2017-07-14
- tag: schema-analysisservices-2016-05-16

```

Please also specify `--azureresourceschema-folder=<path to the root directory of your azure-resource-manager-schemas clone>`.

### Tag: schema-analysisservices-2017-08-01 and azureresourceschema

``` yaml $(tag) == 'schema-analysisservices-2017-08-01' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files across all versions
# all the input files in this apiVersion
input-file:
- Microsoft.AnalysisServices/stable/2017-08-01/analysisservices.json
- Microsoft.AnalysisServices/preview/2017-08-01-beta/analysisservices.json

```

### Tag: schema-analysisservices-2017-07-14 and azureresourceschema

``` yaml $(tag) == 'schema-analysisservices-2017-07-14' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.AnalysisServices/stable/2017-07-14/analysisservices.json

```

### Tag: schema-analysisservices-2016-05-16 and azureresourceschema

``` yaml $(tag) == 'schema-analysisservices-2016-05-16' && $(azureresourceschema)
output-folder: $(azureresourceschema-folder)/schemas

# all the input files in this apiVersion
input-file:
- Microsoft.AnalysisServices/stable/2016-05-16/analysisservices.json

```
```
Loading

0 comments on commit e773233

Please sign in to comment.