Skip to content

Commit

Permalink
Allow setting a description on a derived CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Nov 30, 2023
1 parent 2fc37a2 commit 82d0f8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
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",
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 @@ struct KubeAttrs {
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 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
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 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
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
3 changes: 2 additions & 1 deletion kube-derive/tests/crd_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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

0 comments on commit 82d0f8f

Please sign in to comment.