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(open-api-gateway): support singular tags on operations #276

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

cogwirrel
Copy link
Member

This change adds support for tagging operations, for example:

  /hello:
    get:
      tags:
        - foo
      operationId: sayHello
      responses:
        '200':
          description: Ok

Previously, tagging would cause broken lambda handler wrappers etc to be generated since the CDK construct assumes a single OperationConfig, and tagging APIs caused multiple to be generated.

In this change, we always generate a single OperationConfig, but iterate over all apis to make sure all operations for all tags are included.

⚠️ Note that this change only supports tagging each operation with zero or one tags, multiple tags will cause duplicated code to be generated which will not build - support for multiple tags requires an upstream change in openapi-generator: OpenAPITools/openapi-generator#14568

We change the default configuration for the Smithy openapi projection to preserve tags since if they are specified in the model users would expect them to apply to the generated code/documentation etc. This means that operations can be tagged in the Smithy model like so:

@readonly
@http(method: "GET", uri: "/hello")
@tags(["foo"])
operation SayHello {
    input: SayHelloInput
    output: SayHelloOutput
    errors: [ApiError]
}

This behaviour can be overridden in the project's smithyBuildOptions, ie:

const api = new SmithyApiGatewayTsProject({
  ...
  smithyBuildOptions: {
    projections: {
      openapi: {
        plugins: {
          openapi: {
            tags: false,
          },
        },
      },
    },
  },
});

re #269

@nx-cloud
Copy link

nx-cloud bot commented Feb 2, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 340ab4c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

This change adds support for tagging operations. Previously, tagging would cause broken lambda
handler wrappers etc to be generated since the CDK construct assumes a single OperationConfig, and
tagging APIs caused multiple to be generated. In this change, we always generate a single
OperationConfig, but iterate over all apis to  make sure all operations for all tags are included.
Note that this change only supports tagging each operation with zero or one tags, multiple tags will
cause duplicated code to be generated which will not build - support for multiple tags requires an
upstream change in openapi-generator.

re #269
Copy link
Contributor

@JeremyJonas JeremyJonas left a comment

Choose a reason for hiding this comment

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

Looks awesome, great work adding the validation and actionable error handling :D

@cogwirrel cogwirrel merged commit 8be0798 into mainline Feb 3, 2023
@cogwirrel cogwirrel deleted the feat/tags branch February 3, 2023 04:45
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