-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Respect request validator plugin defined at the document root and hierarchy of plugin definitions #3293
Conversation
@@ -147,3 +147,20 @@ export function joinPath(p1: string, p2: string): string { | |||
|
|||
return `${p1}/${p2}`; | |||
} | |||
|
|||
// Select first unique instance of an array item depending on the property selector | |||
export function distinctByProperty<T>(arr: Array<T>, propertySelector: (item: T) => any): Array<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from packages/openapi-2-kong/src/kubernetes/plugins.js
@@ -237,4 +238,40 @@ describe('common', () => { | |||
expect(result.pathname).toBe('/api/v1'); | |||
}); | |||
}); | |||
|
|||
describe('distinctByProperty()', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from packages/openapi-2-kong/src/kubernetes/__tests__/plugins.test.js
}); | ||
}); | ||
|
||
describe('generatePlugin()', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is only exported for this test, which is covered by a lot of upstream tests already.
@@ -67,6 +67,332 @@ describe('services', () => { | |||
]); | |||
}); | |||
|
|||
it('generates routes with request validator plugin from operation over path over global', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e535aa5
to
e41e047
Compare
b203442
to
b44a251
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!!
I discussed with @sonicyeti that all servers (that differ only by
I do not get the distinction between Expanding on that;
|
Right, so its a requirement for all servers to follow that rule (which we should enforce in the generator logic), therefore allowing for a single
My running understanding/assumption was that each server in the OAS root should map to an individual For instance, if an operation contains a
Essentially, you're saying a If I am understanding your explanation correctly, I can see why plugins on a |
037c6ad
to
d3e6d59
Compare
a0a779f
to
8e50bdf
Compare
@develohpanda that understanding is correct |
8e50bdf
to
07bd964
Compare
07bd964
to
a40f13f
Compare
Rules
The rules for which plugin to use and where to place it in the generated spec are the following:
route
get derived frompath -> operation
service
get derived fromroot
There is one special case to do with the request-validator plugin. This is:
route
gets derived fromroot -> path -> operation
Example
This means, if a plugin (eg.
x-kong-plugin-key-auth
) exists on theroot
,path
andoperation
with different config at each level, in the generated declarative config, the:service
entity will have its plugin derived from theroot
route
entity will have its plugin derived from theoperation
(becauseoperation
takes precedence overpath
)If the request validator plugin (
x-kong-plugin-request-validator
) exists on theroot
, in the generated declarative config, the:service
entity will have it's plugin derived from theroot
(or be a default config if nothing is user defined)route
entity will have its plugin derived from theroot
Similarly, if the request validator plugin (
x-kong-plugin-request-validator
) exists on theroot
andoperation
, in the generated declarative config, the:service
entity will have it's plugin derived from theroot
(or be a default config if nothing is user defined)route
entity will have its plugin derived from theoperation
Fixes INS-610, fixes INS-619