Skip to content

Conversation

@v-jiaodi
Copy link
Member

@v-jiaodi v-jiaodi commented Aug 13, 2025

fixes #3438
image

@MaryGao MaryGao changed the title Verify that the library option is set to true for @azure-rest/purview-datamap Issue found in DPG modular generation - apiVersion parameter missing Sep 10, 2025
@v-jiaodi v-jiaodi requested a review from Copilot September 17, 2025 05:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue in DPG modular generation where the apiVersion parameter was missing by correcting the logic for determining required parameters in client parameter generation.

Key changes:

  • Restructured the condition logic in isRequired function to properly handle the apiVersionAsRequired flag
  • Moved the apiVersion special case to the beginning of the condition to ensure it takes precedence
  • Added a comprehensive test case for Azure Analytics Purview DataMap service to validate the fix

Reviewed Changes

Copilot reviewed 6 out of 48 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/typespec-ts/src/modular/helpers/clientHelpers.ts Fixed parameter requirement logic to properly handle apiVersionAsRequired flag
packages/typespec-test/test/Azure.Analytics.Purview.DataMap/tspconfig.yaml Added TypeSpec configuration for new test case
packages/typespec-test/test/Azure.Analytics.Purview.DataMap/spec/routes.tsp Added comprehensive route definitions for DataMap service test
packages/typespec-test/test/Azure.Analytics.Purview.DataMap/spec/models.tsp Added model definitions for DataMap service test
packages/typespec-test/test/Azure.Analytics.Purview.DataMap/spec/main.tsp Added main service definition for DataMap test
packages/typespec-test/test/Azure.Analytics.Purview.DataMap/spec/client.tsp Added client customizations for DataMap test

@qiaozha qiaozha added the p0 priority 0 label Oct 22, 2025
@v-jiaodi
Copy link
Member Author

The previous logic was to always return false for !p.optional === false. However, for options.apiVersionAsRequired && p.isApiVersionParam === true, regardless of !p.optional, it should return true instead.

Comment on lines 17 to 25
model AtlasApiVersionParameter {
@doc("The API version to use for this operation.")
@query("api-version")
@minLength(1)
apiVersion?: string;
}

alias AtlasApiVersionParameterTraits = Azure.Core.Traits.VersionParameterTrait<AtlasApiVersionParameter>;

Copy link
Member Author

Choose a reason for hiding this comment

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

A custom optional apiVersion was defined, but since all operations use AtlasApiVersionParameterTraits, optional is set to true.

Copy link
Member

Choose a reason for hiding this comment

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

@tadelesh do we allow api-version to be optional in azure scope? if it is, do we still have client-level api-version in TCGC? I am curious about what the behvior would be if the api-version is optional but not set.

Copy link
Member

Choose a reason for hiding this comment

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

TCGC did not take case of the optionality of api version parameter. Thought it is optional, it will also in client.

const isRequired = (p: SdkParameter) =>
!p.optional &&
((!hasDefaultValue(p) &&
// Special case: when apiVersionAsRequired is true, apiVersion should always be considered required
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this fix is correct. We should trust always the defined optionality for api-version. If it is optional in spec, why we set it as required?


- TypeSpec defines an optional api-version parameter: `apiVersion?: string`
- TCGC correctly sets `optional: true` for this parameter
- However, the generated client code incorrectly adds a `ClientApiVersionPolicy` instead of treating it as truly optional
Copy link
Member

Choose a reason for hiding this comment

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

when leveraging AI to generate content pls ensure you understand what AI is said, do you understand what following mentioned?

However, the generated client code incorrectly adds a `ClientApiVersionPolicy` instead of treating it as truly optional

@v-jiaodi v-jiaodi marked this pull request as ready for review November 5, 2025 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p0 priority 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Property 'apiVersion' does not exist on type 'DataMapContext'

5 participants