Skip to content

Commit ca29da5

Browse files
Merge pull request #3016 from Azure/ant/fix_aks
Fix AKS autogeneration
2 parents 6c9d1df + 679d2d3 commit ca29da5

File tree

105 files changed

+95998
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+95998
-411
lines changed

.github/workflows/generate-single.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
required: true
99
default: 'main'
1010
single_path:
11-
description: 'The path to generate types for (e.g. "compute", or "keyvault").'
11+
description: 'The path to generate types for (e.g. "compute/resource-manager", or "keyvault/resource-manager").'
1212
required: true
1313

1414
jobs:
@@ -40,7 +40,7 @@ jobs:
4040
run: |
4141
npm run generate-single -- \
4242
--local-path "$GITHUB_WORKSPACE/workflow-temp/azure-rest-api-specs" \
43-
--base-path '${{ github.event.inputs.single_path }}/resource-manager'
43+
--base-path '${{ github.event.inputs.single_path }}'
4444
working-directory: generator
4545

4646
- name: Create Pull Request

.vscode/launch.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"args": [
2727
"${workspaceFolder}/generator/cmd/generatesingle.ts",
2828
"--base-path",
29-
"${input:resourceProvider}/resource-manager"
29+
"${input:resourceProvider}"
3030
]
3131
},
3232
{
@@ -53,10 +53,10 @@
5353
],
5454
"inputs": [
5555
{
56-
"id": "resourceProvider",
56+
"id": "basePath",
5757
"type": "promptString",
58-
"default": "alertsmanagement",
59-
"description": "The ResourceProvider name, e.g., compute, network"
58+
"default": "alertsmanagement/resource-manager",
59+
"description": "The path to generate types for (e.g. \"compute/resource-manager\", or \"keyvault/resource-manager\")."
6060
}
6161
]
6262
}

generator/autogenlist.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { postProcessor as azureStackHciPostProcessor } from './processors/Micros
1717
import { postProcessor as resourcesPostProcessor } from './processors/Microsoft.Resources';
1818
import { postProcessor as serviceFabricPostProcessor } from './processors/Microsoft.ServiceFabric';
1919
import { lowerCaseEquals } from './utils';
20+
import { detectProviderNamespaces } from './generate';
2021

2122
// New providers are onboarded by default. The providers listed here are the only ones **not** onboarded.
2223
const disabledProviders: AutoGenConfig[] = [
@@ -110,10 +111,16 @@ const disabledProviders: AutoGenConfig[] = [
110111
disabledForAutogen: true
111112
},
112113
{
113-
// Disabled temporally due to unsupported directory structure
114-
basePath: 'containerservice/resource-manager',
114+
basePath: 'containerservice/resource-manager/Microsoft.ContainerService/aks',
115115
namespace: 'Microsoft.ContainerService',
116-
disabledForAutogen: true,
116+
useNamespaceFromConfig: true,
117+
suffix: 'Aks'
118+
},
119+
{
120+
basePath: 'containerservice/resource-manager/Microsoft.ContainerService/fleet',
121+
namespace: 'Microsoft.ContainerService',
122+
useNamespaceFromConfig: true,
123+
suffix: 'Fleet'
117124
},
118125
];
119126

@@ -1160,10 +1167,16 @@ export function findAutogenEntries(basePath: string): AutoGenConfig[] {
11601167
return autoGenList.filter(w => lowerCaseEquals(w.basePath, basePath));
11611168
}
11621169

