-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose collection metadata through the collection API (#1123)
- Loading branch information
Showing
34 changed files
with
429 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{ | ||
"@opentermsarchive/engine": { | ||
"services": { | ||
"declarationsPath": "./demo-declarations/declarations" | ||
} | ||
"collectionPath": "./demo-declarations/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
import express from 'express'; | ||
import yaml from 'js-yaml'; | ||
|
||
import Service from '../../archivist/services/service.js'; | ||
|
||
const METADATA_FILENAME = 'metadata.yml'; | ||
const PACKAGE_JSON_PATH = '../../../package.json'; | ||
|
||
/** | ||
* @swagger | ||
* tags: | ||
* name: Metadata | ||
* description: Collection metadata API | ||
* components: | ||
* schemas: | ||
* Metadata: | ||
* type: object | ||
* description: Collection metadata | ||
* properties: | ||
* id: | ||
* type: string | ||
* description: Unique identifier of the collection | ||
* name: | ||
* type: string | ||
* description: Display name of the collection | ||
* tagline: | ||
* type: string | ||
* description: Short description of the collection | ||
* description: | ||
* type: string | ||
* nullable: true | ||
* description: Detailed description of the collection | ||
* totalTerms: | ||
* type: integer | ||
* description: Total number of terms tracked in the collection | ||
* totalServices: | ||
* type: integer | ||
* description: Total number of services tracked in the collection | ||
* engineVersion: | ||
* type: string | ||
* description: Version of the Open Terms Archive engine in SemVer format (MAJOR.MINOR.PATCH) | ||
* dataset: | ||
* type: string | ||
* format: uri | ||
* description: URL to the dataset releases | ||
* declarations: | ||
* type: string | ||
* format: uri | ||
* description: URL to the declarations repository | ||
* versions: | ||
* type: string | ||
* format: uri | ||
* description: URL to the versions repository | ||
* snapshots: | ||
* type: string | ||
* format: uri | ||
* description: URL to the snapshots repository | ||
* logo: | ||
* type: string | ||
* format: uri | ||
* nullable: true | ||
* description: URL to the collection logo | ||
* languages: | ||
* type: array | ||
* items: | ||
* type: string | ||
* description: List of ISO 639 language codes representing languages allowed by the collection | ||
* jurisdictions: | ||
* type: array | ||
* items: | ||
* type: string | ||
* description: List of ISO 3166-2 country codes representing jurisdictions covered by the collection | ||
* trackingPeriods: | ||
* type: array | ||
* items: | ||
* type: object | ||
* properties: | ||
* startDate: | ||
* type: string | ||
* format: date | ||
* description: The date when tracking started for this period | ||
* schedule: | ||
* type: string | ||
* description: A cron expression defining when terms are tracked (e.g. "0 0 * * *" for daily at midnight) | ||
* serverLocation: | ||
* type: string | ||
* description: The geographic location of the server used for tracking | ||
* endDate: | ||
* type: string | ||
* format: date | ||
* description: The date when tracking ended for this period | ||
* governance: | ||
* type: object | ||
* properties: | ||
* hosts: | ||
* type: array | ||
* items: | ||
* $ref: '#/components/schemas/Organization' | ||
* administrators: | ||
* type: array | ||
* items: | ||
* $ref: '#/components/schemas/Organization' | ||
* curators: | ||
* type: array | ||
* items: | ||
* $ref: '#/components/schemas/Organization' | ||
* maintainers: | ||
* type: array | ||
* items: | ||
* $ref: '#/components/schemas/Organization' | ||
* sponsors: | ||
* type: array | ||
* items: | ||
* $ref: '#/components/schemas/Organization' | ||
* Organization: | ||
* type: object | ||
* properties: | ||
* name: | ||
* type: string | ||
* description: Name of the organization | ||
* url: | ||
* type: string | ||
* format: uri | ||
* description: URL to the organization's website | ||
* logo: | ||
* type: string | ||
* format: uri | ||
* description: URL to the organization's logo | ||
*/ | ||
export default async function metadataRouter(collectionPath, services) { | ||
const router = express.Router(); | ||
|
||
const STATIC_METADATA = yaml.load(await fs.readFile(path.join(collectionPath, METADATA_FILENAME), 'utf8')); | ||
const { version: engineVersion } = JSON.parse(await fs.readFile(new URL(PACKAGE_JSON_PATH, import.meta.url))); | ||
|
||
/** | ||
* @swagger | ||
* /metadata: | ||
* get: | ||
* summary: Get collection metadata | ||
* tags: [Metadata] | ||
* produces: | ||
* - application/json | ||
* responses: | ||
* 200: | ||
* description: Collection metadata | ||
*/ | ||
router.get('/metadata', (req, res) => { | ||
const dynamicMetadata = { | ||
totalServices: Object.keys(services).length, | ||
totalTerms: Service.getNumberOfTerms(services), | ||
engineVersion, | ||
}; | ||
|
||
res.json({ | ||
...STATIC_METADATA, | ||
...dynamicMetadata, | ||
}); | ||
}); | ||
|
||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import fs from 'fs/promises'; | ||
|
||
import { expect } from 'chai'; | ||
import config from 'config'; | ||
import request from 'supertest'; | ||
|
||
import app from '../server.js'; | ||
|
||
const basePath = config.get('@opentermsarchive/engine.collection-api.basePath'); | ||
const { version: engineVersion } = JSON.parse(await fs.readFile(new URL('../../../package.json', import.meta.url))); | ||
|
||
const EXPECTED_RESPONSE = { | ||
totalServices: 7, | ||
totalTerms: 8, | ||
id: 'test', | ||
name: 'test', | ||
tagline: 'Test collection', | ||
description: 'This is a test collection used for testing purposes.', | ||
dataset: 'https://github.com/OpenTermsArchive/test-versions/releases', | ||
declarations: 'https://github.com/OpenTermsArchive/test-declarations', | ||
versions: 'https://github.com/OpenTermsArchive/test-versions', | ||
snapshots: 'https://github.com/OpenTermsArchive/test-snapshots', | ||
donations: null, | ||
logo: 'https://opentermsarchive.org/images/logo/logo-open-terms-archive-black.png', | ||
languages: [ | ||
'en', | ||
], | ||
jurisdictions: [ | ||
'EU', | ||
], | ||
governance: { | ||
hosts: [ | ||
{ name: 'Localhost' }, | ||
], | ||
administrators: [ | ||
{ | ||
name: 'Open Terms Archive', | ||
url: 'https://opentermsarchive.org/', | ||
logo: 'https://opentermsarchive.org/images/logo/logo-open-terms-archive-black.png', | ||
}, | ||
], | ||
curators: [ | ||
{ | ||
name: 'Open Terms Archive', | ||
url: 'https://opentermsarchive.org/', | ||
logo: 'https://opentermsarchive.org/images/logo/logo-open-terms-archive-black.png', | ||
}, | ||
], | ||
maintainers: [ | ||
{ | ||
name: 'Open Terms Archive', | ||
url: 'https://opentermsarchive.org/', | ||
logo: 'https://opentermsarchive.org/images/logo/logo-open-terms-archive-black.png', | ||
}, | ||
], | ||
sponsors: [ | ||
{ | ||
name: 'Open Terms Archive', | ||
url: 'https://opentermsarchive.org/', | ||
logo: 'https://opentermsarchive.org/images/logo/logo-open-terms-archive-black.png', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
describe('Metadata API', () => { | ||
describe('GET /metadata', () => { | ||
let response; | ||
|
||
before(async () => { | ||
response = await request(app).get(`${basePath}/v1/metadata`); | ||
}); | ||
|
||
it('responds with 200 status code', () => { | ||
expect(response.status).to.equal(200); | ||
}); | ||
|
||
it('responds with Content-Type application/json', () => { | ||
expect(response.type).to.equal('application/json'); | ||
}); | ||
|
||
it('returns expected metadata object', () => { | ||
expect(response.body).to.deep.equal({ | ||
...EXPECTED_RESPONSE, | ||
engineVersion, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.