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

Allow setting a description on a derived CRD #1359

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/crd_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize};
plural = "fooz",
root = "FooCrd",
namespaced,
description = "Custom resource representing a Foo",
clux marked this conversation as resolved.
Show resolved Hide resolved
status = "FooStatus",
derive = "PartialEq",
derive = "Default",
Expand Down Expand Up @@ -119,7 +120,7 @@ fn verify_crd() {
],
"schema": {
"openAPIV3Schema": {
"description": "Auto-generated derived type for MyFoo via `CustomResource`",
"description": "Custom resource representing a Foo",
"properties": {
"spec": {
"description": "Our spec for Foo\n\nA struct with our chosen Kind will be created for us, using the following kube attrs",
Expand Down
5 changes: 4 additions & 1 deletion kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
group: String,
version: String,
kind: String,
description: Option<String>,
#[darling(rename = "root")]
kind_struct: Option<String>,
/// lowercase plural of kind (inferred if omitted)
Expand Down Expand Up @@ -145,6 +146,7 @@
kind,
kind_struct,
version,
description,

Check warning on line 149 in kube-derive/src/custom_resource.rs

View check run for this annotation

Codecov / codecov/patch

kube-derive/src/custom_resource.rs#L149

Added line #L149 was not covered by tests
namespaced,
derives,
schema: schema_mode,
Expand Down Expand Up @@ -239,7 +241,8 @@
derive_paths.push(syn::parse_quote! { #schemars::JsonSchema });
}

let docstr = format!(" Auto-generated derived type for {ident} via `CustomResource`");
let docstr = description
.unwrap_or_else(|| format!(" Auto-generated derived type for {ident} via `CustomResource`"));

Check warning on line 245 in kube-derive/src/custom_resource.rs

View check run for this annotation

Codecov / codecov/patch

kube-derive/src/custom_resource.rs#L244-L245

Added lines #L244 - L245 were not covered by tests
let quoted_serde = Literal::string(&serde.to_token_stream().to_string());
let root_obj = quote! {
#[doc = #docstr]
Expand Down
7 changes: 4 additions & 3 deletions kube-derive/tests/crd_schema_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![recursion_limit = "256"]

use assert_json_diff::assert_json_eq;
use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use kube_derive::CustomResource;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -15,6 +15,7 @@ use std::collections::HashMap;
kind = "Foo",
category = "clux",
namespaced,
description = "Custom resource representing a Foo",
derive = "PartialEq",
shortname = "fo",
shortname = "f"
Expand Down Expand Up @@ -132,7 +133,7 @@ fn test_serialized_matches_expected() {
nullable: None,
nullable_skipped_with_default: None,
nullable_with_default: None,
timestamp: DateTime::from_utc(NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), Utc),
timestamp: TimeZone::from_utc_datetime(&Utc, &NaiveDateTime::from_timestamp_opt(0, 0).unwrap()),
clux marked this conversation as resolved.
Show resolved Hide resolved
complex_enum: ComplexEnum::VariantOne { int: 23 },
untagged_enum_person: UntaggedEnumPerson::GenderAndAge(GenderAndAge {
age: 42,
Expand Down Expand Up @@ -195,7 +196,7 @@ fn test_crd_schema_matches_expected() {
"additionalPrinterColumns": [],
"schema": {
"openAPIV3Schema": {
"description": "Auto-generated derived type for FooSpec via `CustomResource`",
"description": "Custom resource representing a Foo",
"properties": {
"spec": {
"properties": {
Expand Down
Loading