Skip to content

Conversation

@lag-of-death
Copy link
Contributor

@lag-of-death lag-of-death commented Aug 7, 2019

Changes

Security array is not flattened now, so that and relation between security schemes can be respected (the relation in described in the links under Specs section below).

The issue: stoplightio/prism#509

Specs:

OAS3: https://swagger.io/docs/specification/authentication/#multiple
OAS2: https://swagger.io/docs/specification/2-0/authentication/#multiple

@lag-of-death lag-of-death requested a review from XVincentX August 14, 2019 16:08
expect(translateToSecurities([[basicSecurity, implicitSecurity, apiSecurity]])).toMatchSnapshot();
});
});
});

Choose a reason for hiding this comment

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

Please add some tests that will verify the OR case (return array of more than one arrays)

[
{
api_key: [],
},

Choose a reason for hiding this comment

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

Looks good but needs some more tests: something that can prove we support both AND & OR cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

@chris-miaskowski @lag-of-death is there anything left to address here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lottamus, no, the test was added:
#15 (comment)

Copy link

@chris-miaskowski chris-miaskowski left a comment

Choose a reason for hiding this comment

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

Hey @lag-of-death looks good in general but missing some tests. I'm happy to approve when you add them.

@lag-of-death
Copy link
Contributor Author

@chris-miaskowski, the tests are added :)

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

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

Dropped some thought and comments, although I kind of remember that the security definitions were flattened for some reason that I can't really recall now. I think @marbemac probably knows/was the author of such choice.

I also think this is likely a breaking change and might have some consequences on Studio as well //cc @lottamus ?

@lag-of-death
Copy link
Contributor Author

thanks for the feedback @XVincentX! I've addressed most of it and left some comments for the rest. Please take a look :)

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

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

This is ok — I'd just hold off on merging to give @marbemac a chance to check out this as well since (again, I might be wrong) I recall he was behind the idea of flattening the security specifications.

@marbemac
Copy link
Contributor

I'd just hold off on merging to give @marbemac a chance to check out this as well since (again, I might be wrong) I recall he was behind the idea of flattening the security specifications.

This was just an oversight on my part. Looks good to me!


@lottamus could you create an issue to update elements for stoplightio/types#50?

@pytlesk4 could you do a quick investigation of updating analyzer to the latest types package (that includes the PR linked above), and if there are any problems then perhaps create an issue to tackle it soon?

@casserni casserni removed their request for review August 19, 2019 15:35
@casserni casserni requested a review from lottamus August 19, 2019 15:35
@lag-of-death
Copy link
Contributor Author

@lottamus, @pytlesk4, I'm a bit unsure here, is this PR OK to be merged? cc @marbemac

Copy link
Contributor

@lottamus lottamus left a comment

Choose a reason for hiding this comment

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

Looks ok to me except one question about keeping the security array keys. I believe we might need a way to figure out what the original security array looks like?

Also I find it a bit weird that we're mapping to an array of arrays...wouldn't an easier interface look something like this that would also have the benefit of preserving the security key: 🤷‍♂

getSecurities(
  spec: Partial<OpenAPIObject>,
  operation: Partial<OperationObject>,
): Array<Dictionary<SecuritySchemeObject, SecurityString>>
[
  {
    "api_key": {
      in: 'header',
      name: 'api_key',
      type: 'apiKey',
    },
    "petstore-oauth2": {
      authorizationUrl: 'http://swagger.io/api/oauth/dialog',
      flow: 'implicit',
      scopes: {
        'read:pets': 'read your pets',
        'write:pets': 'modify pets in your account',
      },
      type: 'oauth2',
    },
  },
  {
    "api_key": {
      in: 'header',
      name: 'api_key',
      type: 'apiKey',
    },
    "basic-auth": {},
  }
]

name: 'api_key',
type: 'apiKey',
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason you can think of that we might need the security array's key here? Currently there is nothing tying this oauth2 object back to the security array. Does that make sense?

Suggested change
{
{
securityKey: 'petstore_auth',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lottamus, I think that given https://github.com/stoplightio/http-spec/pull/15/files#diff-f5ac86d0dd4d4fa1390aca28ac1fbc59L107-L112 it's OK to just not add this securityKey? If it was not a problem before, it shouldn't be a problem now. We can address it later if it turns out to be an issue

@lag-of-death
Copy link
Contributor Author

@lottamus

Also I find it a bit weird that we're mapping to an array of arrays.

I find it a lot easier to work with arrays instead of objects, that's why such a structure

@lag-of-death lag-of-death merged commit 91df1ea into master Aug 22, 2019
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lag-of-death lag-of-death deleted the feat/and-relation-in-security-schemas branch August 22, 2019 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants