Skip to content

Commit

Permalink
docs(type-safe-api): minor improvements to readme files (#577)
Browse files Browse the repository at this point in the history
Update links in model readme files, and omit generating a handler readme when no handler languages
specified
  • Loading branch information
cogwirrel authored Sep 20, 2023
1 parent be0ec24 commit 33e2490
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 1,301 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,5 @@
# Type Safe API

This project contains an API built with [Type Safe API](https://github.com/aws/aws-pdk/tree/mainline/packages/type-safe-api).
This project contains an API built with Type Safe API.

## Project Structure

This project consists of the following components:

### Model

The `model` folder contains the API model, which defines the API operations and their inputs and outputs. For more details, please refer to the [model project README](./model/README.md).

### Runtime

The `runtime` folder contains subprojects for each of the selected runtime languages. These projects include types as well as client and server code, generated from the model.

### Infrastructure

The `infrastructure` folder contains a subproject for the selected infrastructure language. This includes a CDK construct which defines the API Gateway resources to deploy the API defined by the model.

### Documentation

The `documentation` folder contains documentation generated from the model, for each of the selected documentation formats.

## Adding Operations

This section describes the steps required to add a new operation to your API.

### Define the Operation

The API operations are defined by the API model. Please see the [model project README](./model/README.md) for instructions for the specific model language used.

### Build the Project

Next, build the project using the project's build command. This will vary depending on the overall project setup, and is likely documented in the top level README.

The build will trigger regeneration of the `runtime`, `infrastructure` and `documentation` projects, which will include your new operation.

### Add an Integration

If you are using the CDK construct defined in the `infrastructure` folder, you likely encountered a type error in your CDK project, since the construct requires an integration for every operation defined in the model.

Please refer to the [Type Safe API documentation](https://github.com/aws/aws-pdk/tree/mainline/packages/type-safe-api) for details about how to add integrations in your chosen infrastructure language.

### Implement the Operation

Finally, you'll need to implement the operation. If using AWS Lambda for your API integrations, you can make use of the generated lambda handler wrappers from one of the `runtime` projects. These wrappers provide typed interfaces for operations, providing auto-complete in your IDE for inputs, and ensuring you return the output (or one of the errors) defined in the model.

For more details about using the handler wrappers in the various supported languages, please refer to the [Type Safe API documentation](https://github.com/aws/aws-pdk/tree/mainline/packages/type-safe-api).
Please refer to the [Type Safe API Documentation](https://aws.github.io/aws-pdk/developer_guides/type-safe-api/index.html) for details about the project structure and how to add operations.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The entrypoint for the API is `src/main/openapi/main.yaml`. You can add more yam

Resources:
- [OpenAPI v3 Documentation](https://swagger.io/specification/v3/)
- [Type Safe API Documentation](https://github.com/aws/aws-pdk/tree/mainline/packages/type-safe-api)
- [Type Safe API Documentation](https://aws.github.io/aws-pdk/developer_guides/type-safe-api/index.html)

## Adding Operations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The default entrypoint for the API is `src/main/smithy/main.smithy`. You can add

Resources:
- [Smithy Documentation](https://smithy.io/2.0/)
- [Type Safe API Documentation](https://github.com/aws/aws-pdk/tree/mainline/packages/type-safe-api)
- [Type Safe API Documentation](https://aws.github.io/aws-pdk/developer_guides/type-safe-api/index.html)

## Adding Operations

Expand Down Expand Up @@ -97,6 +97,6 @@ For more details, see the [Smithy documentation](https://smithy.io/2.0/spec/serv

The build task for this project will by default generate an Open API specification from the Smithy model, which is then used to generate the runtime, infrastructure, and documentation projects.

You can further customise the build via editing the `TypeSafeApiProject` `model.options.smithyBuildOptions` in the root `.projenrc` file. This includes adding projections, or customising the `openapi` projection used to generate the Open API specification.
You can further customise the build via editing the `TypeSafeApiProject` `model.options.smithy.smithyBuildOptions` in the root `.projenrc` file. This includes adding projections, or customising the `openapi` projection used to generate the Open API specification.

For details about customising the build, please see the [Type Safe API README](https://github.com/aws/aws-pdk/tree/mainline/packages/type-safe-api), and refer to the [Smithy Build documentation](https://smithy.io/2.0/guides/building-models/build-config.html).
For details about customising the build, please refer to the [Smithy Build documentation](https://smithy.io/2.0/guides/building-models/build-config.html).
30 changes: 16 additions & 14 deletions packages/type-safe-api/src/project/codegen/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,22 @@ export const generateHandlersProjects = (
languages: Language[],
options: GenerateHandlersProjectOptions
): { [language: string]: Project } => {
new TextFile(
options.parent,
path.join(options.generatedCodeDir, "README.md"),
{
lines: [
"## Handlers",
"",
"This directory contains lambda handlers for implementing your API.",
"",
"Whenever an operation is annotated with the `@handler` trait in Smithy (or the `x-handler` vendor extension in OpenAPI), a stub handler implementation will be generated for you, which you are free to modify.",
],
readonly: true,
}
);
if (languages.length > 0) {
new TextFile(
options.parent,
path.join(options.generatedCodeDir, "README.md"),
{
lines: [
"## Handlers",
"",
"This directory contains lambda handlers for implementing your API.",
"",
"Whenever an operation is annotated with the `@handler` trait in Smithy (or the `x-handler` vendor extension in OpenAPI), a stub handler implementation will be generated for you, which you are free to modify.",
],
readonly: true,
}
);
}

const generatedHandlers: { [language: string]: Project } = {};
languages.forEach((language) => {
Expand Down
Loading

0 comments on commit 33e2490

Please sign in to comment.