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

[fix] [doc] fix multiple apis in the automatically generated documentation use the same anchor point #19193

Merged

Conversation

poorbarcode
Copy link
Contributor

@poorbarcode poorbarcode commented Jan 11, 2023

Motivation

Now that site admin-rest-api is automatically generated through swagger, each API in the site has its own link that we can walk through, the generated rule of API-link is https://pulsar.apache.org/admin-rest-api/#operation/{operationId}, we call the suffix #operation/{operationId} of link anchor.

Since the {operationId}'s default value is the method name of the endpoint class, and there has the same method name in the multi endpoint-classes, such as Namespaces.setDispatchRate and PersistentTopics.setDispatchRate, so these both APIs will generate the same link: https://pulsar.apache.org/admin-rest-api/#operation/setDispatchRate.

Modifications

In the update to version 3.1.8 of swagger-maven-plugin, there are another ways to set operationId: The Operation Id Format. see https://github.com/kongchen/swagger-maven-plugin/blob/e4cf3af6ed4a4987b2269a05b7037549bc4a5511/src/main/java/com/github/kongchen/swagger/docgen/reader/AbstractReader.java#L535-L540. So we can generate operationId using the specified rule {className}_{methodName}.

截屏2023-03-08 16 04 47

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Jan 11, 2023
Copy link
Member

@dave2wave dave2wave left a comment

Choose a reason for hiding this comment

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

These look like actual API changes. Please explain.

@poorbarcode poorbarcode changed the title [fix] [doc] [fix] [doc] fix multiple apis in the automatically generated documentation use the same anchor point [fix] [doc] fix multiple apis in the automatically generated documentation use the same anchor point Jan 11, 2023
@poorbarcode poorbarcode force-pushed the doc/fix_admin_api_for_swagger branch from 1a991e1 to baf7e79 Compare January 11, 2023 18:02
@poorbarcode
Copy link
Contributor Author

Hi @dave2wave

These look like actual API changes. Please explain.

Already changed the plain to only modify Swagger annotations. please take a look again

@poorbarcode poorbarcode requested a review from dave2wave January 12, 2023 02:00
@mattisonchao
Copy link
Member

mattisonchao commented Jan 12, 2023

@tisonkun What do you think about this PR? I am unfamiliar with swagger, but I know you have recently worked on this part. please help to review it, thanks!

@tisonkun
Copy link
Member

tisonkun commented Jan 12, 2023

I agree that it's not a breaking change for end-users but only affects the doc experience.

Some related works previous:

And I agree that a nickname alias can be a better solution. I can approve this move but I appreciate seeing the discussion on the mailing list continue for a while (days or after the lunar new year holiday).

cc @tuteng @shoothzj

@shoothzj
Copy link
Member

Now we aggregate rest api into a single file. I think it might be better to split them. This is also good for us to generate other language admin clients. I am trying to work on it.

@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Feb 12, 2023
@poorbarcode poorbarcode force-pushed the doc/fix_admin_api_for_swagger branch from 413fb63 to e414067 Compare March 8, 2023 07:56
@poorbarcode
Copy link
Contributor Author

@tisonkun @tuteng @heesung-sn

Please take a look, thanks

@poorbarcode poorbarcode added type/bug The PR fixed a bug or issue reported a bug ready-to-test and removed Stale labels Mar 8, 2023
@poorbarcode poorbarcode self-assigned this Mar 8, 2023
@poorbarcode
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@poorbarcode poorbarcode added this to the 3.0.0 milestone Mar 8, 2023
@poorbarcode
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@tisonkun tisonkun self-requested a review March 8, 2023 11:04
@poorbarcode
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@codecov-commenter
Copy link

Codecov Report

Merging #19193 (e414067) into master (af1360f) will increase coverage by 35.91%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #19193       +/-   ##
=============================================
+ Coverage     26.40%   62.31%   +35.91%     
+ Complexity     6427     3503     -2924     
=============================================
  Files          1597     1848      +251     
  Lines        123682   135866    +12184     
  Branches      13511    14952     +1441     
=============================================
+ Hits          32658    84665    +52007     
+ Misses        86336    43466    -42870     
- Partials       4688     7735     +3047     
Flag Coverage Δ
inttests 24.53% <ø> (-0.05%) ⬇️
systests 25.28% <ø> (?)
unittests 59.54% <ø> (+42.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...in/java/org/apache/pulsar/common/api/AuthData.java 71.42% <0.00%> (ø)
.../apache/pulsar/broker/namespace/LookupOptions.java 87.50% <0.00%> (ø)
.../apache/pulsar/common/naming/SystemTopicNames.java 55.55% <0.00%> (ø)
...apache/pulsar/common/util/SafeCollectionUtils.java 0.00% <0.00%> (ø)
...pache/pulsar/common/configuration/BindAddress.java 22.22% <0.00%> (ø)
...r/client/admin/internal/data/AuthPoliciesImpl.java 65.21% <0.00%> (ø)
...sar/common/policies/data/impl/BundlesDataImpl.java 92.30% <0.00%> (ø)
...ar/common/policies/data/InactiveTopicPolicies.java 83.33% <0.00%> (ø)
...r/authentication/AuthenticationProviderAthenz.java 69.64% <0.00%> (ø)
...r/io/hdfs3/sink/text/HdfsAbstractTextFileSink.java 80.00% <0.00%> (ø)
... and 1354 more

<configuration>
<apiSources>
<apiSource>
<springmvc>false</springmvc>
<operationIdFormat>{{className}}_{{methodName}}</operationIdFormat>
<outputFormats>json</outputFormats>
Copy link
Contributor

@heesung-sn heesung-sn Mar 8, 2023

Choose a reason for hiding this comment

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

nit: Is this json outputFormats necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: Is this json outputFormats necessary?

It should be optional, but maven or swagger had issues, and I had null Pointers when testing locally. I tried troubleshooting the issue yesterday but couldn't get the root cause quickly, so I thought adding this configuration would avoid unnecessary trouble.

<configuration>
<apiSources>
<apiSource>
<springmvc>false</springmvc>
<operationIdFormat>{{className}}_{{methodName}}</operationIdFormat>
Copy link
Contributor

@heesung-sn heesung-sn Mar 8, 2023

Choose a reason for hiding this comment

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

nit: I think {className}_{methodName} is reasonable as the unique operationIdFormat.

LGTM if we don't have duplicated apiSources from the same class and methodName.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After keeping only the latest version of admin API(such as v2, v3), {className}_{methodName} will not conflict. If we open multiple versions of API in the future, we need to change the rule to {package_name}_{className}_{methodName}

@tisonkun tisonkun added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages and removed type/bug The PR fixed a bug or issue reported a bug labels Mar 9, 2023
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Please take a look at the OWASP failure. Although it seems unrelated to this patch, we should fix it later.

@tisonkun tisonkun requested review from shoothzj and tuteng March 9, 2023 02:46
@poorbarcode
Copy link
Contributor Author

Hi @tisonkun

Please take a look at the OWASP failure. Although it seems unrelated to this patch, we should fix it later.

I have pushed a #19764 to fix it, so I am merging the current PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. ready-to-test type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants