Search code examples
azureopenapiautorest

Exclude method from generating in Azure autorest


When trying to generate C# code using Azure Autorest for this specification:

https://github.com/blend/blend-api-specs/blob/master/version_4/v4.2.0_stable.openapi_spec.yaml

I get the following error:

warning | Interpretations | Generating 'operationId' to 'Home Lending - Applications' for 'get' operation on path '/home-lending/applications/{id}/assignees' 
warning | Interpretations | Generating 'operationId' to 'Home Lending - Applications' for 'patch' operation on path '/home-lending/applications/{id}/assignees' 
warning | Interpretations | Generating 'operationId' to 'Home Lending - Applications' for 'put' operation on path '/home-lending/applications/{id}/assignees' 
warning | Modeler/MissingType | The schema 'paths·bz6x3r·home_lending-applications-id·patch·requestbody·content·application-json·schema·properties·loanamount·allof·1' has no type or format information whatsoever. Location:
   file:///home/XX/code/XX-platform/poc/integrations/providers/Blend.autorest/spec/v4.2.0stable.openapi_spec.yaml#/components/schemas/paths·bz6x3r·homelending-applications-id·patch·requestbody·content·application-json·schema·properties·loanamount·allof·1
error   | DuplicateOperation | Duplicate Operation '' > 'HomeLendingApplications' detected(This is most likely due to 2 operation using the same 'operationId' or 'tags'). Duplicates have those paths:
  - /home-lending/applications/{id}/assignees
  - /home-lending/applications/{id}/assignees
  - /home-lending/applications/{id}/assignees
fatal   | Error: 1 errors occured -- cannot continue.
fatal   | Process() cancelled due to failure 
  Error: Plugin checker reported failure.

Since I cannot modify the YAML file (it is a public API), is there a way to avoid generating or ignoring the offending section? Perhaps using directives?


Solution

  • After asking on the Autorest github issues board, I was adviced to use directives, which allow to preprocess a specification on the fly.

    directive:
      - from: openapi-document
        where: '$.paths["/home-lending/applications/{id}/assignees"].get'
        debug: true
        transform: |
          $["operationId"] = "lending-assignees-get";
      - from: openapi-document
        where: '$.paths["/home-lending/applications/{id}/assignees"].put'
        debug: true
        transform: |
          $["operationId"] = "lending-assignees-put";
    

    This particular spec still contains other issues that makes the autorest c# generator fail, but these directives do fix the original issue.