Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide open api schema to dynamic examples generator so you can generate accurate data #706

Conversation

brunotarghetta
Copy link
Contributor

@StefH Having ope api Schema we can use settings like max-length in case of a string to generate more accurate mock data when you implement your dynamic examples

…rate accurate data using settings like max-length in case of a string
@StefH StefH added the feature label Dec 24, 2021
@StefH StefH self-requested a review December 24, 2021 13:00
Copy link
Collaborator

@StefH StefH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments.

And I wonder how to can be used, can you add an example (maybe in the https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.OpenApiParser.ConsoleApp ?)

public string String { get { return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; } set { } }
public string String { get { return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; } set { } }
/// <inheritdoc />
public OpenApiSchema SchemaExample { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just call this Schema ?

@@ -25,5 +26,7 @@ public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleV
public object Object { get; set; } = "example-object";
/// <inheritdoc />
public string String { get; set; } = "example-string";
/// <inheritdoc />
public OpenApiSchema SchemaExample { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably not logical to define a default value for this like the Object and String?

@brunotarghetta
Copy link
Contributor Author

@StefH I've made the changes you suggested. Also I added some code on the ConsoleApp to show you how this can be useful.
Let me share some images

In you swagger file you can specify some attributes (maxLength on string types)
Screen Shot 2021-12-27 at 14 21 46

Screen Shot 2021-12-27 at 14 21 24

So, if you are working with your own example values generator, you can use this settings

Screen Shot 2021-12-27 at 14 41 43

as a result you can check on mapping those examples string with their own length

Screen Shot 2021-12-27 at 14 36 26

In our case this is really useful

Let me know if you need more information.

Thanks in advance.

Copy link
Collaborator

@StefH StefH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Can you do these 2 changes:

Add virtual to all public methods in:

  • WireMockOpenApiParserExampleValues.cs
  • WireMockOpenApiParserDynamicExampleValues.cs

With that change, you can just easily extend from the existing class and override the existing methods. (Can be useful for your new file "DynamicDataGeneration.cs").

…s and ireMockOpenApiParserDynamicExampleValues to extend and overrides examples values
@brunotarghetta
Copy link
Contributor Author

@StefH I've made virtual changes and I extend my DynamicDataGeneration.

@StefH StefH merged commit fd1f496 into WireMock-Net:master Dec 28, 2021
@brunotarghetta
Copy link
Contributor Author

Hi @StefH, good morning! do you know when this features will be release?

@StefH
Copy link
Collaborator

StefH commented Jan 6, 2022

@brunotarghetta

New NuGet packages will be released in a few minutes...

@brunotarghetta
Copy link
Contributor Author

@brunotarghetta

New NuGet packages will be released in a few minutes...

That sound great!!!!!!! Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants