Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ bin/$(CODEGEN): .make/prebuild .make/provider_mod_download provider/cmd/$(CODEGE

# Writes schema-full.json and metadata-compact.json to bin/
# Also re-calculates files in versions/ at same time
bin/schema-full.json bin/metadata-compact.json &: bin/$(CODEGEN) $(SPECS) versions/az-provider-list.json versions/v${PREVIOUS_MAJOR_VERSION}.yaml versions/v${MAJOR_VERSION}-config.yaml versions/v${MAJOR_VERSION}-spec.yaml versions/v${MAJOR_VERSION}-removed.json versions/v${MAJOR_VERSION}-removed-resources.json versions/v${NEXT_MAJOR_VERSION}-removed-resources.json
bin/schema-full.json bin/metadata-compact.json &: bin/$(CODEGEN) $(SPECS) versions/az-provider-list.json versions/v${PREVIOUS_MAJOR_VERSION}.yaml versions/v${MAJOR_VERSION}-config.yaml versions/v${MAJOR_VERSION}-spec.yaml versions/v${MAJOR_VERSION}-removed.json versions/v${MAJOR_VERSION}-removed-resources.json versions/v${NEXT_MAJOR_VERSION}-removed-resources.json $(wildcard autorest/*)
cd autorest && npm ci && npm start
bin/$(CODEGEN) defaultVersions
bin/$(CODEGEN) schema

# Docs schema - treat as phony becasuse it's committed so we always need to rebuild it.
Expand Down
5 changes: 5 additions & 0 deletions autorest/default-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

```yaml
tag: package-2024-04
track2: true
```
90 changes: 90 additions & 0 deletions autorest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { glob } from "fast-glob";
import { writeFile, readFile } from "fs/promises";
import * as path from "path";
import { fileURLToPath } from "url";
import { ConfigurationLoader } from "@autorest/configuration";
import {
ConsoleLogger,
FilterLogger,
AutorestSyncLogger,
} from "@autorest/common";
import { createFolderUri, createFileOrFolderUri } from "@azure-tools/uri";
import yaml from "yaml";

(async () => {
const logger = new AutorestSyncLogger({
sinks: [new ConsoleLogger()],
processors: [new FilterLogger({ level: "error" })],
});
const defaultConfigUri = createFileOrFolderUri(
require.resolve(
"@autorest/configuration/resources/default-configuration.md"
)
);

const specificationRootDir = path.resolve("..", "azure-rest-api-specs");
const readmeFiles = await glob("specification/*/resource-manager/readme.md", {
cwd: specificationRootDir,
});

const result: string[] = [];
for (const readmeFile of readmeFiles) {
const configFolderUri = createFolderUri(
path.dirname(path.resolve(specificationRootDir, readmeFile))
);
const configLoader = new ConfigurationLoader(
logger,
defaultConfigUri,
configFolderUri
);
const config = await configLoader.load([], true);
const inputFiles = config.config.inputFileUris.map((uri) =>
path.relative(specificationRootDir, fileURLToPath(uri))
);
result.push(...inputFiles);
}
result.sort();
writeFile(
"../reports/autorest-input-files.json",
JSON.stringify(result, null, 2)
);

const autorestSpecFilePathsLookup = new Set<string>(result);

const allResourcesByVersionContent = await readFile(
"../reports/allResourcesByVersion.json",
"utf-8"
);
const allResourcesByVersion: Record<
ProviderModule,
Record<ApiVersion, Record<ResourceName, VersionEntry>>
> = JSON.parse(allResourcesByVersionContent);
const specVersions: Record<
ProviderModule,
Record<ResourceName, VersionEntry>
> = {};
for (const [providerModule, versions] of Object.entries(
allResourcesByVersion
)) {
const module: Record<ResourceName, VersionEntry> = {};
specVersions[providerModule] = module;
for (const resources of Object.values(versions)) {
for (const [resourceName, entry] of Object.entries(resources)) {
if (autorestSpecFilePathsLookup.has(entry.SpecFilePath)) {
module[resourceName] = entry;
}
}
}
}
writeFile("../reports/autorest.yaml", yaml.stringify(specVersions, null, 2));
})().catch(console.error);

type ProviderModule = string;
type ApiVersion = string;
type ResourceName = string;
type VersionEntry = {
ApiVersion: ApiVersion;
SpecFilePath: string;
ResourceUri: string;
RpNamespace: string;
};
Loading