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

feat(http-client-csharp): add InputOperation.OperationId #5479

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "@azure-tools/typespec-client-generator-core";
import { getDeprecated, isErrorModel } from "@typespec/compiler";
import { HttpStatusCodeRange } from "@typespec/http";
import { resolveOperationId } from "@typespec/openapi";
import { getResourceOperation } from "@typespec/rest";
import { NetEmitterOptions } from "../options.js";
import { BodyMediaType } from "../type/body-media-type.js";
Expand Down Expand Up @@ -74,6 +75,7 @@ export function fromSdkServiceMethod(
getResourceOperation(sdkContext.program, method.operation.__raw.operation)?.resourceType
.name ??
getOperationGroupName(sdkContext, method.operation, sdkContext.sdkPackage.rootNamespace),
OperationId: resolveOperationId(sdkContext.program, method.operation.__raw.operation),
Copy link
Member Author

Choose a reason for hiding this comment

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

there are 3 ways to resolve the operation id:

  1. @typespec/openapi will use the original resource name, e.g. ignoring renaming by @clientName:
    export function resolveOperationId(program: Program, operation: Operation) {
  2. @typespec-azure/typespec-generator-client-core will honor renaming: https://github.com/Azure/typespec-azure/blob/9d16af124e507f7194d4f378637c9ca557bd6d2e/packages/typespec-client-generator-core/src/example.ts#L142
  3. @typespec-azure/typespec-autorest will honor renaming and make it pascal: https://github.com/Azure/typespec-azure/blob/9d16af124e507f7194d4f378637c9ca557bd6d2e/packages/typespec-autorest/src/utils.ts#L72

I thought we should use option 1 which should be closest to original operation id in swagger. Any thought?

Deprecated: getDeprecated(sdkContext.program, method.__raw!),
Summary: method.summary,
Doc: method.doc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface Paging {
export interface InputOperation {
Name: string;
ResourceName?: string;
OperationId: string;
Summary?: string;
Deprecated?: string;
Doc?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"$id": "6",
"Name": "valid",
"ResourceName": "ApiKey",
"OperationId": "valid",
"Doc": "Check whether client is authenticated",
"Accessibility": "public",
"Parameters": [],
Expand Down Expand Up @@ -72,6 +73,7 @@
"$id": "8",
"Name": "invalid",
"ResourceName": "ApiKey",
"OperationId": "invalid",
"Doc": "Check whether client is authenticated.",
"Accessibility": "public",
"Parameters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"$id": "6",
"Name": "valid",
"ResourceName": "Custom",
"OperationId": "valid",
"Doc": "Check whether client is authenticated",
"Accessibility": "public",
"Parameters": [],
Expand Down Expand Up @@ -72,6 +73,7 @@
"$id": "8",
"Name": "invalid",
"ResourceName": "Custom",
"OperationId": "invalid",
"Doc": "Check whether client is authenticated.",
"Accessibility": "public",
"Parameters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"$id": "6",
"Name": "valid",
"ResourceName": "OAuth2",
"OperationId": "valid",
"Doc": "Check whether client is authenticated",
"Accessibility": "public",
"Parameters": [],
Expand Down Expand Up @@ -72,6 +73,7 @@
"$id": "8",
"Name": "invalid",
"ResourceName": "OAuth2",
"OperationId": "invalid",
"Doc": "Check whether client is authenticated. Will return an invalid bearer error.",
"Accessibility": "public",
"Parameters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"$id": "3",
"Name": "validKey",
"ResourceName": "Union",
"OperationId": "validKey",
"Doc": "Check whether client is authenticated",
"Accessibility": "public",
"Parameters": [],
Expand Down Expand Up @@ -42,6 +43,7 @@
"$id": "5",
"Name": "validToken",
"ResourceName": "Union",
"OperationId": "validToken",
"Doc": "Check whether client is authenticated",
"Accessibility": "public",
"Parameters": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"$id": "28",
"Name": "clientName",
"ResourceName": "Naming",
"OperationId": "operation",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -282,6 +283,7 @@
"$id": "30",
"Name": "parameter",
"ResourceName": "Naming",
"OperationId": "parameter",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -331,6 +333,7 @@
"$id": "34",
"Name": "client",
"ResourceName": "Property",
"OperationId": "Property_client",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -407,6 +410,7 @@
"$id": "40",
"Name": "language",
"ResourceName": "Property",
"OperationId": "Property_language",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -483,6 +487,7 @@
"$id": "46",
"Name": "compatibleWithEncodedName",
"ResourceName": "Property",
"OperationId": "Property_compatibleWithEncodedName",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -559,6 +564,7 @@
"$id": "52",
"Name": "request",
"ResourceName": "Header",
"OperationId": "Header_request",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -608,6 +614,7 @@
"$id": "56",
"Name": "response",
"ResourceName": "Header",
"OperationId": "Header_response",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -691,6 +698,7 @@
"$id": "66",
"Name": "client",
"ResourceName": "Model",
"OperationId": "Model_client",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -767,6 +775,7 @@
"$id": "72",
"Name": "language",
"ResourceName": "Model",
"OperationId": "Model_language",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -887,6 +896,7 @@
"$id": "84",
"Name": "unionEnumName",
"ResourceName": "UnionEnum",
"OperationId": "UnionEnum_unionEnumName",
"Accessibility": "public",
"Parameters": [
{
Expand Down Expand Up @@ -963,6 +973,7 @@
"$id": "90",
"Name": "unionEnumMemberName",
"ResourceName": "UnionEnum",
"OperationId": "UnionEnum_unionEnumMemberName",
"Accessibility": "public",
"Parameters": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"$id": "15",
"Name": "one",
"ResourceName": "ClientOperationGroup",
"OperationId": "ClientOperationGroup_one",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -196,6 +197,7 @@
"$id": "22",
"Name": "two",
"ResourceName": "Group3",
"OperationId": "Group3_two",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -223,6 +225,7 @@
"$id": "24",
"Name": "three",
"ResourceName": "Group3",
"OperationId": "Group3_three",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -302,6 +305,7 @@
"$id": "31",
"Name": "four",
"ResourceName": "Group4",
"OperationId": "Group4_four",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -381,6 +385,7 @@
"$id": "38",
"Name": "five",
"ResourceName": "AnotherClientOperationGroup",
"OperationId": "AnotherClientOperationGroup_five",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -459,6 +464,7 @@
"$id": "45",
"Name": "six",
"ResourceName": "Group5",
"OperationId": "Group5_six",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"$id": "15",
"Name": "one",
"ResourceName": "Service",
"OperationId": "one",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -146,6 +147,7 @@
"$id": "17",
"Name": "two",
"ResourceName": "Service",
"OperationId": "two",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -275,6 +277,7 @@
"$id": "29",
"Name": "seven",
"ResourceName": "Foo",
"OperationId": "Foo_seven",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -354,6 +357,7 @@
"$id": "36",
"Name": "eight",
"ResourceName": "Qux",
"OperationId": "Qux_eight",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -433,6 +437,7 @@
"$id": "43",
"Name": "nine",
"ResourceName": "Bar",
"OperationId": "Bar_nine",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -512,6 +517,7 @@
"$id": "50",
"Name": "three",
"ResourceName": "Foo",
"OperationId": "Foo_three",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -539,6 +545,7 @@
"$id": "52",
"Name": "four",
"ResourceName": "Foo",
"OperationId": "Foo_four",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -618,6 +625,7 @@
"$id": "59",
"Name": "five",
"ResourceName": "Bar",
"OperationId": "Bar_five",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -645,6 +653,7 @@
"$id": "61",
"Name": "six",
"ResourceName": "Bar",
"OperationId": "Bar_six",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"$id": "15",
"Name": "renamedOne",
"ResourceName": "ClientA",
"OperationId": "ClientA_renamedOne",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -145,6 +146,7 @@
"$id": "17",
"Name": "renamedThree",
"ResourceName": "ClientA",
"OperationId": "ClientA_renamedThree",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -172,6 +174,7 @@
"$id": "19",
"Name": "renamedFive",
"ResourceName": "ClientA",
"OperationId": "ClientA_renamedFive",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -250,6 +253,7 @@
"$id": "26",
"Name": "renamedTwo",
"ResourceName": "ClientB",
"OperationId": "ClientB_renamedTwo",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -277,6 +281,7 @@
"$id": "28",
"Name": "renamedFour",
"ResourceName": "ClientB",
"OperationId": "ClientB_renamedFour",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -304,6 +309,7 @@
"$id": "30",
"Name": "renamedSix",
"ResourceName": "ClientB",
"OperationId": "ClientB_renamedSix",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"$id": "15",
"Name": "renamedOne",
"ResourceName": "RenamedOperation",
"OperationId": "RenamedOperation_renamedOne",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -145,6 +146,7 @@
"$id": "17",
"Name": "renamedThree",
"ResourceName": "RenamedOperation",
"OperationId": "RenamedOperation_renamedThree",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -172,6 +174,7 @@
"$id": "19",
"Name": "renamedFive",
"ResourceName": "RenamedOperation",
"OperationId": "RenamedOperation_renamedFive",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -250,6 +253,7 @@
"$id": "26",
"Name": "renamedTwo",
"ResourceName": "Group",
"OperationId": "Group_renamedTwo",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -277,6 +281,7 @@
"$id": "28",
"Name": "renamedFour",
"ResourceName": "Group",
"OperationId": "Group_renamedFour",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down Expand Up @@ -304,6 +309,7 @@
"$id": "30",
"Name": "renamedSix",
"ResourceName": "Group",
"OperationId": "Group_renamedSix",
"Accessibility": "public",
"Parameters": [],
"Responses": [
Expand Down
Loading
Loading