-
Notifications
You must be signed in to change notification settings - Fork 325
Open
Labels
bugSomething isn't workingSomething isn't workingemitter:client:pythonIssue for the Python client emitter: @typespec/http-client-pythonIssue for the Python client emitter: @typespec/http-client-python
Description
Describe the bug
In some scenarios, a service can support both authenticated and unauthenticated requests.
If I have a service namespace with the following:
@useAuth(
NoAuth | OAuth2Auth<[
{
type: OAuth2FlowType.implicit,
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/authorize",
scopes: ["https://monitor.azure.com/.default"],
}
]>
)The Python emitter will generate a Client class and Configuration Class that both have credential as a non-optional positional parameter.
Example generation Configuration:
class AzureMonitorExporterClientConfiguration:
def __init__(
self, credential: "TokenCredential", host: str = "https://dc.services.visualstudio.com", **kwargs: Any
) -> None:
api_version: str = kwargs.pop("api_version", "v2.1")
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
...Ideally, credential should be typed as Optional with a default of None.
Reproduction
Using the Python emitter with a namespace like:
@useAuth(
NoAuth | OAuth2Auth<[
{
type: OAuth2FlowType.implicit,
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/authorize",
scopes: ["https://monitor.azure.com/.default"],
}
]>
)
@service(#{ title: "Azure Monitor Exporter" })
@versioned(Versions)
@server(
"{host}/{apiVersion}",
"Azure MonitorOpenTelemetry Exporter Service",
{
/** Application Insights' Breeze endpoint. */
host: url = "https://dc.services.visualstudio.com",
/** The service API version. */
apiVersion: Versions,
}
)
namespace AzureMonitorExporter;Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingemitter:client:pythonIssue for the Python client emitter: @typespec/http-client-pythonIssue for the Python client emitter: @typespec/http-client-python