Skip to content

Commit 0825d08

Browse files
authored
Before release merge to main
* readme update * swagger processor updates, many new tests * Refactoring to remove replaceer and generator from the library, enum support, test refactoring, readme update * Add Pet tests, Test refactorings, ContentType refactored to Support enums * code cleanup * Update and delete pet tests * upload image test * additional test with readme update * small bug fixes and test upgrade * alpha 1 * Custom exception, cleanup * cleanup * refactorings, more tests * code analysis and build only on pull requests * small code refactoring
1 parent 76cf53a commit 0825d08

File tree

55 files changed

+3439
-419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3439
-419
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
# ******** NOTE ********
12+
13+
name: "CodeQL"
14+
15+
on:
16+
pull_request:
17+
branches: [ develop ]
18+
schedule:
19+
- cron: '36 12 * * 3'
20+
21+
jobs:
22+
analyze:
23+
name: Analyze
24+
runs-on: ubuntu-latest
25+
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
language: [ 'csharp' ]
30+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
31+
# Learn more...
32+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
# Initializes the CodeQL tools for scanning.
39+
- name: Initialize CodeQL
40+
uses: github/codeql-action/init@v1
41+
with:
42+
languages: ${{ matrix.language }}
43+
# If you wish to specify custom queries, you can do so here or in a config file.
44+
# By default, queries listed here will override any specified in a config file.
45+
# Prefix the list here with "+" to use these queries and those in the config file.
46+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
47+
48+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
49+
# If this step fails, then you should remove it and run the build manually (see below)
50+
- name: Autobuild
51+
uses: github/codeql-action/autobuild@v1
52+
53+
# ℹ️ Command-line programs to run using the OS shell.
54+
# 📚 https://git.io/JvXDl
55+
56+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
57+
# and modify them (or add more) to build your code if your project
58+
# uses a compiled language
59+
60+
#- run: |
61+
# make bootstrap
62+
# make release
63+
64+
- name: Perform CodeQL Analysis
65+
uses: github/codeql-action/analyze@v1

.github/workflows/dotnet-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Build .NET Library
22

