Skip to content

Commit d311397

Browse files
Merge pull request #2 from swift-server-community/sebsto/openapi
initial commit for openapi example
2 parents 54e0978 + f3dcf41 commit d311397

File tree

18 files changed

+440
-1
lines changed

18 files changed

+440
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__pycache__/
22
*.__pyc
33
.DS_Store
4+
.build

cookiecutter.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
"path": "templates/scheduler-to-lambda",
2020
"title": "Scheduler to Lambda",
2121
"description": "Scheduled events to Lambda function integration"
22-
}
22+
},
23+
"openapi-to-lambda": {
24+
"path": "templates/openapi-to-lambda",
25+
"title": "OpenAPI definition to Lambda",
26+
"description": "An OpenAPI definition to generate the Lambda function (with API Gateway)"
27+
}
2328
}
2429
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"project_name": "StockQuote OpenApi to Swift Lambda",
3+
"__project_name": "{{ cookiecutter.project_name|lower|replace(' ', '-') }}",
4+
"__architecture": "{{ 'x86_64'|architecture }}",
5+
"_copy_without_render": [".gitignore"],
6+
"_template_name": "OpenApi to Lambda",
7+
"_runtime": "Swift 5.10.0",
8+
"_swift_tools_version": "5.10.0",
9+
"_aws_swift_sdk_version": "0.45.0",
10+
"__project_dir": "{{ 'Change this path'|get_abs_path }}/{{ cookiecutter.__project_name }}",
11+
"_extensions": [
12+
"local_extensions.architecture",
13+
"local_extensions.get_abs_path"
14+
]
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# OpenAPI to Lambda SAM template
2+
3+
This templates allows developers to start with an OpenAPI definition of the REST service they want to create.
4+
5+
The swift OpenAPI generator plugin generates data types and server stubs at each `swift build` command. This ensures your Swift code stays in sync with your OpenAPI definition.
6+
7+
When deploying this project on your AWS account, it created an Amazon API Gateway configured as pass-through. The API Gateway forwards all API calls to your Lambda function.
8+
9+
## How to use this template?
10+
11+
First, clone the template.
12+
13+
```sh
14+
sam init \
15+
--location https://github.com/swift-server-community/aws-lambda-swift-sam-template/tree/main/templates/openapi-to-lambda \
16+
--no-interactive \
17+
--no-input \
18+
--name <your project name>
19+
```
20+
21+
## Testing a template locally
22+
23+
Testing a template locally
24+
You can create a buildable and deployable project folder from a local template using the below command. The `<project_name>` can be whatever you want your project to be called, and `<path/to/init_template>` should point to the existing folder that contains the template.
25+
26+
Command:
27+
28+
```sh
29+
sam init --location <path/to/init_template> \
30+
--no-input \
31+
--name <project_name>
32+
```
33+
34+
For example:
35+
36+
```sh
37+
sam init \
38+
--location /Users/myuser/code/aws-lambda-swift-sam-template/openapi-t-lambda \
39+
--name StockQuoteApi
40+
```
41+
42+
## Learn more
43+
44+
- [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator)
45+
- [Swift OpenAPI Transport for AWS Lambda](https://github.com/swift-server/swift-openapi-lambda)
27.1 KB
Binary file not shown.
Binary file not shown.
25.3 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#===----------------------------------------------------------------------===//
2+
#
3+
# This source file is part of the AWS Lambda Swift
4+
# VSCode extension open source project.
5+
#
6+
# Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors.
7+
# Licensed under Apache License v2.0.
8+
#
9+
# See LICENSE.txt for license information
10+
# See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
#===----------------------------------------------------------------------===//
15+
16+
import platform
17+
import os
18+
from cookiecutter.utils import simple_filter
19+
20+
@simple_filter
21+
def architecture(v):
22+
arch = platform.machine().lower()
23+
if 'aarch' in arch or 'arm' in arch:
24+
return 'arm64'
25+
else:
26+
return v
27+
28+
@simple_filter
29+
def get_abs_path(v):
30+
if os.getcwd():
31+
return os.getcwd()
32+
else:
33+
return v
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.aws-sam/
3+
*/build/*
4+
/.build
5+
/Packages
6+
xcuserdata/
7+
DerivedData/
8+
.swiftpm/configuration/registries.json
9+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
10+
.netrc
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#===----------------------------------------------------------------------===//
2+
#
3+
# This source file is part of the AWS Lambda Swift
4+
# VSCode extension open source project.
5+
#
6+
# Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors.
7+
# Licensed under Apache License v2.0.
8+
#
9+
# See LICENSE.txt for license information
10+
# See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
#===----------------------------------------------------------------------===//
15+
16+
FROM swift:amazonlinux2
17+
18+
RUN yum -y install openssl-devel

0 commit comments

Comments
 (0)