Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Move json_schemas to its own package (#1435)
Browse files Browse the repository at this point in the history
* Move zero_ex.json_schemas to its own package

* Support ALL the schemas

* Stop installing packages as editable

* HACK: cp files because CircleCI isn't

* Add example usage to sra_client README

* Tweak special case: only strip Schema as suffix

* Correct doc titles

* Clarify what kind of support ticket was raised.

* Correct inconsistencies in JSON schema names

In both ref ID's and file names.

* Add entry point for validation of JSON strings
  • Loading branch information
feuGeneA authored Jan 8, 2019
2 parents de927d7 + e62e61b commit 4689f20
Show file tree
Hide file tree
Showing 45 changed files with 565 additions and 54 deletions.
39 changes: 35 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,27 @@ jobs:
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
- restore_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: |
cd python-packages/json_schemas
python -m ensurepip
python -m pip install .[dev]
# HACK! installing the package should do the following
# copy for us, but it's not working in CircleCI for some
# reason. Zendesk support ticket raised (#43979) with
# CircleCI.
mkdir /usr/local/lib/python3.7/site-packages/zero_ex/json_schemas/schemas
cp -R src/zero_ex/json_schemas/schemas/* /usr/local/lib/python3.7/site-packages/zero_ex/json_schemas/schemas
- run:
command: |
cd python-packages/order_utils
python -m ensurepip
python -m pip install -e .[dev]
python -m pip install .[dev]
- run:
command: |
cd python-packages/sra_client
python -m ensurepip
python -m pip install -e .
python -m pip install .[dev]
- save_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand All @@ -219,6 +230,10 @@ jobs:
- '.mypy_cache'
- '.pytest_cache'
- '.tox'
- run:
command: |
cd python-packages/json_schemas
coverage run setup.py test
- run:
command: |
cd python-packages/order_utils
Expand All @@ -227,6 +242,10 @@ jobs:
command: |
cd python-packages/sra_client
coverage run setup.py test
- save_cache:
key: coverage-python-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/python-packages/json_schemas/.coverage
- save_cache:
key: coverage-python-order-utils-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand All @@ -249,7 +268,7 @@ jobs:
command: |
cd python-packages/order_utils
python -m ensurepip
python -m pip install -e .[dev]
python -m pip install .
- save_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand All @@ -273,16 +292,25 @@ jobs:
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
- restore_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: |
cd python-packages/json_schemas
python -m ensurepip
python -m pip install .[dev]
- run:
command: |
cd python-packages/order_utils
python -m ensurepip
python -m pip install -e .[dev]
python -m pip install .[dev]
- save_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
- '/usr/local/bin'
- '/usr/local/lib/python3.7/site-packages'
- run:
command: |
cd python-packages/json_schemas
python setup.py lint
- run:
command: |
cd python-packages/order_utils
Expand Down Expand Up @@ -355,6 +383,9 @@ jobs:
- restore_cache:
keys:
- coverage-contracts-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-order-utils-{{ .Environment.CIRCLE_SHA1 }}
Expand Down
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ lib
/packages/contract-artifacts/artifacts
/python-packages/order_utils/src/zero_ex/contract_artifacts/artifacts
/packages/json-schemas/schemas
/python-packages/order_utils/src/zero_ex/json_schemas/schemas
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
/packages/metacoin/src/contract_wrappers
/packages/metacoin/artifacts
/packages/sra-spec/public/
package.json
scripts/postpublish_utils.js
packages/sol-cov/test/fixtures/artifacts
.pytest_cache
.mypy_cache
.tox
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ Visit our [developer portal](https://0xproject.com/docs/order-utils) for a compr

### Python Packages

| Package | Version | Description |
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [`0x-order-utils`](/python-packages/order_utils) | [![PyPI](https://img.shields.io/pypi/v/0x-order-utils.svg)](https://pypi.org/project/0x-order-utils/) | A set of utilities for generating, parsing, signing and validating 0x orders |
| [`0x-sra-client`](/python-packages/sra_client) | [![PyPI](https://img.shields.io/pypi/v/0x-sra-client.svg)](https://pypi.org/project/0x-sra-client/) | A Python client for interacting with servers conforming to the Standard Relayer API specification |
| Package | Version | Description |
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [`0x-json-schemas`](/python-packages/json_schemas) | [![PyPI](https://img.shields.io/pypi/v/0x-json-schemas.svg)](https://pypi.org/project/0x-json-schemas/) | 0x-related JSON schemas |
| [`0x-order-utils`](/python-packages/order_utils) | [![PyPI](https://img.shields.io/pypi/v/0x-order-utils.svg)](https://pypi.org/project/0x-order-utils/) | A set of utilities for generating, parsing, signing and validating 0x orders |
| [`0x-sra-client`](/python-packages/sra_client) | [![PyPI](https://img.shields.io/pypi/v/0x-sra-client.svg)](https://pypi.org/project/0x-sra-client/) | A Python client for interacting with servers conforming to the Standard Relayer API specification |

### Typescript/Javascript Packages

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/AssetPairsRequestOpts",
"id": "/AssetPairsRequestOptsSchema",
"type": "object",
"properties": {
"assetDataA": { "$ref": "/hexSchema" },
Expand Down
6 changes: 3 additions & 3 deletions packages/json-schemas/schemas/call_data_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"from": { "$ref": "/addressSchema" },
"to": { "$ref": "/addressSchema" },
"value": {
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumber" }]
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }]
},
"gas": {
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumber" }]
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }]
},
"gasPrice": {
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumber" }]
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }]
},
"data": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schemas/schemas/ec_signature_schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/ECSignature",
"id": "/ecSignatureSchema",
"properties": {
"v": {
"type": "number",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/jsNumber",
"id": "/jsNumberSchema",
"type": "number",
"minimum": 0
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/OrderConfigRequest",
"id": "/OrderConfigRequestSchema",
"type": "object",
"properties": {
"makerAddress": { "$ref": "/addressSchema" },
Expand Down
4 changes: 2 additions & 2 deletions packages/json-schemas/schemas/orderbook_request_schema.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "/OrderBookRequest",
"id": "/OrderbookRequestSchema",
"type": "object",
"properties": {
"baseAssetData": { "$ref": "/hexSchema" },
"quoteAssetData": { "$ref": "/hexSchema" }
},
"required": ["baseAssetData", "quoteAssetData"]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/OrdersRequestOpts",
"id": "/OrdersRequestOptsSchema",
"type": "object",
"properties": {
"makerAssetProxyId": { "$ref": "/hexSchema" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/PagedRequestOpts",
"id": "/PagedRequestOptsSchema",
"type": "object",
"properties": {
"page": { "type": "number" },
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schemas/schemas/request_opts_schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "/RequestOpts",
"id": "/RequestOptsSchema",
"type": "object",
"properties": {
"networkId": { "type": "number" }
Expand Down
6 changes: 3 additions & 3 deletions packages/json-schemas/schemas/tx_data_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"from": { "$ref": "/addressSchema" },
"to": { "$ref": "/addressSchema" },
"value": {
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumber" }]
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }]
},
"gas": {
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumber" }]
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }]
},
"gasPrice": {
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumber" }]
"oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }]
},
"data": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schemas/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as ecSignatureSchema from '../schemas/ec_signature_schema.json';
import * as eip712TypedDataSchema from '../schemas/eip712_typed_data_schema.json';
import * as hexSchema from '../schemas/hex_schema.json';
import * as indexFilterValuesSchema from '../schemas/index_filter_values_schema.json';
import * as jsNumber from '../schemas/js_number.json';
import * as jsNumber from '../schemas/js_number_schema.json';
import * as numberSchema from '../schemas/number_schema.json';
import * as orderCancellationRequestsSchema from '../schemas/order_cancel_schema.json';
import * as orderConfigRequestSchema from '../schemas/order_config_request_schema.json';
Expand Down
2 changes: 1 addition & 1 deletion packages/json-schemas/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"./schemas/relayer_api_orders_schema.json",
"./schemas/signed_orders_schema.json",
"./schemas/token_schema.json",
"./schemas/js_number.json",
"./schemas/js_number_schema.json",
"./schemas/zero_ex_transaction_schema.json",
"./schemas/tx_data_schema.json",
"./schemas/index_filter_values_schema.json",
Expand Down
13 changes: 13 additions & 0 deletions python-packages/json_schemas/.discharge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"domain": "0x-json-schemas-py",
"build_command": "python setup.py build_sphinx",
"upload_directory": "build/docs/html",
"index_key": "index.html",
"error_key": "index.html",
"trailing_slashes": true,
"cache": 3600,
"aws_profile": "default",
"aws_region": "us-east-1",
"cdn": false,
"dns_configured": true
}
3 changes: 3 additions & 0 deletions python-packages/json_schemas/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[MESSAGES CONTROL]
disable=C0330,line-too-long,fixme,too-few-public-methods,too-many-ancestors
# C0330 is "bad hanging indent". we use indents per `black`.
45 changes: 45 additions & 0 deletions python-packages/json_schemas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## 0x-json-schemas

0x JSON schemas for those developing on top of 0x protocol.

Read the [documentation](http://0x-json-schemas-py.s3-website-us-east-1.amazonaws.com/)

## Installing

```bash
pip install 0x-json-schemas
```

## Contributing

We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.

Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.

### Install Code and Dependencies

Ensure that you have installed Python >=3.6 and Docker. Then:

```bash
pip install -e .[dev]
```

### Test

Tests depend on a running ganache instance with the 0x contracts deployed in it. For convenience, a docker container is provided that has ganache-cli and a snapshot containing the necessary contracts. A shortcut is provided to run that docker container: `./setup.py ganache`. With that running, the tests can be run with `./setup.py test`.

### Clean

`./setup.py clean --all`

### Lint

`./setup.py lint`

### Build Documentation

`./setup.py build_sphinx`

### More

See `./setup.py --help-commands` for more info.
Loading

0 comments on commit 4689f20

Please sign in to comment.