Skip to content

Commit

Permalink
Fix oneOf constraint for HTTP Bearer scheme (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Mar 5, 2024
1 parent d6a28d7 commit 7eb17ad
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
24 changes: 24 additions & 0 deletions openapi3/entities_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,27 @@ components:

require.NoError(t, s.UnmarshalYAML([]byte(spec)))
}

func TestSpec_MarshalYAML_2(t *testing.T) {
var s openapi3.Spec

spec := `openapi: 3.0.0
info:
title: MyProject
description: "My Project Description"
version: v1.0.0
# 1) Define the security scheme type (HTTP bearer)
components:
securitySchemes:
bearerAuth: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
# 2) Apply the security globally to all operations
security:
- bearerAuth: [] # use the same name as above
paths:
`

require.NoError(t, s.UnmarshalYAML([]byte(spec)))
}
5 changes: 5 additions & 0 deletions openapi31/entities.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions openapi31/entities_extra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package openapi31_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/swaggest/openapi-go/openapi31"
)

func TestSpec_MarshalYAML(t *testing.T) {
var s openapi31.Spec

spec := `openapi: 3.1.0
info:
description: description
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
title: title
version: 2.0.0
servers:
- url: /v2
paths:
/user:
put:
summary: updates the user by id
operationId: UpdateUser
requestBody:
content:
application/json:
schema:
type: string
description: Updated user object
required: true
responses:
"404":
description: User not found
components:
securitySchemes:
api_key:
in: header
name: x-api-key
type: apiKey
bearer_auth:
type: http
scheme: bearer
bearerFormat: JWT`

require.NoError(t, s.UnmarshalYAML([]byte(spec)))
}

func TestSpec_MarshalYAML_2(t *testing.T) {
var s openapi31.Spec

spec := `openapi: 3.1.0
info:
title: MyProject
description: "My Project Description"
version: v1.0.0
# 1) Define the security scheme type (HTTP bearer)
components:
securitySchemes:
bearerAuth: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
# 2) Apply the security globally to all operations
security:
- bearerAuth: [] # use the same name as above
paths:
`

require.NoError(t, s.UnmarshalYAML([]byte(spec)))
}

0 comments on commit 7eb17ad

Please sign in to comment.