Skip to content

Add basic support for server serde in http binding protocols #270

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

Merged
merged 38 commits into from
Mar 1, 2021

Conversation

JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Feb 11, 2021

Description of changes:

This adds basic support for server serde in http binding protocols, which is to say it adds support for serializing responses and deserializing requests. Currently there are a few major points missing:

  • No deserialization support for members bound to the path
  • No deserialization support for members bound to the query string
  • No deserialization support for members bound to the endpoint
  • No protocol tests (this will need an actual interface being generated first)

@adamthom-amzn
@gosar

This adds two new options to TypeScriptSettings which is what the smithy-build.json config is mapped to:

  • generateClient - boolean - default true - triggers client generation
  • generateServerSdk - boolean - default false - triggers ssdk generation

So to do server only you might have something like:

{
    "version" : "1.0",
    "outputDirectory" : "build/output",
    "projections" : {
        "ts-server" : {
            "plugins": {
                "typescript-codegen" : {
                    "generateClient": false,
                    "generateServerSdk": true,
                    "package" : "@bootleg-service/server-bootleg",
                    "packageVersion": "1.0.0-rc.1"
                }
            }
        }
    }
}

This also adds in deser support for the various uri bindings. Here's an example generated deser function:

export const deserializeAws_restJson1GetVenueCommandRequest = async(
  output: __HttpRequest,
  context: __SerdeContext
): Promise<GetVenueCommandInput> => {
  const contents: GetVenueCommandInput = {
    city: undefined,
    hostParam: undefined,
    inputHeader: undefined,
    inputSpecific: undefined,
    name: undefined,
    queryParam: undefined,
  };
  const query = output.endpoint.query
  if (query !== undefined && query !== null) {
    if (query['queryP'] !== undefined) {
      contents.queryParam = query['queryP'];
    }
  }
  const pathRegex = new RegExp("/venues/(?<city>.*)/(?<name>.*)/");
  const parsedPath: RegExpMatchArray = output.endpoint.path.match(pathRegex);
  if (parsedPath.groups !== undefined) {
    contents.name = parsedPath.groups.name;
    contents.city = parsedPath.groups.city;
  }
  const hostRegex = new RegExp("^(?<hostParam>.*)\\.bar\\.baz-bam\\.");
  const parsedHost: RegExpMatchArray = output.endpoint.path.match(pathRegex);
  if (parsedHost.groups !== undefined) {
    contents.hostParam = parsedHost.groups.hostParam;
  }
  if (output.headers["x-amz-input-header"] !== undefined) {
    contents.inputHeader = output.headers['x-amz-input-header'];
  }
  const data: any = (await parseBody(output.body, context));
  if (data.hostParam !== undefined && data.hostParam !== null) {
    contents.hostParam = data.hostParam;
  }
  if (data.inputSpecific !== undefined && data.inputSpecific !== null) {
    contents.inputSpecific = data.inputSpecific;
  }
  return Promise.resolve(contents);
}

Also note that this pr is merging into the ssdk branch and not main

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

kstich and others added 3 commits February 19, 2021 09:55
This commit updates the request body comparison generation for
protocol tests to safely handle having multiple bodyMediaType
settings in the same suite of protocol tests. It also updates the
methodology for comparing blob bodies to not be a special case in
the generator, as they can have alternate media types.
kstich and others added 21 commits February 23, 2021 10:27
This adds the ability to disable generating clients. This is useful if
the customer only wants to generate types for shapes, and will enable
generating a server only.
This adds methods to the ProtocolGenerator interface to enable
generating serializers for responses and deserializers for requests.
Making these separate methods allows the CodegenVisitor to
make sure everything that needs to get called gets called.
This adds support for error serialization. A new interface was needed
to write error headers specifically. This also fixes an issue where
the response serializers were looking at the wrong http bindings.
HttpRequest implements Endpoint, it does not contain one as a member.
I don't think response serialization will need to know about the endpoint, but
I'm keeping the serializer context around in case it is useful in the future.
JordonPhillips and others added 12 commits February 24, 2021 15:22
These might not actually work as-is, this will need to be verified. In
the meantime it at leasts unblocks generation.
The serde functions were not being exported, and their names were aggressively
protocol-specific. This re-exports the protocol-specific serde module under
its own name, so that the functions themselves do not have to have the protocol
name.
This adds an empty enpoint to response serialization. It should never
be used, hopefully. It may be better to replace this with as assertions
later on.
This updates the path parsing regex to differentiate between greedy
and non-greedy labels as well as to disallow empty label segments.
@JordonPhillips JordonPhillips merged commit 289385f into smithy-lang:ssdk Mar 1, 2021
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.

4 participants