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

feat(146): add oas-specific guidance on mutually exclusive fields #274

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GeoffreyXue
Copy link

🍱 Types of changes

What types of changes does your code introduce to AEP? Put an x in the boxes
that apply

  • Enhancement
  • New proposal
  • Migrated from google.aip.dev
  • Chore / Quick Fix

📋 Your checklist for this pull request

Please review the AEP Style and Guidance for
contributing to this repository.

General

💝 Thank you!

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Thank you, nice first round!

The content on union types looks good as is - but we should leave the purpose of the overall AEP alone (generic fields, not shrink that down to union types specifically).

@@ -1,28 +1,29 @@
# Generic fields
# Mutually exclusive fields
Copy link
Member

Choose a reason for hiding this comment

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

note: generic fields covers much more than mutually exclusive fields. It refers to structs and the Any type at minimum, and we may want to cover more things like sets.

I'd suggest creating a sub-section for mutually exclusive fields, or perhaps splitting it into it's own AEP (150? since aip.dev/149 exists).

However, occasionally it is appropriate to have a generic or polymorphic field
of some kind that can conform to multiple schemata, or even be entirely
free-form.
However, occasionally it is appropriate to have a mutually exclusive or
Copy link
Member

Choose a reason for hiding this comment

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

I won't leave a comment everywhere, but I think it'll be important to revert the nomenclature in this PR to continue to refer to the larger design area of generic fields.

the field needs to be; in general, APIs **should** attempt to introduce the
"least generic" approach that is able to satisfy the use case.
While mutually exclusive fields are generally rare, a API **may** introduce
mutually exclusive field where necessary. There are several approaches to this
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mutually exclusive field where necessary. There are several approaches to this
mutually exclusive fields where necessary. There are several approaches,

Comment on lines +19 to +22
For example, an API **should not** use a completely mutually exclusive field
(such as `google.protobuf.Struct` in protobuf APIs) when the value of the field
must correspond to one of a known number of schemas. Instead, the API
**should** use a [`oneof`](./oneof) to represent the known schemas.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think most users would use a protobuf struct to define a mutually exclusive set of fields - perhaps it's better to start with OneOf?

We can always call out bad patterns below, in a new section like Rationale: https://aep.dev/8/#document-structure

Comment on lines +97 to +99
`oneof` in protobuf APIs. Due to the schema's complexity, validation for this
schema **should** be handled server-side, and it is fine to not document the
schema explicitly.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`oneof` in protobuf APIs. Due to the schema's complexity, validation for this
schema **should** be handled server-side, and it is fine to not document the
schema explicitly.
`oneof` in protobuf APIs. Due to the schema's complexity, validation for this
schema **should** be handled server-side, and OpenAPI schemas do not need to document the
schema explicitly.

"it is fine" feels a bit colloquial here - I'd say something along the lines of "do not need" or "are not required".


#### Oneof
#### Type Union
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#### Type Union
#### Union Type

I think most descriptions of types describe this as "Union Types":

https://docs.python.org/3/library/typing.html#typing.Union
https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#use-union-types

Copy link
Member

Choose a reason for hiding this comment

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

Also I don't think protobuf oneofs are union types really - they are a set of fields that are mutually exclusive.

A union type is "field foo can be X or Y" - in this case it's "field foo of type X, or bar of type Y can be set". So really I'd say "mutually exclusive fields" is a better term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants