mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-23 01:04:55 +01:00
Compare commits
89 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7d283e12b | ||
|
|
5280970765 | ||
|
|
6943b90da6 | ||
|
|
4a434b5dba | ||
|
|
3dafd2e725 | ||
|
|
c6e4608039 | ||
|
|
57f89a06e1 | ||
|
|
4d80eb53fe | ||
|
|
13c002fede | ||
|
|
9db6e800ad | ||
|
|
897ee9ffe3 | ||
|
|
8865543bf1 | ||
|
|
48cfd2d20e | ||
|
|
71d2660aff | ||
|
|
7f2a42de96 | ||
|
|
c333b8b263 | ||
|
|
32ddd48321 | ||
|
|
260abf5275 | ||
|
|
d3b2422ec1 | ||
|
|
823917a4ab | ||
|
|
1e968106d1 | ||
|
|
49e10ed20f | ||
|
|
c3ec3a66b3 | ||
|
|
5644491942 | ||
|
|
6e5e629525 | ||
|
|
77ee123340 | ||
|
|
ae2a05e86b | ||
|
|
0e06cf6346 | ||
|
|
e9db520cc3 | ||
|
|
a0e661fae9 | ||
|
|
25666152bb | ||
|
|
6f5eeb5359 | ||
|
|
7ca2095576 | ||
|
|
74edad517b | ||
|
|
6c65dfcff6 | ||
|
|
affe388e30 | ||
|
|
48b3e7a305 | ||
|
|
6194f4e460 | ||
|
|
57cc616aa3 | ||
|
|
a2a581c84b | ||
|
|
e64ed45fcf | ||
|
|
267f0b7b6d | ||
|
|
34083d826e | ||
|
|
72eec7140b | ||
|
|
6fa0f893e7 | ||
|
|
2ab075ee09 | ||
|
|
772398bea1 | ||
|
|
ba0b9d9fd8 | ||
|
|
c67bf75a4b | ||
|
|
ed74871a26 | ||
|
|
cb66c04199 | ||
|
|
fd28ebdffa | ||
|
|
ce36daa326 | ||
|
|
b5a5f5e464 | ||
|
|
f5d624eeed | ||
|
|
799ea2d219 | ||
|
|
0f99e06acc | ||
|
|
9d0682bff6 | ||
|
|
cb1d2a5294 | ||
|
|
4b435faf0b | ||
|
|
5e7cb44525 | ||
|
|
444298c28c | ||
|
|
6f42aa99bc | ||
|
|
8a9ea1b843 | ||
|
|
dade24de37 | ||
|
|
6beaa631f4 | ||
|
|
282281aa7f | ||
|
|
4052a0ef3b | ||
|
|
2ca394b7f6 | ||
|
|
b04000bfdd | ||
|
|
93ab4e1853 | ||
|
|
80b5eaac6e | ||
|
|
a1dc2ba646 | ||
|
|
934c444902 | ||
|
|
83d178bdb5 | ||
|
|
d91b5d5831 | ||
|
|
43b96ce340 | ||
|
|
4d8cf43357 | ||
|
|
328e9090b1 | ||
|
|
a22b3bfbc5 | ||
|
|
29974c7ad4 | ||
|
|
660a09e656 | ||
|
|
fbecd3b119 | ||
|
|
b17840cea9 | ||
|
|
969b0da8e2 | ||
|
|
dc078b57ea | ||
|
|
8140b37095 | ||
|
|
2ad060bbd4 | ||
|
|
d758301e4f |
6
.editorconfig
Normal file
6
.editorconfig
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = crlf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
4
.github/FUNDING.yml
vendored
4
.github/FUNDING.yml
vendored
@@ -1,8 +1,8 @@
|
|||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
github: # [StefH]
|
||||||
patreon: # Replace with a single Patreon username
|
patreon: # Replace with a single Patreon username
|
||||||
open_collective: # Replace with a single Open Collective username
|
open_collective: # wiremocknet
|
||||||
ko_fi: # Replace with a single Ko-fi username
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
|||||||
15
.github/workflows/CreateRelease.yml
vendored
Normal file
15
.github/workflows/CreateRelease.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
name: CreateRelease
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*.*.*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
1511
CHANGELOG.md
1511
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,36 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<MsBuildAllProjects>$(MsBuildAllProjects);$(MsBuildThisFileFullPath)</MsBuildAllProjects>
|
<MsBuildAllProjects>$(MsBuildAllProjects);$(MsBuildThisFileFullPath)</MsBuildAllProjects>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.4.7</VersionPrefix>
|
<VersionPrefix>1.4.29</VersionPrefix>
|
||||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||||
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
<RepositoryType>git</RepositoryType>
|
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../../PackageReleaseNotes.txt"))</PackageReleaseNotes>
|
||||||
<RepositoryUrl>https://github.com/WireMock-Net/WireMock.Net</RepositoryUrl>
|
<RepositoryType>git</RepositoryType>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<RepositoryUrl>https://github.com/WireMock-Net/WireMock.Net</RepositoryUrl>
|
||||||
</PropertyGroup>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
|
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
|
||||||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Choose>
|
<ItemGroup>
|
||||||
<!-- The environment variable `Prerelease` is set in the azure-pipelines.yml file. -->
|
<None Include="../../resources/WireMock.Net-Logo.png" Pack="true" PackagePath="" />
|
||||||
<When Condition=" '$(Prerelease)' != '' ">
|
<!--<None Include="../../PackageReadme.md" Pack="true" PackagePath=""/>-->
|
||||||
<PropertyGroup>
|
</ItemGroup>
|
||||||
<!-- Set the version to x.x.x.x-{Prerelease}-1{Build_BuildId} (this is same buildId as defined in the azure-pipelines.yml file). -->
|
|
||||||
<VersionSuffix>$(Prerelease)-1$(BUILD_BUILDID)</VersionSuffix>
|
<Choose>
|
||||||
</PropertyGroup>
|
<!-- The environment variable `Prerelease` is set in the azure-pipelines.yml file. -->
|
||||||
</When>
|
<When Condition=" '$(Prerelease)' != '' ">
|
||||||
</Choose>
|
<PropertyGroup>
|
||||||
|
<!-- Set the version to x.x.x.x-{Prerelease}-1{Build_BuildId} (this is same buildId as defined in the azure-pipelines.yml file). -->
|
||||||
|
<VersionSuffix>$(Prerelease)-1$(BUILD_BUILDID)</VersionSuffix>
|
||||||
|
</PropertyGroup>
|
||||||
|
</When>
|
||||||
|
</Choose>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
7
Generate-ReleaseNotes.cmd
Normal file
7
Generate-ReleaseNotes.cmd
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
rem https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
|
SET version=1.4.29
|
||||||
|
|
||||||
|
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
|
||||||
|
|
||||||
|
GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc duplicate --template PackageReleaseNotes.template --version %version% --token %GH_TOKEN%
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
https://github.com/StefH/GitHubReleaseNotes
|
|
||||||
|
|
||||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.4.7
|
|
||||||
6
PackageReleaseNotes.template
Normal file
6
PackageReleaseNotes.template
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# {{releaseInfos.0.FriendlyName}} ({{formatDate releaseInfos.0.When "dd MMMM yyyy"}})
|
||||||
|
{{#each releaseInfos.0.issueInfos}}
|
||||||
|
- #{{Number}} {{Title}}{{#if Labels}} [{{join Labels ", "}}]{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
5
PackageReleaseNotes.txt
Normal file
5
PackageReleaseNotes.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# 1.4.29 (12 December 2021)
|
||||||
|
- #699 GUID Pattern support in RegexMatcher
|
||||||
|
- #700 RegexExtended in settings [feature]
|
||||||
|
|
||||||
|
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
@@ -34,8 +34,11 @@ For more info, see also this WIKI page: [What is WireMock.Net](https://github.co
|
|||||||
| **WireMock.Net** | [](https://www.nuget.org/packages/WireMock.Net) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net)
|
| **WireMock.Net** | [](https://www.nuget.org/packages/WireMock.Net) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net)
|
||||||
| **WireMock.Net.StandAlone** | [](https://www.nuget.org/packages/WireMock.Net.StandAlone) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.StandAlone)
|
| **WireMock.Net.StandAlone** | [](https://www.nuget.org/packages/WireMock.Net.StandAlone) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.StandAlone)
|
||||||
| **WireMock.Net.FluentAssertions** | [](https://www.nuget.org/packages/WireMock.Net.FluentAssertions) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.FluentAssertions)
|
| **WireMock.Net.FluentAssertions** | [](https://www.nuget.org/packages/WireMock.Net.FluentAssertions) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.FluentAssertions)
|
||||||
| **WireMock.Net.RestClient** | [](https://www.nuget.org/packages/WireMock.Net.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient)
|
|
||||||
| **WireMock.Net.Matchers.CSharpCode** | [](https://www.nuget.org/packages/WireMock.Net.Matchers.CSharpCode) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.Matchers.CSharpCode)
|
| **WireMock.Net.Matchers.CSharpCode** | [](https://www.nuget.org/packages/WireMock.Net.Matchers.CSharpCode) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.Matchers.CSharpCode)
|
||||||
|
| **WireMock.Net.OpenApiParser** | [](https://www.nuget.org/packages/WireMock.Net.OpenApiParser) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.OpenApiParser)
|
||||||
|
| **WireMock.Net.RestClient** | [](https://www.nuget.org/packages/WireMock.Net.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient)
|
||||||
|
| **WireMock.Org.RestClient** | [](https://www.nuget.org/packages/WireMock.Org.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Org.RestClient)
|
||||||
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
For the supported frameworks and build information, see [this](https://github.com/WireMock-Net/WireMock.Net/wiki/Development-Information) page.
|
For the supported frameworks and build information, see [this](https://github.com/WireMock-Net/WireMock.Net/wiki/Development-Information) page.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.30114.105
|
VisualStudioVersion = 17.0.31521.260
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8F890C6F-9ACC-438D-928A-AD61CDA862F2}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8F890C6F-9ACC-438D-928A-AD61CDA862F2}"
|
||||||
EndProject
|
EndProject
|
||||||
@@ -21,16 +21,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{98
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7EFB2C5B-1BB2-4AAF-BC9F-216ED80C594D}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7EFB2C5B-1BB2-4AAF-BC9F-216ED80C594D}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.editorconfig = .editorconfig
|
||||||
.gitignore = .gitignore
|
.gitignore = .gitignore
|
||||||
azure-pipelines-ci-linux.yml = azure-pipelines-ci-linux.yml
|
|
||||||
azure-pipelines-ci.yml = azure-pipelines-ci.yml
|
|
||||||
azure-pipelines-linux.yml = azure-pipelines-linux.yml
|
|
||||||
azure-pipelines-nuget.yml = azure-pipelines-nuget.yml
|
|
||||||
build-info.md = build-info.md
|
build-info.md = build-info.md
|
||||||
CHANGELOG.md = CHANGELOG.md
|
CHANGELOG.md = CHANGELOG.md
|
||||||
Directory.Build.props = Directory.Build.props
|
Directory.Build.props = Directory.Build.props
|
||||||
GitHubReleaseNotes.txt = GitHubReleaseNotes.txt
|
Generate-ReleaseNotes.cmd = Generate-ReleaseNotes.cmd
|
||||||
nuget.config = nuget.config
|
nuget.config = nuget.config
|
||||||
|
PackageReleaseNotes.template = PackageReleaseNotes.template
|
||||||
|
PackageReleaseNotes.txt = PackageReleaseNotes.txt
|
||||||
README.md = README.md
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
@@ -82,7 +81,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Matchers.CShar
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Net472.Classic", "examples\WireMock.Net.Console.Net472.Classic\WireMock.Net.Console.Net472.Classic.csproj", "{6580580B-1EFD-4922-B0EC-FF290DB279EE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Net472.Classic", "examples\WireMock.Net.Console.Net472.Classic\WireMock.Net.Console.Net472.Classic.csproj", "{6580580B-1EFD-4922-B0EC-FF290DB279EE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.XamarinUI.Tests", "test\WireMock.Net.XamarinUI.Tests\WireMock.Net.XamarinUI.Tests.csproj", "{0DE14F1B-A51E-4B59-A87C-C6012DCD2844}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{1DAEFF47-D117-4E95-8B3E-4F7C8B92011A}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.github\workflows\CreateRelease.yml = .github\workflows\CreateRelease.yml
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure Pipelines", "Azure Pipelines", "{5B64F6CA-BF6B-4F67-BB2A-9C47E441703E}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
azure-pipelines-ci-linux.yml = azure-pipelines-ci-linux.yml
|
||||||
|
azure-pipelines-ci.yml = azure-pipelines-ci.yml
|
||||||
|
azure-pipelines-linux.yml = azure-pipelines-linux.yml
|
||||||
|
azure-pipelines-nuget.yml = azure-pipelines-nuget.yml
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Org.RestClient", "src\WireMock.Org.RestClient\WireMock.Org.RestClient.csproj", "{08B29DB1-FEFE-408A-AD0A-6BA6DDC8D70F}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Org.Abstractions", "src\WireMock.Org.Abstractions\WireMock.Org.Abstractions.csproj", "{3BA5109E-5F30-4CC2-B699-02EC82560AA6}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -206,14 +220,14 @@ Global
|
|||||||
{6580580B-1EFD-4922-B0EC-FF290DB279EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6580580B-1EFD-4922-B0EC-FF290DB279EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6580580B-1EFD-4922-B0EC-FF290DB279EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6580580B-1EFD-4922-B0EC-FF290DB279EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6580580B-1EFD-4922-B0EC-FF290DB279EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6580580B-1EFD-4922-B0EC-FF290DB279EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{0DE14F1B-A51E-4B59-A87C-C6012DCD2844}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{08B29DB1-FEFE-408A-AD0A-6BA6DDC8D70F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{0DE14F1B-A51E-4B59-A87C-C6012DCD2844}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{08B29DB1-FEFE-408A-AD0A-6BA6DDC8D70F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{0DE14F1B-A51E-4B59-A87C-C6012DCD2844}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{08B29DB1-FEFE-408A-AD0A-6BA6DDC8D70F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{0DE14F1B-A51E-4B59-A87C-C6012DCD2844}.Release|Any CPU.Build.0 = Release|Any CPU
|
{08B29DB1-FEFE-408A-AD0A-6BA6DDC8D70F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{B6269AAC-170A-4346-8B9A-444DED3D9A44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{3BA5109E-5F30-4CC2-B699-02EC82560AA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{B6269AAC-170A-4346-8B9A-444DED3D9A44}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{3BA5109E-5F30-4CC2-B699-02EC82560AA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B6269AAC-170A-4346-8B9A-444DED3D9A44}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3BA5109E-5F30-4CC2-B699-02EC82560AA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B6269AAC-170A-4346-8B9A-444DED3D9A44}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3BA5109E-5F30-4CC2-B699-02EC82560AA6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -247,9 +261,11 @@ Global
|
|||||||
{40BF24B5-12E6-4610-9489-138798632E28} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
{40BF24B5-12E6-4610-9489-138798632E28} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
||||||
{3F8CF0AE-5F24-4A54-89E7-A3EE829DB5F8} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{3F8CF0AE-5F24-4A54-89E7-A3EE829DB5F8} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{B6269AAC-170A-4346-8B9A-444DED3D9A44} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
{B6269AAC-170A-4346-8B9A-444DED3D9A44} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
||||||
{B6269AAC-170A-4346-8B9A-444DED3D9A44} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
|
||||||
{6580580B-1EFD-4922-B0EC-FF290DB279EE} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{6580580B-1EFD-4922-B0EC-FF290DB279EE} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{0DE14F1B-A51E-4B59-A87C-C6012DCD2844} = {0BB8B634-407A-4610-A91F-11586990767A}
|
{1DAEFF47-D117-4E95-8B3E-4F7C8B92011A} = {7EFB2C5B-1BB2-4AAF-BC9F-216ED80C594D}
|
||||||
|
{5B64F6CA-BF6B-4F67-BB2A-9C47E441703E} = {7EFB2C5B-1BB2-4AAF-BC9F-216ED80C594D}
|
||||||
|
{08B29DB1-FEFE-408A-AD0A-6BA6DDC8D70F} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
||||||
|
{3BA5109E-5F30-4CC2-B699-02EC82560AA6} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
|
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=funcs/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=funcs/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raml/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stef/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stef/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Webhook/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Webhooks/@EntryIndexedValue">True</s:Boolean>
|
||||||
</wpf:ResourceDictionary>
|
</wpf:ResourceDictionary>
|
||||||
@@ -28,6 +28,7 @@ jobs:
|
|||||||
|
|
||||||
- task: SonarCloudPrepare@1
|
- task: SonarCloudPrepare@1
|
||||||
displayName: 'Prepare analysis on SonarCloud'
|
displayName: 'Prepare analysis on SonarCloud'
|
||||||
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
inputs:
|
inputs:
|
||||||
SonarCloud: SonarCloud
|
SonarCloud: SonarCloud
|
||||||
organization: wiremock-net
|
organization: wiremock-net
|
||||||
@@ -52,9 +53,11 @@ jobs:
|
|||||||
|
|
||||||
- task: SonarCloudAnalyze@1
|
- task: SonarCloudAnalyze@1
|
||||||
displayName: 'SonarCloud: Run Code Analysis'
|
displayName: 'SonarCloud: Run Code Analysis'
|
||||||
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
|
|
||||||
- task: SonarCloudPublish@1
|
- task: SonarCloudPublish@1
|
||||||
displayName: 'SonarCloud: Publish Quality Gate Result'
|
displayName: 'SonarCloud: Publish Quality Gate Result'
|
||||||
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
|
|
||||||
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
|
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
|
||||||
displayName: 'WhiteSource Bolt'
|
displayName: 'WhiteSource Bolt'
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ namespace WireMock.Net.Client
|
|||||||
var settings1 = await api.GetSettingsAsync();
|
var settings1 = await api.GetSettingsAsync();
|
||||||
Console.WriteLine($"settings1 = {JsonConvert.SerializeObject(settings1)}");
|
Console.WriteLine($"settings1 = {JsonConvert.SerializeObject(settings1)}");
|
||||||
|
|
||||||
|
var settingsViaBuilder = new FluentBuilder.SettingsModelBuilder()
|
||||||
|
.WithGlobalProcessingDelay(1077)
|
||||||
|
.WithoutGlobalProcessingDelay()
|
||||||
|
.Build();
|
||||||
|
|
||||||
settings1.GlobalProcessingDelay = 1077;
|
settings1.GlobalProcessingDelay = 1077;
|
||||||
api.PostSettingsAsync(settings1).Wait();
|
api.PostSettingsAsync(settings1).Wait();
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="RestEase" Version="1.4.10" />
|
<PackageReference Include="RestEase" Version="1.5.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
|
|
||||||
@@ -80,6 +80,12 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
return File.ReadAllBytes(AdjustPath(path));
|
return File.ReadAllBytes(AdjustPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IFileSystemHandler.ReadFileAsString"/>
|
||||||
|
public string ReadFileAsString(string path)
|
||||||
|
{
|
||||||
|
return File.ReadAllText(path);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adjusts the path to the MappingFolder.
|
/// Adjusts the path to the MappingFolder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using HandlebarsDotNet;
|
using HandlebarsDotNet;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -59,6 +59,10 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
//},
|
//},
|
||||||
PreWireMockMiddlewareInit = app => { System.Console.WriteLine($"PreWireMockMiddlewareInit : {app.GetType()}"); },
|
PreWireMockMiddlewareInit = app => { System.Console.WriteLine($"PreWireMockMiddlewareInit : {app.GetType()}"); },
|
||||||
PostWireMockMiddlewareInit = app => { System.Console.WriteLine($"PostWireMockMiddlewareInit : {app.GetType()}"); },
|
PostWireMockMiddlewareInit = app => { System.Console.WriteLine($"PostWireMockMiddlewareInit : {app.GetType()}"); },
|
||||||
|
|
||||||
|
#if USE_ASPNETCORE
|
||||||
|
AdditionalServiceRegistration = services => { System.Console.WriteLine($"AdditionalServiceRegistration : {services.GetType()}"); },
|
||||||
|
#endif
|
||||||
Logger = new WireMockConsoleLogger(),
|
Logger = new WireMockConsoleLogger(),
|
||||||
|
|
||||||
HandlebarsRegistrationCallback = (handlebarsContext, fileSystemHandler) =>
|
HandlebarsRegistrationCallback = (handlebarsContext, fileSystemHandler) =>
|
||||||
@@ -73,9 +77,17 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
System.Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
System.Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||||
|
|
||||||
server.SetBasicAuthentication("a", "b");
|
server.SetBasicAuthentication("a", "b");
|
||||||
|
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
|
||||||
|
|
||||||
// server.AllowPartialMapping();
|
// server.AllowPartialMapping();
|
||||||
|
|
||||||
|
server.Given(Request.Create().WithPath("/mypath").UsingPost())
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithHeader("Content-Type", "application/json")
|
||||||
|
.WithBodyAsJson("{{JsonPath.SelectToken request.body \"..name\"}}")
|
||||||
|
.WithTransformer()
|
||||||
|
);
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
|
.Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
|
||||||
.AtPriority(4)
|
.AtPriority(4)
|
||||||
|
|||||||
@@ -33,9 +33,12 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>..\..\WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>..\..\resources\WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="AnyOf, Version=0.2.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\AnyOf.0.2.0\lib\net45\AnyOf.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Handlebars, Version=2.0.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.0.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.0.4\lib\net452\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.0.4\lib\net452\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="AnyOf" version="0.2.0" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net" version="2.0.4" targetFramework="net452" />
|
<package id="Handlebars.Net" version="2.0.4" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net452" />
|
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net452" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net452" />
|
||||||
|
|||||||
@@ -35,6 +35,9 @@
|
|||||||
<StartupObject>WireMock.Net.ConsoleApplication.Program</StartupObject>
|
<StartupObject>WireMock.Net.ConsoleApplication.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="AnyOf, Version=0.2.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\AnyOf.0.2.0\lib\net45\AnyOf.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Handlebars, Version=2.0.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.0.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.0.4\lib\net46\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.0.4\lib\net46\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -47,6 +50,9 @@
|
|||||||
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="AnyOf" version="0.2.0" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net" version="2.0.4" targetFramework="net461" />
|
<package id="Handlebars.Net" version="2.0.4" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net461" />
|
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net461" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net461" />
|
||||||
<package id="log4net" version="2.0.12" targetFramework="net461" />
|
<package id="log4net" version="2.0.12" targetFramework="net461" />
|
||||||
|
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net461" />
|
||||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
|
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
|
||||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
||||||
<package id="System.ValueTuple" version="4.3.0" targetFramework="net461" />
|
<package id="System.ValueTuple" version="4.3.0" targetFramework="net461" />
|
||||||
|
|||||||
@@ -39,6 +39,9 @@
|
|||||||
<StartupObject>WireMock.Net.ConsoleApplication.Program</StartupObject>
|
<StartupObject>WireMock.Net.ConsoleApplication.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="AnyOf, Version=0.2.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\AnyOf.0.2.0\lib\net45\AnyOf.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Fare, Version=2.1.0.0, Culture=neutral, PublicKeyToken=ea68d375bf33a7c8, processorArchitecture=MSIL">
|
<Reference Include="Fare, Version=2.1.0.0, Culture=neutral, PublicKeyToken=ea68d375bf33a7c8, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Fare.2.1.1\lib\net35\Fare.dll</HintPath>
|
<HintPath>..\..\packages\Fare.2.1.1\lib\net35\Fare.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="AnyOf" version="0.2.0" targetFramework="net472" />
|
||||||
<package id="Fare" version="2.1.1" targetFramework="net472" />
|
<package id="Fare" version="2.1.1" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net" version="2.0.4" targetFramework="net472" />
|
<package id="Handlebars.Net" version="2.0.4" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net472" />
|
||||||
@@ -73,7 +74,7 @@
|
|||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
||||||
<package id="System.Security.Cryptography.Cng" version="4.5.0" targetFramework="net472" />
|
<package id="System.Security.Cryptography.Cng" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="net472" />
|
<package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="net472" />
|
<package id="System.Text.Encodings.Web" version="4.5.1" targetFramework="net472" />
|
||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net472" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net472" />
|
||||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="WireMock.Net" version="1.4.2" targetFramework="net472" />
|
<package id="WireMock.Net" version="1.4.2" targetFramework="net472" />
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
|
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
{
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"title": "Swagger Petstore",
|
||||||
|
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||||
|
"termsOfService": "http://swagger.io/terms/",
|
||||||
|
"contact": {
|
||||||
|
"name": "Swagger API Team"
|
||||||
|
},
|
||||||
|
"license": {
|
||||||
|
"name": "MIT"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"host": "petstore.swagger.io",
|
||||||
|
"basePath": "/api",
|
||||||
|
"schemes": [
|
||||||
|
"http"
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/pets": {
|
||||||
|
"get": {
|
||||||
|
"description": "Returns all pets from the system that the user has access to",
|
||||||
|
"operationId": "findPets",
|
||||||
|
"produces": [
|
||||||
|
"application/json",
|
||||||
|
"application/xml",
|
||||||
|
"text/xml",
|
||||||
|
"text/html"
|
||||||
|
],
|
||||||
|
"parameters": [{
|
||||||
|
"name": "tags",
|
||||||
|
"in": "query",
|
||||||
|
"description": "tags to filter by",
|
||||||
|
"required": false,
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"collectionFormat": "csv"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query",
|
||||||
|
"description": "maximum number of results to return",
|
||||||
|
"required": false,
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "pet response",
|
||||||
|
"schema": {
|
||||||
|
"example": [{
|
||||||
|
"name": "MEXAMPLE",
|
||||||
|
"tag": "MEXAMPLE",
|
||||||
|
"id": 9988
|
||||||
|
}, {
|
||||||
|
"name": "OtherExample",
|
||||||
|
"tag": "OtherExample",
|
||||||
|
"id": 8877
|
||||||
|
}],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Pet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ErrorModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"description": "Creates a new pet in the store. Duplicates are allowed",
|
||||||
|
"operationId": "addPet",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"parameters": [{
|
||||||
|
"name": "pet",
|
||||||
|
"in": "body",
|
||||||
|
"description": "Pet to add to the store",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/NewPet"
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "pet response",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Pet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ErrorModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/pet": {
|
||||||
|
"get": {
|
||||||
|
"description": "Returns a pet from the system that the user has access to",
|
||||||
|
"operationId": "findPet",
|
||||||
|
"produces": [
|
||||||
|
"application/json",
|
||||||
|
"application/xml",
|
||||||
|
"text/xml",
|
||||||
|
"text/html"
|
||||||
|
],
|
||||||
|
"parameters": [{
|
||||||
|
"name": "tags",
|
||||||
|
"in": "query",
|
||||||
|
"description": "tags to filter by",
|
||||||
|
"required": false,
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"collectionFormat": "csv"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query",
|
||||||
|
"description": "maximum number of results to return",
|
||||||
|
"required": false,
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "pet response",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Pet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ErrorModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/pets/{id}": {
|
||||||
|
"get": {
|
||||||
|
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
|
||||||
|
"operationId": "findPetById",
|
||||||
|
"produces": [
|
||||||
|
"application/json",
|
||||||
|
"application/xml",
|
||||||
|
"text/xml",
|
||||||
|
"text/html"
|
||||||
|
],
|
||||||
|
"parameters": [{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"description": "ID of pet to fetch",
|
||||||
|
"required": true,
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
}],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "pet response",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Pet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ErrorModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"description": "deletes a single pet based on the ID supplied",
|
||||||
|
"operationId": "deletePet",
|
||||||
|
"parameters": [{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"description": "ID of pet to delete",
|
||||||
|
"required": true,
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
}],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "pet deleted"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ErrorModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"Pet": {
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [{
|
||||||
|
"$ref": "#/definitions/NewPet"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"required": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"NewPet": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"tag": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ErrorModel": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"code",
|
||||||
|
"message"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"code": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,732 @@
|
|||||||
|
swagger: '2.0'
|
||||||
|
info:
|
||||||
|
description: 'This is a sample server Petstore server. Copied from https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml.'
|
||||||
|
version: 1.0.0
|
||||||
|
title: Swagger Petstore
|
||||||
|
termsOfService: 'http://swagger.io/terms/'
|
||||||
|
contact:
|
||||||
|
email: apiteam@swagger.io
|
||||||
|
license:
|
||||||
|
name: Apache-2.0
|
||||||
|
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
|
||||||
|
host: petstore.swagger.io
|
||||||
|
basePath: /v2
|
||||||
|
tags:
|
||||||
|
- name: pet
|
||||||
|
description: Everything about your Pets
|
||||||
|
externalDocs:
|
||||||
|
description: Find out more
|
||||||
|
url: 'http://swagger.io'
|
||||||
|
- name: store
|
||||||
|
description: Access to Petstore orders
|
||||||
|
- name: user
|
||||||
|
description: Operations about user
|
||||||
|
externalDocs:
|
||||||
|
description: Find out more about our store
|
||||||
|
url: 'http://swagger.io'
|
||||||
|
schemes:
|
||||||
|
- http
|
||||||
|
paths:
|
||||||
|
/pet:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Add a new pet to the store
|
||||||
|
description: ''
|
||||||
|
operationId: addPet
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
- application/xml
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: Pet object that needs to be added to the store
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Pet'
|
||||||
|
responses:
|
||||||
|
'405':
|
||||||
|
description: Invalid input
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Update an existing pet
|
||||||
|
description: ''
|
||||||
|
operationId: updatePet
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
- application/xml
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: Pet object that needs to be added to the store
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Pet'
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Pet not found
|
||||||
|
'405':
|
||||||
|
description: Validation exception
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
/pet/findByStatus:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Finds Pets by status
|
||||||
|
description: Multiple status values can be provided with comma separated strings
|
||||||
|
operationId: findPetsByStatus
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: status
|
||||||
|
in: query
|
||||||
|
description: Status values that need to be considered for filter
|
||||||
|
required: true
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- available
|
||||||
|
- pending
|
||||||
|
- sold
|
||||||
|
default: available
|
||||||
|
collectionFormat: csv
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid status value
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
/pet/findByTags:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Finds Pets by tags
|
||||||
|
description: 'Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.'
|
||||||
|
operationId: findPetsByTags
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: tags
|
||||||
|
in: query
|
||||||
|
description: Tags to filter by
|
||||||
|
required: true
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
collectionFormat: csv
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid tag value
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
deprecated: true
|
||||||
|
'/pet/{petId}':
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Find pet by ID
|
||||||
|
description: Returns a single pet
|
||||||
|
operationId: getPetById
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: ID of pet to return
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Pet not found
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Updates a pet in the store with form data
|
||||||
|
description: ''
|
||||||
|
operationId: updatePetWithForm
|
||||||
|
consumes:
|
||||||
|
- application/x-www-form-urlencoded
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: ID of pet that needs to be updated
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
- name: name
|
||||||
|
in: formData
|
||||||
|
description: Updated name of the pet
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
- name: status
|
||||||
|
in: formData
|
||||||
|
description: Updated status of the pet
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'405':
|
||||||
|
description: Invalid input
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Deletes a pet
|
||||||
|
description: ''
|
||||||
|
operationId: deletePet
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: api_key
|
||||||
|
in: header
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: Pet id to delete
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
'400':
|
||||||
|
description: Invalid pet value
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
'/pet/{petId}/uploadImage':
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: uploads an image
|
||||||
|
description: ''
|
||||||
|
operationId: uploadFile
|
||||||
|
consumes:
|
||||||
|
- multipart/form-data
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: ID of pet to update
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
- name: additionalMetadata
|
||||||
|
in: formData
|
||||||
|
description: Additional data to pass to server
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
- name: file
|
||||||
|
in: formData
|
||||||
|
description: file to upload
|
||||||
|
required: false
|
||||||
|
type: file
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ApiResponse'
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
/store/inventory:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Returns pet inventories by status
|
||||||
|
description: Returns a map of status codes to quantities
|
||||||
|
operationId: getInventory
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
parameters: []
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
/store/order:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Place an order for a pet
|
||||||
|
description: ''
|
||||||
|
operationId: placeOrder
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: order placed for purchasing the pet
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Order'
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Order'
|
||||||
|
'400':
|
||||||
|
description: Invalid Order
|
||||||
|
'/store/order/{orderId}':
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Find purchase order by ID
|
||||||
|
description: 'For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions'
|
||||||
|
operationId: getOrderById
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: orderId
|
||||||
|
in: path
|
||||||
|
description: ID of pet that needs to be fetched
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
maximum: 5
|
||||||
|
minimum: 1
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Order'
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Order not found
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Delete purchase order by ID
|
||||||
|
description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
|
operationId: deleteOrder
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: orderId
|
||||||
|
in: path
|
||||||
|
description: ID of the order that needs to be deleted
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Order not found
|
||||||
|
/user:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Create user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: createUser
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: Created user object
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
/user/createWithArray:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Creates list of users with given input array
|
||||||
|
description: ''
|
||||||
|
operationId: createUsersWithArrayInput
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: List of user object
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
/user/createWithList:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Creates list of users with given input array
|
||||||
|
description: ''
|
||||||
|
operationId: createUsersWithListInput
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: List of user object
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
/user/login:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Logs user into the system
|
||||||
|
description: ''
|
||||||
|
operationId: loginUser
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: query
|
||||||
|
description: The user name for login
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- name: password
|
||||||
|
in: query
|
||||||
|
description: The password for login in clear text
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
headers:
|
||||||
|
X-Rate-Limit:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
description: calls per hour allowed by the user
|
||||||
|
X-Expires-After:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
description: date in UTC when toekn expires
|
||||||
|
'400':
|
||||||
|
description: Invalid username/password supplied
|
||||||
|
/user/logout:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Logs out current logged in user session
|
||||||
|
description: ''
|
||||||
|
operationId: logoutUser
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters: []
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
'/user/{username}':
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Get user by user name
|
||||||
|
description: ''
|
||||||
|
operationId: getUserByName
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: path
|
||||||
|
description: 'The name that needs to be fetched. Use user1 for testing.'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
|
'400':
|
||||||
|
description: Invalid username supplied
|
||||||
|
'404':
|
||||||
|
description: User not found
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Updated user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: updateUser
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: path
|
||||||
|
description: name that need to be deleted
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- in: body
|
||||||
|
name: body
|
||||||
|
description: Updated user object
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid user supplied
|
||||||
|
'404':
|
||||||
|
description: User not found
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Delete user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: deleteUser
|
||||||
|
produces:
|
||||||
|
- application/xml
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: path
|
||||||
|
description: The name that needs to be deleted
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid username supplied
|
||||||
|
'404':
|
||||||
|
description: User not found
|
||||||
|
securityDefinitions:
|
||||||
|
petstore_auth:
|
||||||
|
type: oauth2
|
||||||
|
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
|
||||||
|
flow: implicit
|
||||||
|
scopes:
|
||||||
|
'write:pets': modify pets in your account
|
||||||
|
'read:pets': read your pets
|
||||||
|
api_key:
|
||||||
|
type: apiKey
|
||||||
|
name: api_key
|
||||||
|
in: header
|
||||||
|
definitions:
|
||||||
|
Order:
|
||||||
|
title: Pet Order
|
||||||
|
description: An order for a pets from the pet store
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
petId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
quantity:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
shipDate:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Order Status
|
||||||
|
enum:
|
||||||
|
- placed
|
||||||
|
- approved
|
||||||
|
- delivered
|
||||||
|
complete:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
xml:
|
||||||
|
name: Order
|
||||||
|
Category:
|
||||||
|
title: Pet category
|
||||||
|
description: A category for a pet
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
xml:
|
||||||
|
name: Category
|
||||||
|
User:
|
||||||
|
title: a User
|
||||||
|
description: A User who is purchasing from the pet store
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
phone:
|
||||||
|
type: string
|
||||||
|
userStatus:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
description: User Status
|
||||||
|
xml:
|
||||||
|
name: User
|
||||||
|
Tag:
|
||||||
|
title: Pet Tag
|
||||||
|
description: A tag for a pet
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
xml:
|
||||||
|
name: Tag
|
||||||
|
Pet:
|
||||||
|
title: a Pet
|
||||||
|
description: A pet for sale in the pet store
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
- photoUrls
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
category:
|
||||||
|
$ref: '#/definitions/Category'
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
example: doggie
|
||||||
|
photoUrls:
|
||||||
|
type: array
|
||||||
|
xml:
|
||||||
|
name: photoUrl
|
||||||
|
wrapped: true
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
tags:
|
||||||
|
type: array
|
||||||
|
xml:
|
||||||
|
name: tag
|
||||||
|
wrapped: true
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Tag'
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: pet status in the store
|
||||||
|
enum:
|
||||||
|
- available
|
||||||
|
- pending
|
||||||
|
- sold
|
||||||
|
xml:
|
||||||
|
name: Pet
|
||||||
|
ApiResponse:
|
||||||
|
title: An uploaded response
|
||||||
|
description: Describes the result of uploading an image resource
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
#issue: https://github.com/swagger-api/swagger-codegen/issues/7980
|
||||||
|
Amount:
|
||||||
|
type: object
|
||||||
|
description: >
|
||||||
|
some description
|
||||||
|
properties:
|
||||||
|
value:
|
||||||
|
format: double
|
||||||
|
type: number
|
||||||
|
minimum: 0.01
|
||||||
|
maximum: 1000000000000000
|
||||||
|
description: >
|
||||||
|
some description
|
||||||
|
currency:
|
||||||
|
$ref: '#/definitions/Currency'
|
||||||
|
required:
|
||||||
|
- value
|
||||||
|
- currency
|
||||||
|
Currency:
|
||||||
|
type: string
|
||||||
|
pattern: '^[A-Z]{3,3}$'
|
||||||
|
description: >
|
||||||
|
some description
|
||||||
|
externalDocs:
|
||||||
|
description: Find out more about Swagger
|
||||||
|
url: 'http://swagger.io'
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
openapi: "3.0.0"
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
title: Swagger Petstore
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
servers:
|
||||||
|
- url: http://petstore.swagger.io/v1
|
||||||
|
paths:
|
||||||
|
/pets:
|
||||||
|
get:
|
||||||
|
summary: List all pets
|
||||||
|
operationId: listPets
|
||||||
|
tags:
|
||||||
|
- pets
|
||||||
|
parameters:
|
||||||
|
- name: limit
|
||||||
|
in: query
|
||||||
|
description: How many items to return at one time (max 100)
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: An paged array of pets
|
||||||
|
headers:
|
||||||
|
x-next:
|
||||||
|
description: A link to the next page of responses
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Pets"
|
||||||
|
default:
|
||||||
|
description: unexpected error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
post:
|
||||||
|
summary: Create a pet
|
||||||
|
operationId: createPets
|
||||||
|
tags:
|
||||||
|
- pets
|
||||||
|
responses:
|
||||||
|
201:
|
||||||
|
description: Null response
|
||||||
|
default:
|
||||||
|
description: unexpected error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/pets/{petId}:
|
||||||
|
get:
|
||||||
|
summary: Info for a specific pet
|
||||||
|
operationId: showPetById
|
||||||
|
tags:
|
||||||
|
- pets
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The id of the pet to retrieve
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Expected response to a valid request
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Pets"
|
||||||
|
default:
|
||||||
|
description: unexpected error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Pet:
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- name
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
tag:
|
||||||
|
type: string
|
||||||
|
Pets:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/Pet"
|
||||||
|
Error:
|
||||||
|
required:
|
||||||
|
- code
|
||||||
|
- message
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
title: API_Test
|
||||||
|
version: v1
|
||||||
|
paths:
|
||||||
|
/WeatherForecast:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- WeatherForecast
|
||||||
|
parameters:
|
||||||
|
- in: "header"
|
||||||
|
name: X-Correlation-ID
|
||||||
|
type: "string"
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Success
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/WeatherForecast'
|
||||||
|
/leolplex:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- WeatherForecast
|
||||||
|
parameters:
|
||||||
|
- in: "header"
|
||||||
|
name: X-Correlation-ID
|
||||||
|
type: "string"
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Success
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
example:
|
||||||
|
- date: 2021-10-21T09:13:00.552+00:00
|
||||||
|
temperatureC: 111
|
||||||
|
temperatureF: 111
|
||||||
|
summary: Just-summary
|
||||||
|
- date: 2021-10-21T09:13:00.000+00:00
|
||||||
|
temperatureC: 222
|
||||||
|
temperatureF: 222
|
||||||
|
summary: Just-summary2
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/WeatherForecast'
|
||||||
|
/exampleop:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
example:
|
||||||
|
id: 1
|
||||||
|
name: get food
|
||||||
|
completed: false
|
||||||
|
schema:
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
completed:
|
||||||
|
type: boolean
|
||||||
|
completed_at:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
nullable: true
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- name
|
||||||
|
- completed
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
WeatherForecast:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
date:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
temperatureC:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
temperatureF:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
readOnly: true
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
additionalProperties: false
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
using Microsoft.OpenApi.Readers;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
@@ -7,15 +5,23 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
private const string Folder = "OpenApiFiles";
|
||||||
{
|
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
|
||||||
Formatting = Formatting.Indented
|
|
||||||
};
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Run.RunServer("petstore-openapi3.json");
|
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "https://localhost:9091/");
|
||||||
|
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "https://localhost:9092/");
|
||||||
|
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "https://localhost:9093/");
|
||||||
|
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "https://localhost:9094/");
|
||||||
|
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "https://localhost:9095/");
|
||||||
|
|
||||||
|
Console.WriteLine("Press any key to stop the servers");
|
||||||
|
Console.ReadKey();
|
||||||
|
|
||||||
|
serverOpenAPIExamples.Stop();
|
||||||
|
serverPetstore_V2_json.Stop();
|
||||||
|
serverPetstore_V2_yaml.Stop();
|
||||||
|
serverPetstore_V300_yaml.Stop();
|
||||||
|
serverPetstore_V302_json.Stop();
|
||||||
|
|
||||||
//IWireMockOpenApiParser parser = new WireMockOpenApiParser();
|
//IWireMockOpenApiParser parser = new WireMockOpenApiParser();
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,44 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
|
using WireMock.Net.OpenApiParser.Extensions;
|
||||||
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
|
using WireMock.Net.OpenApiParser.Types;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
using WireMock.Net.OpenApiParser.Extensions;
|
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.ConsoleApp
|
namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||||
{
|
{
|
||||||
public static class Run
|
public static class Run
|
||||||
{
|
{
|
||||||
public static void RunServer(string path)
|
public static WireMockServer RunServer(string path, string url, bool dynamicExamples = true)
|
||||||
{
|
{
|
||||||
string url1 = "http://localhost:9091/";
|
|
||||||
|
|
||||||
var server = WireMockServer.Start(new WireMockServerSettings
|
var server = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
AllowCSharpCodeMatcher = true,
|
AllowCSharpCodeMatcher = true,
|
||||||
Urls = new[] { url1 },
|
Urls = new[] { url },
|
||||||
StartAdminInterface = true,
|
StartAdminInterface = true,
|
||||||
ReadStaticMappings = false,
|
ReadStaticMappings = false,
|
||||||
WatchStaticMappings = false,
|
WatchStaticMappings = false,
|
||||||
WatchStaticMappingsInSubdirectories = false,
|
WatchStaticMappingsInSubdirectories = false,
|
||||||
Logger = new WireMockConsoleLogger(),
|
Logger = new WireMockConsoleLogger()
|
||||||
});
|
});
|
||||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||||
|
|
||||||
server.SetBasicAuthentication("a", "b");
|
server.SetBasicAuthentication("a", "b");
|
||||||
|
|
||||||
server.WithMappingFromOpenApiFile(path, out var diag);
|
var settings = new WireMockOpenApiParserSettings
|
||||||
|
{
|
||||||
|
DynamicExamples = dynamicExamples,
|
||||||
|
PathPatternToUse = ExampleValueType.Wildcard,
|
||||||
|
HeaderPatternToUse = ExampleValueType.Wildcard
|
||||||
|
};
|
||||||
|
|
||||||
Console.WriteLine("Press any key to stop the server");
|
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
||||||
System.Console.ReadKey();
|
|
||||||
server.Stop();
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RunServer(IEnumerable<MappingModel> mappings)
|
public static void RunServer(IEnumerable<MappingModel> mappings)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -15,6 +15,21 @@
|
|||||||
<None Update="infura.yaml">
|
<None Update="infura.yaml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="OpenApiFiles\openAPIExamples.yaml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="OpenApiFiles\Swagger_Petstore_V2.0.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="OpenApiFiles\Swagger_Petstore_V2.0.yaml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="OpenApiFiles\Swagger_Petstore_V3.0.0.yaml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="OpenApiFiles\Swagger_Petstore_V3.0.2.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="petstore-openapi3.json">
|
<None Update="petstore-openapi3.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
@@ -32,11 +32,8 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Handlebars, Version=1.9.5.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.1.9.5\lib\net452\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||||
</Reference>
|
|
||||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||||
@@ -57,6 +54,7 @@
|
|||||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll</HintPath>
|
<HintPath>..\..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Handlebars.Net" version="1.9.5" targetFramework="net452" />
|
<package id="log4net" version="2.0.12" targetFramework="net452" />
|
||||||
<package id="log4net" version="2.0.10" targetFramework="net452" />
|
|
||||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
|
||||||
@@ -12,6 +11,6 @@
|
|||||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
||||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
||||||
<package id="System.Net.Http" version="4.3.3" targetFramework="net452" />
|
<package id="System.Net.Http" version="4.3.4" targetFramework="net452" />
|
||||||
<package id="XPath2" version="1.1.0" targetFramework="net452" />
|
<package id="XPath2" version="1.1.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Config;
|
using log4net.Config;
|
||||||
using log4net.Repository;
|
using log4net.Repository;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.Net.StandAlone.NETCoreApp
|
namespace WireMock.Net.StandAlone.NETCoreApp
|
||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
||||||
// private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
// private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
||||||
|
|
||||||
private static int sleepTime = 30000;
|
private static int sleepTime = 30000;
|
||||||
private static WireMockServer _server;
|
private static WireMockServer _server;
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
|
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
|
||||||
|
|
||||||
if (!WireMockServerSettingsParser.TryParseArguments(args, out var settings, new WireMockLog4NetLogger()))
|
if (!WireMockServerSettingsParser.TryParseArguments(args, out var settings, new WireMockLog4NetLogger()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||||
|
|
||||||
_server = WireMockServer.Start(settings);
|
_server = WireMockServer.Start(settings);
|
||||||
|
|
||||||
_server.Given(Request.Create().WithPath("/api/sap")
|
_server.Given(Request.Create().WithPath("/api/sap")
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
.WithBody((IBodyData xmlData) => {
|
.WithBody((IBodyData xmlData) => {
|
||||||
@@ -43,37 +43,37 @@ namespace WireMock.Net.StandAlone.NETCoreApp
|
|||||||
}))
|
}))
|
||||||
.RespondWith(Response.Create().WithStatusCode(System.Net.HttpStatusCode.OK));
|
.RespondWith(Response.Create().WithStatusCode(System.Net.HttpStatusCode.OK));
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingAnyMethod())
|
.UsingAnyMethod())
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithTransformer()
|
.WithTransformer()
|
||||||
.WithBody("{{Random Type=\"Integer\" Min=100 Max=999999}} {{DateTime.Now}} {{DateTime.Now \"yyyy-MMM\"}} {{String.Format (DateTime.Now) \"MMM-dd\"}}"));
|
.WithBody("{{Random Type=\"Integer\" Min=100 Max=999999}} {{DateTime.Now}} {{DateTime.Now \"yyyy-MMM\"}} {{String.Format (DateTime.Now) \"MMM-dd\"}}"));
|
||||||
|
|
||||||
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
|
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
|
||||||
|
|
||||||
Console.CancelKeyPress += (s, e) =>
|
Console.CancelKeyPress += (s, e) =>
|
||||||
{
|
{
|
||||||
Stop("CancelKeyPress");
|
Stop("CancelKeyPress");
|
||||||
};
|
};
|
||||||
|
|
||||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
||||||
{
|
{
|
||||||
Stop("AssemblyLoadContext.Default.Unloading");
|
Stop("AssemblyLoadContext.Default.Unloading");
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running : {_server.IsStarted}");
|
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running : {_server.IsStarted}");
|
||||||
Thread.Sleep(sleepTime);
|
Thread.Sleep(sleepTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Stop(string why)
|
private static void Stop(string why)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
|
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
|
||||||
_server.Stop();
|
_server.Stop();
|
||||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
|
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"WireMock.Net.StandAlone.NETCoreApp": {
|
"WireMock.Net.StandAlone.NETCoreApp": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "--Urls https://localhost:10080 --WireMockLogger WireMockConsoleLogger"
|
"commandLineArgs": "--Urls http://localhost:9091 --WireMockLogger WireMockConsoleLogger"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
|
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
|
||||||
<StartupObject>WireMock.Net.StandAlone.NETCoreApp.Program</StartupObject>
|
<StartupObject>WireMock.Net.StandAlone.NETCoreApp.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,14 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>..\..\WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>..\..\resources\WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<StartupObject>WireMock.Net.StandAlone.Net452.Program</StartupObject>
|
<StartupObject>WireMock.Net.StandAlone.Net452.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.4.0.0\lib\net451\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.4.0.0\lib\net451\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||||
@@ -49,12 +49,14 @@
|
|||||||
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="System.Net.Http.Formatting, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Numerics" />
|
<Reference Include="System.Numerics" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="2.0.10" targetFramework="net452" />
|
<package id="log4net" version="2.0.12" targetFramework="net452" />
|
||||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net452" />
|
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Host.HttpListener" version="4.0.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Host.HttpListener" version="4.0.0" targetFramework="net452" />
|
||||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
||||||
|
|||||||
@@ -204,8 +204,8 @@
|
|||||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="RestEase, Version=1.4.10.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="RestEase, Version=1.5.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\RestEase.1.4.10\lib\net45\RestEase.dll</HintPath>
|
<HintPath>..\..\packages\RestEase.1.5.5\lib\net45\RestEase.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="SimMetrics.Net, Version=1.0.5.0, Culture=neutral, PublicKeyToken=c58dc06d59f3391b, processorArchitecture=MSIL">
|
<Reference Include="SimMetrics.Net, Version=1.0.5.0, Culture=neutral, PublicKeyToken=c58dc06d59f3391b, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll</HintPath>
|
<HintPath>..\..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll</HintPath>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
<package id="MimeKitLite" version="2.0.7" targetFramework="net461" />
|
<package id="MimeKitLite" version="2.0.7" targetFramework="net461" />
|
||||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
|
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
|
||||||
<package id="Owin" version="1.0" targetFramework="net461" />
|
<package id="Owin" version="1.0" targetFramework="net461" />
|
||||||
<package id="RestEase" version="1.4.10" targetFramework="net461" />
|
<package id="RestEase" version="1.5.5" targetFramework="net461" />
|
||||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
||||||
<package id="System.Buffers" version="4.5.0" targetFramework="net461" />
|
<package id="System.Buffers" version="4.5.0" targetFramework="net461" />
|
||||||
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net461" />
|
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net461" />
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
|
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
|
||||||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
|
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
|
||||||
<package id="System.Security.Principal.Windows" version="4.5.1" targetFramework="net461" />
|
<package id="System.Security.Principal.Windows" version="4.5.1" targetFramework="net461" />
|
||||||
<package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="net461" />
|
<package id="System.Text.Encodings.Web" version="4.5.1" targetFramework="net461" />
|
||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net461" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net461" />
|
||||||
<package id="XPath2" version="1.1.0" targetFramework="net461" />
|
<package id="XPath2" version="1.1.0" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -2,6 +2,5 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
|
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
|
||||||
<add key="coverlet" value="https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json" />
|
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Body Model
|
/// Body Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class BodyModel
|
public class BodyModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// ClientIPModel
|
/// ClientIPModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class ClientIPModel
|
public class ClientIPModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cookie Model
|
/// Cookie Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class CookieModel
|
public class CookieModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// EncodingModel
|
/// EncodingModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class EncodingModel
|
public class EncodingModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fault Model
|
/// Fault Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class FaultModel
|
public class FaultModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Header Model
|
/// Header Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class HeaderModel
|
public class HeaderModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using WireMock.Models;
|
||||||
|
|
||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MappingModel
|
/// MappingModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class MappingModel
|
public class MappingModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -12,6 +14,11 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid? Guid { get; set; }
|
public Guid? Guid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the TimeSettings when which this mapping should be used.
|
||||||
|
/// </summary>
|
||||||
|
public TimeSettingsModel TimeSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The unique title.
|
/// The unique title.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,5 +59,15 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// Saves this mapping as a static mapping file.
|
/// Saves this mapping as a static mapping file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? SaveToFile { get; set; }
|
public bool? SaveToFile { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Webhook.
|
||||||
|
/// </summary>
|
||||||
|
public WebhookModel Webhook { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Webhooks.
|
||||||
|
/// </summary>
|
||||||
|
public WebhookModel[] Webhooks { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MatcherModel
|
/// MatcherModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class MatcherModel
|
public class MatcherModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -11,15 +12,20 @@
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the pattern. Can be a string (default) or an object;
|
/// Gets or sets the pattern. Can be a string (default) or an object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Pattern { get; set; }
|
public object Pattern { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the patterns. Can be array of strings (default) or an array of objects;
|
/// Gets or sets the patterns. Can be array of strings (default) or an array of objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object[] Patterns { get; set; }
|
public object[] Patterns { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the pattern as a file.
|
||||||
|
/// </summary>
|
||||||
|
public string PatternAsFile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ignore case.
|
/// Gets or sets the ignore case.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Param Model
|
/// Param Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class ParamModel
|
public class ParamModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// PathModel
|
/// PathModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class PathModel
|
public class PathModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// RequestModel
|
/// RequestModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class RequestModel
|
public class RequestModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WireMock.Types;
|
|
||||||
|
|
||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ResponseModel
|
/// ResponseModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class ResponseModel
|
public class ResponseModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -83,6 +83,16 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int? Delay { get; set; }
|
public int? Delay { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the minimum random delay in milliseconds.
|
||||||
|
/// </summary>
|
||||||
|
public int? MinimumRandomDelay { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the maximum random delay in milliseconds.
|
||||||
|
/// </summary>
|
||||||
|
public int? MaximumRandomDelay { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Proxy URL.
|
/// Gets or sets the Proxy URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Status
|
/// Status
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class StatusModel
|
public class StatusModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace WireMock.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// TimeSettingsModel: Start, End and TTL
|
||||||
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
|
public class TimeSettingsModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the DateTime from which this mapping should be used. In case this is not defined, it's used (default behavior).
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? Start { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the DateTime from until this mapping should be used. In case this is not defined, it's used forever (default behavior).
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? End { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the TTL (Time To Live) in seconds for this mapping. In case this is not defined, it's used (default behavior).
|
||||||
|
/// </summary>
|
||||||
|
public int? TTL { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// UrlModel
|
/// UrlModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class UrlModel
|
public class UrlModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// WebProxy settings
|
/// WebProxy settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class WebProxyModel
|
public class WebProxyModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
14
src/WireMock.Net.Abstractions/Admin/Mappings/WebhookModel.cs
Normal file
14
src/WireMock.Net.Abstractions/Admin/Mappings/WebhookModel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace WireMock.Admin.Mappings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Webhook
|
||||||
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
|
public class WebhookModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Webhook Request.
|
||||||
|
/// </summary>
|
||||||
|
public WebhookRequestModel Request { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Admin.Mappings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// RequestModel
|
||||||
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
|
public class WebhookRequestModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Url.
|
||||||
|
/// </summary>
|
||||||
|
public string Url { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The methods
|
||||||
|
/// </summary>
|
||||||
|
public string Method { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the headers.
|
||||||
|
/// </summary>
|
||||||
|
public IDictionary<string, string> Headers { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the body.
|
||||||
|
/// </summary>
|
||||||
|
public string Body { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the body (as JSON object).
|
||||||
|
/// </summary>
|
||||||
|
public object BodyAsJson { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use ResponseMessage Transformer.
|
||||||
|
/// </summary>
|
||||||
|
public bool? UseTransformer { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the type of the transformer.
|
||||||
|
/// </summary>
|
||||||
|
public string TransformerType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace WireMock.Admin.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request Log Model
|
/// Request Log Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class LogEntryModel
|
public class LogEntryModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace WireMock.Admin.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// LogRequestMatchModel
|
/// LogRequestMatchModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class LogRequestMatchModel
|
public class LogRequestMatchModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace WireMock.Admin.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// RequestMessage Model
|
/// RequestMessage Model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class LogRequestModel
|
public class LogRequestModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace WireMock.Admin.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Response MessageModel
|
/// Response MessageModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class LogResponseModel
|
public class LogResponseModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// ScenarioStateModel
|
/// ScenarioStateModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class ScenarioStateModel
|
public class ScenarioStateModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Settings
|
/// Settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
public class SettingsModel
|
public class SettingsModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace WireMock.Handlers
|
namespace WireMock.Handlers
|
||||||
@@ -89,5 +89,12 @@ namespace WireMock.Handlers
|
|||||||
/// <param name="filename">The filename.</param>
|
/// <param name="filename">The filename.</param>
|
||||||
/// <returns>The file content as bytes.</returns>
|
/// <returns>The file content as bytes.</returns>
|
||||||
byte[] ReadFile([NotNull] string filename);
|
byte[] ReadFile([NotNull] string filename);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read a file as string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">The filename.</param>
|
||||||
|
/// <returns>The file content as a string.</returns>
|
||||||
|
string ReadFileAsString([NotNull] string filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
25
src/WireMock.Net.Abstractions/Models/ITimeSettings.cs
Normal file
25
src/WireMock.Net.Abstractions/Models/ITimeSettings.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace WireMock.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// TimeSettings: Start, End and TTL
|
||||||
|
/// </summary>
|
||||||
|
public interface ITimeSettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the DateTime from which this mapping should be used. In case this is not defined, it's used (default behavior).
|
||||||
|
/// </summary>
|
||||||
|
DateTime? Start { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the DateTime from until this mapping should be used. In case this is not defined, it's used forever (default behavior).
|
||||||
|
/// </summary>
|
||||||
|
DateTime? End { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the TTL (Time To Live) in seconds for this mapping. In case this is not defined, it's used (default behavior).
|
||||||
|
/// </summary>
|
||||||
|
int? TTL { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/WireMock.Net.Abstractions/Models/IWebhook.cs
Normal file
13
src/WireMock.Net.Abstractions/Models/IWebhook.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace WireMock.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IWebhook
|
||||||
|
/// </summary>
|
||||||
|
public interface IWebhook
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Request
|
||||||
|
/// </summary>
|
||||||
|
IWebhookRequest Request { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/WireMock.Net.Abstractions/Models/IWebhookRequest.cs
Normal file
42
src/WireMock.Net.Abstractions/Models/IWebhookRequest.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using WireMock.Types;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
|
namespace WireMock.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IWebhookRequest
|
||||||
|
/// </summary>
|
||||||
|
public interface IWebhookRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Webhook Url.
|
||||||
|
/// </summary>
|
||||||
|
string Url { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The method to use.
|
||||||
|
/// </summary>
|
||||||
|
string Method { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Headers to send.
|
||||||
|
/// </summary>
|
||||||
|
IDictionary<string, WireMockList<string>> Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body to send.
|
||||||
|
/// </summary>
|
||||||
|
IBodyData BodyData { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use Transformer.
|
||||||
|
/// </summary>
|
||||||
|
bool? UseTransformer { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The transformer type.
|
||||||
|
/// </summary>
|
||||||
|
TransformerType TransformerType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -104,9 +104,9 @@ namespace WireMock.Server
|
|||||||
void ReadStaticMappings([CanBeNull] string folder = null);
|
void ReadStaticMappings([CanBeNull] string folder = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the basic authentication.
|
/// Removes the authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void RemoveBasicAuthentication();
|
void RemoveAuthentication();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets LogEntries and Mappings.
|
/// Resets LogEntries and Mappings.
|
||||||
@@ -134,6 +134,13 @@ namespace WireMock.Server
|
|||||||
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
||||||
void SaveStaticMappings([CanBeNull] string folder = null);
|
void SaveStaticMappings([CanBeNull] string folder = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the basic authentication.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tenant">The Tenant.</param>
|
||||||
|
/// <param name="audience">The Audience or Resource.</param>
|
||||||
|
void SetAzureADAuthentication([NotNull] string tenant, [NotNull] string audience);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the basic authentication.
|
/// Sets the basic authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,37 +1,46 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>Commonly used interfaces, models, enumerations and types.</Description>
|
<Description>Commonly used models, enumerations and types.</Description>
|
||||||
<AssemblyTitle>WireMock.Net.Abstractions</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.Abstractions</AssemblyTitle>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>net45;netstandard1.0;netstandard2.0;netstandard2.1</TargetFrameworks>
|
<TargetFrameworks>net45;netstandard1.0;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
|
||||||
<AssemblyName>WireMock.Net.Abstractions</AssemblyName>
|
|
||||||
<PackageId>WireMock.Net.Abstractions</PackageId>
|
|
||||||
<PackageTags>wiremock;interfaces;models;classes;enumerations;types</PackageTags>
|
|
||||||
<RootNamespace>WireMock</RootNamespace>
|
|
||||||
<ProjectGuid>{B6269AAC-170A-4346-8B9A-579DED3D9A94}</ProjectGuid>
|
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
|
||||||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
|
|
||||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
|
||||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
|
||||||
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<SignAssembly>true</SignAssembly>
|
|
||||||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
|
||||||
<!--<DelaySign>true</DelaySign>-->
|
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<!--<PathMap>$(MSBuildProjectDirectory)=/</PathMap>-->
|
<NoWarn>$(NoWarn);1591;8603</NoWarn>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<AssemblyName>WireMock.Net.Abstractions</AssemblyName>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
<PackageId>WireMock.Net.Abstractions</PackageId>
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageTags>wiremock;wiremock.org;interfaces;models;classes;enumerations;types</PackageTags>
|
||||||
</ItemGroup>
|
<RootNamespace>WireMock</RootNamespace>
|
||||||
|
<ProjectGuid>{B6269AAC-170A-4346-8B9A-579DED3D9A94}</ProjectGuid>
|
||||||
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
|
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
|
||||||
|
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||||
|
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<SignAssembly>true</SignAssembly>
|
||||||
|
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
||||||
|
<!--<DelaySign>true</DelaySign>-->
|
||||||
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<!--<PathMap>$(MSBuildProjectDirectory)=/</PathMap>-->
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||||
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
|
|
||||||
|
<!-- See also https://mstack.nl/blog/20210801-source-generators -->
|
||||||
|
<PackageReference Include="FluentBuilder" Version="0.0.11">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -36,7 +36,7 @@ namespace WireMock.FluentAssertions
|
|||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value, string because = "", params object[] becauseArgs)
|
||||||
=> WithHeader(expectedKey, new[] {value}, because, becauseArgs);
|
=> WithHeader(expectedKey, new[] { value }, because, becauseArgs);
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
|
||||||
@@ -69,7 +69,7 @@ namespace WireMock.FluentAssertions
|
|||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> AtUrl(string url, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> AtUrl(string url, string because = "", params object[] becauseArgs)
|
||||||
{
|
{
|
||||||
@@ -85,10 +85,10 @@ namespace WireMock.FluentAssertions
|
|||||||
.FailWith(
|
.FailWith(
|
||||||
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but didn't find it among the calls to {1}.",
|
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but didn't find it among the calls to {1}.",
|
||||||
_ => url, requests => requests.Select(request => request.Url));
|
_ => url, requests => requests.Select(request => request.Url));
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> WithProxyUrl(string proxyUrl, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> WithProxyUrl(string proxyUrl, string because = "", params object[] becauseArgs)
|
||||||
{
|
{
|
||||||
@@ -104,10 +104,10 @@ namespace WireMock.FluentAssertions
|
|||||||
.FailWith(
|
.FailWith(
|
||||||
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but didn't find it among the calls with {1}.",
|
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but didn't find it among the calls with {1}.",
|
||||||
_ => proxyUrl, requests => requests.Select(request => request.ProxyUrl));
|
_ => proxyUrl, requests => requests.Select(request => request.ProxyUrl));
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> FromClientIP(string clientIP, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> FromClientIP(string clientIP, string because = "", params object[] becauseArgs)
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ namespace WireMock.FluentAssertions
|
|||||||
.FailWith(
|
.FailWith(
|
||||||
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but didn't find it among the calls from IP(s) {1}.",
|
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but didn't find it among the calls from IP(s) {1}.",
|
||||||
_ => clientIP, requests => requests.Select(request => request.ClientIP));
|
_ => clientIP, requests => requests.Select(request => request.ClientIP));
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,39 @@ using WireMock.Server;
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions
|
namespace WireMock.FluentAssertions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
|
||||||
|
/// </summary>
|
||||||
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
|
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
|
||||||
{
|
{
|
||||||
public WireMockReceivedAssertions(IWireMockServer server)
|
/// <summary>
|
||||||
|
/// Create a WireMockReceivedAssertions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server">The <see cref="IWireMockServer"/>.</param>
|
||||||
|
public WireMockReceivedAssertions(IWireMockServer server) : base(server)
|
||||||
{
|
{
|
||||||
Subject = server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asserts if <see cref="IWireMockServer"/> has received a call.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see cref="WireMockAssertions"/></returns>
|
||||||
public WireMockAssertions HaveReceivedACall()
|
public WireMockAssertions HaveReceivedACall()
|
||||||
{
|
{
|
||||||
return new WireMockAssertions(Subject, null);
|
return new WireMockAssertions(Subject, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asserts if <see cref="IWireMockServer"/> has received n-calls.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callsCount"></param>
|
||||||
|
/// <returns><see cref="WireMockANumberOfCallsAssertions"/></returns>
|
||||||
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
|
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
|
||||||
{
|
{
|
||||||
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
|
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ReferenceTypeAssertions{IWireMockServer, WireMockReceivedAssertions}.Identifier"/>
|
||||||
protected override string Identifier => "wiremockserver";
|
protected override string Identifier => "wiremockserver";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,16 @@ using WireMock.Server;
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions
|
namespace WireMock.FluentAssertions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for custom assertions in unit tests.
|
||||||
|
/// </summary>
|
||||||
public static class WireMockExtensions
|
public static class WireMockExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a <see cref="WireMockReceivedAssertions"/> object that can be used to assert the current <see cref="IWireMockServer"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="instance">The WireMockServer</param>
|
||||||
|
/// <returns><see cref="WireMockReceivedAssertions"/></returns>
|
||||||
public static WireMockReceivedAssertions Should(this IWireMockServer instance)
|
public static WireMockReceivedAssertions Should(this IWireMockServer instance)
|
||||||
{
|
{
|
||||||
return new WireMockReceivedAssertions(instance);
|
return new WireMockReceivedAssertions(instance);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>FluentAssertions extensions for WireMock.Net</Description>
|
<Description>FluentAssertions extensions for WireMock.Net</Description>
|
||||||
@@ -29,13 +29,20 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'net451' or '$(TargetFramework)' == 'netstandard1.3'">
|
||||||
|
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' != 'net451' and '$(TargetFramework)' != 'netstandard1.3'">
|
||||||
|
<PackageReference Include="FluentAssertions" Version="6.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,225 +1,228 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using JetBrains.Annotations;
|
using AnyOfTypes;
|
||||||
using Newtonsoft.Json.Linq;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Exceptions;
|
using Newtonsoft.Json.Linq;
|
||||||
using WireMock.Validation;
|
using WireMock.Exceptions;
|
||||||
|
using WireMock.Extensions;
|
||||||
namespace WireMock.Matchers
|
using WireMock.Models;
|
||||||
{
|
using WireMock.Validation;
|
||||||
/// <summary>
|
|
||||||
/// CSharpCode / CS-Script Matcher
|
namespace WireMock.Matchers
|
||||||
/// </summary>
|
{
|
||||||
/// <inheritdoc cref="ICSharpCodeMatcher"/>
|
/// <summary>
|
||||||
internal class CSharpCodeMatcher : ICSharpCodeMatcher
|
/// CSharpCode / CS-Script Matcher
|
||||||
{
|
/// </summary>
|
||||||
private const string TemplateForIsMatchWithString = "public class CodeHelper {{ public bool IsMatch(string it) {{ {0} }} }}";
|
/// <inheritdoc cref="ICSharpCodeMatcher"/>
|
||||||
|
internal class CSharpCodeMatcher : ICSharpCodeMatcher
|
||||||
private const string TemplateForIsMatchWithDynamic = "public class CodeHelper {{ public bool IsMatch(dynamic it) {{ {0} }} }}";
|
{
|
||||||
|
private const string TemplateForIsMatchWithString = "public class CodeHelper {{ public bool IsMatch(string it) {{ {0} }} }}";
|
||||||
private readonly string[] _usings =
|
|
||||||
{
|
private const string TemplateForIsMatchWithDynamic = "public class CodeHelper {{ public bool IsMatch(dynamic it) {{ {0} }} }}";
|
||||||
"System",
|
|
||||||
"System.Linq",
|
private readonly string[] _usings =
|
||||||
"System.Collections.Generic",
|
{
|
||||||
"Microsoft.CSharp",
|
"System",
|
||||||
"Newtonsoft.Json.Linq"
|
"System.Linq",
|
||||||
};
|
"System.Collections.Generic",
|
||||||
|
"Microsoft.CSharp",
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
"Newtonsoft.Json.Linq"
|
||||||
|
};
|
||||||
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
|
||||||
public bool ThrowException { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
private readonly string[] _patterns;
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="CSharpCodeMatcher"/> class.
|
private readonly AnyOf<string, StringPattern>[] _patterns;
|
||||||
/// </summary>
|
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <summary>
|
||||||
public CSharpCodeMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
/// Initializes a new instance of the <see cref="CSharpCodeMatcher"/> class.
|
||||||
{
|
/// </summary>
|
||||||
}
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
public CSharpCodeMatcher([NotNull] params AnyOf<string, StringPattern>[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
||||||
/// <summary>
|
{
|
||||||
/// Initializes a new instance of the <see cref="CSharpCodeMatcher"/> class.
|
}
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// Initializes a new instance of the <see cref="CSharpCodeMatcher"/> class.
|
||||||
public CSharpCodeMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
|
/// </summary>
|
||||||
{
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
public CSharpCodeMatcher(MatchBehaviour matchBehaviour, [NotNull] params AnyOf<string, StringPattern>[] patterns)
|
||||||
MatchBehaviour = matchBehaviour;
|
{
|
||||||
ThrowException = false;
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
_patterns = patterns;
|
|
||||||
}
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = false;
|
||||||
public double IsMatch(string input)
|
_patterns = patterns;
|
||||||
{
|
}
|
||||||
return IsMatchInternal(input);
|
|
||||||
}
|
public double IsMatch(string input)
|
||||||
|
{
|
||||||
public double IsMatch(object input)
|
return IsMatchInternal(input);
|
||||||
{
|
}
|
||||||
return IsMatchInternal(input);
|
|
||||||
}
|
public double IsMatch(object input)
|
||||||
|
{
|
||||||
public double IsMatchInternal(object input)
|
return IsMatchInternal(input);
|
||||||
{
|
}
|
||||||
double match = MatchScores.Mismatch;
|
|
||||||
|
public double IsMatchInternal(object input)
|
||||||
if (input != null)
|
{
|
||||||
{
|
double match = MatchScores.Mismatch;
|
||||||
match = MatchScores.ToScore(_patterns.Select(pattern => IsMatch(input, pattern)));
|
|
||||||
}
|
if (input != null)
|
||||||
|
|
||||||
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsMatch(dynamic input, string pattern)
|
|
||||||
{
|
|
||||||
bool isMatchWithString = input is string;
|
|
||||||
var inputValue = isMatchWithString ? input : JObject.FromObject(input);
|
|
||||||
string source = GetSourceForIsMatchWithString(pattern, isMatchWithString);
|
|
||||||
|
|
||||||
object result = null;
|
|
||||||
|
|
||||||
#if (NET451 || NET452)
|
|
||||||
var compilerParams = new System.CodeDom.Compiler.CompilerParameters
|
|
||||||
{
|
|
||||||
GenerateInMemory = true,
|
|
||||||
GenerateExecutable = false,
|
|
||||||
ReferencedAssemblies =
|
|
||||||
{
|
|
||||||
"System.dll",
|
|
||||||
"System.Core.dll",
|
|
||||||
"Microsoft.CSharp.dll",
|
|
||||||
"Newtonsoft.Json.dll"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var codeProvider = new Microsoft.CSharp.CSharpCodeProvider())
|
|
||||||
{
|
|
||||||
var compilerResults = codeProvider.CompileAssemblyFromSource(compilerParams, source);
|
|
||||||
|
|
||||||
if (compilerResults.Errors.Count != 0)
|
|
||||||
{
|
|
||||||
var errors = from System.CodeDom.Compiler.CompilerError er in compilerResults.Errors select er.ToString();
|
|
||||||
throw new WireMockException(string.Join(", ", errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
object helper = compilerResults.CompiledAssembly.CreateInstance("CodeHelper");
|
|
||||||
if (helper == null)
|
|
||||||
{
|
|
||||||
throw new WireMockException("CSharpCodeMatcher: Unable to create instance from WireMock.CodeHelper");
|
|
||||||
}
|
|
||||||
|
|
||||||
var methodInfo = helper.GetType().GetMethod("IsMatch");
|
|
||||||
if (methodInfo == null)
|
|
||||||
{
|
|
||||||
throw new WireMockException("CSharpCodeMatcher: Unable to find method 'IsMatch' in WireMock.CodeHelper");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
result = methodInfo.Invoke(helper, new[] { inputValue });
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new WireMockException("CSharpCodeMatcher: Unable to call method 'IsMatch' in WireMock.CodeHelper", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif (NET46 || NET461)
|
|
||||||
dynamic script;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
script = CSScriptLibrary.CSScript.Evaluator.CompileCode(source).CreateObject("*");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new WireMockException("CSharpCodeMatcher: Unable to create compiler for WireMock.CodeHelper", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
result = script.IsMatch(inputValue);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1 || NET5_0)
|
|
||||||
Assembly assembly;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
assembly = CSScriptLib.CSScript.Evaluator.CompileCode(source);
|
match = MatchScores.ToScore(_patterns.Select(pattern => IsMatch(input, pattern.GetPattern())));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
throw new WireMockException($"CSharpCodeMatcher: Unable to compile code `{source}` for WireMock.CodeHelper", ex);
|
}
|
||||||
}
|
|
||||||
|
private bool IsMatch(dynamic input, string pattern)
|
||||||
dynamic script;
|
{
|
||||||
|
bool isMatchWithString = input is string;
|
||||||
|
var inputValue = isMatchWithString ? input : JObject.FromObject(input);
|
||||||
|
string source = GetSourceForIsMatchWithString(pattern, isMatchWithString);
|
||||||
|
|
||||||
|
object result = null;
|
||||||
|
|
||||||
|
#if (NET451 || NET452)
|
||||||
|
var compilerParams = new System.CodeDom.Compiler.CompilerParameters
|
||||||
|
{
|
||||||
|
GenerateInMemory = true,
|
||||||
|
GenerateExecutable = false,
|
||||||
|
ReferencedAssemblies =
|
||||||
|
{
|
||||||
|
"System.dll",
|
||||||
|
"System.Core.dll",
|
||||||
|
"Microsoft.CSharp.dll",
|
||||||
|
"Newtonsoft.Json.dll"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using (var codeProvider = new Microsoft.CSharp.CSharpCodeProvider())
|
||||||
|
{
|
||||||
|
var compilerResults = codeProvider.CompileAssemblyFromSource(compilerParams, source);
|
||||||
|
|
||||||
|
if (compilerResults.Errors.Count != 0)
|
||||||
|
{
|
||||||
|
var errors = from System.CodeDom.Compiler.CompilerError er in compilerResults.Errors select er.ToString();
|
||||||
|
throw new WireMockException(string.Join(", ", errors));
|
||||||
|
}
|
||||||
|
|
||||||
|
object helper = compilerResults.CompiledAssembly.CreateInstance("CodeHelper");
|
||||||
|
if (helper == null)
|
||||||
|
{
|
||||||
|
throw new WireMockException("CSharpCodeMatcher: Unable to create instance from WireMock.CodeHelper");
|
||||||
|
}
|
||||||
|
|
||||||
|
var methodInfo = helper.GetType().GetMethod("IsMatch");
|
||||||
|
if (methodInfo == null)
|
||||||
|
{
|
||||||
|
throw new WireMockException("CSharpCodeMatcher: Unable to find method 'IsMatch' in WireMock.CodeHelper");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = methodInfo.Invoke(helper, new[] { inputValue });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new WireMockException("CSharpCodeMatcher: Unable to call method 'IsMatch' in WireMock.CodeHelper", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif (NET46 || NET461)
|
||||||
|
dynamic script;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if NETSTANDARD2_0
|
script = CSScriptLibrary.CSScript.Evaluator.CompileCode(source).CreateObject("*");
|
||||||
script = csscript.GenericExtensions.CreateObject(assembly, "*");
|
}
|
||||||
#else
|
catch (Exception ex)
|
||||||
script = CSScriptLib.ReflectionExtensions.CreateObject(assembly, "*");
|
{
|
||||||
|
throw new WireMockException("CSharpCodeMatcher: Unable to create compiler for WireMock.CodeHelper", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = script.IsMatch(inputValue);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1 || NET5_0)
|
||||||
|
Assembly assembly;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
assembly = CSScriptLib.CSScript.Evaluator.CompileCode(source);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new WireMockException($"CSharpCodeMatcher: Unable to compile code `{source}` for WireMock.CodeHelper", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamic script;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#if NETSTANDARD2_0
|
||||||
|
script = csscript.GenericExtensions.CreateObject(assembly, "*");
|
||||||
|
#else
|
||||||
|
script = CSScriptLib.ReflectionExtensions.CreateObject(assembly, "*");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new WireMockException("CSharpCodeMatcher: Unable to create object from assembly", ex);
|
throw new WireMockException("CSharpCodeMatcher: Unable to create object from assembly", ex);
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
result = script.IsMatch(inputValue);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
|
try
|
||||||
#endif
|
{
|
||||||
try
|
result = script.IsMatch(inputValue);
|
||||||
{
|
}
|
||||||
return (bool)result;
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
catch
|
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
||||||
{
|
}
|
||||||
throw new WireMockException($"Unable to cast result '{result}' to bool");
|
#else
|
||||||
}
|
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
|
||||||
}
|
#endif
|
||||||
|
try
|
||||||
private string GetSourceForIsMatchWithString(string pattern, bool isMatchWithString)
|
{
|
||||||
{
|
return (bool)result;
|
||||||
string template = isMatchWithString ? TemplateForIsMatchWithString : TemplateForIsMatchWithDynamic;
|
}
|
||||||
|
catch
|
||||||
var stringBuilder = new StringBuilder();
|
{
|
||||||
|
throw new WireMockException($"Unable to cast result '{result}' to bool");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetSourceForIsMatchWithString(string pattern, bool isMatchWithString)
|
||||||
|
{
|
||||||
|
string template = isMatchWithString ? TemplateForIsMatchWithString : TemplateForIsMatchWithDynamic;
|
||||||
|
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
foreach (string @using in _usings)
|
foreach (string @using in _usings)
|
||||||
{
|
{
|
||||||
stringBuilder.AppendLine($"using {@using};");
|
stringBuilder.AppendLine($"using {@using};");
|
||||||
}
|
}
|
||||||
stringBuilder.AppendLine();
|
stringBuilder.AppendLine();
|
||||||
stringBuilder.AppendFormat(template, pattern);
|
stringBuilder.AppendFormat(template, pattern);
|
||||||
|
|
||||||
return stringBuilder.ToString();
|
return stringBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
||||||
public string[] GetPatterns()
|
public AnyOf<string, StringPattern>[] GetPatterns()
|
||||||
{
|
{
|
||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.Name"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public string Name => "CSharpCodeMatcher";
|
public string Name => "CSharpCodeMatcher";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<Target Name="CheckIfShouldKillVBCSCompiler" />
|
<Target Name="CheckIfShouldKillVBCSCompiler" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
|
|
||||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#if NET46 || NETSTANDARD2_0
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Extensions
|
||||||
|
{
|
||||||
|
internal static class DictionaryExtensions
|
||||||
|
{
|
||||||
|
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
|
||||||
|
{
|
||||||
|
if (dictionary is null || dictionary.ContainsKey(key))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary[key] = value;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Microsoft.OpenApi.Readers;
|
using Microsoft.OpenApi.Readers;
|
||||||
|
using SharpYaml.Model;
|
||||||
|
using Stef.Validation;
|
||||||
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Extensions
|
namespace WireMock.Net.OpenApiParser.Extensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Some extension methods for <see cref="IWireMockServer"/>.
|
||||||
|
/// </summary>
|
||||||
public static class WireMockServerExtensions
|
public static class WireMockServerExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -15,18 +22,26 @@ namespace WireMock.Net.OpenApiParser.Extensions
|
|||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
||||||
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
||||||
|
[PublicAPI]
|
||||||
public static IWireMockServer WithMappingFromOpenApiFile(this IWireMockServer server, string path, out OpenApiDiagnostic diagnostic)
|
public static IWireMockServer WithMappingFromOpenApiFile(this IWireMockServer server, string path, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
if (server == null)
|
return WithMappingFromOpenApiFile(server, path, null, out diagnostic);
|
||||||
{
|
}
|
||||||
throw new ArgumentNullException(nameof(server));
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(path))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
var mappings = new WireMockOpenApiParser().FromFile(path, out diagnostic);
|
/// <summary>
|
||||||
|
/// Register the mappings via an OpenAPI (swagger) V2 or V3 file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
|
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
||||||
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
||||||
|
/// <param name="settings">Additional settings</param>
|
||||||
|
[PublicAPI]
|
||||||
|
public static IWireMockServer WithMappingFromOpenApiFile(this IWireMockServer server, string path, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
||||||
|
{
|
||||||
|
Guard.NotNull(server, nameof(server));
|
||||||
|
Guard.NotNullOrEmpty(path, nameof(path));
|
||||||
|
|
||||||
|
var mappings = new WireMockOpenApiParser().FromFile(path, settings, out diagnostic);
|
||||||
|
|
||||||
return server.WithMapping(mappings.ToArray());
|
return server.WithMapping(mappings.ToArray());
|
||||||
}
|
}
|
||||||
@@ -37,9 +52,27 @@ namespace WireMock.Net.OpenApiParser.Extensions
|
|||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
||||||
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
||||||
|
[PublicAPI]
|
||||||
public static IWireMockServer WithMappingFromOpenApiStream(this IWireMockServer server, Stream stream, out OpenApiDiagnostic diagnostic)
|
public static IWireMockServer WithMappingFromOpenApiStream(this IWireMockServer server, Stream stream, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
var mappings = new WireMockOpenApiParser().FromStream(stream, out diagnostic);
|
return WithMappingFromOpenApiStream(server, stream, null, out diagnostic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Register the mappings via an OpenAPI (swagger) V2 or V3 stream.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
|
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
||||||
|
/// <param name="settings">Additional settings</param>
|
||||||
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
||||||
|
[PublicAPI]
|
||||||
|
public static IWireMockServer WithMappingFromOpenApiStream(this IWireMockServer server, Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
||||||
|
{
|
||||||
|
Guard.NotNull(server, nameof(server));
|
||||||
|
Guard.NotNull(stream, nameof(stream));
|
||||||
|
Guard.NotNull(settings, nameof(settings));
|
||||||
|
|
||||||
|
var mappings = new WireMockOpenApiParser().FromStream(stream, settings, out diagnostic);
|
||||||
|
|
||||||
return server.WithMapping(mappings.ToArray());
|
return server.WithMapping(mappings.ToArray());
|
||||||
}
|
}
|
||||||
@@ -49,9 +82,14 @@ namespace WireMock.Net.OpenApiParser.Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="document">The OpenAPI document to use as mappings.</param>
|
/// <param name="document">The OpenAPI document to use as mappings.</param>
|
||||||
public static IWireMockServer WithMappingFromOpenApiDocument(this IWireMockServer server, OpenApiDocument document)
|
/// <param name="settings">Additional settings [optional]</param>
|
||||||
|
[PublicAPI]
|
||||||
|
public static IWireMockServer WithMappingFromOpenApiDocument(this IWireMockServer server, OpenApiDocument document, WireMockOpenApiParserSettings settings = null)
|
||||||
{
|
{
|
||||||
var mappings = new WireMockOpenApiParser().FromDocument(document);
|
Guard.NotNull(server, nameof(server));
|
||||||
|
Guard.NotNull(document, nameof(document));
|
||||||
|
|
||||||
|
var mappings = new WireMockOpenApiParser().FromDocument(document, settings);
|
||||||
|
|
||||||
return server.WithMapping(mappings.ToArray());
|
return server.WithMapping(mappings.ToArray());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,57 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Microsoft.OpenApi.Readers;
|
using Microsoft.OpenApi.Readers;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
namespace WireMock.Net.OpenApiParser
|
|
||||||
{
|
namespace WireMock.Net.OpenApiParser
|
||||||
/// <summary>
|
{
|
||||||
/// Parse a OpenApi/Swagger/V2/V3 or Raml to WireMock MappingModels.
|
/// <summary>
|
||||||
/// </summary>
|
/// Parse a OpenApi/Swagger/V2/V3 or Raml to WireMock MappingModels.
|
||||||
public interface IWireMockOpenApiParser
|
/// </summary>
|
||||||
{
|
public interface IWireMockOpenApiParser
|
||||||
/// <summary>
|
{
|
||||||
/// Generate <see cref="IEnumerable{MappingModel}"/> from an <seealso cref="OpenApiDocument"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="document">The source OpenApiDocument</param>
|
|
||||||
/// <returns>MappingModel</returns>
|
|
||||||
IEnumerable<MappingModel> FromDocument(OpenApiDocument document);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate <see cref="IEnumerable{MappingModel}"/> from a <seealso cref="Stream"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="stream">The source stream</param>
|
|
||||||
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
|
||||||
/// <returns>MappingModel</returns>
|
|
||||||
IEnumerable<MappingModel> FromStream(Stream stream, out OpenApiDiagnostic diagnostic);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IEnumerable{MappingModel}"/> from a file-path.
|
/// Generate <see cref="IEnumerable{MappingModel}"/> from a file-path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3 or Raml file.</param>
|
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3 or Raml file.</param>
|
||||||
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
/// <returns>MappingModel</returns>
|
/// <returns>MappingModel</returns>
|
||||||
IEnumerable<MappingModel> FromFile(string path, out OpenApiDiagnostic diagnostic);
|
IEnumerable<MappingModel> FromFile(string path, out OpenApiDiagnostic diagnostic);
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate <see cref="IEnumerable{MappingModel}"/> from a file-path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3 or Raml file.</param>
|
||||||
|
/// <param name="settings">Additional settings</param>
|
||||||
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
|
/// <returns>MappingModel</returns>
|
||||||
|
IEnumerable<MappingModel> FromFile(string path, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate <see cref="IEnumerable{MappingModel}"/> from an <seealso cref="OpenApiDocument"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="document">The source OpenApiDocument</param>
|
||||||
|
/// <param name="settings">Additional settings [optional]</param>
|
||||||
|
/// <returns>MappingModel</returns>
|
||||||
|
IEnumerable<MappingModel> FromDocument(OpenApiDocument document, WireMockOpenApiParserSettings settings = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate <see cref="IEnumerable{MappingModel}"/> from a <seealso cref="Stream"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">The source stream</param>
|
||||||
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
|
/// <returns>MappingModel</returns>
|
||||||
|
IEnumerable<MappingModel> FromStream(Stream stream, out OpenApiDiagnostic diagnostic);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate <see cref="IEnumerable{MappingModel}"/> from a <seealso cref="Stream"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">The source stream</param>
|
||||||
|
/// <param name="settings">Additional settings</param>
|
||||||
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
|
/// <returns>MappingModel</returns>
|
||||||
|
IEnumerable<MappingModel> FromStream(Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
385
src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs
Normal file
385
src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs
Normal file
@@ -0,0 +1,385 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.OpenApi;
|
||||||
|
using Microsoft.OpenApi.Any;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Microsoft.OpenApi.Writers;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Stef.Validation;
|
||||||
|
using WireMock.Admin.Mappings;
|
||||||
|
using WireMock.Net.OpenApiParser.Extensions;
|
||||||
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
|
using WireMock.Net.OpenApiParser.Types;
|
||||||
|
using WireMock.Net.OpenApiParser.Utils;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Mappers
|
||||||
|
{
|
||||||
|
internal class OpenApiPathsMapper
|
||||||
|
{
|
||||||
|
private const string HeaderContentType = "Content-Type";
|
||||||
|
|
||||||
|
private readonly WireMockOpenApiParserSettings _settings;
|
||||||
|
private readonly ExampleValueGenerator _exampleValueGenerator;
|
||||||
|
|
||||||
|
public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
||||||
|
{
|
||||||
|
_settings = Guard.NotNull(settings, nameof(settings));
|
||||||
|
_exampleValueGenerator = new ExampleValueGenerator(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<MappingModel> ToMappingModels(OpenApiPaths paths, IList<OpenApiServer> servers)
|
||||||
|
{
|
||||||
|
return paths.Select(p => MapPath(p.Key, p.Value, servers)).SelectMany(x => x);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<MappingModel> MapPaths(OpenApiPaths paths, IList<OpenApiServer> servers)
|
||||||
|
{
|
||||||
|
return paths.Select(p => MapPath(p.Key, p.Value, servers)).SelectMany(x => x);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<MappingModel> MapPath(string path, OpenApiPathItem pathItem, IList<OpenApiServer> servers)
|
||||||
|
{
|
||||||
|
return pathItem.Operations.Select(o => MapOperationToMappingModel(path, o.Key.ToString().ToUpperInvariant(), o.Value, servers));
|
||||||
|
}
|
||||||
|
|
||||||
|
private MappingModel MapOperationToMappingModel(string path, string httpMethod, OpenApiOperation operation, IList<OpenApiServer> servers)
|
||||||
|
{
|
||||||
|
var queryParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Query);
|
||||||
|
var pathParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Path);
|
||||||
|
var headers = operation.Parameters.Where(p => p.In == ParameterLocation.Header);
|
||||||
|
|
||||||
|
var response = operation.Responses.FirstOrDefault();
|
||||||
|
|
||||||
|
TryGetContent(response.Value?.Content, out OpenApiMediaType responseContent, out string responseContentType);
|
||||||
|
var responseSchema = response.Value?.Content?.FirstOrDefault().Value?.Schema;
|
||||||
|
var responseExample = responseContent?.Example;
|
||||||
|
var responseSchemaExample = responseContent?.Schema?.Example;
|
||||||
|
|
||||||
|
var body = responseExample != null ? MapOpenApiAnyToJToken(responseExample) :
|
||||||
|
responseSchemaExample != null ? MapOpenApiAnyToJToken(responseSchemaExample) :
|
||||||
|
MapSchemaToObject(responseSchema);
|
||||||
|
|
||||||
|
var requestBodyModel = new BodyModel();
|
||||||
|
if (operation.RequestBody != null && operation.RequestBody.Content != null && operation.RequestBody.Required)
|
||||||
|
{
|
||||||
|
var request = operation.RequestBody.Content;
|
||||||
|
TryGetContent(request, out OpenApiMediaType requestContent, out string requestContentType);
|
||||||
|
|
||||||
|
var requestBodySchema = operation.RequestBody.Content.First().Value?.Schema;
|
||||||
|
var requestBodyExample = requestContent.Example;
|
||||||
|
var requestBodySchemaExample = requestContent.Schema?.Example;
|
||||||
|
|
||||||
|
var requestBodyMapped = requestBodyExample != null ? MapOpenApiAnyToJToken(requestBodyExample) :
|
||||||
|
requestBodySchemaExample != null ? MapOpenApiAnyToJToken(requestBodySchemaExample) :
|
||||||
|
MapSchemaToObject(requestBodySchema);
|
||||||
|
|
||||||
|
requestBodyModel = MapRequestBody(requestBodyMapped);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!int.TryParse(response.Key, out var httpStatusCode))
|
||||||
|
{
|
||||||
|
httpStatusCode = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MappingModel
|
||||||
|
{
|
||||||
|
Guid = Guid.NewGuid(),
|
||||||
|
Request = new RequestModel
|
||||||
|
{
|
||||||
|
Methods = new[] { httpMethod },
|
||||||
|
Path = MapBasePath(servers) + MapPathWithParameters(path, pathParameters),
|
||||||
|
Params = MapQueryParameters(queryParameters),
|
||||||
|
Headers = MapRequestHeaders(headers),
|
||||||
|
Body = requestBodyModel
|
||||||
|
},
|
||||||
|
Response = new ResponseModel
|
||||||
|
{
|
||||||
|
StatusCode = httpStatusCode,
|
||||||
|
Headers = MapHeaders(responseContentType, response.Value?.Headers),
|
||||||
|
BodyAsJson = body
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private BodyModel MapRequestBody(object requestBody)
|
||||||
|
{
|
||||||
|
if (requestBody == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BodyModel
|
||||||
|
{
|
||||||
|
Matcher = new MatcherModel
|
||||||
|
{
|
||||||
|
Name = "JsonMatcher",
|
||||||
|
Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented),
|
||||||
|
IgnoreCase = _settings.RequestBodyIgnoreCase
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetContent(IDictionary<string, OpenApiMediaType> contents, out OpenApiMediaType openApiMediaType, out string contentType)
|
||||||
|
{
|
||||||
|
openApiMediaType = null;
|
||||||
|
contentType = null;
|
||||||
|
|
||||||
|
if (contents == null || contents.Values.Count == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contents.TryGetValue("application/json", out var content))
|
||||||
|
{
|
||||||
|
openApiMediaType = content;
|
||||||
|
contentType = "application/json";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var first = contents.FirstOrDefault();
|
||||||
|
openApiMediaType = first.Value;
|
||||||
|
contentType = first.Key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object MapSchemaToObject(OpenApiSchema schema, string name = null)
|
||||||
|
{
|
||||||
|
if (schema == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (schema.GetSchemaType())
|
||||||
|
{
|
||||||
|
case SchemaType.Array:
|
||||||
|
var jArray = new JArray();
|
||||||
|
for (int i = 0; i < _settings.NumberOfArrayItems; i++)
|
||||||
|
{
|
||||||
|
if (schema.Items.Properties.Count > 0)
|
||||||
|
{
|
||||||
|
var arrayItem = new JObject();
|
||||||
|
foreach (var property in schema.Items.Properties)
|
||||||
|
{
|
||||||
|
var objectValue = MapSchemaToObject(property.Value, property.Key);
|
||||||
|
if (objectValue is JProperty jp)
|
||||||
|
{
|
||||||
|
arrayItem.Add(jp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arrayItem.Add(new JProperty(property.Key, objectValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jArray.Add(arrayItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jArray.Add(MapSchemaToObject(schema.Items, name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.AllOf.Count > 0)
|
||||||
|
{
|
||||||
|
jArray.Add(MapSchemaAllOfToObject(schema));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jArray;
|
||||||
|
|
||||||
|
case SchemaType.Boolean:
|
||||||
|
case SchemaType.Integer:
|
||||||
|
case SchemaType.Number:
|
||||||
|
case SchemaType.String:
|
||||||
|
return _exampleValueGenerator.GetExampleValue(schema);
|
||||||
|
|
||||||
|
case SchemaType.Object:
|
||||||
|
var propertyAsJObject = new JObject();
|
||||||
|
foreach (var schemaProperty in schema.Properties)
|
||||||
|
{
|
||||||
|
propertyAsJObject.Add(MapPropertyAsJObject(schemaProperty.Value, schemaProperty.Key));
|
||||||
|
}
|
||||||
|
if (schema.AllOf.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var property in schema.AllOf)
|
||||||
|
{
|
||||||
|
foreach (var item in property.Properties)
|
||||||
|
{
|
||||||
|
propertyAsJObject.Add(MapPropertyAsJObject(item.Value, item.Key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return name != null ? new JProperty(name, propertyAsJObject) : (JToken)propertyAsJObject;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private JObject MapSchemaAllOfToObject(OpenApiSchema schema)
|
||||||
|
{
|
||||||
|
var arrayItem = new JObject();
|
||||||
|
foreach (var property in schema.AllOf)
|
||||||
|
{
|
||||||
|
foreach (var item in property.Properties)
|
||||||
|
{
|
||||||
|
arrayItem.Add(MapPropertyAsJObject(item.Value, item.Key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arrayItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object MapPropertyAsJObject(OpenApiSchema openApiSchema, string key)
|
||||||
|
{
|
||||||
|
if (openApiSchema.GetSchemaType() == SchemaType.Object || openApiSchema.GetSchemaType() == SchemaType.Array)
|
||||||
|
{
|
||||||
|
var mapped = MapSchemaToObject(openApiSchema, key);
|
||||||
|
if (mapped is JProperty jp)
|
||||||
|
{
|
||||||
|
return jp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new JProperty(key, mapped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
||||||
|
return new JProperty(key, _exampleValueGenerator.GetExampleValue(openApiSchema));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string MapPathWithParameters(string path, IEnumerable<OpenApiParameter> parameters)
|
||||||
|
{
|
||||||
|
if (parameters == null)
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
string newPath = path;
|
||||||
|
foreach (var parameter in parameters)
|
||||||
|
{
|
||||||
|
var exampleMatcherModel = GetExampleMatcherModel(parameter.Schema, _settings.PathPatternToUse);
|
||||||
|
newPath = newPath.Replace($"{{{parameter.Name}}}", exampleMatcherModel.Pattern as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string MapBasePath(IList<OpenApiServer> servers)
|
||||||
|
{
|
||||||
|
if (servers == null || servers.Count == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenApiServer server = servers.First();
|
||||||
|
if (Uri.TryCreate(server.Url, UriKind.RelativeOrAbsolute, out Uri uriResult))
|
||||||
|
{
|
||||||
|
return uriResult.IsAbsoluteUri ? uriResult.AbsolutePath : uriResult.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JToken MapOpenApiAnyToJToken(IOpenApiAny any)
|
||||||
|
{
|
||||||
|
if (any == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var outputString = new StringWriter();
|
||||||
|
var writer = new OpenApiJsonWriter(outputString);
|
||||||
|
any.Write(writer, OpenApiSpecVersion.OpenApi3_0);
|
||||||
|
|
||||||
|
if (any.AnyType == AnyType.Array)
|
||||||
|
{
|
||||||
|
return JArray.Parse(outputString.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return JObject.Parse(outputString.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDictionary<string, object> MapHeaders(string responseContentType, IDictionary<string, OpenApiHeader> headers)
|
||||||
|
{
|
||||||
|
var mappedHeaders = headers.ToDictionary(
|
||||||
|
item => item.Key,
|
||||||
|
item => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(responseContentType))
|
||||||
|
{
|
||||||
|
mappedHeaders.TryAdd(HeaderContentType, responseContentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList<ParamModel> MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)
|
||||||
|
{
|
||||||
|
var list = queryParameters
|
||||||
|
.Where(req => req.Required)
|
||||||
|
.Select(qp => new ParamModel
|
||||||
|
{
|
||||||
|
Name = qp.Name,
|
||||||
|
IgnoreCase = _settings.QueryParameterPatternIgnoreCase,
|
||||||
|
Matchers = new[]
|
||||||
|
{
|
||||||
|
GetExampleMatcherModel(qp.Schema, _settings.QueryParameterPatternToUse)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return list.Any() ? list : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList<HeaderModel> MapRequestHeaders(IEnumerable<OpenApiParameter> headers)
|
||||||
|
{
|
||||||
|
var list = headers
|
||||||
|
.Where(req => req.Required)
|
||||||
|
.Select(qp => new HeaderModel
|
||||||
|
{
|
||||||
|
Name = qp.Name,
|
||||||
|
IgnoreCase = _settings.HeaderPatternIgnoreCase,
|
||||||
|
Matchers = new[]
|
||||||
|
{
|
||||||
|
GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return list.Any() ? list : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MatcherModel GetExampleMatcherModel(OpenApiSchema schema, ExampleValueType type)
|
||||||
|
{
|
||||||
|
return type switch
|
||||||
|
{
|
||||||
|
ExampleValueType.Value => new MatcherModel { Name = "ExactMatcher", Pattern = GetExampleValueAsStringForSchemaType(schema), IgnoreCase = _settings.IgnoreCaseExampleValues },
|
||||||
|
|
||||||
|
_ => new MatcherModel { Name = "WildcardMatcher", Pattern = "*" }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetExampleValueAsStringForSchemaType(OpenApiSchema schema)
|
||||||
|
{
|
||||||
|
var value = _exampleValueGenerator.GetExampleValue(schema);
|
||||||
|
|
||||||
|
return value switch
|
||||||
|
{
|
||||||
|
string valueAsString => valueAsString,
|
||||||
|
|
||||||
|
_ => value.ToString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A interface defining the example values to use for the different types.
|
||||||
|
/// </summary>
|
||||||
|
public interface IWireMockOpenApiParserExampleValues
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a Boolean.
|
||||||
|
/// </summary>
|
||||||
|
bool Boolean { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for an Integer.
|
||||||
|
/// </summary>
|
||||||
|
int Integer { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a Float.
|
||||||
|
/// </summary>
|
||||||
|
float Float { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a Double.
|
||||||
|
/// </summary>
|
||||||
|
double Double { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a Date.
|
||||||
|
/// </summary>
|
||||||
|
Func<DateTime> Date { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a DateTime.
|
||||||
|
/// </summary>
|
||||||
|
Func<DateTime> DateTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for Bytes.
|
||||||
|
/// </summary>
|
||||||
|
byte[] Bytes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a Object.
|
||||||
|
/// </summary>
|
||||||
|
object Object { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An example value for a String.
|
||||||
|
/// </summary>
|
||||||
|
string String { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using RandomDataGenerator.FieldOptions;
|
||||||
|
using RandomDataGenerator.Randomizers;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class defining the random example values to use for the different types.
|
||||||
|
/// </summary>
|
||||||
|
public class WireMockOpenApiParserDynamicExampleValues : IWireMockOpenApiParserExampleValues
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool Boolean { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true; } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public int Integer { get { return RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42; } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public float Float { get { return RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f; } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public double Double { get { return RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d; } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Func<DateTime> Date { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date; } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Func<DateTime> DateTime { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow; } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public byte[] Bytes { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate(); } set { } }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public object Object { get; set; } = "example-object";
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string String { get { return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; } set { } }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class defining the example values to use for the different types.
|
||||||
|
/// </summary>
|
||||||
|
public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleValues
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool Boolean { get; set; } = true;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public int Integer { get; set; } = 42;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public float Float { get; set; } = 4.2f;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public double Double { get; set; } = 4.2d;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Func<DateTime> Date { get; set; } = () => System.DateTime.UtcNow.Date;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Func<DateTime> DateTime { get; set; } = () => System.DateTime.UtcNow;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public byte[] Bytes { get; set; } = { 48, 49, 50 };
|
||||||
|
/// <inheritdoc />
|
||||||
|
public object Object { get; set; } = "example-object";
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string String { get; set; } = "example-string";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using WireMock.Net.OpenApiParser.Types;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The WireMockOpenApiParser Settings
|
||||||
|
/// </summary>
|
||||||
|
public class WireMockOpenApiParserSettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The number of array items to generate (default is 3).
|
||||||
|
/// </summary>
|
||||||
|
public int NumberOfArrayItems { get; set; } = 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The example value type to use when generating a Path
|
||||||
|
/// </summary>
|
||||||
|
public ExampleValueType PathPatternToUse { get; set; } = ExampleValueType.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The example value type to use when generating a Header
|
||||||
|
/// </summary>
|
||||||
|
public ExampleValueType HeaderPatternToUse { get; set; } = ExampleValueType.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The example value type to use when generating a Query Parameter
|
||||||
|
/// </summary>
|
||||||
|
public ExampleValueType QueryParameterPatternToUse { get; set; } = ExampleValueType.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The example values to use.
|
||||||
|
///
|
||||||
|
/// Default implementations are:
|
||||||
|
/// - <see cref="WireMockOpenApiParserExampleValues"/>
|
||||||
|
/// - <see cref="WireMockOpenApiParserDynamicExampleValues"/>
|
||||||
|
/// </summary>
|
||||||
|
public IWireMockOpenApiParserExampleValues ExampleValues { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a Header match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool HeaderPatternIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a Query Parameter match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool QueryParameterPatternIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a Request Body match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool RequestBodyIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a ExampleValue match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool IgnoreCaseExampleValues { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are examples generated dynamically? (default is false).
|
||||||
|
/// </summary>
|
||||||
|
public bool DynamicExamples { get; set; } = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/WireMock.Net.OpenApiParser/Types/ExampleValueType.cs
Normal file
20
src/WireMock.Net.OpenApiParser/Types/ExampleValueType.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace WireMock.Net.OpenApiParser.Types
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The example value to use
|
||||||
|
/// </summary>
|
||||||
|
public enum ExampleValueType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 1. Use a generated example value based on the SchemaType (default).
|
||||||
|
/// 2. If there is no example value defined in the schema,
|
||||||
|
/// then the <see cref="Settings.IWireMockOpenApiParserExampleValues"/> will be used (custom, fixed or dynamic).
|
||||||
|
/// </summary>
|
||||||
|
Value,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Just use a Wildcard (*) character.
|
||||||
|
/// </summary>
|
||||||
|
Wildcard
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,51 +1,125 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.OpenApi.Any;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Stef.Validation;
|
||||||
using WireMock.Net.OpenApiParser.Extensions;
|
using WireMock.Net.OpenApiParser.Extensions;
|
||||||
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
using WireMock.Net.OpenApiParser.Types;
|
using WireMock.Net.OpenApiParser.Types;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Utils
|
namespace WireMock.Net.OpenApiParser.Utils
|
||||||
{
|
{
|
||||||
internal static class ExampleValueGenerator
|
internal class ExampleValueGenerator
|
||||||
{
|
{
|
||||||
public static object GetExampleValue(OpenApiSchema schema)
|
private readonly WireMockOpenApiParserSettings _settings;
|
||||||
|
|
||||||
|
public ExampleValueGenerator(WireMockOpenApiParserSettings settings)
|
||||||
{
|
{
|
||||||
|
_settings = Guard.NotNull(settings, nameof(settings));
|
||||||
|
|
||||||
|
// Check if user provided an own implementation
|
||||||
|
if (settings.ExampleValues is null)
|
||||||
|
{
|
||||||
|
if (_settings.DynamicExamples)
|
||||||
|
{
|
||||||
|
_settings.ExampleValues = new WireMockOpenApiParserDynamicExampleValues();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_settings.ExampleValues = new WireMockOpenApiParserExampleValues();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetExampleValue(OpenApiSchema schema)
|
||||||
|
{
|
||||||
|
var schemaExample = schema?.Example;
|
||||||
|
var schemaEnum = GetRandomEnumValue(schema?.Enum);
|
||||||
|
|
||||||
switch (schema?.GetSchemaType())
|
switch (schema?.GetSchemaType())
|
||||||
{
|
{
|
||||||
case SchemaType.Boolean:
|
case SchemaType.Boolean:
|
||||||
return true;
|
var exampleBoolean = (OpenApiBoolean)schemaExample;
|
||||||
|
return exampleBoolean is null ? _settings.ExampleValues.Boolean : exampleBoolean.Value;
|
||||||
|
|
||||||
case SchemaType.Integer:
|
case SchemaType.Integer:
|
||||||
return 42;
|
switch (schema?.GetSchemaFormat())
|
||||||
|
{
|
||||||
|
case SchemaFormat.Int64:
|
||||||
|
var exampleLong = (OpenApiLong)schemaExample;
|
||||||
|
var enumLong = (OpenApiLong)schemaEnum;
|
||||||
|
var valueLongEnumOrExample = enumLong is null ? exampleLong?.Value : enumLong?.Value;
|
||||||
|
return valueLongEnumOrExample ?? _settings.ExampleValues.Integer;
|
||||||
|
|
||||||
|
default:
|
||||||
|
var exampleInteger = (OpenApiInteger)schemaExample;
|
||||||
|
var enumInteger = (OpenApiInteger)schemaEnum;
|
||||||
|
var valueIntegerEnumOrExample = enumInteger is null ? exampleInteger?.Value : enumInteger?.Value;
|
||||||
|
return valueIntegerEnumOrExample ?? _settings.ExampleValues.Integer;
|
||||||
|
}
|
||||||
|
|
||||||
case SchemaType.Number:
|
case SchemaType.Number:
|
||||||
switch (schema?.GetSchemaFormat())
|
switch (schema?.GetSchemaFormat())
|
||||||
{
|
{
|
||||||
case SchemaFormat.Float:
|
case SchemaFormat.Float:
|
||||||
return 4.2f;
|
var exampleFloat = (OpenApiFloat)schemaExample;
|
||||||
|
var enumFloat = (OpenApiFloat)schemaEnum;
|
||||||
|
var valueFloatEnumOrExample = enumFloat is null ? exampleFloat?.Value : enumFloat?.Value;
|
||||||
|
return valueFloatEnumOrExample ?? _settings.ExampleValues.Float;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 4.2d;
|
var exampleDouble = (OpenApiDouble)schemaExample;
|
||||||
|
var enumDouble = (OpenApiDouble)schemaEnum;
|
||||||
|
var valueDoubleEnumOrExample = enumDouble is null ? exampleDouble?.Value : enumDouble?.Value;
|
||||||
|
return valueDoubleEnumOrExample ?? _settings.ExampleValues.Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
switch (schema?.GetSchemaFormat())
|
switch (schema?.GetSchemaFormat())
|
||||||
{
|
{
|
||||||
case SchemaFormat.Date:
|
case SchemaFormat.Date:
|
||||||
return DateTimeUtils.ToRfc3339Date(DateTime.UtcNow);
|
var exampleDate = (OpenApiDate)schemaExample;
|
||||||
|
var enumDate = (OpenApiDate)schemaEnum;
|
||||||
|
var valueDateEnumOrExample = enumDate is null ? exampleDate?.Value : enumDate?.Value;
|
||||||
|
return DateTimeUtils.ToRfc3339Date(valueDateEnumOrExample ?? _settings.ExampleValues.Date());
|
||||||
|
|
||||||
case SchemaFormat.DateTime:
|
case SchemaFormat.DateTime:
|
||||||
return DateTimeUtils.ToRfc3339DateTime(DateTime.UtcNow);
|
var exampleDateTime = (OpenApiDateTime)schemaExample;
|
||||||
|
var enumDateTime = (OpenApiDateTime)schemaEnum;
|
||||||
|
var valueDateTimeEnumOrExample = enumDateTime is null ? exampleDateTime?.Value : enumDateTime?.Value;
|
||||||
|
return DateTimeUtils.ToRfc3339DateTime(valueDateTimeEnumOrExample?.DateTime ?? _settings.ExampleValues.DateTime());
|
||||||
|
|
||||||
case SchemaFormat.Byte:
|
case SchemaFormat.Byte:
|
||||||
return new byte[] { 48, 49, 50 };
|
var exampleByte = (OpenApiByte)schemaExample;
|
||||||
|
var enumByte = (OpenApiByte)schemaEnum;
|
||||||
|
var valueByteEnumOrExample = enumByte is null ? exampleByte?.Value : enumByte?.Value;
|
||||||
|
return valueByteEnumOrExample ?? _settings.ExampleValues.Bytes;
|
||||||
|
|
||||||
case SchemaFormat.Binary:
|
case SchemaFormat.Binary:
|
||||||
return "example-object";
|
var exampleBinary = (OpenApiBinary)schemaExample;
|
||||||
|
var enumBinary = (OpenApiBinary)schemaEnum;
|
||||||
|
var valueBinaryEnumOrExample = enumBinary is null ? exampleBinary?.Value : enumBinary?.Value;
|
||||||
|
return valueBinaryEnumOrExample ?? _settings.ExampleValues.Object;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "example-string";
|
var exampleString = (OpenApiString)schemaExample;
|
||||||
|
var enumString = (OpenApiString)schemaEnum;
|
||||||
|
var valueStringEnumOrExample = enumString is null ? exampleString?.Value : enumString?.Value;
|
||||||
|
return valueStringEnumOrExample ?? _settings.ExampleValues.String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IOpenApiAny GetRandomEnumValue(IList<IOpenApiAny> schemaEnum)
|
||||||
|
{
|
||||||
|
if (schemaEnum?.Count > 0)
|
||||||
|
{
|
||||||
|
int maxValue = schemaEnum.Count - 1;
|
||||||
|
int randomEnum = new Random().Next(0, maxValue);
|
||||||
|
return schemaEnum[randomEnum];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
<LangVersion>8.0</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
@@ -21,17 +22,15 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
||||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.1.1" />
|
<PackageReference Include="RamlToOpenApiConverter" Version="0.6.0" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
||||||
|
<PackageReference Include="Stef.Validation" Version="0.0.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Options\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,34 +1,33 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Microsoft.OpenApi;
|
|
||||||
using Microsoft.OpenApi.Any;
|
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Microsoft.OpenApi.Readers;
|
using Microsoft.OpenApi.Readers;
|
||||||
using Microsoft.OpenApi.Writers;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using RamlToOpenApiConverter;
|
using RamlToOpenApiConverter;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Net.OpenApiParser.Extensions;
|
using WireMock.Net.OpenApiParser.Mappers;
|
||||||
using WireMock.Net.OpenApiParser.Types;
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
using WireMock.Net.OpenApiParser.Utils;
|
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser
|
namespace WireMock.Net.OpenApiParser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a OpenApi/Swagger/V2/V3 or Raml to WireMock MappingModels.
|
/// Parse a OpenApi/Swagger/V2/V3 or Raml to WireMock.Net MappingModels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WireMockOpenApiParser : IWireMockOpenApiParser
|
public class WireMockOpenApiParser : IWireMockOpenApiParser
|
||||||
{
|
{
|
||||||
private const int ArrayItems = 3;
|
|
||||||
|
|
||||||
private readonly OpenApiStreamReader _reader = new OpenApiStreamReader();
|
private readonly OpenApiStreamReader _reader = new OpenApiStreamReader();
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockOpenApiParser.FromFile" />
|
/// <inheritdoc cref="IWireMockOpenApiParser.FromFile(string, out OpenApiDiagnostic)" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public IEnumerable<MappingModel> FromFile(string path, out OpenApiDiagnostic diagnostic)
|
public IEnumerable<MappingModel> FromFile(string path, out OpenApiDiagnostic diagnostic)
|
||||||
|
{
|
||||||
|
return FromFile(path, new WireMockOpenApiParserSettings(), out diagnostic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IWireMockOpenApiParser.FromFile(string, WireMockOpenApiParserSettings, out OpenApiDiagnostic)" />
|
||||||
|
[PublicAPI]
|
||||||
|
public IEnumerable<MappingModel> FromFile(string path, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
OpenApiDocument document;
|
OpenApiDocument document;
|
||||||
if (Path.GetExtension(path).EndsWith("raml", StringComparison.OrdinalIgnoreCase))
|
if (Path.GetExtension(path).EndsWith("raml", StringComparison.OrdinalIgnoreCase))
|
||||||
@@ -42,248 +41,28 @@ namespace WireMock.Net.OpenApiParser
|
|||||||
document = reader.Read(File.OpenRead(path), out diagnostic);
|
document = reader.Read(File.OpenRead(path), out diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FromDocument(document);
|
return FromDocument(document, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockOpenApiParser.FromStream" />
|
/// <inheritdoc cref="IWireMockOpenApiParser.FromStream(Stream, out OpenApiDiagnostic)" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public IEnumerable<MappingModel> FromStream(Stream stream, out OpenApiDiagnostic diagnostic)
|
public IEnumerable<MappingModel> FromStream(Stream stream, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
return FromDocument(_reader.Read(stream, out diagnostic));
|
return FromDocument(_reader.Read(stream, out diagnostic));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockOpenApiParser.FromDocument" />
|
/// <inheritdoc cref="IWireMockOpenApiParser.FromStream(Stream, WireMockOpenApiParserSettings, out OpenApiDiagnostic)" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public IEnumerable<MappingModel> FromDocument(OpenApiDocument openApiDocument)
|
public IEnumerable<MappingModel> FromStream(Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
return MapPaths(openApiDocument.Paths);
|
return FromDocument(_reader.Read(stream, out diagnostic), settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<MappingModel> MapPaths(OpenApiPaths paths)
|
/// <inheritdoc cref="IWireMockOpenApiParser.FromDocument(OpenApiDocument, WireMockOpenApiParserSettings)" />
|
||||||
|
[PublicAPI]
|
||||||
|
public IEnumerable<MappingModel> FromDocument(OpenApiDocument openApiDocument, WireMockOpenApiParserSettings settings = null)
|
||||||
{
|
{
|
||||||
return paths.Select(p => MapPath(p.Key, p.Value)).SelectMany(x => x);
|
return new OpenApiPathsMapper(settings).ToMappingModels(openApiDocument.Paths, openApiDocument.Servers);
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<MappingModel> MapPath(string path, OpenApiPathItem pathItem)
|
|
||||||
{
|
|
||||||
return pathItem.Operations.Select(o => MapOperationToMappingModel(path, o.Key.ToString().ToUpperInvariant(), o.Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MappingModel MapOperationToMappingModel(string path, string httpMethod, OpenApiOperation operation)
|
|
||||||
{
|
|
||||||
var queryParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Query);
|
|
||||||
var pathParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Path);
|
|
||||||
var response = operation.Responses.FirstOrDefault();
|
|
||||||
TryGetContent(response.Value?.Content, out OpenApiMediaType responseContent, out string responseContentType);
|
|
||||||
var responseSchema = response.Value?.Content?.FirstOrDefault().Value?.Schema;
|
|
||||||
var responseExample = responseContent?.Example;
|
|
||||||
|
|
||||||
var body = responseExample != null ? MapOpenApiAnyToJToken(responseExample) : MapSchemaToObject(responseSchema);
|
|
||||||
|
|
||||||
if (int.TryParse(response.Key, out var httpStatusCode))
|
|
||||||
{
|
|
||||||
httpStatusCode = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MappingModel
|
|
||||||
{
|
|
||||||
Guid = Guid.NewGuid(),
|
|
||||||
Request = new RequestModel
|
|
||||||
{
|
|
||||||
Methods = new[] { httpMethod },
|
|
||||||
Path = MapPathWithParameters(path, pathParameters),
|
|
||||||
Params = MapQueryParameters(queryParameters)
|
|
||||||
},
|
|
||||||
Response = new ResponseModel
|
|
||||||
{
|
|
||||||
StatusCode = httpStatusCode,
|
|
||||||
Headers = MapHeaders(responseContentType, response.Value?.Headers),
|
|
||||||
BodyAsJson = body
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TryGetContent(IDictionary<string, OpenApiMediaType> contents, out OpenApiMediaType openApiMediaType, out string contentType)
|
|
||||||
{
|
|
||||||
openApiMediaType = null;
|
|
||||||
contentType = null;
|
|
||||||
|
|
||||||
if (contents == null || contents.Values.Count == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contents.TryGetValue("application/json", out var content))
|
|
||||||
{
|
|
||||||
openApiMediaType = content;
|
|
||||||
contentType = "application/json";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var first = contents.FirstOrDefault();
|
|
||||||
openApiMediaType = first.Value;
|
|
||||||
contentType = first.Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static object MapSchemaToObject(OpenApiSchema schema, string name = null)
|
|
||||||
{
|
|
||||||
if (schema == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (schema.GetSchemaType())
|
|
||||||
{
|
|
||||||
case SchemaType.Array:
|
|
||||||
var jArray = new JArray();
|
|
||||||
for (int i = 0; i < ArrayItems; i++)
|
|
||||||
{
|
|
||||||
if (schema.Items.Properties.Count > 0)
|
|
||||||
{
|
|
||||||
var arrayItem = new JObject();
|
|
||||||
foreach (var property in schema.Items.Properties)
|
|
||||||
{
|
|
||||||
var objectValue = MapSchemaToObject(property.Value, property.Key);
|
|
||||||
if (objectValue is JProperty jp)
|
|
||||||
{
|
|
||||||
arrayItem.Add(jp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
arrayItem.Add(new JProperty(property.Key, objectValue));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jArray.Add(arrayItem);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jArray.Add(MapSchemaToObject(schema.Items, name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return jArray;
|
|
||||||
|
|
||||||
case SchemaType.Boolean:
|
|
||||||
case SchemaType.Integer:
|
|
||||||
case SchemaType.Number:
|
|
||||||
case SchemaType.String:
|
|
||||||
return ExampleValueGenerator.GetExampleValue(schema);
|
|
||||||
|
|
||||||
case SchemaType.Object:
|
|
||||||
var propertyAsJObject = new JObject();
|
|
||||||
foreach (var schemaProperty in schema.Properties)
|
|
||||||
{
|
|
||||||
string propertyName = schemaProperty.Key;
|
|
||||||
var openApiSchema = schemaProperty.Value;
|
|
||||||
if (openApiSchema.GetSchemaType() == SchemaType.Object)
|
|
||||||
{
|
|
||||||
var mapped = MapSchemaToObject(schemaProperty.Value, schemaProperty.Key);
|
|
||||||
if (mapped is JProperty jp)
|
|
||||||
{
|
|
||||||
propertyAsJObject.Add(jp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
|
||||||
|
|
||||||
propertyAsJObject.Add(new JProperty(propertyName, ExampleValueGenerator.GetExampleValue(openApiSchema)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return name != null ? new JProperty(name, propertyAsJObject) : (JToken)propertyAsJObject;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string MapPathWithParameters(string path, IEnumerable<OpenApiParameter> parameters)
|
|
||||||
{
|
|
||||||
if (parameters == null)
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
string newPath = path;
|
|
||||||
foreach (var parameter in parameters)
|
|
||||||
{
|
|
||||||
newPath = newPath.Replace($"{{{parameter.Name}}}", ExampleValueGenerator.GetExampleValue(parameter.Schema).ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return newPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JToken MapOpenApiAnyToJToken(IOpenApiAny any)
|
|
||||||
{
|
|
||||||
if (any == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var outputString = new StringWriter())
|
|
||||||
{
|
|
||||||
var writer = new OpenApiJsonWriter(outputString);
|
|
||||||
any.Write(writer, OpenApiSpecVersion.OpenApi3_0);
|
|
||||||
|
|
||||||
return JObject.Parse(outputString.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IDictionary<string, object> MapHeaders(string responseContentType, IDictionary<string, OpenApiHeader> headers)
|
|
||||||
{
|
|
||||||
var mappedHeaders = headers.ToDictionary(item => item.Key, item => ExampleValueGenerator.GetExampleValue(null));
|
|
||||||
if (!string.IsNullOrEmpty(responseContentType))
|
|
||||||
{
|
|
||||||
if (!mappedHeaders.ContainsKey("Content-Type"))
|
|
||||||
{
|
|
||||||
mappedHeaders.Add("Content-Type", responseContentType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mappedHeaders["Content-Type"] = responseContentType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IList<ParamModel> MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)
|
|
||||||
{
|
|
||||||
var list = queryParameters
|
|
||||||
.Select(qp => new ParamModel
|
|
||||||
{
|
|
||||||
Name = qp.Name,
|
|
||||||
Matchers = new[]
|
|
||||||
{
|
|
||||||
new MatcherModel
|
|
||||||
{
|
|
||||||
Name = "ExactMatcher",
|
|
||||||
Pattern = GetDefaultValueAsStringForSchemaType(qp.Schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return list.Any() ? list : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetDefaultValueAsStringForSchemaType(OpenApiSchema schema)
|
|
||||||
{
|
|
||||||
var value = ExampleValueGenerator.GetExampleValue(schema);
|
|
||||||
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case string valueAsString:
|
|
||||||
return valueAsString;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>A RestClient using RestEase to access the admin interface.</Description>
|
<Description>A RestClient using RestEase to access the admin interface.</Description>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="RestEase" Version="1.4.10" />
|
<PackageReference Include="RestEase" Version="1.5.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
@@ -12,6 +13,8 @@ namespace WireMock.Net.StandAlone
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class StandAloneApp
|
public static class StandAloneApp
|
||||||
{
|
{
|
||||||
|
private static readonly string Version = typeof(StandAloneApp).GetTypeInfo().Assembly.GetName().Version.ToString();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
|
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,7 +26,8 @@ namespace WireMock.Net.StandAlone
|
|||||||
|
|
||||||
var server = WireMockServer.Start(settings);
|
var server = WireMockServer.Start(settings);
|
||||||
|
|
||||||
settings.Logger?.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
|
settings.Logger?.Info("Version [{0}]", Version);
|
||||||
|
settings.Logger?.Info("Server listening at {0}", string.Join(",", server.Urls));
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
@@ -40,7 +44,8 @@ namespace WireMock.Net.StandAlone
|
|||||||
|
|
||||||
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
||||||
{
|
{
|
||||||
settings.Logger?.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
settings.Logger?.Info("Version [{0}]", Version);
|
||||||
|
settings.Logger?.Debug("Server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||||
|
|
||||||
return Start(settings);
|
return Start(settings);
|
||||||
}
|
}
|
||||||
@@ -61,7 +66,8 @@ namespace WireMock.Net.StandAlone
|
|||||||
|
|
||||||
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
||||||
{
|
{
|
||||||
settings.Logger?.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
settings.Logger?.Info("Version [{0}]", Version);
|
||||||
|
settings.Logger?.Debug("Server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||||
|
|
||||||
server = Start(settings);
|
server = Start(settings);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user