-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resolver): added openapi file resolver for json and yaml parsers
Signed-off-by: João Reigota <[email protected]>
- Loading branch information
1 parent
d764d19
commit 890228d
Showing
59 changed files
with
2,988 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Swagger Petstore | ||
description: Multi-file boilerplate for OpenAPI Specification. | ||
license: | ||
name: MIT | ||
contact: | ||
name: API Support | ||
url: http://www.example.com/support | ||
email: [email protected] | ||
servers: | ||
- url: http://petstore.swagger.io/v1 | ||
tags: | ||
- name: pets | ||
paths: | ||
/pets: | ||
$ref: "./resources/pets.yaml" | ||
/pets/{petId}: | ||
$ref: "./resources/pet.yaml" | ||
components: | ||
parameters: | ||
$ref: "./parameters/_index.yaml" | ||
schemas: | ||
$ref: "./schemas/_index.yaml" | ||
responses: | ||
$ref: "./responses/_index.yaml" |
7 changes: 7 additions & 0 deletions
7
e2e/fixtures/samples/unresolved_openapi/parameters/_index.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# path | ||
petId: | ||
$ref: './path/petId.yaml' | ||
|
||
# limit | ||
limit: | ||
$ref: './query/limit.yaml' |
6 changes: 6 additions & 0 deletions
6
e2e/fixtures/samples/unresolved_openapi/parameters/path/petId.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: petId | ||
in: path | ||
required: true | ||
description: The id of the pet to retrieve | ||
schema: | ||
type: string |
7 changes: 7 additions & 0 deletions
7
e2e/fixtures/samples/unresolved_openapi/parameters/query/limit.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: limit | ||
in: query | ||
description: How many items to return at one time (max 100) | ||
required: false | ||
schema: | ||
type: integer | ||
format: int32 |
17 changes: 17 additions & 0 deletions
17
e2e/fixtures/samples/unresolved_openapi/resources/pet.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
get: | ||
summary: Detail | ||
operationId: showPetById | ||
description: Info for a specific pet | ||
tags: | ||
- pets | ||
parameters: | ||
- $ref: "../parameters/path/petId.yaml" | ||
responses: | ||
'200': | ||
description: Expected response to a valid request | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "../schemas/Pet.yaml" | ||
default: | ||
$ref: "../responses/UnexpectedError.yaml" |
34 changes: 34 additions & 0 deletions
34
e2e/fixtures/samples/unresolved_openapi/resources/pets.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
get: | ||
summary: List | ||
operationId: listPets | ||
description: List all pets | ||
tags: | ||
- pets | ||
parameters: | ||
- $ref: "../parameters/query/limit.yaml" | ||
responses: | ||
'200': | ||
description: A paged array of pets | ||
headers: | ||
x-next: | ||
description: A link to the next page of responses | ||
schema: | ||
type: string | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "../schemas/Pet.yaml" | ||
default: | ||
$ref: "../responses/UnexpectedError.yaml" | ||
post: | ||
summary: Create | ||
operationId: createPets | ||
description: Create a pet | ||
tags: | ||
- pets | ||
responses: | ||
'201': | ||
$ref : "../responses/NullResponse.yaml" | ||
default: | ||
$ref : "../responses/UnexpectedError.yaml" | ||
|
1 change: 1 addition & 0 deletions
1
e2e/fixtures/samples/unresolved_openapi/responses/NullResponse.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
description: Null response |
5 changes: 5 additions & 0 deletions
5
e2e/fixtures/samples/unresolved_openapi/responses/UnexpectedError.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref : "../schemas/Error.yaml" |
4 changes: 4 additions & 0 deletions
4
e2e/fixtures/samples/unresolved_openapi/responses/_index.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
UnexpectedError: | ||
$ref: "./UnexpectedError.yaml" | ||
NullResponse: | ||
$ref: "./NullResponse.yaml" |
10 changes: 10 additions & 0 deletions
10
e2e/fixtures/samples/unresolved_openapi/schemas/Error.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type: object | ||
required: | ||
- code | ||
- message | ||
properties: | ||
code: | ||
type: integer | ||
format: int32 | ||
message: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type: object | ||
required: | ||
- id | ||
- name | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
name: | ||
type: string | ||
tag: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Pet: | ||
$ref: "./Pet.yaml" | ||
Error: | ||
$ref: "./Error.yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package testcases | ||
|
||
import "regexp" | ||
|
||
// E2E-CLI-055 - Kics scan command with openapi files that are not resolved | ||
// should resolve openapi files and return results in different files | ||
func init() { //nolint | ||
testSample := TestCase{ | ||
Name: "should resolve openapi files and return results in different files [E2E-CLI-055]", | ||
Args: args{ | ||
Args: []cmdArgs{ | ||
[]string{"scan", "-p", "/path/e2e/fixtures/samples/unresolved_openapi"}, | ||
}, | ||
}, | ||
WantStatus: []int{50}, | ||
Validation: func(outputText string) bool { | ||
matchQueryPath1, _ := regexp.MatchString(`UnexpectedError.yaml`, outputText) | ||
matchQueryPath2, _ := regexp.MatchString(`petId.yaml`, outputText) | ||
return matchQueryPath1 && matchQueryPath2 | ||
}, | ||
} | ||
|
||
Tests = append(Tests, testSample) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.