# Autorest Generate Issue Renaming Classes to patchjsonbody or generating random classes

**URL:** <https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565>\
**Category:** support\
**Tags:** storefront, module\
**Created:** [March 29, 2023, 12:15pm UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565 "2023-03-29T12:15:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koshalgarg155](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/koshalgarg155/32/1053_2.png) [@Koshalgarg155](https://www.virtocommerce.org/u/Koshalgarg155)\
**Post date:** [March 29, 2023, 12:15pm UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/1 "2023-03-29T12:15:38Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/virtocommerce/original/2X/e/e72c1da65b7be7a6a57e0a654aa9f70b91380f6c.png)  
 ![image](https://canada1.discourse-cdn.com/flex032/uploads/virtocommerce/original/2X/2/24695e8cad47caec92c4e58f368c03ad7e933552.png)

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

JSON file for auto rest-

```auto
{
  "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": { }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![OlegoO](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/olegoo/32/27_2.png) [@OlegoO](https://www.virtocommerce.org/u/OlegoO)\
**Post date:** [March 30, 2023, 8:56am UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/2 "2023-03-30T08:56:22Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/virtocommerce/original/2X/6/6237cfa62d74b38176e98d32c38da5903bf08e1e.png)

---

<div class="post-metadata">

**Author:** ![Koshalgarg155](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/koshalgarg155/32/1053_2.png) [@Koshalgarg155](https://www.virtocommerce.org/u/Koshalgarg155)\
**Post date:** [March 30, 2023, 9:50am UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/3 "2023-03-30T09:50:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Koshalgarg155](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/koshalgarg155/32/1053_2.png) [@Koshalgarg155](https://www.virtocommerce.org/u/Koshalgarg155)\
**Post date:** [March 30, 2023, 10:01am UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/4 "2023-03-30T10:01:07Z")

</div>

```auto
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

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/virtocommerce/original/2X/9/95b064f591691a998a48f9831b6fb5046e45155d.png)

---

<div class="post-metadata">

**Author:** ![OlegoO](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/olegoo/32/27_2.png) [@OlegoO](https://www.virtocommerce.org/u/OlegoO)\
**Post date:** [March 30, 2023, 12:25pm UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/5 "2023-03-30T12:25:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Koshalgarg155](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/koshalgarg155/32/1053_2.png) [@Koshalgarg155](https://www.virtocommerce.org/u/Koshalgarg155)\
**Post date:** [March 30, 2023, 12:51pm UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/6 "2023-03-30T12:51:22Z")

</div>

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

> **[GitHub - Koshalgarg155/autorest-file](https://github.com/Koshalgarg155/autorest-file)**
>
> Contribute to Koshalgarg155/autorest-file development by creating an account on GitHub.

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.

---

<div class="post-metadata">

**Author:** ![OlegoO](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/olegoo/32/27_2.png) [@OlegoO](https://www.virtocommerce.org/u/OlegoO)\
**Post date:** [April 3, 2023, 6:54am UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/7 "2023-04-03T06:54:21Z")

</div>

Thank you for the detail.

Because it’s a part of custom solutiuon. Please contact [Support : Virto Commerce Helpdesk](https://help.virtocommerce.com/support/home), our support team will help you.

---

<div class="post-metadata">

**Author:** ![Koshalgarg155](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/koshalgarg155/32/1053_2.png) [@Koshalgarg155](https://www.virtocommerce.org/u/Koshalgarg155)\
**Post date:** [April 3, 2023, 12:46pm UTC](https://www.virtocommerce.org/t/autorest-generate-issue-renaming-classes-to-patchjsonbody-or-generating-random-classes/565/8 "2023-04-03T12:46:11Z")

</div>

ok I will create a ticket on the helpdesk  
Thank you
