FlexJobsSponsor

Try FlexJobs for a better remote and flexible job search experience!

Free and Premium plans are available.

Try FlexJobs for Free Today!

Error Message

I ran into this error message when trying to create a REST API Client in Visual Studio for a C# class from an Open API Swagger document:

Generate client code for REST API with following parameters:
REST API Name: Test API, Base namespace: App.TestApi, Metadata file path: C:\repos\TestApi\TestApiDocumentation.json
[Info]0.16.0.0
[Info]Parsing swagger json file.
[Info]Generating client model from swagger model.
[Fatal]OperationId is required for all operations. Please add it for 'get' operation of '/ping' path. 
Exception: There was an error during code generation when trying to add a client for the REST API
Generating client code and adding to project failed
Adding REST API client for failed

Solution

In order to resolve this error, I needed to add an operationId property to all of the paths in my Open API Swagger document.

Here is what one of my paths looked like after adding the proper operationId:

{
  "paths": {
    "/ping": {
      "get": {
        "tags": [
          "ping"
        ],
        "summary": "Check API server status",
        "description": "Check API server status\n",
        "operationId": "ping",
        "produces": [
          "application/json"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Status OK"
          }
        }
      }
    }
  }
}

After updating each path with a relevant operationId, I was able to re-run the Create REST API Client for my C# class.

Here is the successful console output:

Generate client code for REST API with following parameters:
REST API Name: Test API, Base namespace: App.TestApi, Metadata file path: C:\repos\TestApi\TestApiDocumentation.json
[Info]0.16.0.0
[Info]Parsing swagger json file.
[Info]Generating client model from swagger model.
Generating client code and adding to project succeeded
Install nuget package into project : Microsoft.Rest.ClientRuntime 2.3.2
Installing nuget package started
Installing nuget package succeeded
Adding REST API client for succeeded
FlexJobsSponsor

Try FlexJobs for a better remote and flexible job search experience!

Free and Premium plans are available.

Try FlexJobs for Free Today!
FeedbackI'd love to hear your feedback!
Did this blog post help fix your issue? Still having trouble?
Tweet At Me
Brendan SlukeSoftware Engineer

Hi, I'm Brendan Sluke and I love writing code and blogging about software engineering.

Follow Me On Twitter Read My Blog
Recommended Blog PostsBlog Posts I Think You Will Find Interesting
Go Back To Top of Page