Azure / azure-sdk-tools

Tools repository leveraged by the Azure SDK team.
MIT License
111 stars 176 forks source link

[LintDiff] Upgrade autorest to latest #7755

Open mikeharder opened 7 months ago

mikeharder commented 7 months ago

LintDiff is currently using autorest pinned to 3.6.1:

https://dev.azure.com/devdiv/DevDiv/_git/openapi-alps?path=/private/azure-swagger-validation/azureSwaggerValidation/package.json&version=GBmain&line=36&lineEnd=37&lineStartColumn=1&lineEndColumn=1&lineStyle=plain&_a=contents

It should probably be upgraded to the latest version 3.7.1, since 3.6.1 is two years old now. However, I'm not aware of any current issues using 3.6.1, so maybe it's better to not touch it unless we need to?

I believe autorest@3.6.1 should automatically use the latest version of @autorest/core, since by default autorest floats the dependency as @autorest/core@^3.2.0:

if (args["v3"] && !args["version"]) {
  // --v3 without --version infers --version:^3.2.0 +
  args["version"] = "^3.2.0";
}

https://github.com/Azure/autorest/blob/8d137ce24e1af96444766688e7cd851767d6543c/packages/apps/autorest/src/app.ts#L42

For reference:

timotheeguerin commented 7 months ago

I think that's just the CLI version which I don't think would solve the issue in question(It wouldnt' be bad to update that too, however).

What is failing the x-ms-enum.name I beleive is the version of autorest core

konrad-jamrozik commented 7 months ago

@timotheeguerin how to update the core?

timotheeguerin commented 7 months ago

Core would either use the latest or a version configured by --version or version: in the README.md.

konrad-jamrozik commented 7 months ago

@timotheeguerin from this recent example log we can see:

Executing AutoRest with LintDiff: node /mnt/vss/_work/_tasks/AzureApiValidation_5654d05d-82c1-48da-ad8f-161b817f6d41/0.0.79/private/azure-swagger-validation/azureSwaggerValidation/node_modules/autorest/dist/app.js --v3 --spectral --azure-validator --semantic-validator=false --model-validator=false --message-format=json --openapi-type=data-plane --openapi-subtype=data-plane  --use=@microsoft.azure/openapi-validator@2.1.7 --tag=package-2018-01 /mnt/vss/_work/1/azure-rest-api-specs/specification/eventgrid/data-plane/readme.md
Execution of AutoRest with LintDiff done. Error is not null: true, stdout contains AutoRest 'error': true, stdout contains AutoRest 'fatal': true, stderr contains AutoRest 'error': false, stderr contains AutoRest 'fatal': false
RETURN definition momentOfTruth.executeAutoRestWithLintDiff.
{"level":"information","message":"AutoRest core version selected from configuration: ^3.2.0."}

There is a new version of AutoRest available (3.7.1).
 > You can install the newer version with with npm install -g autorest@latest

Notably:

"AutoRest core version selected from configuration: ^3.2.0."} and There is a new version of AutoRest available (3.7.1). (because we use 3.6.1)

Judging based on that, the issue is with CLI or Core or hard to say?

timotheeguerin commented 7 months ago

the cli just basically loads autorest/core which then deals with all the logic. However I don't see here in the logs which version of autorest core is actually loaded. It just says it found some config that said to load ^3.2.0.

The original issue is complaining about missing name property under x-ms-enum.

For example having this:

"x-ms-enum": { "modelAsString": false}

There was some assumption that might have just been an older autorest complaining but it might be something else using an outdated json schema to validate.

abatishchev commented 7 months ago

Please prioritize. the ShiftLeft pipeline started failing and it's unclear to me what I have to change/fix in order to get it unblocked

konrad-jamrozik commented 7 months ago

Please prioritize. the ShiftLeft pipeline started failing and it's unclear to me what I have to change/fix in order to get it unblocked

Relevant discussion on Teams here