-
Notifications
You must be signed in to change notification settings - Fork 495
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
Add POST codable route support without input object. #1491
base: master
Are you sure you want to change the base?
Conversation
This allows to create a resource without arguments.
Thanks for the PR! We'll get it reviewed. |
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.
I'm not sure whether REST has an opinion on doing this, but I can imagine there may be circumstances where you might want a resource that contains only values generated by the server. Could you elaborate a little on the use-cases for this?
Regarding tests, you can add a new test to TestCodableRouter
, copying the example from testBasicPost
: https://github.com/IBM-Swift/Kitura/blob/master/Tests/KituraTests/TestCodableRouter.swift#L143
I think it would also be useful to add a test to the SwaggerGenerator to make sure the generated document makes sense - unfortunately the tests here are not quite so well crafted, but you can follow the example of an existing POST route test here:
- route handler: https://github.com/IBM-Swift/Kitura/blob/master/Tests/KituraTests/TestSwaggerGeneration.swift#L123
- route registration: https://github.com/IBM-Swift/Kitura/blob/master/Tests/KituraTests/TestSwaggerGeneration.swift#L214
- path assertion: https://github.com/IBM-Swift/Kitura/blob/master/Tests/KituraTests/TestSwaggerGeneration.swift#L229
- content assertions: https://github.com/IBM-Swift/Kitura/blob/master/Tests/KituraTests/TestSwaggerGeneration.swift#L620
I've updated the tests. |
@@ -617,6 +623,15 @@ final class TestSwaggerGeneration: KituraTest, KituraTestSuite { | |||
} | |||
|
|||
func pathContentAssertions3(paths: [String: Any]) { | |||
// Test empty POST | |||
if let path = paths["/me/new"] as? [String: Any] { | |||
if let new = path["new"] as? [String: Any] { |
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 line generates a compile warning because new
is not used. Could change to let _ =
or maybe there's a neater way to check the type?
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.
Fixed! Thanks.
@ianpartridge The code for this change looks okay, what do you think? |
The Travis failure on this job is unrelated to this PR, and has been happening on the CRON builds for master since about 3 weeks ago, eg: https://travis-ci.org/IBM-Swift/Kitura/jobs/648208574 |
Add a new codable route for POST with no object as input.
Description
This allows to create a resource without arguments, like this:
Motivation and Context
It is not possible to use the POST verb without argument, making it weird to create a new resource from an endpoint that has no dependencies.
How Has This Been Tested?
External testing done. I'm unsure about where to add the test if needed.
Checklist: