Skip to content

Commit

Permalink
Swagger support (#749)
Browse files Browse the repository at this point in the history
* r

* fix

* sw

* x

* s

* .

* .

* .

* CreateTypeFromJObject

* .

* .

* f

* c

* .

* .

* .

* .

* .

* .

* ok

* ,

* .

* .

* .

* .

* n

* pact

* fix

* schema

* null

* fluent

* r

* -p

* .

* .

* refs

* .
  • Loading branch information
StefH authored May 13, 2022
1 parent 0d8b3b1 commit 5e301fd
Show file tree
Hide file tree
Showing 45 changed files with 2,405 additions and 1,157 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<PropertyGroup>
<VersionPrefix>1.4.41</VersionPrefix>
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https:/WireMock-Net/WireMock.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
1 change: 1 addition & 0 deletions WireMock.Net Solution.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Victoor/@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>
<s:Boolean x:Key="/Default/UserDictionary/Words/=wiremockserver/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System;
using Microsoft.OpenApi.Models;
using RandomDataGenerator.FieldOptions;
using RandomDataGenerator.Randomizers;
using WireMock.Net.OpenApiParser.Settings;

namespace WireMock.Net.OpenApiParser.ConsoleApp
namespace WireMock.Net.OpenApiParser.ConsoleApp;

public class DynamicDataGeneration : WireMockOpenApiParserDynamicExampleValues
{
public class DynamicDataGeneration : WireMockOpenApiParserDynamicExampleValues
public override string String
{
public override string String
get
{
get
{
//Since you have your Schema, you can get if max-lenght is set. You can generate accurate examples with this settings
var maxLength = this.Schema.MaxLength ?? 9;
// Since you have your Schema, you can get if max-length is set. You can generate accurate examples with this settings
var maxLength = Schema.MaxLength ?? 9;

return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex
{
Pattern = $"[0-9A-Z]{{{maxLength}}}"
}).Generate() ?? "example-string";
}
set { }
return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex
{
Pattern = $"[0-9A-Z]{{{maxLength}}}"
}).Generate() ?? "example-string";
}
set { }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
openapi: 3.0.1
info:
title: Basic-String-Test
description: Basic string test
version: "4.5.2"
servers:
- url: https://localhost/examples
paths:
/string/basic:
get:
tags:
- basic-string
description: Basic string test
operationId: getBasicString1
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
/string/maxlenght/minlenght:
get:
tags:
- basic-string
description: Basic string test with maxlength and minlength properties
operationId: getBasicString2
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
maxLength: 8
minLength: 8
/string/maxlenght:
get:
tags:
- basic-string
description: Basic string test with maxlength property
operationId: getBasicString3

responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
maxLength: 5
/string/minlenght:
get:
tags:
- basic-string
description: Basic string test with minlength property
operationId: getBasicString
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
minLength: 10
/string/enum:
get:
tags:
- basic-string
description: Basic string test with enum property
operationId: getBasicString4
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
enum:
- response1
- response2
/string/pattern/uri:
get:
tags:
- basic-string
description: Basic string test with uri pattern property
operationId: getBasicString5
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
pattern: '^(http|https|ftp|sftp)://((([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))|((www\.|())[a-z0-9]{2,5}\.([a-z]{2,3}((\.[a-z]{2})|()))))(()|(:((102[5-9])|(1[0-9][3-9][0-9])|(1[1-9][0-9]{2})|([2-9][0-9]{3})|([2-5][0-9]{4})|(1[0-9]{4})|(60000))))$'
/string/pattern/ipv4:
get:
tags:
- basic-string
description: Basic string test with ipv4 pattern property
operationId: getBasicString6
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
pattern: '^(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))$'
/string/header/ipv4:
get:
tags:
- basic-string
description: Basic string test with ipv4 pattern property
operationId: getBasicString7
parameters:
- name: Header-Sample
in: header
required: true
schema:
type: string
pattern: "ipv4 pattern"
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
pattern: '^(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))\.){3}([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]))$'
157 changes: 157 additions & 0 deletions examples/WireMock.Net.OpenApiParser.ConsoleApp/OpenApiFiles/pet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"openapi": "3.0.2",
"info": {
"title": "Swagger Petstore - OpenAPI 3.0",
"description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https:/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https:/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)",
"termsOfService": "http://swagger.io/terms/",
"contact": { "email": "[email protected]" },
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0.11"
},
"externalDocs": {
"description": "Find out more about Swagger",
"url": "http://swagger.io"
},
"servers": [ { "url": "/api/v3" } ],
"tags": [
{
"name": "pet",
"description": "Everything about your Pets",
"externalDocs": {
"description": "Find out more",
"url": "http://swagger.io"
}
},
{
"name": "store",
"description": "Access to Petstore orders",
"externalDocs": {
"description": "Find out more about our store",
"url": "http://swagger.io"
}
},
{
"name": "user",
"description": "Operations about user"
}
],
"paths": {
"/pet": {
"put": {
"tags": [ "pet" ],
"summary": "Update an existing pet",
"description": "Update an existing pet by Id",
"operationId": "updatePet",
"parameters": [
{
"name": "api_key",
"in": "header",
"description": "",
"required": true,
"schema": { "type": "string" }
}
],
"requestBody": {
"description": "Update an existent pet in the store",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/Pet" }
},
"application/xml": {
"schema": { "$ref": "#/components/schemas/Pet" }
},
"application/x-www-form-urlencoded": {
"schema": { "$ref": "#/components/schemas/Pet" }
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/xml": {
"schema": { "$ref": "#/components/schemas/Pet" }
},
"application/json": {
"schema": { "$ref": "#/components/schemas/Pet" }
}
}
},
"400": { "description": "Invalid ID supplied" },
"404": { "description": "Pet not found" },
"405": { "description": "Validation exception" }
},
"security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ]
}
}
},
"components": {
"schemas": {
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 1
},
"name": {
"type": "string",
"example": "Dogs"
}
},
"xml": { "name": "category" }
},
"Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": { "type": "string" }
},
"xml": { "name": "tag" }
},
"Pet": {
"required": [ "name", "photoUrls" ],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 10
},
"name": {
"type": "string",
"example": "doggie"
},
"category": { "$ref": "#/components/schemas/Category" },
"photoUrls": {
"type": "array",
"xml": { "wrapped": true },
"items": {
"type": "string",
"xml": { "name": "photoUrl" }
}
},
"tags": {
"type": "array",
"xml": { "wrapped": true },
"items": { "$ref": "#/components/schemas/Tag" }
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [ "available", "pending", "sold" ]
}
},
"xml": { "name": "pet" }
}
}
}
}
Loading

0 comments on commit 5e301fd

Please sign in to comment.