Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1535
Closed
Open
Issue created Nov 23, 2018 by Administrator@rootContributor

[typescript-fetch] (4.0.X) Missing queryParameters initialization

Created by: someone1

Description

Testing out the updated generator from PR #569 and I noticed an issue where I have multiple authentication requirements for an API endpoint (logical AND - both required) for an API key via query parameter and via an Authorization header. The generated code places both in correctly, however, for endpoints where I otherwise have no other query parameters (e.g. the authentication method is the only one), the variable queryParameters is never defined and its not passed in to the request.

openapi-generator version

4.0.0-20181118.115720-41

OpenAPI declaration file content or url (partial)
swagger: "2.0"

paths:
  "/admin/users/{id}/clearTokens":
    post:
      operationId: "users.clear_tokens"
      responses:
        204:
          description: Success
      parameters:
        - in: path
          name: id
          required: true
          type: string
      security:
        - google_id_token: []
          api_key: []

securityDefinitions:
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"
  google_id_token:
    authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth"
    flow: "implicit"
    type: "oauth2"

Generated Code excerpt:

async usersClearTokensRaw(requestParameters: UsersClearTokensRequest): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.id === null || requestParameters.id === undefined) {
            throw new runtime.RequiredError('id','Required parameter requestParameters.id was null or undefined when calling usersClearTokens.');
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            queryParameters["key"] = this.configuration.apiKey("key"); // api_key authentication
        }

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            if (typeof this.configuration.accessToken === 'function') {
                headerParameters["Authorization"] = this.configuration.accessToken("google_id_token", []);
            } else {
                headerParameters["Authorization"] = this.configuration.accessToken;
            }
        }

        const response = await this.request({
            path: `/admin/users/{id}/clearTokens`.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters.id))),
            method: 'POST',
            headers: headerParameters,
        });

        return new runtime.VoidApiResponse(response);
    }
Command line used for generation

openapi-generator generate -i openapi.yaml -l typescript-fetch -c es6.json -o ./typescript-api/

Steps to reproduce
  1. Use the provided yaml excerpt above to generate a client with the provided command line
  2. Buggy code generated
Related issues/PRs

PR #569

Suggest a fix/enhancement

Template variable #hasQueryParams should be set to true if an authentication method required for that endpoint uses query parameters.

Assignee
Assign to
Time tracking