Skip to content

Add flattenNamespaces transformer#572

Merged
srchase merged 3 commits intosmithy-lang:masterfrom
srchase:namespace-flattening-transformer
Sep 29, 2020
Merged

Add flattenNamespaces transformer#572
srchase merged 3 commits intosmithy-lang:masterfrom
srchase:namespace-flattening-transformer

Conversation

@srchase
Copy link
Copy Markdown
Contributor

@srchase srchase commented Sep 17, 2020

Adds flattenNamespaces transformer that flattens the namespaces of shapes connected to a specified service in a model into a target namespace. Shapes that are not connected to the service will not be flattened, unless they have been tagged with a tag that has been included in the includeTagged configuration list. Tagged shapes that conflict with an existing shape within the service closure will not be flattened.

Example configuration:

{
    "version": "1.0",
    "projections": {
        "exampleProjection": {
            "transforms": [
                {
                    "name": "flattenNamespaces",
                    "args": {
                        "namespace": "ns.foo",
                        "service": "ns.foo#MyService,
                        "includeTagged": ["include", "conflict"],
                    }
                }
            ]
        }
    }
}

Input model:

{
  "smithy": "1.0",
  "shapes": {
    "ns.foo#MyService": {
      "type": "service",
      "version": "2017-01-19",
      "operations": [
        {
          "target": "ns.bar#MyOperation"
        }
      ]
    },
    "ns.bar#MyOperation": {
      "type": "operation",
      "output": {
        "target": "ns.baz#MyOperationOutput"
      }
    },
    "ns.baz#MyOperationOutput": {
      "type": "structure",
      "members": {
        "foo": {
          "target": "smithy.api#String"
        }
      }
    },
    "ns.corge#UnconnectedFromService": {
      "type": "string",
      "traits": {
        "smithy.api#tags": ["include"]
      }
    },
    "ns.corge#MyOperationOutput": {
      "type": "string",
      "traits": {
        "smithy.api#tags": ["conflict"]
      }
    },
    "ns.corge#AnotherString": {
      "type": "string",
      "traits": {
        "smithy.api#tags": ["ignored"]
      }
    }
  }
}

Transformed model:

{
  "smithy": "1.0",
  "shapes": {
    "ns.foo#MyService": {
      "type": "service",
      "version": "2017-01-19",
      "operations": [
        {
          "target": "ns.foo#MyOperation"
        }
      ]
    },
    "ns.foo#MyOperation": {
      "type": "operation",
      "output": {
        "target": "ns.foo#MyOperationOutput"
      }
    },
    "ns.foo#MyOperationOutput": {
      "type": "structure",
      "members": {
        "foo": {
          "target": "smithy.api#String"
        }
      }
    },
    "ns.foo#UnconnectedFromService": {
      "traits": {
        "smithy.api#tags": ["include"]
      }
    }
  }
}

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

@srchase srchase requested a review from kstich September 18, 2020 15:52
@srchase srchase force-pushed the namespace-flattening-transformer branch from 736c00e to 8d32b18 Compare September 22, 2020 16:20
@srchase srchase requested a review from mtdowling September 23, 2020 20:22
@srchase srchase requested a review from mtdowling September 25, 2020 20:04
@srchase srchase force-pushed the namespace-flattening-transformer branch from 1ec1787 to fe2c03d Compare September 28, 2020 23:47
@srchase srchase requested a review from mtdowling September 29, 2020 15:27
@srchase srchase merged commit 2b4e4c9 into smithy-lang:master Sep 29, 2020
@srchase srchase deleted the namespace-flattening-transformer branch September 29, 2020 17:59
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