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

Tags for Endpoint API #2716

Open
987Nabil opened this issue Mar 7, 2024 · 3 comments
Open

Tags for Endpoint API #2716

987Nabil opened this issue Mar 7, 2024 · 3 comments
Labels
💎 Bounty enhancement New feature or request

Comments

@987Nabil
Copy link
Contributor

987Nabil commented Mar 7, 2024

Both smithy and OpenAPI offer tagging for endpoints.

The Endpoint API should have a concept of tagging endpoints. And they should be included in generated OpenAPI objects

@987Nabil 987Nabil added the enhancement New feature or request label Mar 7, 2024
@Petrosz007
Copy link

Petrosz007 commented May 23, 2024

This would be a nice feature to have.

As a workaround until this gets implemented, I added the tags manually to the generated OpenAPI spec. It's a bit hacky, but it works:

val openApiSpec: OpenAPI =
    def addTagsToOperation(operation: OpenAPI.Operation, tags: Seq[String]): OpenAPI.Operation =
      operation.copy(tags = operation.tags ++ tags)

    def addTagsToPathItem(pathItem: OpenAPI.PathItem, tags: Seq[String]): OpenAPI.PathItem =
      pathItem.copy(
        get = pathItem.get.map(addTagsToOperation(_, tags)),
        put = pathItem.put.map(addTagsToOperation(_, tags)),
        post = pathItem.post.map(addTagsToOperation(_, tags)),
        delete = pathItem.delete.map(addTagsToOperation(_, tags)),
        options = pathItem.options.map(addTagsToOperation(_, tags)),
        head = pathItem.head.map(addTagsToOperation(_, tags)),
        patch = pathItem.patch.map(addTagsToOperation(_, tags)),
        trace = pathItem.trace.map(addTagsToOperation(_, tags))
      )

    def addTagsToOpenApiSpec(openApiSpec: OpenAPI, tags: Seq[String]): OpenAPI =
      openApiSpec.copy(paths = openApiSpec.paths.map {
        case (path, pathItem) => (path, addTagsToPathItem(pathItem, tags))
      })

    val defaultEndpointSpec = addTagsToOpenApiSpec(OpenAPIGen.fromEndpoints(defaultEndpoints), Seq("default"))
    val adminSpec = addTagsToOpenApiSpec(OpenAPIGen.fromEndpoints(adminEndpoints), Seq("admin"))

    (defaultEndpointSpec ++ adminSpec)
      .title("Example service")
      .copy(tags = List(OpenAPI.Tag("default", None, None), OpenAPI.Tag("admin", None, None)))

@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $150

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $150 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2716 with your implementation plan
  2. Submit work: Create a pull request including /claim #2716 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants