diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d73e4d..bb65575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index dc7730d..c7c6ef9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/index.js b/src/index.js index 73aeeb3..b151175 100644 --- a/src/index.js +++ b/src/index.js @@ -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) => { diff --git a/test/samples/complex/input.json b/test/samples/complex/input.json index 28d49d7..e5197c0 100644 --- a/test/samples/complex/input.json +++ b/test/samples/complex/input.json @@ -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" } } diff --git a/test/samples/fieldDescription/expected.json b/test/samples/fieldDescription/expected.json new file mode 100644 index 0000000..f88000c --- /dev/null +++ b/test/samples/fieldDescription/expected.json @@ -0,0 +1,12 @@ +{ + "schema": { + "fields": [ + { + "description": "the first name", + "name": "first_name", + "type": "STRING", + "mode": "NULLABLE" + } + ] + } +} diff --git a/test/samples/fieldDescription/input.json b/test/samples/fieldDescription/input.json new file mode 100644 index 0000000..321e472 --- /dev/null +++ b/test/samples/fieldDescription/input.json @@ -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" + } + } +} diff --git a/test/samples/nullable/input.json b/test/samples/nullable/input.json index 455b635..4cd4b41 100644 --- a/test/samples/nullable/input.json +++ b/test/samples/nullable/input.json @@ -4,11 +4,9 @@ "type": "object", "properties": { "first_name": { - "description": "the first name", "type": "string" }, "last_name": { - "description": "the last name", "type": "string" } }, diff --git a/test/samples/simple/input.json b/test/samples/simple/input.json index 07fda4e..aa2b9f0 100644 --- a/test/samples/simple/input.json +++ b/test/samples/simple/input.json @@ -4,11 +4,9 @@ "type": "object", "properties": { "first_name": { - "description": "the first name", "type": "string" }, "last_name": { - "description": "the last name", "type": "string" } } diff --git a/test/samples/typeArray/input.json b/test/samples/typeArray/input.json index a311983..502dd5a 100644 --- a/test/samples/typeArray/input.json +++ b/test/samples/typeArray/input.json @@ -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"