Azure / azure-rest-api-specs

The source for REST API specifications for Microsoft Azure.
MIT License
2.69k stars 5.11k forks source link

[BUG] [JS SDK] generateMetadata cannot be set to false under `@azure-tools/typespec-ts` #31610

Open maorleger opened 2 days ago

maorleger commented 2 days ago

API Spec link

https://github.com/Azure/azure-rest-api-specs/blob/2822c0909ef7e9aa52c2921e5f0fdb0027ee3f82/specification/keyvault/Security.KeyVault.Administration/tspconfig.yaml

API Spec version

N/A

Describe the bug

When generateMetadata is false, JS SDK CI validation will fail due to automation deleting all files when generating JS SDK (including package.json)

Example typespec-ts configuration:

  "@azure-tools/typespec-ts":
    package-dir: "keyvault-admin"
    generateMetadata: false
    generateTest: false
    experimentalExtensibleEnums: true
    isModularLibrary: true
    packageDetails:
      name: "@azure/keyvault-admin"
      description: "Azure Key Vault Administration"
    flavor: azure

Expected behavior

JS SDK code generation should not be a destructive operation for files it does not regenerate

Actual behavior

Adding the above typespec-ts entry to the yaml causes CI to start failing with (what I think is): [automation_generate.sh] [ERROR]: Failed to generate package due to Error: Could not read package.json: Error: ENOENT: no such file or directory, open '/mnt/vss/_work/1/s/azure-sdk-for-js/sdk/keyvault/keyvault-admin/package.json'

Reproduction Steps

(this tspconfig.yaml has not been merged yet, depending on whether its merged the steps may change)

  1. checkout commit sha 2822c0909ef7e9aa52c2921e5f0fdb0027ee3f82
  2. Create a pull request

Environment

No response

maorleger commented 2 days ago

A bit more infor:

this commit in this PR https://github.com/Azure/azure-rest-api-specs/pull/30239/commits/2822c0909ef7e9aa52c2921e5f0fdb0027ee3f82 adds typespec-ts input for keyvault-admin generateMetadata is false as expected for packages that are pre-existing and being converted (we do not need to generate package.json files and such) keyvault-admin is a brownfield service that is migrating from swagger to typespec azure-sdk-for-js/sdk/keyvault/keyvault-admin at main · Azure/azure-sdk-for-js Adding the above typespec-ts entry to the yaml causes CI to start failing with (what I think is): [automation_generate.sh] [ERROR]: Failed to generate package due to Error: Could not read package.json: Error: ENOENT: no such file or directory, open '/mnt/vss/_work/1/s/azure-sdk-for-js/sdk/keyvault/keyvault-admin/package.json' https://dev.azure.com/azure-sdk/internal/_build/results?buildId=4325911&view=logs&j=47092895-c7c8-567a-c7a6-8c88f3ec178e&t=d293a8e8-c6af-5091-cdf7-4c66482dd6f2&l=347

The generated JS PR shows that all the metadata files are deleted: [AutoPR default] [Key Vault] TypeSpec for Administration library by azure-sdk · Pull Request #12803 · azure-sdk/azure-sdk-for-js

v-jiaodi commented 1 day ago

@mccoyp Please help take a look, thanks.