I am trying to generate the client code from the following swagger file: http://transport.opendata.ch/swagger.json
However with version
(C) 2017 Microsoft Corporation.
https://aka.ms/autorest
Showing All Installed Extensions
Type Extension Name Version location
core @microsoft.azure/autorest-core 2.0.4147 C:\Users\kevin\.autorest\@[email protected]
extension @microsoft.azure/autorest.csharp 2.0.21 C:\Users\kevin\.autorest\@[email protected]
extension @microsoft.azure/autorest.modeler 2.0.18 C:\Users\kevin\.autorest\@[email protected]
I get the following error:
FATAL: OperationId is required for all operations. Please add it for 'get' operation of '/locations' path.
FATAL: AutoRest.Core.Logging.CodeGenerationException: OperationId is required for all operations. Please add it for 'get' operation of '/locations' path.
Is this a problem with AutoRest or am I just incapable of using the tool? I generated source for multiple REST-APIs before, but there I was the one who added the swagger file generation. Here I don't have any control over the swagger file.
AutoRest uses operationId to determine the class name/method name for a given API.
If you want to use something like tags, you can use a configuration file to acheive something similar:
create an autorest configuration file:
~~~ markdown
This is the AutoRest configuration file for the Transport APIs.
These are the global settings for Transport APIs.
# list all the input OpenAPI files (may be YAML, JSON, or Literate- OpenAPI markdown)
input-file:
- http://transport.opendata.ch/swagger.json
# this allows you to programatically tweak the swagger file before it is modeled.
directive:
from: swagger-document # do it globally
where: $.paths.*.*
# set each operationId to 'Transport_<Tag>'
transform: $.operationId = `Transport_${$.tags[0]}`
~~~
Worked like a charm. Didn't even know about the fact that you could put everything into the config file instead of needing to have a ton of parameters.
Hi @fearthecowboy , thank you for your answer. I am having the same error. I have followed the solution above by adding 'transform' field in 'directive'.
It works. But I only see the the 'transform' field is the 'serializedName in the file 'code-model-v1', file.
Can you please tell me what is that file 'code-model-v1' for?
Using the transform command is not working for Constant Contact's API v3 swagger file. Anyone can download their swagger file here:
https://v3.developer.constantcontact.com/api_guide/v3api_schema.html#download
I have saved the following as sample.yaml
``
sample.yaml.txt
When I run it, I get the following error:
WARNING: Directive with 'where' clause '$.paths..' failed to execute transformation '$.operationId = Transport_${$.tags[0]}' in path 'paths,/idfed,get: 'Cannot read property '0' of undefined'
Most helpful comment
AutoRest uses
operationIdto determine the class name/method name for a given API.If you want to use something like
tags, you can use a configuration file to acheive something similar:create an autorest configuration file:
~~~ markdown
OpenData Transport
This is the AutoRest configuration file for the Transport APIs.
Basic Information
These are the global settings for Transport APIs.
~~~