Skip to content

Commit 0276651

Browse files
committed
Merge branch 'master' into erikw/lambda-error-msg
2 parents 107dbe6 + ddba7fc commit 0276651

File tree

9 files changed

+246
-18
lines changed

9 files changed

+246
-18
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
99

10+
## [2.21.1](https://github.com/netlify/open-api/compare/v2.21.0...v2.21.1) (2023-09-07)
11+
12+
13+
### Bug Fixes
14+
15+
* fileUpload error casting does not conform to interface ([#486](https://github.com/netlify/open-api/issues/486)) ([f95a00b](https://github.com/netlify/open-api/commit/f95a00bf160dcbbcd89a71e98f6e4eda986e8f9b))
16+
17+
## [2.21.0](https://github.com/netlify/open-api/compare/v2.20.0...v2.21.0) (2023-08-25)
18+
19+
20+
### Features
21+
22+
* support function route `methods` field ([b930d21](https://github.com/netlify/open-api/commit/b930d21384358d86ec9ec6f06fec403ade9119f0))
23+
24+
## [2.20.0](https://github.com/netlify/open-api/compare/v2.19.1...v2.20.0) (2023-08-09)
25+
26+
27+
### Features
28+
29+
* add support for custom function routes ([#481](https://github.com/netlify/open-api/issues/481)) ([d30c25b](https://github.com/netlify/open-api/commit/d30c25b9f6d2f9626c51e4a938c11cfbfc51ee93))
30+
1031
## [2.19.1](https://github.com/netlify/open-api/compare/v2.19.0...v2.19.1) (2023-07-12)
1132

1233

go/models/function_config.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/models/function_route.go

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/porcelain/deploy.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"time"
2222

2323
"github.com/cenkalti/backoff/v4"
24-
apierrors "github.com/go-openapi/errors"
2524
"github.com/pkg/errors"
2625
"github.com/rsc/goversion/version"
2726
"github.com/sirupsen/logrus"
@@ -101,6 +100,11 @@ type DeployOptions struct {
101100
functionsConfig map[string]models.FunctionConfig
102101
}
103102

103+
type deployApiError interface {
104+
error
105+
Code() int
106+
}
107+
104108
type uploadError struct {
105109
err error
106110
mutex *sync.Mutex
@@ -473,6 +477,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
473477
"deploy_id": d.ID,
474478
"file_path": f.Name,
475479
"file_sum": f.Sum,
480+
"file_size": f.Size,
476481
}).Debug("Uploading file")
477482

478483
b := backoff.NewExponentialBackOff()
@@ -539,7 +544,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
539544

540545
if operationError != nil {
541546
context.GetLogger(ctx).WithError(operationError).Errorf("Failed to upload file %v", f.Name)
542-
apiErr, ok := operationError.(apierrors.Error)
547+
apiErr, ok := operationError.(deployApiError)
543548

544549
if ok {
545550
if apiErr.Code() == 401 {
@@ -801,10 +806,21 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
801806
})
802807
}
803808

804-
if function.DisplayName != "" || function.Generator != "" {
809+
routes := make([]*models.FunctionRoute, len(function.Routes))
810+
for i, route := range function.Routes {
811+
routes[i] = &models.FunctionRoute{
812+
Pattern: route.Pattern,
813+
Literal: route.Literal,
814+
Expression: route.Expression,
815+
Methods: route.Methods,
816+
}
817+
}
818+
819+
if function.DisplayName != "" || function.Generator != "" || len(routes) > 0 {
805820
functionsConfig[file.Name] = models.FunctionConfig{
806821
DisplayName: function.DisplayName,
807822
Generator: function.Generator,
823+
Routes: routes,
808824
}
809825
}
810826

go/porcelain/deploy_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,18 @@ func TestBundleWithManifest(t *testing.T) {
593593
"displayName": "Hello Javascript Function",
594594
"generator": "@netlify/[email protected]",
595595
"name": "hello-js-function-test",
596-
"schedule": "* * * * *"
596+
"schedule": "* * * * *",
597+
"routes": [
598+
{
599+
"pattern": "/products",
600+
"literal": "/products"
601+
},
602+
{
603+
"pattern": "/products/:id",
604+
"expression": "^/products/(.*)$",
605+
"methods": ["GET", "POST"]
606+
}
607+
]
597608
},
598609
{
599610
"path": "%s",
@@ -623,9 +634,20 @@ func TestBundleWithManifest(t *testing.T) {
623634
assert.Equal(t, "some-other-runtime", functions.Files["hello-py-function-test"].Runtime)
624635
assert.Equal(t, "stream", functions.Files["hello-py-function-test"].FunctionMetadata.InvocationMode)
625636

637+
helloJSConfig := functionsConfig["hello-js-function-test"]
638+
626639
assert.Equal(t, 1, len(functionsConfig))
627-
assert.Equal(t, "Hello Javascript Function", functionsConfig["hello-js-function-test"].DisplayName)
628-
assert.Equal(t, "@netlify/[email protected]", functionsConfig["hello-js-function-test"].Generator)
640+
assert.Equal(t, "Hello Javascript Function", helloJSConfig.DisplayName)
641+
assert.Equal(t, "@netlify/[email protected]", helloJSConfig.Generator)
642+
643+
assert.Equal(t, "/products", helloJSConfig.Routes[0].Pattern)
644+
assert.Equal(t, "/products", helloJSConfig.Routes[0].Literal)
645+
assert.Empty(t, helloJSConfig.Routes[0].Expression)
646+
647+
assert.Equal(t, "/products/:id", helloJSConfig.Routes[1].Pattern)
648+
assert.Empty(t, helloJSConfig.Routes[1].Literal)
649+
assert.Equal(t, "^/products/(.*)$", helloJSConfig.Routes[1].Expression)
650+
assert.Equal(t, []string{"GET", "POST"}, helloJSConfig.Routes[1].Methods)
629651
}
630652

631653
func TestReadZipRuntime(t *testing.T) {

go/porcelain/functions_manifest.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ type functionsManifest struct {
77
}
88

99
type functionsManifestEntry struct {
10-
MainFile string `json:"mainFile"`
11-
Name string `json:"name"`
12-
Path string `json:"path"`
13-
Runtime string `json:"runtime"`
14-
RuntimeVersion string `json:"runtimeVersion"`
15-
Schedule string `json:"schedule"`
16-
DisplayName string `json:"displayName"`
17-
Generator string `json:"generator"`
18-
InvocationMode string `json:"invocationMode"`
10+
MainFile string `json:"mainFile"`
11+
Name string `json:"name"`
12+
Path string `json:"path"`
13+
Runtime string `json:"runtime"`
14+
RuntimeVersion string `json:"runtimeVersion"`
15+
Schedule string `json:"schedule"`
16+
DisplayName string `json:"displayName"`
17+
Generator string `json:"generator"`
18+
InvocationMode string `json:"invocationMode"`
19+
Routes []functionRoute `json:"routes"`
20+
}
21+
22+
type functionRoute struct {
23+
Pattern string `json:"pattern"`
24+
Literal string `json:"literal"`
25+
Expression string `json:"expression"`
26+
Methods []string `json:"methods"`
1927
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@netlify/open-api",
33
"description": "Netlify's open-api definition as a module",
4-
"version": "2.19.1",
4+
"version": "2.21.1",
55
"author": "Netlify",
66
"ava": {
77
"files": [

swagger.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
swagger: '2.0'
22
info:
3-
version: 2.19.1
3+
version: 2.21.1
44
title: Netlify's API documentation
55
description: >-
66
Netlify is a hosting service for the programmable web. It understands your
@@ -3620,6 +3620,24 @@ definitions:
36203620
type: string
36213621
generator:
36223622
type: string
3623+
routes:
3624+
type: array
3625+
items:
3626+
$ref: '#/definitions/functionRoute'
3627+
functionRoute:
3628+
type: object
3629+
properties:
3630+
pattern:
3631+
type: string
3632+
literal:
3633+
type: string
3634+
expression:
3635+
type: string
3636+
methods:
3637+
type: array
3638+
items:
3639+
type: string
3640+
enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
36233641
parameters:
36243642
page:
36253643
type: integer

0 commit comments

Comments
 (0)