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

Add flattenNamespaces transformer #572

Merged
merged 3 commits into from
Sep 29, 2020

Conversation

srchase
Copy link
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 force-pushed the namespace-flattening-transformer branch from 1ec1787 to fe2c03d Compare September 28, 2020 23:47
@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