Skip to content

Commit

Permalink
Merge pull request #3 from thedumbterminal/typeArray
Browse files Browse the repository at this point in the history
support descriptions
  • Loading branch information
thedumbterminal authored Jul 25, 2018
2 parents 065a494 + 81b2ec6 commit c941a19
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v0.0.3 (25/07/2018)

* Now supporting fields with type(s) as an array.
* Field descriptions now supported.

## v0.0.2 (23/07/2018)

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Please ensure that the input JSON schema is dereferenced so that all external re
* Repeated fields.
* Enums.
* Error messages.
* Descriptions.
* Handle `oneOf`, `anyOf` and `allOf`.
* Fields with multiple types.

6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ jsonSchemaBigquery._getMode = (required, name, item) => {
}

jsonSchemaBigquery._convertProperty = (name, value, mode) => {
return {
let field = {
name: name,
type: jsonSchemaBigquery._getType(value.type),
mode: mode
}
if(value.description){
field.description = value.description
}
return field
}

jsonSchemaBigquery._getType = (types) => {
Expand Down
3 changes: 0 additions & 3 deletions test/samples/complex/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
"type": "object",
"properties": {
"address": {
"description": "the address",
"type": "object",
"properties": {
"street_address": {
"description": "the street address",
"type": "string"
},
"country": {
"description": "the country",
"type" : "string"
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/samples/fieldDescription/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"schema": {
"fields": [
{
"description": "the first name",
"name": "first_name",
"type": "STRING",
"mode": "NULLABLE"
}
]
}
}
11 changes: 11 additions & 0 deletions test/samples/fieldDescription/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "http://yourdomain.com/schemas/myschema.json",
"description": "Example description",
"type": "object",
"properties": {
"first_name": {
"description": "the first name",
"type": "string"
}
}
}
2 changes: 0 additions & 2 deletions test/samples/nullable/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
"type": "object",
"properties": {
"first_name": {
"description": "the first name",
"type": "string"
},
"last_name": {
"description": "the last name",
"type": "string"
}
},
Expand Down
2 changes: 0 additions & 2 deletions test/samples/simple/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
"type": "object",
"properties": {
"first_name": {
"description": "the first name",
"type": "string"
},
"last_name": {
"description": "the last name",
"type": "string"
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/samples/typeArray/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
"type": "object",
"properties": {
"first_name": {
"description": "the first name",
"type": [
"string",
"null"
]
},
"last_name": {
"description": "the first name",
"type": [
"string",
"null"
Expand Down

0 comments on commit c941a19

Please sign in to comment.