Skip to content
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

Does not generate proper client if two in:path parameters #1124

Open
sergik opened this issue Jan 4, 2018 · 4 comments
Open

Does not generate proper client if two in:path parameters #1124

sergik opened this issue Jan 4, 2018 · 4 comments
Milestone

Comments

@sergik
Copy link

sergik commented Jan 4, 2018

Have the following spec with method with 2 in path parameters:

  workspaceId:
    name: workspaceId
    in: path
    description: Workspace id
    type: string
    required: true
    x-example: "c1a90175-d011-4519-945c-ce934a205292"
  userId:
    name: userId
    in: path
    description: Global id of user
    type: string
    format: uuid
    required: true
    x-example: "c1a90175-d011-4519-945c-ce934a205293"
'/workspaces/{workspaceId}/users/{userId}':
    x-swagger-router-controller: workspaces
    parameters:
      - $ref: '#/parameters/userId'
      - $ref: '#/parameters/workspaceId'
    post:
      summary: Add user to workspace
      description: Add user to workspace
      operationId: addUserToWorkspace
      tags:
        - Workspaces
      security:
        - service:
          - workspaces:write
      responses:
        201:
          description: Successful response
        401:
          $ref: '#/responses/Unauthorized'
        403:
          $ref: '#/responses/Forbidden'
        404:
          $ref: '#/responses/NotFound'
        500:
          $ref: '#/responses/GeneralError'

And the following code is generated:

 addUserToWorkspace(userId: string): Promise<void> {
        let url_ = this.baseUrl + "/workspaces/{workspaceId}/users/{userId}";
        if (userId === undefined || userId === null)
            throw new Error("The parameter 'userId' must be defined.");
        url_ = url_.replace("{userId}", encodeURIComponent("" + userId)); 
        url_ = url_.replace(/[?&]$/, "");

        let options_ = <RequestInit>{
            method: "POST",
            headers: new Headers({
                "Content-Type": "application/json", 
            })
        };

        return this.http.fetch(url_, options_).then((_response: Response) => {
            return this.processAddUserToWorkspace(_response);
        });
    }

Generated with:
nswag swagger2tsclient /ClassName:Client /Template:Fetch /PromiseType:Promise /DateTimeType:Date /GenerateClientInterfaces:true /GenerateConstructorInterface:true /GenerateDefaultValues:true /Output:src/client/src/client.ts /TypeStyle:Interface /TypeScriptVersion:2.5 /WrapDtoExceptions:false

@sergik
Copy link
Author

sergik commented Jan 15, 2018

any updates on this?

@RicoSuter
Copy link
Owner

Very strange, in general multiple path parameters should be supported...

@RicoSuter RicoSuter added this to the vNext milestone Jan 16, 2018
@cslutgen
Copy link

@RicoSuter Any update on this? It is still not working. If multiple path parameters are explicitly defined, it works as expected. The problem is if multiple path parameters are referencing shared global parameter definitions. In that case, only the first path parameter is generated.

If multiple referenced parameters are provided in the operation itself, it works correctly.

This works:

'/workspaces/{workspaceId}/users/{userId}':
parameters:
-userId:
in: path
name: userId
type: integer
required: true
-workspaceId:
in: path
name: workspaceId
type: integer
required: true
get:

--- This does not work

'/workspaces/{workspaceId}/users/{userId}':
parameters:
- $ref: '#/parameters/userId'
- $ref: '#/parameters/workspaceId'
get:

parameters:
userId:
in: path
name: userId
type: integer
required: true
workspaceId:
in: path
name: workspaceId
type: integer
required: true

@MirKml
Copy link

MirKml commented Apr 25, 2019

Confirmed, for path with more parameters in URI and $ref in parameter, generated code is bad, cannot be compiled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants