disneystreaming / smithy-translate

Other
55 stars 12 forks source link

openapi tags should be translated to smithy #217

Closed MoeQuadrat closed 10 months ago

MoeQuadrat commented 10 months ago

Overview: Enhance the functionality of smithy-translate by introducing a CLI-Flag that allows the splitting of an OpenAPI file into multiple Smithy services based on their tags. I think i've observed this functionality when using OpenAPITools/openapi-generator.

Proposed Solution: The feature would involve parsing the OpenAPI file and organizing its components into separate Smithy services based on the specified tags.

Use Case: Users frequently leverage OpenAPI tags to categorize and organize endpoints logically. By extending this concept to Smithy, we enhance the adaptability and user-friendliness of the translation process. This would it make easier to handle Conflicting URLs by giving them different tags in the openapi and thus splitting them into different services.

Example:

# OpenAPI file with tags
openapi: 3.0.0
info:
  title: My API
  version: 1.0.0
paths:
  /resource1:
    get:
      tags:
        - service1
      # ... endpoint details
  /resource2:
    post:
      tags:
        - service2
      # ... endpoint details

The translation process could result in two separate Smithy services, service1 and service2, each containing the relevant endpoints.

Is something like this doable or do you have any suggestions on how to achieve this without creating a separate OpenAPI for each service?

Baccata commented 10 months ago

This is going to remain out of the scope of what smithy-translate aims at achieving.

The smithy-model library contains all the necessary constructs and utilities you need to programatically post-process a smithy model. I suggest you familiarise yourself with it, as it's a very empowering library that'll let you solve a lot of problems.

If you use Smithy4s (which it seems you are), we even have a guide on how to wire these kinds of transformations : https://disneystreaming.github.io/smithy4s/docs/guides/model-preprocessing

Now that being said : what we could do is translate the tags from openapi to retain the information in the smithy model. A projection transformer written in userland could then leverage this information in order to split a service definition into smaller ones.

MoeQuadrat commented 10 months ago

Thank you for showing me smithy-model and how to implement it through the model preprocessing in smithy4s. As this might be useful for other cases aswell.

If retaining the informations in the smithy model works for you i would be fine with that approach.