Skip to content

Commit 838c6d8

Browse files
committed
Only serialize metadata fields that has value
1 parent 17e8353 commit 838c6d8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/metadata.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,82 @@ pub struct Metadata {
1818
pub version: String,
1919
/// A Platform specification describing an operating system supported by the distribution
2020
/// which is not listed in the “Operating System” Trove classifiers.
21-
#[cfg_attr(feature = "serde", serde(rename = "platform"))]
21+
#[cfg_attr(
22+
feature = "serde",
23+
serde(rename = "platform", skip_serializing_if = "Vec::is_empty")
24+
)]
2225
pub platforms: Vec<String>,
2326
/// Binary distributions containing a PKG-INFO file will use the Supported-Platform field
2427
/// in their metadata to specify the OS and CPU for which the binary distribution was compiled.
2528
#[cfg_attr(feature = "serde", serde(skip_serializing))]
2629
pub supported_platforms: Vec<String>,
2730
/// A one-line summary of what the distribution does.
31+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
2832
pub summary: Option<String>,
2933
/// A longer description of the distribution that can run to several paragraphs.
34+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
3035
pub description: Option<String>,
3136
/// A list of additional keywords, separated by commas, to be used to
3237
/// assist searching for the distribution in a larger catalog.
38+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
3339
pub keywords: Option<String>,
3440
/// A string containing the URL for the distribution’s home page.
41+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
3542
pub home_page: Option<String>,
3643
/// A string containing the URL from which this version of the distribution can be downloaded.
44+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
3745
pub download_url: Option<String>,
3846
/// A string containing the author’s name at a minimum; additional contact information may be provided.
47+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
3948
pub author: Option<String>,
4049
/// A string containing the author’s e-mail address. It can contain a name and e-mail address in the legal forms for a RFC-822 `From:` header.
50+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
4151
pub author_email: Option<String>,
4252
/// Text indicating the license covering the distribution where the license is not a selection from the `License` Trove classifiers.
53+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
4354
pub license: Option<String>,
4455
/// Each entry is a string giving a single classification value for the distribution.
56+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty"))]
4557
pub classifiers: Vec<String>,
4658
/// Each entry contains a string naming some other distutils project required by this distribution.
59+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty"))]
4760
pub requires_dist: Vec<String>,
4861
/// Each entry contains a string naming a Distutils project which is contained within this distribution.
62+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty"))]
4963
pub provides_dist: Vec<String>,
5064
/// Each entry contains a string describing a distutils project’s distribution which this distribution renders obsolete,
5165
/// meaning that the two projects should not be installed at the same time.
66+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty"))]
5267
pub obsoletes_dist: Vec<String>,
5368
/// A string containing the maintainer’s name at a minimum; additional contact information may be provided.
5469
///
5570
/// Note that this field is intended for use when a project is being maintained by someone other than the original author:
5671
/// it should be omitted if it is identical to `author`.
72+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
5773
pub maintainer: Option<String>,
5874
/// A string containing the maintainer’s e-mail address.
5975
/// It can contain a name and e-mail address in the legal forms for a RFC-822 `From:` header.
6076
///
6177
/// Note that this field is intended for use when a project is being maintained by someone other than the original author:
6278
/// it should be omitted if it is identical to `author_email`.
79+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
6380
pub maintainer_email: Option<String>,
6481
/// This field specifies the Python version(s) that the distribution is guaranteed to be compatible with.
82+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
6583
pub requires_python: Option<String>,
6684
/// Each entry contains a string describing some dependency in the system that the distribution is to be used.
85+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty"))]
6786
pub requires_external: Vec<String>,
6887
/// A string containing a browsable URL for the project and a label for it, separated by a comma.
88+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty"))]
6989
pub project_urls: Vec<String>,
7090
/// A string containing the name of an optional feature. Must be a valid Python identifier.
7191
/// May be used to make a dependency conditional on whether the optional feature has been requested.
7292
#[cfg_attr(feature = "serde", serde(skip_serializing))]
7393
pub provides_extras: Vec<String>,
7494
/// A string stating the markup syntax (if any) used in the distribution’s description,
7595
/// so that tools can intelligently render the description.
96+
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
7697
pub description_content_type: Option<String>,
7798
/// A string containing the name of another core metadata field.
7899
#[cfg_attr(feature = "serde", serde(skip_serializing))]

0 commit comments

Comments
 (0)