Skip to content

Path parameters with dots generates nonfunctional typescript #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ianrose14 opened this issue Sep 23, 2022 · 2 comments
Closed

Path parameters with dots generates nonfunctional typescript #413

ianrose14 opened this issue Sep 23, 2022 · 2 comments
Assignees
Labels
bug Something isn't working next release

Comments

@ianrose14
Copy link

Summary

If a path parameter has a dot in it (e.g. item.id) then swagger-typescript-api will rewrite this to camelCase for the parameter name but not in the path string interpolation, which leads in nonfunctional code.

Repro

Here's a minimal (or at least small) input to reproduce this:

{
  "swagger": "2.0",
  "info": {
    "title": "unset",
    "version": "unset"
  },
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "paths": {
    "/foobar/{truck.id}/item": {
      "post": {
        "summary": "Repros an issue",
        "operationId": "ReproFunc",
        "responses": {
          "default": {
            "description": "A response.",
            "schema": {
              "$ref": "#/definitions/myResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "truck.id",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ]
      }
    }
  },
  "definitions": {
    "myResponse": {
      "type": "object"
    }
  }
}

Expected output:

  foobar = {
    /**
     * No description
     *
     * @name ReproFunc
     * @summary Repros an issue
     * @request POST:/foobar/{truck.id}/item
     */
    reproFunc: (truckId: string, params: RequestParams = {}) =>
      this.request<any, MyResponse>({
        path: `/foobar/{truckId}/item`,
        method: "POST",
        ...params,
      }),
  };

Actual output:

  foobar = {
    /**
     * No description
     *
     * @name ReproFunc
     * @summary Repros an issue
     * @request POST:/foobar/{truck.id}/item
     */
    reproFunc: (truckId: string, params: RequestParams = {}) =>
      this.request<any, MyResponse>({
        path: `/foobar/{truck.id}/item`,
        method: "POST",
        ...params,
      }),
  };

Note that the path (/foobar/{truck.id}/item) references a variable ("truck.id") that does not exist, since the function parameter was rewritten to be truckId.

p.s. The obvious solution here is "don't use parameters with dots in them - that's weird!". Unfortunately the swagger we are using is itself generated by grpc-gateway which supports nested fields via dot notation (example) so there's no easy way to avoid this...

@js2me js2me self-assigned this Oct 22, 2022
@js2me js2me added bug Something isn't working next release labels Oct 22, 2022
@js2me
Copy link
Member

js2me commented Oct 22, 2022

Hi @ianrose14 ! Thanks for this issue, will fix it soon

@js2me js2me mentioned this issue Oct 24, 2022
@js2me
Copy link
Member

js2me commented Nov 12, 2022

@ianrose14 should be fixed in 11.0.0 release.
Please reopen this issue if problem is still occurring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release
Projects
None yet
Development

No branches or pull requests

2 participants