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

[BUG] Operation codegen always contains all scopes for oauth2 #2603

Closed
4 of 6 tasks
ybelenko opened this issue Apr 4, 2019 · 3 comments
Closed
4 of 6 tasks

[BUG] Operation codegen always contains all scopes for oauth2 #2603

ybelenko opened this issue Apr 4, 2019 · 3 comments

Comments

@ybelenko
Copy link
Contributor

ybelenko commented Apr 4, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I've noticed that current codegen always includes all scopes for oauth2 security schema within operations.
Invalid codegen example of updatePetWithForm operation which requires only write:pets and read:pets scopes but contains all existed:

...
    "authMethods": [
        {
            "name": "petstore_auth",
            "type": "oauth2",
            "hasMore": false,
            "isBasic": false,
            "isOAuth": true,
            "isApiKey": false,
            "isBasicBasic": false,
            "isBasicBearer": false,
            "vendorExtensions": {},
            "isKeyInQuery": false,
            "isKeyInHeader": false,
            "isKeyInCookie": false,
            "flow": "implicit",
            "authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog",
            "scopes": [
                {
                    "scope": "write:pets",
                    "hasMore": "true",
                    "description": "modify pets in your account"
                },
                {
                    "scope": "read:pets",
                    "hasMore": "true",
                    "description": "read your pets"
                },
                {
                    "scope": "test:test",
                    "description": "just for tests purpose"
                }
            ],
            "isCode": false,
            "isPassword": false,
            "isApplication": false,
            "isImplicit": true
        }
    ],
...
openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url
diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
index 8d7070b2df..62e480a1bd 100644
--- a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
+++ b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
@@ -1080,6 +1080,7 @@ securityDefinitions:
     scopes:
       'write:pets': modify pets in your account
       'read:pets': read your pets
+      'test:test': just for tests purpose
   api_key:
     type: apiKey
     name: api_key
Command line used for generation

Added -DdebugSupportingFiles to print codegen

java -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -jar ./modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -DdebugSupportingFiles -t modules/openapi-generator/src/main/resources/php-slim-server -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php-slim -o samples/server/petstore/php-slim
Steps to reproduce
  1. Add 'test:test': just for tests purpose scope to petstore_auth in securityDefinitions.
  2. Start any generator with -DdebugSupportingFiles option.
  3. Check that all secured endpoints have just created scope(test:test) in authMethods property which is wrong because they need write:pets and read:pets only.
Suggest a fix

Include only required scopes in codegen of each operation or mark somehow required ones.

@wing328
Copy link
Member

wing328 commented Apr 4, 2019

@ybelenko
Copy link
Contributor Author

ybelenko commented Apr 5, 2019

@wing328
Checked both PRs.
Luckely, #1982 fixes this issue. First PR doesn't.

@ybelenko
Copy link
Contributor Author

ybelenko commented Apr 5, 2019

Fixed by #1982

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

2 participants