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.
Per much discussion we've had, we want to support properties in our API endpoints which may be set to the value
null
.We can indicate this in Swagger with the
x-nullable
property, for which there is precedent[1].For existing users of the binary types, this is a breaking change.
This is achieved through the introduction of a new type,
Nullable<T>
.The nullable type represents values that are present on the API request, but have the value
null
.Values that are null are represented as
Null
, while values that are present are represented asPresent(value)
.This is distinct from values that are not present in the request JSON.
If a nullable value is not present in a request, the deserialization fails, as it would with any other non-optional value.
Nullable values may themselves be optional, through the
Option<Nullable<T>>
type.Again, the distinction is made between a value that is not present, and a value that is
null
- values that are not present areOption::None
, null values areOption::Some(Nullable::Null)
, and present values areOption::Some(Nullable::Present(value))
.All of this, of course, also applies to response values (i.e. both Deserialization and Serialization are supported).
For convenience, the
Nullable
type implements many of the methods present on theOption
type, such asmap
,unwrap
, andand_then
.In order to accomplish this implementation, a modification has been made to the representation of binary string (i.e. base64-encoded) types.
Previously, these were represented as
Vec<u8>
s, and had a special annotation added to the generated model to ensure they were (de)serialized by the correct method.This annotation clashed with the annotation required by optional nullable types, and so these have been moved to a Newtype, namely
ByteArray(Vec<u8>)
.This type implements the Deserialize and Serialize traits, meaning no annotation is required.
Existing users of the binary types who regenerate their code must then wrap their
Vec<u8>
instantiations in a constructor for theByteArray
type.The Deref trait has been implemented to allow automatic deref coercion to the underlying
Vec<u8>
type.This merge has a related code changes in a merge request to the code generator, which includes the necessary Rust changes to correctly use these types, as well as documentation generation changes.