> For the complete documentation index, see [llms.txt](https://furkans-organization-1.gitbook.io/cypress-notlari/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://furkans-organization-1.gitbook.io/cypress-notlari/19.-chai-ile-schema-olusturma-ornekleri.md).

# 19. Chai ile Schema Oluşturma Örnekleri

## 1. Örnek

```javascript
// Data
const validData = {
    name: "Furkan", // required field => string
    age: 24 // optional => null or number
}

const invalidData = {
    name: 24, // required field => string
    age: "Furkan" // optional => null or number
}

// Schema
const dataSchema = {
    title: "Data Schema",
    type: "object",
    required: ["name"],
    properties: {
        name: {
            type: "string"
        },
        age: {
            type: ["number", "null"],
        }
    }
}

```

Cypress testlerini yazalım.

```javascript
// Cypress test
it("test schema with valid data", () => {
    expect(validData).to.be.jsonSchema(dataSchema);
})
 
// Cypress test
it("test schema with invalid data", () => {
    expect(badData).to.not.be.jsonSchema(dataSchema);
})
```

## 2.Örnek

```javascript
// Data
const goodApple = {
    skin: "thin",
    colors: ["red", "green", "yellow"],
    taste: 10,
};

const badApple = {
    colors: ["brown"],
    taste: 0,
    worms: 2,
};

// Schema
const fruitSchema = {
	title: "fresh fruit schema ",
	type: "object",
	required: ["skin", "colors", "taste"],
	properties: {
		colors: {
		   type: ["array", "null"], // null değerleri de kabul eder
		   minItems: 1,
		   uniqueItems: true,
		   items: {
			   type: "string",
		    },
		},
		skin: {
		    type: "string",
		},
		taste: {
		    type: "number",
		    minimum: 5,
		},
	},
};
```

Cypress testlerini yazalım.

```javascript
// Cypress test
it("test schema with valid data", () => {
    expect(goodApple).to.be.jsonSchema(fruitSchema);
})
 
// Cypress test
it("test schema with invalid data", () => {
    expect(badApple).to.not.be.jsonSchema(fruitSchema);
})
```
