Skip to content

V2: For deprecated elements, generate a @deprecated tag on descriptors#818

Merged
timostamm merged 2 commits intov2from
tstamm/generate-deprecated-tag-on-desc
Apr 26, 2024
Merged

V2: For deprecated elements, generate a @deprecated tag on descriptors#818
timostamm merged 2 commits intov2from
tstamm/generate-deprecated-tag-on-desc

Conversation

@timostamm
Copy link
Member

Following up on #814 (comment), this adds a @deprecated tag to generated descriptors. For example:

syntax="proto3";

message Example {
  option deprecated = true;
}

Already generates:

/**
 * @generated from message Example
 * @deprecated
 */
export type DeprecatedMessage = Message<"Example"> & {};

With this change, the descriptor is also marked deprecated:

/**
 * Describes the message Example.
 * Use `create(ExampleDesc)` to create a new message.
 * @deprecated
 */
export const ExampleDesc: GenDescMessage<Example> = /*@__PURE__*/
  messageDesc(fileDesc_example, 0);

Previously, we generated line comments for descriptors, but since the @deprecated tag is ignored in line comments, we're switching to block comments.

This also improves implicit deprecation: If a message, extension, or enum is nested in a deprecated message, it is also generated with a @deprecated tag. Similar for files that are marked deprecated.

@@ -233,6 +232,36 @@ function generateDts(schema: Schema) {
}
}

function generateDescDoc(
Copy link
Member Author

Choose a reason for hiding this comment

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

Generates the block comments for descriptors.

Comment on lines +79 to +80
deprecated =
desc.deprecated || parentTypes(desc).some((d) => d.deprecated);
Copy link
Member Author

Choose a reason for hiding this comment

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

Improves existing behavior for implicit deprecation.

@timostamm timostamm requested a review from srikrsna-buf April 26, 2024 08:56
@timostamm timostamm marked this pull request as ready for review April 26, 2024 09:53
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