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

Add notes to explain how API fields should be documented in conventions #1069

Merged
merged 4 commits into from
Apr 4, 2022

Conversation

JoelSpeed
Copy link
Contributor

@JoelSpeed JoelSpeed commented Mar 22, 2022

As an API reviewer, I would like to see thorough documentation added to new API fields so that I can understand the mechanics of the changes we are adding to our API and so that customers can understand how they can and can't use the new fields.

To encourage better documentation on ur APIs, I think we should add some notes to the conventions prompting users with a number of questions to think about when writing their godoc and some examples of how this might look in practice.

This is a first draft of this to gather initial feedback:

  • Is this the right location for this kind of content?
  • What other questions should users be asked when writing their godoc
  • Do we have any other recommendations about godoc that aren't already noted

ToDo:

  • Add more examples of where the godoc is used
  • Provide example of godoc output for examples to help authors understand what the user might see
  • Clarify any language guidance we have for writing these godoc (Eg should we follow product doc styling)
  • Confirm we want to split out an official API conventions/style guide

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 22, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 22, 2022

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@mdbooth
Copy link
Contributor

mdbooth commented Mar 22, 2022

Couple of drive-by thoughts:

  • Is there a generally-accepted godoc style bible? If so, is it worth linking to it and defining OpenShift policy in relation to it?
  • How would I annotate a deprecated field?

Copy link
Contributor

@dhellmann dhellmann left a comment

Choose a reason for hiding this comment

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

We do have some other similar advice in the conventions file, and this addition fits thematically. We also have the dev-guide directory, and so you might consider adding a separate file with API advice there if there is going to be a lot of information to document over time.

CONVENTIONS.md Outdated
// + This can be used to add notes for developers that aren't intended for end users.
type Example struct {
// Type allows the user to determine how to interpret the example given.
// It must be set to one of the following values; Documentation, Convention, or Mixed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to type out the values for an enum if they're also included in the kubebuilder validation directive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you don't add them to the godoc, then they won't appear in oc explain as it doesn't print out the enum values. So i think the convention has been to include them in the documentation explicitly as well as having the enum for validation purposes

@deads2k
Copy link
Contributor

deads2k commented Mar 22, 2022

Explaining this makes sense. Since so much of the openshift API is now configuration API describing how our product can be configured, detailed documentation that will automatically appear in everything consuming openAPI is extremely valuable and serves as a good starting point for writing online documentation.

@JoelSpeed
Copy link
Contributor Author

Is there a generally-accepted godoc style bible? If so, is it worth linking to it and defining OpenShift policy in relation to it?

Good question, not that I'm aware of. I'm happy to expand on some of the style guidelines if we want to. I'll check in with docs as well if they have anything. One thing I was thinking is that, for example, a MachineSet is normally written as a machine set in docs for readability reasons, do we want to enforce/recommend that here too? I'm not sure, but maybe we can iterate on that

How would I annotate a deprecated field?

Not sure I know this one, I think a // DEPRECATED: <context> comment line would suffice, but perhaps @deads2k can confirm

We do have some other similar advice in the conventions file, and this addition fits thematically. We also have the dev-guide directory, and so you might consider adding a separate file with API advice there if there is going to be a lot of information to document over time.

Yeah I noticed the other notes about API conventions in here and how we differ from upstream Kube conventions, I think if we are going to put this in the dev-guide section we should move the rest of the API conventions from this doc as well.
I'm happy to do that, but would want a sign off on that from @deads2k as API conventions are his area of ownership much more than they are mine

Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

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

This looks excellent. I'm glad we're getting more of these conventions formally documented.

Comment on lines +58 to +64
// + ---
// + Note that this comment line will not end up in the generated API schema as it is
// + preceded by a `+`. The `---` also prevents anything after it from being added to
// + the swagger docs.
// + This can be used to add notes for developers that aren't intended for end users.
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL!

// + This can be used to add notes for developers that aren't intended for end users.
type Example struct {
// Type allows the user to determine how to interpret the example given.
// It must be set to one of the following values; Documentation, Convention, or Mixed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// It must be set to one of the following values; Documentation, Convention, or Mixed.
// It must be set to one of the following values: Documentation, Convention, or Mixed.

type Example struct {
// Type allows the user to determine how to interpret the example given.
// It must be set to one of the following values; Documentation, Convention, or Mixed.
// +kubebuilder:validation:Enum:Documentation;Convention;Mixed
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// +kubebuilder:validation:Enum:Documentation;Convention;Mixed
// +kubebuilder:validation:Enum=Documentation;Convention;Mixed

dev-guide/api-conventions.md Outdated Show resolved Hide resolved
// Documentation allows the user to define documentation for the example.
// When this value is provided, the `type` must be set to either `Documentation` or `Mixed`.
// The content of the documentation is free form text but must be no longer than 512 characters.
// +kubebuilder:validation:MaxLength:=512
Copy link
Contributor

Choose a reason for hiding this comment

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

I've noticed that we sometimes use := and sometimes use =, and I haven't been able to find any documentation on the distinction. As far as I can tell, they are interchangeable in practice, and if that is true, I would prefer we settle on a preferred style. We can leave that for a later PR if it requires debate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have erred towards := because that's how it's represented in the kubebuilder documentation. I don't think there's any different from a usage perspective though

dev-guide/api-conventions.md Outdated Show resolved Hide resolved
Comment on lines 90 to 91
// + Note: In this example, the `platform` refers to OpenShift Container Platform and not
// + a cloud provider (commonly referred to among engineers as platforms).
Copy link
Contributor

@Miciah Miciah Mar 24, 2022

Choose a reason for hiding this comment

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

I'm not sure this is a good example use of +. The clarification could be useful to end users reading the oc explain output or Swagger documentation, and really, the text could be written to avoid the ambiguous use of "platform" in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps I should pull this out of the Godoc in the example. The wording here is something that has been recommended to me across several API reviews so I thought it was standard wording.

Perhaps we can come up with a different wording that has less ambiguity?

CC @deads2k in case you have an opinion on this wording?

@JoelSpeed JoelSpeed changed the title [WIP] Add notes to explain how API fields should be documented in conventions Add notes to explain how API fields should be documented in conventions Mar 24, 2022
@JoelSpeed JoelSpeed marked this pull request as ready for review March 24, 2022 15:08
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 24, 2022
@JoelSpeed
Copy link
Contributor Author

Given the feedback so far, it seems like we have a good basis here to build upon. To avoid this becoming a complete documentation through a single PR, I'm going to defer the question about marking fields deprecated for now as that seems like it deserves its own section. I will follow up to add a deprecated fields section once I've done a bit more research on that

@openshift-ci openshift-ci bot requested review from hardys and soltysh March 24, 2022 15:10
@Miciah
Copy link
Contributor

Miciah commented Mar 28, 2022

LGTM.

@dhellmann
Copy link
Contributor

@JoelSpeed there are a couple of suggestions on the review. Did you want to resolve those here, or iterate?

/assign @dhellmann

@JoelSpeed
Copy link
Contributor Author

@dhellmann Thanks for the prompt, missed those. I think for now let's merge this and iterate on the outstanding points. I'll try to get some opinions on the wording around "platform" and follow up to clarify that and the deprecation point

@dhellmann
Copy link
Contributor

@JoelSpeed that works for me

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 31, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dhellmann

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 31, 2022

type <string>
Type allows the user to determine how to interpret the example given. It must be set to one of the following
values; Documentation, Convention, or Mixed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
values; Documentation, Convention, or Mixed.
values: Documentation, Convention, or Mixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, missed that while updating the other location, have updated now

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 4, 2022

@JoelSpeed: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@Miciah
Copy link
Contributor

Miciah commented Apr 4, 2022

Thanks!
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 4, 2022
@openshift-merge-robot openshift-merge-robot merged commit e3cf697 into openshift:master Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants