# 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);
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://furkans-organization-1.gitbook.io/cypress-notlari/19.-chai-ile-schema-olusturma-ornekleri.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
