swagger-api / swagger-api/swagger-codegen

[Typescript-Angular2] Generation of POST parameter with "array" schema causes Error.

Open
#6,098 4 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

This problem appeared in v.2.2.3.
I'm trying to generate "typescript-angular2" client API with http://generator.swagger.io/#!/clients/generateClient service.
I cutted my configuration to make it more readable and it looks like this:

{
    "spec": {
        "swagger": "2.0",
        "info": {
            "version": "v1",
            "title": "Star.Web.Api"
        },
        "host": "localhost:5000",
        "schemes": ["http"],
        "paths": {
            "/api/notifications/read": {
                "put": {
                    "tags": ["Notifications"],
                    "summary": "Mark notifications as read",
                    "operationId": "Notifications_PutMultiRead",
                    "consumes": ["application/json", "text/json", "application/x-www-form-urlencoded"],
                    "produces": [],
                    "parameters": [{
                        "name": "ids",
                        "in": "body",
                        "description": "UID's of notifications",
                        "required": true,
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }],
                    "responses": {
                        "204": {
                            "description": "No Content"
                        }
                    },
                    "security": [{
                        "oauth2": []
                    }]
                }
            }
        }
    },
    "options": {
        "modelPropertyNaming":"camelCase",
        "apiPackage":"app.webapi.api",
        "modelPackage":"app.webapi.model"
    }
}

Such a description leads to an error:

{
  "code": 1,
  "type": "error",
  "message": "Unable to build target: Could not generate api file for 'Notifications'"
}

That's because of the schema of my parameter:

"schema": {
    "type": "array",
    "items": {
        "type": "string"
    }
}

If I change it to object or to constant, everything OK. For example:

"schema": {
    "type": "string"
}

The Swagger spec say's that such a schema for parameter is absoluty legal:
https://swagger.io/specification/#parameterIn (see example where body parameter is an array of string values)

Swagger-codegen version

2.2.3

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 generator.swagger.io generateClient entry point and reproduce the failure using the provided Swagger 2.0 specification and typescript-angular2 target. Trace handling of the body parameter whose schema is an array of strings; done means the client generates successfully for this valid schema without regressing object or string parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.