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: Add documentation generation for operations. #578

Merged
merged 13 commits into from
Aug 15, 2023

Conversation

sichanyoo
Copy link
Contributor

@sichanyoo sichanyoo commented Aug 10, 2023

This PR adds in-line documentation generation for operations.

Issue #

awslabs/aws-sdk-swift#1033

Description of changes

Issue #1033 is resolved by adding documentation generation for errors thrown by operations.
When a service client protocol and service client are generated, for each and every operation, the code generator now generates in-line documentation for parameters, return type, and each and every error thrown by that operation (both errors common to that service, and errors bound to that operation), in the standard Swift in-line documentation format accepted by Swift DocC, like the following :

    /// This operation is cool.
    ///
    /// - Parameter TestStreamOpInput : [no documentation found]
    ///
    /// - Returns: `TestStreamOpOutputResponse` : [no documentation found]
    ///
    /// - Throws: One of the exceptions listed below __Possible Exceptions__.
    ///
    /// __Possible Exceptions:__
    /// - `SomeError` : You don't have permission.

Error name is extracted from name of the error structs from the corresponding operation shape.
Error cause is extracted from documentation on the error struct from the the corresponding service model file. If no documentation is provided for a given error struct in the original model file, "[no documentation found]" is appended as the error cause.

Below are example code-generated output, as well as what it looks like in Swift DocC:

Generated in-line documentation:

image

Quick-help view of in-line doc:

image

Documentation built with generated in-line doc:

image

This change was tested using tests in the smithy-swift project, as well as codegen tests in aws-sdk-swift project.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@jbelkins jbelkins left a comment

Choose a reason for hiding this comment

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

A couple things:

  • We should change the format to the following:
    /// - Throws: `BucketAlreadyExists`: The requested bucket name is not available.
    ///
    /// `BucketAlreadyOwnedByYou`: The bucket you tried to create already exists, and you own it.

Note the backticks around the exception name and the empty comment line between exceptions. This renders as follows in Xcode inline docs:

Screenshot 2023-08-11 at 3 32 45 PM
  • We should add Parameters and Returns to the inline function comment docs as well, for completeness. We can write a separate ticket for that feature though.

@sichanyoo sichanyoo changed the title fix: Add error info generation for operations. fix: Add documentation generation for operations. Aug 13, 2023
Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

Just a few more Kotlin syntax suggestions!

…ithy-swift into fix/add-error-info-generation
@sichanyoo sichanyoo force-pushed the fix/add-error-info-generation branch from 9cacbe3 to 958caf2 Compare August 14, 2023 21:29
Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

One more change to make use of Kotlin syntax and then I am good to approve!

Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

LGTM

@sichanyoo sichanyoo merged commit 0cc2193 into main Aug 15, 2023
7 checks passed
@sichanyoo sichanyoo deleted the fix/add-error-info-generation branch August 15, 2023 18:24
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.

3 participants