Skip to content

Commit

Permalink
Added JSON-Schema and how to set it up in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
leorush committed Jul 1, 2022
1 parent c46354f commit ba88b1e
Show file tree
Hide file tree
Showing 3 changed files with 691 additions and 0 deletions.
69 changes: 69 additions & 0 deletions README-ru.md
Expand Up @@ -10,6 +10,7 @@ Gonkey протестирует ваши сервисы, используя их
- моки для имитации внешних сервисов
- можно подключить к проекту как библиотеку и запускать вместе с юнит-тестами
- запись результата тестов в виде отчета [Allure](http://allure.qatools.ru/)
- имеется [JSON-schema](#json-schema) для автодополнения и валидации YAML-файлов Gonkey

## Содержание

Expand Down Expand Up @@ -1455,3 +1456,71 @@ Example:
- '{ "id": 2, "name": "John", "surname": "Doe" }'
- '{ "id": 1, "name": "Jane", "surname": "Doe" }'
```

## JSON-schema
Для упрощения написания тестов на Gonkey, используйте [файл со схемой](https://raw.githubusercontent.com/lamoda/gonkey/master/gonkey.json)

Он добавляет in-line документацию и авто-дополнение в IDE которые это поддерживают.


Пример работы в IDE Jetbrains:
![Example Jetbrains](https://i.imgur.com/oYuPuR3.gif)

Пример работы в IDE VSCode:
![Example Jetbrains](https://i.imgur.com/hBIGjP9.gif)


### Настройка на IDE Jetbrains
Скачайте [файл со схемой](https://raw.githubusercontent.com/lamoda/gonkey/master/gonkey.json).
В настройках Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings

![Jetbrains IDE Settings](https://i.imgur.com/xkO22by.png)

Добавьте новую схему

![Add schema](https://i.imgur.com/XHw14GJ.png)

Задайте имя схемы, выберите скачанный файл, а также выберите версию схем Draft 7

![Name, file, version](https://i.imgur.com/LfJfis0.png)

После этого добавьте маппинг. Можно выбрать файл, папку с тестами или маску.

![Mapping](https://i.imgur.com/iFjm0Ld.png)

Выберите то что удобно для вас.

![Mapping pattern](https://i.imgur.com/WIK6sZW.png)

После этого сохраните настройки, и если вы всё сделали правильно в нижнем правом углу окна IDE не должно
отображатся No JSON Schema
![No Schema](https://i.imgur.com/zLqv1Zv.png)

А должно быть ваше название схемы.

![Schema Name](https://i.imgur.com/DDXdCO7.png)

### Настройка на IDE VSCode

Для начала вам нужно установить плагин для работы с YAML
Откройте меню Code(File)->Preferences->Extensions

![VSCode Preferences](https://i.imgur.com/X7bk5Kh.png)

Наберите в поиске YAML, и установите расширение YAML Language Support by Red Hat

![Yaml Extension](https://i.imgur.com/57onioF.png)

Откройте меню Code(File)->Preferences->Settings
Наберите YAML:Schemas и нажмите на ссылку _Edit in settings.json_
![Yaml link](https://i.imgur.com/IEwxWyG.png)

Добавьте маппинг файла и путь к схеме
```
"yaml.schemas": {
"C:\\Users\\Leo\\gonkey.json": ["*.gonkey.yaml"]
}
```

В примере выше, схема из файла C:\Users\Leo\gonkey.json будет применяться ко всем файлам
с расширением .gonkey.yaml
71 changes: 71 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,7 @@ Capabilities:
- provides mocks for external services
- can be used as a library and ran together with unit-tests
- stores the results as an [Allure](http://allure.qatools.ru/) report
- there is a [JSON-schema](#json-schema) to add autocomletion and validation for gonkey YAML files

## Table of contents

Expand Down Expand Up @@ -1455,3 +1456,73 @@ Example:
- '{ "id": 2, "name": "John", "surname": "Doe" }'
- '{ "id": 1, "name": "Jane", "surname": "Doe" }'
```

## JSON-schema
For easier test writing with Gonkey, use [file with schema](https://raw.githubusercontent.com/lamoda/gonkey/master/gonkey.json)

It adds in-line documentation and auto-completion to any IDE that supports it.



Example in Jetbrains IDE:
![Example Jetbrains](https://i.imgur.com/oYuPuR3.gif)

Example in VSCode IDE:
![Example Jetbrains](https://i.imgur.com/hBIGjP9.gif)


### Setup in Jetbrains IDE
Download [file with schema](https://raw.githubusercontent.com/lamoda/gonkey/master/gonkey.json).
Open preferences by going to PyCharm(File)->Preferences
In Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings

![Jetbrains IDE Settings](https://i.imgur.com/xkO22by.png)

Add new schema

![Add schema](https://i.imgur.com/XHw14GJ.png)

Specify schema name, schema file, and select Schema version: Draft 7

![Name, file, version](https://i.imgur.com/LfJfis0.png)

After that add mapping. You can choose from single file, directory, or file mask.

![Mapping](https://i.imgur.com/iFjm0Ld.png)

Choose what suits you best.

![Mapping pattern](https://i.imgur.com/WIK6sZW.png)

Save your preferences. If you done everything right, you should not see No JSON Schema in bottom right corner

![No Schema](https://i.imgur.com/zLqv1Zv.png)

Instead, you should see your schema name

![Schema Name](https://i.imgur.com/DDXdCO7.png)

### Setup is VSCode IDE

At first, you need to download YAML Language plugin
Open Extensions by going to Code(File)->Preferences->Extensions

![VSCode Preferences](https://i.imgur.com/X7bk5Kh.png)

Look for YAML and install YAML Language Support by Red Hat

![Yaml Extension](https://i.imgur.com/57onioF.png)

Open Settings by going to Code(File)->Preferences->Settings

Open Schema Settings by typing YAML:Schemas and click on _Edit in settings.json_
![Yaml link](https://i.imgur.com/IEwxWyG.png)

Add file match to apply the JSON on YAML files.
```
"yaml.schemas": {
"C:\\Users\\Leo\\gonkey.json": ["*.gonkey.yaml"]
}
```

In the example above the JSON schema stored in C:\Users\Leo\gonkey.json will be applied on all the files that ends with .gonkey.yaml

0 comments on commit ba88b1e

Please sign in to comment.