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

fix: unable to export route with nil methods field #1673

Conversation

Jaycean
Copy link
Member

@Jaycean Jaycean commented Mar 26, 2021

Please answer these questions before submitting a pull request, or your PR will get closed.

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

  1. Fixed the bug that when creating route, the methods field is nil or [] and the data cannot be exported.

  2. When there is no plugin data in the route, the empty field is not exported.

Related issues

fix/resolve #1668

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@juzhiyuan juzhiyuan requested a review from starsz March 26, 2021 05:07
@codecov-io
Copy link

codecov-io commented Mar 26, 2021

Codecov Report

Merging #1673 (0fb644b) into master (c6c5d14) will decrease coverage by 10.24%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1673       +/-   ##
===========================================
- Coverage   72.59%   62.34%   -10.25%     
===========================================
  Files         133       47       -86     
  Lines        5728     3126     -2602     
  Branches      666        0      -666     
===========================================
- Hits         4158     1949     -2209     
+ Misses       1327      865      -462     
- Partials      243      312       +69     
Flag Coverage Δ
backend-e2e-test 62.34% <100.00%> (+0.21%) ⬆️
backend-e2e-test-ginkgo 48.36% <0.00%> (+0.10%) ⬆️
backend-unit-test ?
frontend-e2e-test ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/internal/handler/data_loader/route_export.go 72.46% <100.00%> (+3.29%) ⬆️
api/internal/utils/runtime/runtime.go 0.00% <0.00%> (-64.29%) ⬇️
api/internal/core/store/validate_mock.go 0.00% <0.00%> (-50.00%) ⬇️
api/internal/filter/authentication.go 47.22% <0.00%> (-30.56%) ⬇️
api/internal/handler/service/service.go 62.60% <0.00%> (-29.57%) ⬇️
api/internal/core/store/store.go 59.63% <0.00%> (-27.11%) ⬇️
api/internal/filter/ip_filter.go 48.71% <0.00%> (-23.08%) ⬇️
api/internal/handler/global_rule/global_rule.go 64.51% <0.00%> (-19.36%) ⬇️
...pi/internal/handler/plugin_config/plugin_config.go 59.57% <0.00%> (-18.09%) ⬇️
api/internal/utils/json_patch.go 44.82% <0.00%> (-13.80%) ⬇️
... and 101 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6c5d14...0fb644b. Read the comment docs.

@Jaycean Jaycean requested a review from nic-chen March 26, 2021 09:41
@Jaycean Jaycean requested review from gxthrj, imjoey and tokers March 26, 2021 16:02
if route.Methods != nil && len(route.Methods) > 0 {
routeMethods = route.Methods
} else {
routeMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch, http.MethodHead, http.MethodConnect, http.MethodTrace, http.MethodOptions}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a pre-defined unexportable variable to indicate this default method set?

Copy link
Member Author

@Jaycean Jaycean Mar 27, 2021

Choose a reason for hiding this comment

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

Yeah,Because these methods such as "GET", "POST" and so on are immutable, the use here is more uniform, and "Get", "get" and "GET" will not appear.
They don't affect the output.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean creating a variable _allHTTPMethods, which is:

var (
    _allHTTPMethods = []string{http.MethodGet, http.MethodPost, ...}
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I misunderstood.
Done. Thks

@@ -131,7 +129,6 @@
}
},
"x-apisix-enable_websocket": false,
"x-apisix-plugins": {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Just want to know why delete it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The design of import and export is to export when there is data, and not export when there is no data. Here, no data is empty. I don't think it's necessary to export, so I delete it.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it is not deleted, Fe ci will report an error.

Copy link
Member

Choose a reason for hiding this comment

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

@Jaycean do we have some test case for x-apisix-plugins not empty ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, most of the other test cases have data in x-apisix-plugins
For example, this test case:

func TestExportRoutes1(t *testing.T) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation.Got it.

"172.16.238.20:1980": 1
},
"type": "roundrobin"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

They are the same. Can we use a variable instead?

                                        "requestBody": {},
					"responses": {
						"default": {
							"description": ""
						}
					},
					"x-apisix-enable_websocket": false,
					"x-apisix-hosts": ["test.com"],
					"x-apisix-priority": 0,
					"x-apisix-status": 1,
					"x-apisix-upstream": {
						"nodes": {
							"172.16.238.20:1980": 1
						},
						"type": "roundrobin"
					}

Copy link
Member Author

Choose a reason for hiding this comment

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

Here, I intend to modify it uniformly when using ginkgo rewriting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it.

@juzhiyuan juzhiyuan requested a review from starsz March 29, 2021 15:12
@juzhiyuan juzhiyuan merged commit 37f4cd8 into apache:master Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The route imported through Apisix's interface using Export OpenAPI exported file is empty
6 participants