-
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
fix(openapi2kong): removing unused component reference #4911
fix(openapi2kong): removing unused component reference #4911
Conversation
* @param keyForPath path to look for in JSON Schema for resolving in the nested object | ||
* @returns a list of path string values | ||
*/ | ||
export function resolveObjectPathRecursively(unknownObject: unknown, keyForPath = '$ref'): string[] { |
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.
Please feel free to add a unit test for this or enhance.
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.
This looks good! a circular reference test, and getting rid of unused references. Especially the latter will really slim down the resulting configs.
I'll leave it to others to judge the code and test coverage.
a4adc2e
to
c1f56df
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.
we made some great progress simplifying the test case, but now we need to reevaluate based on what we learned (real quick!)
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! 👍
There's still one issue
I'm getting an error on generated files, when running deck sync -s <file>
:
(...)
Summary:
Created: 0
Updated: 1
Deleted: 0
Error: 1 errors occurred:
while processing event: {Create} plugin request-validator for route 3bc7df06-b6c3-4d21-a8db-8a7a3ec79b25 failed: HTTP status 400 (message: "schema violation ([string \"jsonschema:anonymous\"]:20: stack overflow)")
Note:
deck validate -s <file>
seems to work ok.
Sharing here the generated files in case it helps:
Archive.zip
just ried importing
Looks like the problem is with Kong, or even the JSONschema library used 😞 . I thought I had checked this, but apparently I missed something. Maybe I checked the lib, but not Kong 🤔 |
Hi @Tieske , can you please try it with the actual example instead of circular-requestBody.expected.json |
The circular-requestBody.expected.json was introduced to narrow down to minimal requirements to reproduce the bug but that may not reflect on the real schema conversions. For instance, "post" path has request but no response defined. I am still curious what makes such difference, but when I ran with the following configuration generated, it passes db_import command. {
"_format_version": "1.1",
"services": [
{
"name": "Testing_Circular_3",
"protocol": "https",
"host": "some.random.url",
"port": 443,
"path": "/",
"plugins": [
{
"name": "request-validator",
"config": {
"version": "draft4",
"body_schema": "{}",
"verbose_response": true
},
"tags": [
"OAS3_import"
],
"enabled": true
}
],
"routes": [
{
"tags": [
"OAS3_import"
],
"name": "Testing_Circular_3-testing-testingId-testing-endpoint-post",
"methods": [
"POST"
],
"paths": [
"/testing/(?<testingId>[^\\/]+)/testing-endpoint$"
],
"strip_path": false,
"plugins": [
{
"name": "request-validator",
"config": {
"version": "draft4",
"parameter_schema": [
{
"in": "path",
"explode": false,
"required": true,
"name": "testingId",
"schema": "{\"type\":\"string\",\"maxLength\":50}",
"style": "simple"
}
],
"body_schema": "{\"description\":\"desc\",\"allOf\":[{\"$ref\":\"#/components/schemas/Entity1\"}],\"components\":{\"schemas\":{\"Entity1\":{\"description\":\"desc\",\"type\":\"object\",\"properties\":{\"entity1Prop1\":{\"$ref\":\"#/components/schemas/Entity2\"}}},\"Entity2\":{\"description\":\"desc\",\"oneOf\":[{\"$ref\":\"#/components/schemas/EntityCircularStart\"}],\"discriminator\":{\"propertyName\":\"entity5Type\",\"mapping\":{\"ENTITY_CIRCULAR_START\":\"#/components/schemas/EntityCircularStart\"}}},\"EntityCircularStart\":{\"description\":\"desc\",\"allOf\":[{\"$ref\":\"#/components/schemas/Entity5Common\"},{\"$ref\":\"#/components/schemas/Entity4Common\"}]},\"Entity5Common\":{\"description\":\"desc\",\"type\":\"string\"},\"Entity4Common\":{\"description\":\"desc\",\"type\":\"string\",\"properties\":{\"owners\":{\"$ref\":\"#/components/schemas/Entity4Owners\"}}},\"Entity4Owners\":{\"type\":\"array\",\"description\":\"desc\",\"items\":{\"$ref\":\"#/components/schemas/Entity6\"}},\"Entity6\":{\"description\":\"desc\",\"type\":\"object\",\"required\":[\"entity5\"],\"properties\":{\"entity5\":{\"$ref\":\"#/components/schemas/Entity5AsOwner\"}}},\"Entity5AsOwner\":{\"description\":\"desc\",\"oneOf\":[{\"$ref\":\"#/components/schemas/Entity3AsOwner\"}],\"discriminator\":{\"propertyName\":\"entity5Type\",\"mapping\":{\"ENTITY_3\":\"#/components/schemas/Entity3AsOwner\"}}},\"Entity3AsOwner\":{\"description\":\"desc\",\"allOf\":[{\"$ref\":\"#/components/schemas/Entity3Common\"}]},\"Entity3Common\":{\"description\":\"desc\",\"allOf\":[{\"$ref\":\"#/components/schemas/Entity5Common\"},{\"$ref\":\"#/components/schemas/Entity4Common\"}]}}},\"$schema\":\"https://json-schema.org/schema#\"}",
"allowed_content_types": [
"application/json"
],
"verbose_response": true
},
"tags": [
"OAS3_import"
],
"enabled": true
}
]
}
],
"tags": [
"OAS3_import"
]
}
]
} |
21cee0e
to
afec746
Compare
afec746
to
f86c086
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.
@marckong and I just tested this in every way we know how, including with the user-provided original (multi-thousand line) YAML document that began this investigation.
We definitely identified a lot of areas for improvement, but at this juncture, it looks like it does what it needs to do and this is a good place to "draw the line in the sand" considering we have test coverage for this now and all the manual testing.
This PR is to address the issue mentioned in this comment.
I found it exhausting to work on the openapi2kong. I didn't have energy to really care about the code quality for the recursions written in this PR. If you find it can be enhanced, please feel free to commit the enhanced version of the recursions.
changelog(Improvements): Improved Kong Declarative Config generation for OpenAPI specs with circular dependencies and also added logic to ignore unreferenced components from the generated config