Skip to content

Commit

Permalink
Merge pull request #339 from tdakkota/fix/content-path-paramater-panic
Browse files Browse the repository at this point in the history
fix(gen): handle path parameters with unsupported content correctly
  • Loading branch information
ernado authored May 13, 2022
2 parents 4cb0388 + 9d881fb commit f2079f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
22 changes: 22 additions & 0 deletions _testdata/positive/test_content_path_parameter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: 3.0.0
info:
title: Test schema
version: 0.1.0
paths:
/{shortURL}:
get:
parameters:
- name: shortURL
in: path
required: true
content:
'*/*':
schema:
type: string
responses:
'200':
description: Response
content:
application/json:
schema:
type: string
8 changes: 7 additions & 1 deletion gen/gen_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ func (g *Generator) generateParameters(ctx *genctx, opName string, params []*ope
result := make([]*ir.Parameter, 0, len(params))
for i, p := range params {
if p.Content != nil {
if err := g.fail(&ErrNotImplemented{"parameter content field"}); err != nil {
notImplemented := &ErrNotImplemented{"parameter content field"}
if err := g.fail(notImplemented); err != nil {
return nil, errors.Wrap(err, "fail")
}

// Path parameters are required.
if p.In == openapi.LocationPath {
return nil, notImplemented
}

continue
}

Expand Down
3 changes: 2 additions & 1 deletion gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"embed"
"io/fs"
"path/filepath"
"runtime/debug"
"strings"
"testing"

Expand Down Expand Up @@ -33,7 +34,7 @@ func testGenerate(_ bool, name string, ignore ...string) func(t *testing.T) {
t.Run("Gen", func(t *testing.T) {
defer func() {
if rr := recover(); rr != nil {
t.Fatalf("panic: %+v", rr)
t.Fatalf("panic: %+v\n%s", rr, debug.Stack())
}
}()

Expand Down

0 comments on commit f2079f6

Please sign in to comment.