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

Document every public derived fn from kube-derive #919

Merged
merged 4 commits into from
May 25, 2022
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
8 changes: 4 additions & 4 deletions examples/crd_apply.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Generated types support documentation
#![deny(missing_docs)]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use tracing::*;
Expand All @@ -11,10 +13,7 @@ use kube::{
Client, CustomResource, CustomResourceExt,
};

// NB: This example uses server side apply and beta1 customresources
// Please test against Kubernetes 1.16.X!

// Own custom resource
/// Spec object for Foo
#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
#[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)]
#[kube(status = "FooStatus")]
Expand All @@ -25,6 +24,7 @@ pub struct FooSpec {
replicas: isize,
}

/// Status object for Foo
#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
pub struct FooStatus {
is_bad: bool,
Expand Down
4 changes: 4 additions & 0 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,14 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
#[serde(rename_all = "camelCase")]
#visibility struct #rootident {
#schemars_skip
/// Metadata on derived type
#visibility metadata: #k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
/// Spec on derived type
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, this is actually annoying... it means schemars will use this rather than what's in front of FooSpec:

    expected:
        "Spec on derived type"
    actual:
        "Our spec for Foo\n\nA struct with our chosen Kind will be created for us, using the following kube attrs"

via crd_derive tests. Probably need to try to re-use the docs for the type in here.

Copy link
Member Author

@clux clux May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have changed the dummy doc strings for a #[allow(missing_docs)] on the generated root struct instead...

this allows the schemas to pick up the right property, although it is slightly on the hackier side

#visibility spec: #ident,
#status_field
}
impl #rootident {
/// Spec based constructor for derived custom resource
pub fn new(name: &str, spec: #ident) -> Self {
Self {
metadata: #k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta {
Expand Down Expand Up @@ -567,6 +570,7 @@ fn process_status(
let ident = format_ident!("{}", status_name);
StatusInformation {
field: quote! {
/// Status on derived type
#[serde(skip_serializing_if = "Option::is_none")]
#visibility status: Option<#ident>,
},
Expand Down