epam-cross-platform-lab / swagger-dart-code-generator

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter
Apache License 2.0
263 stars 121 forks source link

[BUG] Incorrect JSON Structure in PATCH API #662

Closed mehrzut closed 1 year ago

mehrzut commented 1 year ago

When using the API call function of a PATCH request, the generated JSON structure includes an extra "patchDocument" object wrapping the operations. It should instead directly contain the "operations" array.

Expected JSON Structure:

{"patchDocument": [
  // operators here
]}

Actual JSON Structure:

{"patchDocument": {
  "operations": [
    // operators here
  ]}
}
Vovanella95 commented 1 year ago

Hi @mehrzut , could you please provide swagger file example. expected and actual results for comparation?

mehrzut commented 1 year ago

Hi actually I found out that the swagger itself is showing the body like this:

  "patchDocument": {
    "contractResolver": {}
  }

but the backend developer says they used the .Net class as the input like this: public JsonPatchDocument<Model> PatchDocument { get; set; } Is there a problem with the backend?

Vovanella95 commented 1 year ago

That's would be great to take a look to full swagger file. you can rename everything and change urls if it's secret. Or share it to my email vovanella95@mail.ru

Because for now I don't know what is patchDocument and contractResolver :D

I want to check it in swagger editor and understand, what should be generated

mehrzut commented 1 year ago

That's would be great to take a look to full swagger file. you can rename everything and change urls if it's secret. Or share it to my email vovanella95@mail.ru

Because for now I don't know what is patchDocument and contractResolver :D

I want to check it in swagger editor and understand, what should be generated

I sent it to you.

Vovanella95 commented 1 year ago

@mehrzut yes, thanks, seen your message. Working on it

Vovanella95 commented 1 year ago

Hi @mehrzut , I've checked your swagger file. You can also check it in Swagger Editor. Looks like patchDocument indeed the field of UpdateDriverCommand class. Example of request body looks like

{
  "driverId": 0,
  "patchDocument": {
    "contractResolver": {}
  }
}

For actual swagger file, according scheme, DriverJsonPatchDocument is a class with two properties: operations (List of DriverOperation) and contracResolver- IContractResolver class.

"DriverJsonPatchDocument": {
        "type": "object",
        "properties": {
          "operations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DriverOperation"
            },
            "nullable": true,
            "readOnly": true
          },
          "contractResolver": {
            "$ref": "#/components/schemas/IContractResolver"
          }
        },
        "additionalProperties": false
      },

So, if this patchDocument is not needed - then it's swagger file issue. You can always check swagger file in Swagger Editor portal to check all schemas, requests and examples.

I'm closing the issue. But if you have any questions - feel free to reopen it.

Vovanella95 commented 1 year ago
Снимок экрана 2023-10-20 в 11 47 00