Autorest Generate Issue Renaming Classes to patchjsonbody or generating random classes

Hi,
I am facing an issue while generating autotest for custom modules. When I generated autorest it generates extra random classes.

Platform version - 3.253.3

autorest command -
autorest VirtoCommerce.Storefront\AutoRestClients\array-in-query-fix.yml --version=3.0.6274 --v3 --debug --input-file=path to file/swagger.json --output-folder=.\VirtoCommerce.Storefront\AutoRestClients --output-file=ModuleApi.cs --namespace=VirtoCommerce.Storefront.AutoRestClients.

ModuleApi --override-client-name=ModuleClient --add-credentials --csharp --generate-empty-classes=true


In this search method parameter .it should have proper classes but its generating some random classes.

JSON file for auto rest-

{
  "openapi": "3.0.1",
  "info": {
    "title": "Dh.DaivsModule",
    "version": "v1"
  },
  "paths": {
    "/api/daivs/drawing/validate": {
      "post": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "ApiDaivsService_ValidateDrawings",
        "requestBody": {
          "content": {
            "application/json-patch+json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "nullable": true
              }
            },
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "nullable": true
              }
            },
            "text/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "nullable": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:access"
            ]
          }
        ]
      }
    },
    "/api/daivs": {
      "post": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "DaivsModule_Update",
        "requestBody": {
          "content": {
            "application/json-patch+json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                ],
                "nullable": true
              }
            },
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                ],
                "nullable": true
              }
            },
            "text/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                ],
                "nullable": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:update"
            ]
          }
        ]
      }
    },
    "/api/daivs/bulk": {
      "post": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "DaivsModule_CreateUpdateRequestInBulk",
        "requestBody": {
          "content": {
            "application/json-patch+json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                },
                "nullable": true
              }
            },
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                },
                "nullable": true
              }
            },
            "text/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                },
                "nullable": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:update"
            ]
          }
        ]
      }
    },
    "/api/daivs/{id}": {
      "get": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "DaivsModule_GetDrawingAccessRequestById",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequest"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:read"
            ]
          }
        ]
      },
      "delete": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "DaivsModule_Delete",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:access"
            ]
          }
        ]
      }
    },
    "/api/daivs/search": {
      "post": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "DaivsModule_Search",
        "requestBody": {
          "content": {
            "application/json-patch+json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/DrawingAccessRequestSearchCriteria"
                  }
                ],
                "nullable": true
              }
            },
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/DrawingAccessRequestSearchCriteria"
                  }
                ],
                "nullable": true
              }
            },
            "text/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/DrawingAccessRequestSearchCriteria"
                  }
                ],
                "nullable": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequestSearchResult"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequestSearchResult"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrawingAccessRequestSearchResult"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:read"
            ]
          }
        ]
      }
    },
    "/api/daivs/organization/{organizationId}": {
      "get": {
        "tags": [
          "De Havilland Engg Drawing Daivs Module"
        ],
        "operationId": "DaivsModule_GetDrawingAccessByOrgId",
        "parameters": [
          {
            "name": "organizationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DrawingAccessRequest"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "security": [
          {
            "oauth2": [
              "DaivsModule:read"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "Status": {
        "enum": [
          "PendingApproval",
          "Approved",
          "Rejected",
          "Canceled"
        ],
        "type": "string"
      },
      "DrawingAccessRequest": {
        "type": "object",
        "properties": {
          "drawingNumber": {
            "type": "string",
            "nullable": true
          },
          "drawingRequester": {
            "type": "string",
            "nullable": true
          },
          "accessExpiry": {
            "type": "string",
            "format": "date-time"
          },
          "drawingApprover": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "enum": [
              "PendingApproval",
              "Approved",
              "Rejected",
              "Canceled"
            ],
            "type": "string",
            "allOf": [
              {
                "$ref": "#/components/schemas/Status"
              }
            ]
          },
          "armsAccessId": {
            "type": "string",
            "nullable": true
          },
          "organizationId": {
            "type": "string",
            "nullable": true
          },
          "isForever": {
            "type": "boolean"
          },
          "createdDate": {
            "type": "string",
            "format": "date-time"
          },
          "modifiedDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "maxLength": 64,
            "minLength": 0,
            "type": "string",
            "nullable": true
          },
          "modifiedBy": {
            "maxLength": 64,
            "minLength": 0,
            "type": "string",
            "nullable": true
          },
          "id": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "SortDirection": {
        "enum": [
          "Ascending",
          "Descending"
        ],
        "type": "string"
      },
      "SortInfo": {
        "type": "object",
        "properties": {
          "sortColumn": {
            "type": "string",
            "nullable": true
          },
          "sortDirection": {
            "enum": [
              "Ascending",
              "Descending"
            ],
            "type": "string",
            "allOf": [
              {
                "$ref": "#/components/schemas/SortDirection"
              }
            ]
          }
        },
        "additionalProperties": false
      },
      "DrawingAccessRequestSearchCriteria": {
        "type": "object",
        "properties": {
          "drawingNumber": {
            "type": "string",
            "nullable": true
          },
          "drawingRequester": {
            "type": "string",
            "nullable": true
          },
          "drawingApprover": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "nullable": true
          },
          "drawingNumbers": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "armsAccessIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "organizationIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "responseGroup": {
            "type": "string",
            "nullable": true
          },
          "objectType": {
            "type": "string",
            "nullable": true
          },
          "objectTypes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "objectIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "keyword": {
            "type": "string",
            "nullable": true
          },
          "searchPhrase": {
            "type": "string",
            "nullable": true
          },
          "languageCode": {
            "type": "string",
            "nullable": true
          },
          "sort": {
            "type": "string",
            "nullable": true
          },
          "sortInfos": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SortInfo"
            },
            "nullable": true,
            "readOnly": true
          },
          "skip": {
            "type": "integer",
            "format": "int32"
          },
          "take": {
            "type": "integer",
            "format": "int32"
          }
        },
        "additionalProperties": false
      },
      "DrawingAccessRequestSearchResult": {
        "type": "object",
        "properties": {
          "totalCount": {
            "type": "integer",
            "format": "int32"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DrawingAccessRequest"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth2 Resource Owner Password Grant flow",
        "flows": {
          "password": {
            "tokenUrl": "/connect/token",
            "scopes": { }
          }
        }
      }
    }
  }
}

I think you need to find Why some attributes from json file were added to class name.

Thanks for the reply.
I did try to find it but was not able to find it. I even tried with different autorest versions and with existing virto modules. its happening in existing virto modules and custom modules btoh.

autorest VirtoCommerce.Storefront\AutoRestClients\array-in-query-fix.yml --version=3.0.6274 --v3 --debug --input-file=http://localhost:10645/docs/Dh.Mcr/swagger.json --output-folder=.\VirtoCommerce.Storefront\AutoRestClients --output-file=McrModuleApi.cs --namespace=VirtoCommerce.Storefront.AutoRestClients.McrModuleApi --override-client-name=McrModuleClient --add-credentials --csharp

When i use this command it gives this error. So to solve this I have added at last
“–generate-empty-classes=true”.
After adding this in autorest command generate code but also these classes and mess up some functions

Hi

You should not change the version of Autorest because they change output format.

Could you share the original file and original error message as text?

In this repo I have pushed the generated file and swagger.json

This is the error message

FATAL: The schema’s ‘schemas:69’ ancestors should have at lease one property
FATAL: AutoRest.Core.Logging.CodeGenerationException: The schema’s ‘schemas:69’ ancestors should have at lease one property
at AutoRest.Modeler.SwaggerModeler.BuildCompositeTypes() in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 361
at AutoRest.Modeler.SwaggerModeler.Build(ServiceDefinition serviceDefinition) in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 66
at AutoRest.Modeler.Program.d2.MoveNext() in /opt/vsts/work/1/s/src/Program.cs:line 60
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NewPlugin.d15.MoveNext()
C:\Users\lenovo.autorest@autorest_core@3.0.6274\node_modules@autorest\core\dist\lib\pipeline\pipeline.js - FAILURE {}
Process() cancelled due to exception : Plugin imodeler1 reported failure. / Error: Plugin imodeler1 reported failure.
at C:\Users\lenovo.autorest@autorestcore@3.0.6274\nodemodules@autorest\core\dist\lib\pipeline\plugins\external.js:26:19
at async ScheduleNode (C:\Users\lenovo.autorest@autorestcore@3.0.6274\nodemodules@autorest\core\dist\lib\pipeline\pipeline.js:294:33)
Error: Plugin imodeler1 reported failure.
[3.78 s] Shutting Down.
[3.78 s] Exiting.

1 Like

Thank you for the detail.

Because it’s a part of custom solutiuon. Please contact Support : Virto Commerce Helpdesk, our support team will help you.

ok I will create a ticket on the helpdesk
Thank you