Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

Translates boolean parameter type to any #28

Closed arkraft closed 5 years ago

arkraft commented 5 years ago

First of all, thank you for this codegen and the time you put into it.

I have a problem converting boolean parameter types. They are correctly defined as boolean in the swagger.json file, but the generated client replaces them with any:

      "get": {
        "summary": "Notifications",
        "operationId": "getNotifications",
        "parameters": [
          {
            "type": "boolean",
            "name": "groups",
            "required": true,
            "in": "query"
          },
          {
            "type": "boolean",
            "name": "onlyUnread",
            "required": true,
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/NotificationDto"
              }
            }
          },
        },
        "tags": [
          "Notification"
        ],
        "security": [
          {
            "oauth2": []
          }
        ],
        "produces": [
          "application/json"
        ],
        "consumes": [
          "application/json"
        ]
      }

and this is the generated method:

  /**
   * Notifications
   */
  getNotifications(
    params: {
      /**  */
      groups: any;
      /**  */
      onlyUnread: any;
    } = {} as any,
    options: IRequestOptions = {},
  ): Promise<NotificationDto[]> {
    return new Promise((resolve, reject) => {
      const configs: IRequestConfig = { ...options, method: 'get' };
      configs.headers = {
        ...options.headers,
        'Content-Type': 'application/json',
      };
      const url = '/api/notifications';

      configs.url = url;
      configs.params = { groups: params.groups, onlyUnread: params.onlyUnread };
      const data = null;

      configs.data = data;
      axios(configs)
        .then((res) => {
          resolve(res.data);
        })
        .catch((err) => {
          reject(err);
        });
    });
  }

The notifications parameters for groups and onlyUnread are of type any. It works for strings and numbers as far as i can tell