33
on:
4-
push:
54
pull_request:
5+
branches: [ develop, main ]
66
release:
77
types:
88
- published

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.1.1</Version>
3+
<Version>0.1.6</Version>
44
</PropertyGroup>
55
</Project>

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# QAToolKit.Source.Swagger
22
![.NET Core](https://github.com/qatoolkit/qatoolkit-source-swagger-net/workflows/.NET%20Core/badge.svg)
33

4-
`QAToolKit.Source.Swagger` is a .NET standard library, which generates `IList<HttpTestRequest>` object that is the input for other components.
4+
`QAToolKit.Source.Swagger` is a .NET standard library, which generates `IEnumerable<HttpRequest>` object that is the input for other components.
55

66
Major features:
77

8-
- Parses `OpenAPI v3.0` Swagger files,
8+
- Parses `OpenAPI v3.0` Swagger files (JSON or YAML),
99
- swagger.json can be loaded from `disk` or from `URL`,
10-
- path parameters, URL paramters and JSON body models are replaced with custom values,
1110
- access swagger.json from URL, which is protected by `basic authentication`,
12-
- control which swagger endpoints are called by specifying `request filters` (check below)
11+
- control which swagger endpoints are returned by specifying `request filters` (check below)
1312

1413
## Sample
1514

@@ -20,28 +19,19 @@ This is a sample of instantiating a new Swagger Source object from URL.
2019
SwaggerUrlSource swaggerSource = new SwaggerUrlSource(
2120
options =>
2221
{
23-
options.AddReplacementValues(new ReplacementValue[] {
24-
new ReplacementValue()
25-
{
26-
Key = "version",
27-
Value = "1"
28-
},
29-
{
30-
Key = "parentId",
31-
Value = "4"
32-
}
33-
});
3422
options.AddBasicAuthentication("myuser", "mypassword");
3523
options.AddRequestFilters(new RequestFilter()
3624
{
3725
AuthenticationTypes = new List<AuthenticationType>() { AuthenticationType.Customer },
3826
TestTypes = new List<TestType>() { TestType.LoadTest },
3927
EndpointNameWhitelist = new string[] { "GetCategories" }
4028
});
29+
options.AddBaseUrl(new Uri("https://dev.myapi.com"));
30+
options.UseSwaggerExampleValues = true;
4131
});
4232

4333
//To run the Swagger parser we need to pass an array of URLs
44-
IList<HttpTestRequest> requests = await swaggerSource.Load(new Uri[] {
34+
IEnumerable<HttpRequest> requests = await swaggerSource.Load(new Uri[] {
4535
new Uri("https://api.demo.com/swagger/v1/swagger.json"),
4636
new Uri("https://api2.demo.com/swagger/v1/swagger.json")
4737
});
@@ -51,24 +41,13 @@ The above code is quite simple, but it needs some explanation.
5141

5242
## Description
5343

54-
#### 1. AddReplacementValues
55-
This is a method that will add key/value pairs for replacement values you need to replace in the Swagger requests.
56-
57-
In the example above we say: "Replace `{version}` placeholder in Path and URL parameters and JSON body models."
58-
59-
In other words, if you have a test API endpoint like this: https://api.demo.com/v{version}/categories?parent={parentId} that will be set to https://api.demo.com/v1/categories?parent=4.
60-
61-
That, does not stop there, you can also populate JSON request bodies in this way:
62-
63-
[TODO sample JSON Body]
64-
65-
#### 2. AddBasicAuthentication
44+
#### 1. AddBasicAuthentication
6645
If your Swagger.json files are protected by basic authentication, you can set those with `AddBasicAuthentication`.
6746

68-
#### 3, AddRequestFilters
69-
Filters comprise of different types. Those are `AuthenticationTypes`, `TestTypes` and `EndpointNameWhitelist`.
47+
#### 2. AddRequestFilters
48+
Filters comprise of different types. Those are `AuthenticationTypes`, `TestTypes` and `EndpointNameWhitelist`. All are optional.
7049

71-
##### 3.1. AuthenticationTypes
50+
##### 2.1. AuthenticationTypes
7251
Here we specify a list of Authentication types, that will be filtered out from the whole swagger file. This is where QA Tool Kit presents a convention.
7352
The built-in types are:
7453
- `AuthenticationType.Customer` which specifies a string `"@customer"`,
@@ -79,7 +58,7 @@ The built-in types are:
7958

8059
In order to apply filters, you need to tag your API endpoints with those strings.
8160

82-
We normally do it in Swagger endpoint description. An example might be: `Get categories from the system. @customer,@administrator,@oauth2.`
61+
We normally do that, by adding the tags in the Swagger endpoint description. An example might be: `Get categories from the system. @customer,@administrator,@oauth2.`
8362

8463
This is an example from swagger.json excerpt:
8564

@@ -96,14 +75,14 @@ This is an example from swagger.json excerpt:
9675

9776
Parser then finds those string in the description field and populates the `RequestFilter` property.
9877

99-
##### 3.2 TestTypes
100-
Similarly as in the `AuthenticationTypes` you can filter out certain endpoints to be used in certain test scenarios. Currently libraray supports:
78+
##### 2.2 TestTypes
79+
Similarly as in the `AuthenticationTypes` you can filter out certain endpoints to be used in different test scenarios. Currently library supports:
10180

10281
- TestType.LoadTest which specifies a string `"@loadtest"`,
10382
- TestType.IntegrationTest which specifies a string `"@integrationtest"`,
10483
- TestType.SecurityTest which specifies a string `"@securitytest"`,
10584

106-
The same swagger-json excerpt which allows load and integration tests.
85+
The same swagger.json excerpt which support test type tags might look like this:
10786

10887
```json
10988
"/v{version}/categories?parent={parentId}": {
@@ -116,14 +95,35 @@ The same swagger-json excerpt which allows load and integration tests.
11695
"operationId": "GetCategories",
11796
```
11897

119-
##### 3.3 EndpointNameWhitelist
98+
If you feed the list of `HttpRequest` objects with load type tags to the library like `QAToolKit.Engine.Bombardier`, only those requests will be tested.
99+
100+
##### 2.3 EndpointNameWhitelist
120101
Final `RequestFilter` option is `EndpointNameWhitelist`. With it you can specify a list of endpoints that will be included in the results.
121102

122-
Every other endpoint will be excluded. In the sample above we have set the result to include only `GetCategories` endpoint. That corresponds to the `operationId` in the swagger file above.
103+
Every other endpoint will be excluded. In the sample above we have set the result to include only `GetCategories` endpoint.
104+
That corresponds to the `operationId` in the swagger file above.
105+
106+
#### 3. AddBaseUrl
107+
Your swagger file has a `Server section`, where you can specify an server URI and can be absolute or relative. An example of relative server section is:
108+
```json
109+
"servers": [
110+
{
111+
"url": "/api/v3"
112+
}
113+
],
114+
```
115+
In case of relative paths you need to add an absolute base URL to `Swagger Processor` with `AddBaseUrl`, otherwise the one from the `Servers section` will be used.
116+
117+
#### 4. UseSwaggerExampleValues
118+
You can set `UseSwaggerExampleValues = true` in the SwaggerOptions when creating new Swagger source object. This will
119+
check Swagger for example files and populate those.
120+
121+
By default this option is set to false.
123122

124-
## TO-DO
123+
## Limitations
125124

126-
- Support for automatic model data generation.
125+
- Swagger processor only returns `application/json` content type. Support for other might come later.
126+
- Data generation and replacement is only supported for Path, Url and Json Body properties.
127127

128128
## License
129129

0 commit comments

Comments
 (0)