diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..946088ce --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,39 @@ +--- +name: Test + +on: [pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby: +# - "2.0" +# - "2.1" +# - "2.2" +# - "2.3" +# - "2.4" +# - "2.5" +# - "2.6.3" +# - "2.6.7" + - "2.7.8" + env: + TEST_ALL: 1 + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} +# - run: gem install rubygems-update -v '<= 2.7.8' +# if: ${{ matrix.ruby == '2.0' || matrix.ruby == '2.1' || matrix.ruby == '2.2' }} +# - run: gem update --system 2.7.8 +# if: ${{ matrix.ruby == '2.0' || matrix.ruby == '2.1' || matrix.ruby == '2.2' }} +# - run: gem install rubygems-update -v '<= ${{matrix.ruby}}' +# if: ${{ matrix.ruby != '2.0' && matrix.ruby != '2.1' && matrix.ruby != '2.2' }} +# - run: gem update --system +# if: ${{ matrix.ruby != '2.0' && matrix.ruby != '2.1' && matrix.ruby != '2.2' }} + - run: gem install bundler -v 1.17.3 + - run: bundle install + - run: bin/rake build format_json && git status -s && [[ -z $(git status -s) ]] + - run: bundle exec rspec diff --git a/.gitignore b/.gitignore index fef3ac04..70080e41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.bundle /.rvmrc +/.idea /coverage /pkg /rdoc diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..e261122d --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.6.7 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 398343bd..00000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -sudo: false -language: ruby -cache: bundler -env: - - TEST_ALL=true -rvm: - - 1.9.3 - - 2.0.0 - - 2.1 - - 2.2 - - 2.3 - - 2.4 - - 2.5 - - 2.6 -before_install: - - gem update --system 2.7.8 - - gem install bundler -v 1.17.3 -before_script: bin/rake build format_json && git status -s && [[ -z $(git status -s) ]] diff --git a/Gemfile b/Gemfile index 8b2de3b9..91b54d11 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source "https://rubygems.org" -gem "openc-json_schema" -gem "rake" -gem "rspec" -gem "json_validation" -gem "openc_json_schema_formats" +group :development, :test do + gem "rake", "~> 10.3" + gem "rspec", "~> 3" +end + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 8b91b0e5..3b7a2519 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,18 @@ +PATH + remote: . + specs: + openc-schema (1.1.0) + json_validation (= 0.1.0) + openc-json_schema (= 0.0.14) + openc_json_schema_formats (= 0.1.3) + GEM remote: https://rubygems.org/ specs: addressable (2.3.8) diff-lcs (1.3) json-pointer (0.0.1) - json-schema (2.6.0) + json-schema (2.6.2) addressable (~> 2.3.8) json_validation (0.1.0) addressable @@ -32,11 +40,9 @@ PLATFORMS ruby DEPENDENCIES - json_validation - openc-json_schema - openc_json_schema_formats - rake - rspec + openc-schema! + rake (~> 10.3) + rspec (~> 3) BUNDLED WITH - 1.16.2 + 1.17.2 diff --git a/README.md b/README.md index f68bb7d7..02f994df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,27 @@ # openc-schema -JSON Schema to validate data before sending to OpenCorporates. +JSON Schema to validate data before sending it to be **ingested into** OpenCorporates. + +Originally these files were designed for use by external developers, along with the [openc_bot gem](https://github.com/openc/openc_bot), with OpenCorporates encouraging anyone to join in with writing bots for data gathering and ingestion. Lately we have moved away from that approach, and all meaningful use of these schema files is confined to bots living in our own private repos. + +Looking for a schema description of the OpenCorporates API? We're working on something, so let us know you're interested (But this repo is not it!) + +## Usage + +Include it in your Gemfile: + +``` +gem "openc-schema", git: "https://github.com/openc/openc-schema", tag: "vx.y.z" +``` + +Then get the path to the schema files: + +``` +File.join(Gem.loaded_specs['openc-schema'].full_gem_path, "schemas/company-schema.json") +``` + +If you are using a library that uses this gem, you must include this gem along with the library in your Gemfile. +This will be required until this gem is hosted in a proper gem registry. ## Tasks diff --git a/build/accounts-statement-schema.json b/build/accounts-statement-schema.json index 09538268..f3653819 100644 --- a/build/accounts-statement-schema.json +++ b/build/accounts-statement-schema.json @@ -657,6 +657,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -795,6 +796,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -957,6 +959,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/alternate-registration-schema.json b/build/alternate-registration-schema.json index 0955ef04..147a1edf 100644 --- a/build/alternate-registration-schema.json +++ b/build/alternate-registration-schema.json @@ -567,6 +567,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -705,6 +706,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -867,6 +869,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/alternative-name-schema.json b/build/alternative-name-schema.json new file mode 100644 index 00000000..45e9decd --- /dev/null +++ b/build/alternative-name-schema.json @@ -0,0 +1,85 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "Doing Business As, also known as fictitious name or trade name", + "type": "object", + "properties": { + "name": { + "description": "The name registered", + "type": "string" + }, + "type": { + "description": "Type of alternative name", + "type": "string", + "enum": [ + "Assumed Name", + "Trade Name", + "DBA / doing business as", + "Fictitious Name", + "Other" + ] + }, + "registered_address": { + "description": "The address filing was registered to", + "type": "object" + }, + "start_date": { + "type": "string", + "format": "date" + }, + "end_date": { + "type": "string", + "format": "date" + }, + "filing_number": { + "description": "The registers unique id for this record", + "type": "string" + }, + "source_jurisdiction": { + "type": "string", + "minLength": 1 + }, + "source_url": { + "description": "Place where this fact can be verified", + "type": "string", + "minLength": 1 + }, + "confidence": { + "description": "Confidence in accuracy of data", + "type": "string", + "enum": [ + "HIGH", + "MEDIUM", + "LOW" + ] + }, + "sample_date": { + "description": "Date on which we know this to be true (usually date this information was retrieved from the source)", + "type": "string", + "format": "date" + }, + "retrieved_at": { + "description": "The time or date at which the source URL was requested", + "type": "string", + "format": "date-time" + }, + "owner_entities": { + "description": "Lists of owner companies, and persons should this data be available", + "type": "object" + }, + "other_attributes": { + "description": "Dump of all other relevant data for which we don't yet have curated schema attributes", + "type": "object" + } + }, + "required": [ + "name", + "type", + "owner_entities", + "retrieved_at", + "sample_date", + "source_url", + "source_jurisdiction" + ], + "definitions": { + } +} \ No newline at end of file diff --git a/build/company-schema.json b/build/company-schema.json index 2bd74c6a..5ccbc9a4 100644 --- a/build/company-schema.json +++ b/build/company-schema.json @@ -399,6 +399,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -537,6 +538,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -699,6 +701,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/control-statement-schema.json b/build/control-statement-schema.json index bbd73a13..74ccf286 100644 --- a/build/control-statement-schema.json +++ b/build/control-statement-schema.json @@ -853,6 +853,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -991,6 +992,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -1153,6 +1155,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/filing-schema.json b/build/filing-schema.json index 2a9c01dd..19c0e95e 100644 --- a/build/filing-schema.json +++ b/build/filing-schema.json @@ -580,6 +580,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -718,6 +719,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -880,6 +882,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/gazette-notice-schema.json b/build/gazette-notice-schema.json index c061fa62..a9bdbd7f 100644 --- a/build/gazette-notice-schema.json +++ b/build/gazette-notice-schema.json @@ -1211,6 +1211,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -1349,6 +1350,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -1511,6 +1513,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/licence-schema.json b/build/licence-schema.json index dda781a3..66e526d9 100644 --- a/build/licence-schema.json +++ b/build/licence-schema.json @@ -589,6 +589,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -727,6 +728,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -889,6 +891,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/register-entry-schema.json b/build/register-entry-schema.json index ac4debff..c828d896 100644 --- a/build/register-entry-schema.json +++ b/build/register-entry-schema.json @@ -366,6 +366,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" @@ -800,6 +801,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -938,6 +940,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] diff --git a/build/sanctioned-entity-schema.json b/build/sanctioned-entity-schema.json index 05524d72..61afa000 100644 --- a/build/sanctioned-entity-schema.json +++ b/build/sanctioned-entity-schema.json @@ -364,6 +364,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" @@ -798,6 +799,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -936,6 +938,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] diff --git a/build/subsequent-registration-schema.json b/build/subsequent-registration-schema.json index bfefb936..31a435bc 100644 --- a/build/subsequent-registration-schema.json +++ b/build/subsequent-registration-schema.json @@ -568,6 +568,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -706,6 +707,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -868,6 +870,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/supplier-relationship-schema.json b/build/supplier-relationship-schema.json index 17fdb007..bff8b1be 100644 --- a/build/supplier-relationship-schema.json +++ b/build/supplier-relationship-schema.json @@ -561,6 +561,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -699,6 +700,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -861,6 +863,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/build/trademark-registration-schema.json b/build/trademark-registration-schema.json index 09d50b9b..5926eb93 100644 --- a/build/trademark-registration-schema.json +++ b/build/trademark-registration-schema.json @@ -676,6 +676,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] @@ -814,6 +815,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] @@ -976,6 +978,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/openc-schema.gemspec b/openc-schema.gemspec new file mode 100644 index 00000000..0d259cce --- /dev/null +++ b/openc-schema.gemspec @@ -0,0 +1,23 @@ +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +Gem::Specification.new do |spec| + spec.name = "openc-schema" + spec.version = "1.1.0" + spec.authors = ["OpenCorporates dev team"] + + spec.summary = %q{JSON Schema to validate data before sending to OpenCorporates.} + spec.homepage = "https://github.com/openc/openc-schema" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)|\.ruby-version/}) } + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + + spec.add_runtime_dependency "openc-json_schema", "= 0.0.14" + spec.add_runtime_dependency "json_validation", "= 0.1.0" + spec.add_runtime_dependency "openc_json_schema_formats", "= 0.1.3" +end diff --git a/schemas/includes/alternative-name.json b/schemas/includes/alternative-name.json index 12a6c7ad..549a035a 100644 --- a/schemas/includes/alternative-name.json +++ b/schemas/includes/alternative-name.json @@ -31,6 +31,7 @@ ] } }, + "additionalProperties": false, "required": [ "company_name", "type" diff --git a/schemas/includes/officer.json b/schemas/includes/officer.json index e973e954..d5608f0f 100644 --- a/schemas/includes/officer.json +++ b/schemas/includes/officer.json @@ -67,6 +67,7 @@ } } }, + "additionalProperties": false, "required": [ "name" ] diff --git a/schemas/includes/total-shares.json b/schemas/includes/total-shares.json index a945f4fe..077161f9 100644 --- a/schemas/includes/total-shares.json +++ b/schemas/includes/total-shares.json @@ -11,6 +11,7 @@ "minLength": 1 } }, + "additionalProperties": false, "required": [ "number" ] diff --git a/spec/sample-data/invalid/company/additional-alternative_names.0.con_date.json b/spec/sample-data/invalid/company/additional-alternative_names.0.con_date.json new file mode 100644 index 00000000..68516ad2 --- /dev/null +++ b/spec/sample-data/invalid/company/additional-alternative_names.0.con_date.json @@ -0,0 +1,13 @@ +{ + "name": "Foo Inc Alternative", + "jurisdiction_code": "us_de", + "company_number": "12345", + "alternative_names": [ + { + "company_name": "Foobar Inc", + "type": "trading", + "con_date": "2020-03-04" + } + ], + "retrieved_at": "2018-03-09T12:34:56Z" +} diff --git a/spec/sample-data/invalid/company/additional-officers.0.dob.json b/spec/sample-data/invalid/company/additional-officers.0.dob.json new file mode 100644 index 00000000..4a26098e --- /dev/null +++ b/spec/sample-data/invalid/company/additional-officers.0.dob.json @@ -0,0 +1,12 @@ +{ + "name": "Foo Inc", + "company_number": "12345", + "jurisdiction_code": "ie", + "officers": [ + { + "name": "Fred", + "dob": "1980-02-16" + } + ], + "retrieved_at": "2018-03-09T12:34:56Z" +} diff --git a/spec/sample-data/invalid/company/additional-officers.0.type.json b/spec/sample-data/invalid/company/additional-officers.0.type.json new file mode 100644 index 00000000..cbb12650 --- /dev/null +++ b/spec/sample-data/invalid/company/additional-officers.0.type.json @@ -0,0 +1,12 @@ +{ + "name": "Foo Inc", + "company_number": "12345", + "jurisdiction_code": "ie", + "officers": [ + { + "name": "Fred", + "type": "Company" + } + ], + "retrieved_at": "2018-03-09T12:34:56Z" +} diff --git a/spec/sample-data/invalid/includes/total-shares/additional-foo.json b/spec/sample-data/invalid/includes/total-shares/additional-foo.json new file mode 100644 index 00000000..4f32df9c --- /dev/null +++ b/spec/sample-data/invalid/includes/total-shares/additional-foo.json @@ -0,0 +1,5 @@ +{ + "number": 100, + "share_class": "A", + "foo": "bar" +} diff --git a/spec/sample-data/valid/includes/total-shares-01.json b/spec/sample-data/valid/includes/total-shares-01.json new file mode 100644 index 00000000..8dd2a075 --- /dev/null +++ b/spec/sample-data/valid/includes/total-shares-01.json @@ -0,0 +1,4 @@ +{ + "number": 100, + "share_class": "A" +}