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

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

Merged
merged 2 commits into from
Apr 26, 2024

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 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