Franky
Franky

Reputation: 1604

Semantic violation while generating Swagger/Autorest API client

I've followed this article to use autorest to generate API client library:

How to Automatically Generate Clients for your REST API

I executed this command in VS2019 first:

iwr http://localhost:5000/swagger/v1/swagger.json -o ./docs/openapi/api-v1.json

This works well. I can see the json file generated successfully. I then executed this autorest command:

autorest --input-file=./docs/openapi/api-v1.json --v3 --csharp --use-datetimeoffset=true --sync-methods=none --output-folder=./src/SampleApi.Client --namespace=SampleApi.Client

Bunch of errors occurred and they are all the same type:

node.exe : ERROR: Semantic violation: Path parameter 'SchoolKey' referenced in path '/Schools/Details/{SchoolKey}' needs to be defined in every operation at either the path or operation level. (Missing in 'post') (paths > /Schools/Details/{SchoolKey})

I am not sure what this error means and how to fix it? This is my function:

    [HttpPost]
    [Authorize(Policy = Policies.User)]
    [Route("{SchoolKey}")]
    public async Task<ApiResponse> Details(string schoolKey)
    {
       ...
    }

And my controller is like this:

[ApiController]
[Route("[controller]/[action]")]
public class SchoolsController

The end point of the API is "/Schools/Details/12345"

So what do I need to change my function/controller to make autorest work?

Thanks!

Upvotes: 2

Views: 205

Answers (0)

Related Questions