1163-
export function findOrGenerateAutogenEntries(basePath: string, namespaces: string[]): AutoGenConfig[] {
1164-
const entries = findAutogenEntries(basePath).filter(e => namespaces.some(ns => lowerCaseEquals(e.namespace, ns)));
1170+
export async function findOrGenerateAutogenEntries(basePath: string, readme: string): Promise<AutoGenConfig[]> {
1171+
let entries = findAutogenEntries(basePath);
1172+
if (entries.some(e => e.useNamespaceFromConfig)) {
1173+
return entries;
1174+
}
1175+
1176+
const detectedNamespaces = await detectProviderNamespaces(readme);
1177+
entries = entries.filter(e => detectedNamespaces.some(ns => lowerCaseEquals(e.namespace, ns)));
11651178

1166-
for (const namespace of namespaces) {
1179+
for (const namespace of detectedNamespaces) {
11671180
if (!entries.some(e => lowerCaseEquals(e.namespace, namespace))) {
11681181
// Generate configuration for any RPs not explicitly declared in the autogen list
11691182
entries.push({

generator/cmd/generateall.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Licensed under the MIT License.
33
import * as constants from '../constants';
44
import { cloneAndGenerateBasePaths, generateBasePaths, getPackageString, resolveAbsolutePath, validateAndReturnReadmePath } from '../specs';
5-
import { SchemaConfiguration, generateSchemas, clearAutoGeneratedSchemaRefs, saveAutoGeneratedSchemaRefs, getApiVersionsByNamespace } from '../generate';
5+
import { SchemaConfiguration, generateSchemas, clearAutoGeneratedSchemaRefs, saveAutoGeneratedSchemaRefs } from '../generate';
66
import { findOrGenerateAutogenEntries } from '../autogenlist';
77
import colors from 'colors';
8-
import { flatten, keys } from 'lodash';
8+
import { flatten } from 'lodash';
99
import { executeSynchronous, chunker, writeJsonFile } from '../utils';
1010
import { Package } from '../models';
1111
import yargs from 'yargs';
@@ -72,8 +72,7 @@ executeSynchronous(async () => {
7272
for (const basePath of basePaths) {
7373
try {
7474
const readme = validateAndReturnReadmePath(localPath, basePath);
75-
const namespaces = keys(await getApiVersionsByNamespace(readme));
76-
let filteredAutoGenList = findOrGenerateAutogenEntries(basePath, namespaces)
75+
let filteredAutoGenList = (await findOrGenerateAutogenEntries(basePath, readme))
7776
.filter(x => x.disabledForAutogen !== true);
7877

7978
if (args['readme-files']) {

generator/cmd/generateonboardedreport.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import * as constants from '../constants';
44
import { cloneAndGenerateBasePaths, validateAndReturnReadmePath } from '../specs';
55
import { findOrGenerateAutogenEntries } from '../autogenlist';
66
import { executeSynchronous, writeJsonFile, safeMkdir } from '../utils';
7-
import { getApiVersionsByNamespace } from '../generate';
8-
import { keys, partition } from 'lodash';
7+
import { partition } from 'lodash';
98
import path from 'path';
109

1110
executeSynchronous(async () => {
@@ -15,8 +14,7 @@ executeSynchronous(async () => {
1514

1615
for (const basePath of basePaths) {
1716
const readme = validateAndReturnReadmePath(constants.specsRepoPath, basePath);
18-
const namespaces = keys(await getApiVersionsByNamespace(readme));
19-
const autogenlistEntries = findOrGenerateAutogenEntries(basePath, namespaces);
17+
const autogenlistEntries = await findOrGenerateAutogenEntries(basePath, readme);
2018

2119
const [unautogened, autogened] = partition(
2220
autogenlistEntries,

generator/cmd/generatesingle.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// Licensed under the MIT License.
33
import * as constants from '../constants';
44
import { cloneAndGenerateBasePaths, resolveAbsolutePath, validateAndReturnReadmePath } from '../specs';
5-
import { generateSchemas, saveAutoGeneratedSchemaRefs, getApiVersionsByNamespace } from '../generate';
5+
import { generateSchemas, saveAutoGeneratedSchemaRefs } from '../generate';
66
import { findOrGenerateAutogenEntries } from '../autogenlist';
77
import colors from 'colors';
8-
import { keys } from 'lodash';
98
import { executeSynchronous } from '../utils';
109
import yargs from 'yargs';
1110

@@ -34,8 +33,7 @@ executeSynchronous(async () => {
3433
}
3534

3635
const schemaConfigs = [];
37-
const namespaces = keys(await getApiVersionsByNamespace(readme));
38-
const autoGenEntries = findOrGenerateAutogenEntries(basePath, namespaces);
36+
const autoGenEntries = await findOrGenerateAutogenEntries(basePath, readme);
3937

4038
for (const autoGenConfig of autoGenEntries) {
4139
if (autoGenConfig.disabledForAutogen === true) {

generator/cmd/listbasepaths.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import { cloneAndGenerateBasePaths, validateAndReturnReadmePath } from '../specs
55
import colors from 'colors';
66
import { findOrGenerateAutogenEntries } from '../autogenlist';
77
import { executeSynchronous } from '../utils';
8-
import { getApiVersionsByNamespace } from '../generate';
9-
import { keys, partition } from 'lodash';
8+
import { partition } from 'lodash';
109

1110
executeSynchronous(async () => {
1211
const basePaths = await cloneAndGenerateBasePaths(constants.specsRepoPath, constants.specsRepoUri, constants.specsRepoCommitHash);
1312

1413
for (const basePath of basePaths) {
1514
const readme = validateAndReturnReadmePath(constants.specsRepoPath, basePath);
16-
const namespaces = keys(await getApiVersionsByNamespace(readme));
17-
const autogenlistEntries = findOrGenerateAutogenEntries(basePath, namespaces);
15+
const autogenlistEntries = await findOrGenerateAutogenEntries(basePath, readme);
1816

1917
const [unautogened, autogened] = partition(
2018
autogenlistEntries,

generator/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export const generatorRoot = path.resolve(__dirname, '../');
88
export const specsRepoPath = path.join(os.tmpdir(), 'schm_azspc');
99
export const specsRepoUri = 'https://github.com/azure/azure-rest-api-specs';
1010
export const specsRepoCommitHash = 'origin/main';
11-
// eslint-disable-next-line no-useless-escape
12-
export const pathRegex = /(microsoft\.\w+|NGINX.NGINXPLUS|DYNATRACE.OBSERVABILITY)[\\\/]\S*[\\\/](\d{4}-\d{2}-\d{2}(|-preview))[\\\/]/i;
1311

1412
export const autoRestVerboseOutput = false;
1513

generator/generate.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Licensed under the MIT License.
33
import path from 'path';
44
import os from 'os';
5-
import { findRecursive, findDirRecursive, executeCmd, rmdirRecursive, lowerCaseCompare, lowerCaseCompareLists, lowerCaseStartsWith, readJsonFile, writeJsonFile, safeMkdir, safeUnlink, fileExists, lowerCaseEquals, lowerCaseContains } from './utils';
5+
import { findRecursive, findDirRecursive, executeCmd, rmdirRecursive, lowerCaseCompare, lowerCaseCompareLists, lowerCaseStartsWith, readJsonFile, writeJsonFile, safeMkdir, safeUnlink, fileExists, lowerCaseEquals } from './utils';
66
import * as constants from './constants';
77
import { prepareReadme } from './specs';
88
import colors from 'colors';
99
import { ScopeType, AutoGenConfig } from './models';
10-
import { get, set, flatten, uniq, concat, Dictionary, groupBy, keys, difference, pickBy } from 'lodash';
10+
import { get, set, flatten, uniq, concat, Dictionary, groupBy, keys, difference } from 'lodash';
1111

1212
const autorestBinary = os.platform() === 'win32' ? 'autorest.cmd' : 'autorest';
13-
const apiVersionRegex = /^\d{4}-\d{2}-\d{2}(|-preview)$/;
13+
export const apiVersionRegex = /^\d{4}-\d{2}-\d{2}(|-preview)$/;
1414

1515
export interface SchemaConfiguration {
1616
references: SchemaReference[];
@@ -35,27 +35,17 @@ const RootSchemaConfigs: Map<ScopeType, RootSchemaConfiguration> = new Map([
3535
[ScopeType.ManagementGroup, constants.managementGroupRootSchema]
3636
]);
3737

38-
export async function getApiVersionsByNamespace(readme: string): Promise<Dictionary<string[]>> {
38+
export async function detectProviderNamespaces(readme: string) {
3939
const searchPath = path.resolve(`${readme}/..`);
40-
const apiVersionPaths = await findDirRecursive(searchPath, p => path.basename(p).match(apiVersionRegex) !== null);
41-
42-
const output: Dictionary<string[]> = {};
43-
for (const [namespace, , apiVersion] of apiVersionPaths.map(p => path.relative(searchPath, p).split(path.sep))) {
44-
output[namespace] = [...(output[namespace] ?? []), apiVersion];
45-
}
4640

47-
return output;
41+
// To try and detect possible provider namespaces, assume a folder structure of <provider>/preview|stable/<api-version>/..., based on convention
42+
const apiVersionPaths = await findDirRecursive(searchPath, p => path.basename(p).match(apiVersionRegex) !== null);
43+
return uniq(apiVersionPaths.map(p => path.relative(searchPath, p).split(path.sep)[0]));
4844
}
4945

50-
export async function generateSchemas(readme: string, autoGenConfig?: AutoGenConfig): Promise<SchemaConfiguration[]> {
46+
export async function generateSchemas(readme: string, autoGenConfig: AutoGenConfig): Promise<SchemaConfiguration[]> {
5147
await prepareReadme(readme, autoGenConfig);
5248

53-
const apiVersionsByNamespace = pickBy(
54-
await getApiVersionsByNamespace(readme),
55-
(_, key) => !autoGenConfig || lowerCaseEquals(key, autoGenConfig.namespace));
56-
57-
const namespaces = keys(apiVersionsByNamespace);
58-
5949
const schemaConfigs: SchemaConfiguration[] = [];
6050
const tmpFolder = path.join(os.tmpdir(), Math.random().toString(36).substr(2));
6151

@@ -64,7 +54,7 @@ export async function generateSchemas(readme: string, autoGenConfig?: AutoGenCon
6454

6555
for (const schemaPath of generatedSchemas) {
6656
const namespace = path.basename(schemaPath.substring(0, schemaPath.lastIndexOf(path.extname(schemaPath))));
67-
if (!lowerCaseContains(namespaces, namespace)) {
57+
if (!lowerCaseEquals(autoGenConfig.namespace, namespace)) {
6858
continue;
6959
}
7060

generator/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface AutoGenConfig {
1414
disabledForAutogen?: true,
1515
basePath: string,
1616
namespace: string,
17+
useNamespaceFromConfig?: boolean,
1718
readmeFile?: string,
1819
readmeTag?: ReadmeTag,
1920
suffix?: string,

0 commit comments

Comments
 (0)