Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate schemas using autorest.bicep #1740

Merged
merged 2 commits into from
Apr 10, 2024
Merged

Generate schemas using autorest.bicep #1740

merged 2 commits into from
Apr 10, 2024

Conversation

anthony-c-martin
Copy link
Member

@anthony-c-martin anthony-c-martin commented Jul 27, 2023

https://github.com/Azure/azure-resource-manager-schemas has a dependency on a very old and unsupported Autorest plugin (source repo here), and to be able to keep supporting this process, it would make sense to try and upgrade to a more recent version.

Rather than forking this repo and creating a new TS-based plugin, it feels better to try and share the code. This PR adds an optional flag --arm-schema that'll generate JSON instead of Bicep if used.

@codecov-commenter
Copy link

codecov-commenter commented Jul 27, 2023

Codecov Report

Merging #1740 (ea43986) into main (d5e8a05) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1740   +/-   ##
=======================================
  Coverage   95.00%   95.00%           
=======================================
  Files           2        2           
  Lines          20       20           
=======================================
  Hits           19       19           
  Misses          1        1           
Flag Coverage Δ
dotnet 95.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@anthony-c-martin anthony-c-martin force-pushed the ant/schemas branch 3 times, most recently from e4caeb0 to 9082b99 Compare August 7, 2023 01:05
@anthony-c-martin anthony-c-martin changed the title [POC] Generate schemas using autorest.bicep Generate schemas using autorest.bicep Aug 7, 2023
@anthony-c-martin anthony-c-martin marked this pull request as ready for review August 7, 2023 01:12
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { AutorestExtensionHost, Channel } from '@autorest/extension-base';
Copy link
Member Author

@anthony-c-martin anthony-c-martin Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI a lot of the quirks in this file are due to trying to maintain bug-for-bug compatibility with the current generator (https://github.com/Azure/autorest.azureresourceschema). I initially worked on this by comparing the output and iterating to match it.

@@ -189,7 +192,7 @@ ${yaml.dump({ 'input-file': filesByTag[tag] }, { lineWidth: 1000})}
await writeFile(bicepReadmePath, generatedContent);
}

async function generateSchema(logger: ILogger, readme: string, outputBaseDir: string, logLevel: string, waitForDebugger: boolean) {
async function runAutorest(logger: ILogger, readme: string, outputBaseDir: string, logLevel: string, waitForDebugger: boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would users rely on this file to generate schemas? Unlike with the version in src/autorest.bicep/test/integration/utils.ts, I don't see a way to run autorest with the flag --arm-schema=true via this command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To start off with, I'm planning to add this as a git submodule to https://github.com/Azure/azure-resource-manager-schemas, and running it directly from the orchestration scripts there.

It has its own schemas folder structure and fairly complex generation script that I'm not ready to change yet. If I'm able to clean that up sufficiently, I might try and migrate it into this repo.

};
}

function throwIfNull<TSchema extends Schema>(putSchema: TSchema | undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is TSchema | undefined different from TSchema??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of how the function is processed, I don't think so. It does make the argument optional, which is a bit odd - e.g. you could call throwIfNull()

src/autorest.bicep/src/schema-generator.ts Outdated Show resolved Hide resolved
src/autorest.bicep/src/schema-generator.ts Outdated Show resolved Hide resolved
@anthony-c-martin anthony-c-martin merged commit 0203647 into main Apr 10, 2024
5 checks passed
@anthony-c-martin anthony-c-martin deleted the ant/schemas branch April 10, 2024 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants