Skip to content

typescript-node: Fix cookie auth, fix multiple API key auth #3927

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

Merged
merged 3 commits into from
Sep 23, 2019

Conversation

janjongboom
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

TC: @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @nicokoenig (2018/09) @topce @akehir

Description of the PR

This pull request fixes two issues with the typescript-node generator:

  1. If multiple API Key authentication schemas are defined the generator emits code that won't compile.
  2. in: cookie is not supported.

Multiple API Key authentication schemas

If you have the following OpenAPI definition:

components:
    securitySchemes:
        ApiKeyAuthentication:
            type: apiKey
            in: header
            name: x-api-key
        JWTAuthentication:
            type: apiKey
            in: cookie
            name: jwt

The generator emits the following code:

import { ApiKeyAuth } from '../model/models';		
import { ApiKeyAuth } from '../model/models';		

This won't compile. In api-single.mustache there's currently a loop around all authentication methods that outputs a single line depending on the authentication mode. This is not necessary as HttpBasicAuth, ApiKeyAuth and OAuth are always present in ../models/models. Always emitting a single line that references all of these will prevent this error.

in: cookie

components:
    securitySchemes:
        JWTAuthentication:
            type: apiKey
            in: cookie
            name: jwt

Will emit code that adds the API key to the query string, as in: cookie is not handled at all. This patch adds a handler that sets the Cookie header if this field is present.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@macjohnny
Copy link
Member

@ janjongboom please re-generate the samples, see https://circleci.com/gh/OpenAPITools/openapi-generator/9024#tests/containers/2

@janjongboom
Copy link
Contributor Author

@macjohnny Pushed updated samples.

@macjohnny
Copy link
Member

macjohnny commented Sep 23, 2019

@janjongboom
Copy link
Contributor Author

@macjohnny As far as I can see I ran both the ./bin and the ./bin/openapi3 scripts... But I see you did a new push, so not sure if you require action from me at this point.

@macjohnny
Copy link
Member

let's see what the CI says, but I think no more actions are required

@macjohnny macjohnny merged commit 6f1b8ef into OpenAPITools:master Sep 23, 2019
@janjongboom
Copy link
Contributor Author

Great, thanks for the quick review @macjohnny

Jesse0Michael pushed a commit to Jesse0Michael/openapi-generator that referenced this pull request Oct 3, 2019
…ools#3927)

* typescript-node: Fix cookie auth, fix multiple API key auth

* Re-generate samples

* Re-generate samples
@wing328
Copy link
Member

wing328 commented Oct 4, 2019

@janjongboom thanks for the PR, which has been included in the v4.1.3 release: https://twitter.com/oas_generator/status/1180123829626003456

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

Successfully merging this pull request may close these issues.

4 participants