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

How to control GenerateData() not to generate additional properties? #530

Closed
1 task done
JohnnyPoon opened this issue Sep 22, 2023 · 1 comment
Closed
1 task done
Labels
pkg:schema-datagen question Further information is requested

Comments

@JohnnyPoon
Copy link

Nuget Package

JsonSchema.Net.DataGeneration

Package Version

1.1.0

What's your question?

I have a schema

{
  "title": "Basic",
  "type": "object",
  "required": [
    "model",
    "target"
  ],
  "properties": {
    "model": {
      "type": "string",
      "enumSource": [
        {
          "source": [],
          "title": "{{item.name}}",
          "value": "{{item.value}}"
        }
      ]
    },
    "target": {
      "type": "string",
      "enumSource": [
        {
          "source": [],
          "title": "{{item.name}}",
          "value": "{{item.value}}"
        }
      ]
    }
  }
}

And I have the following code

            var jschema = JsonSchema.FromText(processedSchema);
            var generationResult = jschema.GenerateData();
            if(generationResult.IsSuccess)
                info.SampleData = generationResult.Result;

The resulting json data generated is

{
	"model":"est",
	"target":"Qui dolores voluptatum. Repudiandae consequatur omnis laudantium deserunt unde sed. Eum beatae aut.",
	"Perspiciatis":495038260733229032,
	"consectetur":false,
	"molestias":"neque",
	"pariatur":null,
	"dolores":null,
	"maxime":3922733966446187980282553020.5
}

I just want to have the properties "model" and "target" without additional randomly generated properties. Can I do that?

Is there any other information you'd like to share regarding this bug?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@JohnnyPoon JohnnyPoon added the question Further information is requested label Sep 22, 2023
@gregsdennis
Copy link
Collaborator

gregsdennis commented Sep 22, 2023

That's kind of the neat thing about this library: it'll generate data you don't expect if your schema isn't specific enough. The idea is that it'll generate chaos until you've added enough constraints to perfectly describe only the data you want.

Just add additionalProperties: false to your schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:schema-datagen question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants