Conversation
Collaborator
|
@djones6 has a conflict... |
Codecov Report
@@ Coverage Diff @@
## master #1242 +/- ##
==========================================
+ Coverage 88.11% 88.15% +0.04%
==========================================
Files 37 37
Lines 2347 2355 +8
==========================================
+ Hits 2068 2076 +8
Misses 279 279
Continue to review full report at Codecov.
|
2 tasks
Collaborator
Author
|
@ianpartridge I've rebased this (and Kitura/KituraContracts#18) on the latest from master, and proposed a solution for the issue of POST / PUT which I have detailed in 'Notable changes to behaviour' in the description above. |
ianpartridge
requested changes
May 9, 2018
Sources/Kitura/CodableRouter.swift
Outdated
|
|
||
| // POST | ||
| fileprivate func postSafely<I: Codable, O: Codable>(_ route: String, handler: @escaping CodableClosure<I, O>) { | ||
| // POST |
Collaborator
There was a problem hiding this comment.
Please remove the stray space.
Sources/Kitura/CodableRouter.swift
Outdated
|
|
||
| // PUT with Identifier | ||
| fileprivate func putSafely<Id: Identifier, I: Codable, O: Codable>(_ route: String, handler: @escaping IdentifierCodableClosure<Id, I, O>) { | ||
| // PUT with Identifier |
| } | ||
|
|
||
| enum OnlyEncodable: Encodable { | ||
| case data(String) |
| } | ||
|
|
||
| enum OnlyDecodable: Decodable { | ||
| case data(String) |
Collaborator
Author
|
@ianpartridge done. |
2 tasks
djones6
added a commit
that referenced
this pull request
May 16, 2018
djones6
added a commit
that referenced
this pull request
May 30, 2018
- and permit `nil` Codable responses when a default or custom success status is returned (building on #1254)
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implementation of Kitura Evolution proposal: Relax Type Constraints for Codable Routing
Resolves #1235 by relaxing the type requirements on the Codable Router to Decodable for input types, and Encodable for output types.
This also requires a corresponding Pull Request in KituraContracts: Kitura/KituraContracts#18
Motivation and Context
See #1235.
The Codable Router was designed with a symmetry in mind for types to be shared between the client and server side (KituraKit <-> Kitura), which requires those types to be both Encodable and Decodable.
In addition, for types that contain purely Codable attributes, conformance to Codable can be synthesized by the compiler. However, there are cases where conformance must be implemented manually.
For cases where the user only wants to use type safety in a single direction (such as Decodable for a type that will only be received), we currently require them to implement conformance to Encodable (at least dummy conformance to satisfy the type requirement).
Notable changes to behaviour
In order to facilitate the receiving of a
Decodabletype in a PUT or POST, without requiring that we respond with the same type (or some dummy type) conforms toEncodable, it is necessary to allow Codable responses of(nil, .someSuccessStatus).In the current implementation I have relaxed this to also permit
(nil, nil), where the nilRequestErrorsignifies success (with the default code for that method), and the nilEncodablesignifies that we wish to return no data.Previously, such a response would have failed (due to trying to JSON encode a
nil), and resulted in logging in error (Could not encode result: invalidValue(nil, ....) and returning.internalServerErrorstatus.How Has This Been Tested?
Checklist: