Closed larssb closed 6 years ago
Currently it breaks, because the operationId
is used to generate the operation class name and the method name. IIRC, Swagger codegen uses tags for similar behavior (neither is 'wrong' as the names of generated code classes aren't technically part of the OpenAPI's specification)
I'm a bit swamped this morning, but I can fashion a configuration that can set operationIds based on tags information...
I'm unaware how PSSwagger works, but you'd have to create an autorest configuration file called readme.md
and reference the
# MyAPIs
> see https://aka.ms/autorest
This is the AutoRest configuration file for the APIs.
---
#### Basic Information
These are the global settings for APIs.
``` yaml
# list all the input OpenAPI files (may be YAML, JSON, or Literate- OpenAPI markdown)
input-file:
- my-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 'MyAPI<Tag>'
transform: $.operationId = `MyAPI_${$.tags[0]}`
```
That's a real issue, Many other swagger client generators are not require operationId and they can generate method names by other conventions.
@totht91 Which is why I've provided a configuration file that provides a means by other conventions.
I don't know that I'm not looking enought hard for but I don't find the configuration API's docs.
ps: found: https://github.com/Azure/autorest/blob/master/docs/user/literate-file-formats/configuration.md
Look up : https://github.com/Azure/autorest/issues/2645#issuecomment-336208070 shows an example how to set the operationId
to whatever you'd like it to be.
Closing, assuming this is resolve. Please reopen if this still an issue! 🙂
When running PSSwagger against an API implementing OpenAPI v2, that lacks the operationid field for its paths, autorest terminates with the following error:
FATAL: AutoRest.Core.Logging.CodeGenerationException: OperationId is required for all operations. Please add it for 'get ' operation of '/api/accounts/all' path. at AutoRest.Swagger.SwaggerModeler.Build(ServiceDefinition serviceDefinition) at Modeler.<ProcessInternal>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NewPlugin.<Process>d__11.MoveNext() FATAL: csharp/modeler - FAILED FATAL: Error: Plugin modeler reported failure. Error: Plugin modeler reported failure. at C:\PATH\.autorest\plugins\autorest\1.2.2\node_modules\autorest-core\lib\pipeline\pipeline.js:90:19 at Generator.next (<anonymous>) at fulfilled (C:\PATH\AppData\Roaming\npm\node_modules\autorest\lib\polyfill.min.js:14:62) at <anonymous> AutoRest resulted in an error At C:\Program Files\WindowsPowerShell\Modules\PSSwagger\0.2.0\PSSwagger.psm1:625 char:13
+throw $LocalizedData.AutoRestError
+`~~~~~~~~~~Does it need to be breaking? For example codegen, a tool in the Swagger.io toolbox (https://swagger.io/swagger-codegen/) does not break. Rather it warns with the following message:
[main] WARN io.swagger.codegen.DefaultCodegen - Empty operationId found for path: post /api/teams. Renamed to auto-generated operationId: apiTeamsPost
Would be lovely if autorest would do the same thing. I do have reported the missing operationid implementation to the creators of the API that makes autorest throw the above described error. Haven't heard from them yet and I'm not 100% sure if implementing the operationid is optional.
As a side-note, this makes PSSwagger fail as it uses autorest.
What is your opinion on the above and thank you very much.