swagger-api / swagger-api/swagger-codegen

swagger json to client conversion is not working if it has in:body as array string

Open
#10,172 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I'm trying to generate a swagger client from swagger JSON but when I run swagger code-gen it throws error like could not complete the operation. Below is my swagger JSON

"swagger": "2.0",

"/api/{id}/MO/{MOid}/pop/api": {
      "post": {
        "tags": [
          "cam"
        ],
        "summary": "summay",
        "operationId": "ApiCamByIdMOByMOIdPOPApiPost",
        "consumes": [
          "application/json-patch+json",
          "application/json",
          "text/json",
          "application/*+json"
        ],
        "produces": [
          "text/plain",
          "application/json",
          "text/json"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "cam id",
            "required": true,
            "type": "string"
          },
          {
            "name": "moId",
            "in": "path",
            "description": "mo's id",
            "required": true,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "apiItemIds",
            "in": "body",
            "description": "List of api items",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "API pop report",
            "schema": {
              "$ref": "#/definitions/Operation"
            }
          },
        }
      }
    },

When I try to convert this JSON to java client using swagger code Gen. It fails with Could not process operation.

Once I remove below part Code generation works fine

 {
            "name": "apiItemIds",
            "in": "body",
            "description": "List of api items",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }

Code generation works fine. I don't know what's wrong with this part looks everything fine to me. I tried this request in postman and curl command it worked fine. I tried many things with no progress.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Swagger 2.0 operation and its array-of-string body parameter, then reproduce the failure while generating a Java client. Compare generation with and without that parameter; done means the definition is accepted and the Java client is generated without “Could not process operation.”

Written by the indexing model from the issue text.

Assessment

Tech stack
java, json, yaml
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.