diff --git a/swagger/index.yaml b/swagger/index.yaml index 00c1f32463c92d6023f992de241b92bfe94e52ce..a8a506b7cb8bd979533e17d18503f9fd949e2acd 100644 --- a/swagger/index.yaml +++ b/swagger/index.yaml @@ -28,9 +28,23 @@ tags: description: Collection operations paths: - $ref: ./paths/index.yaml -# definitions: - # $ref: ./definitions/index.yaml + $include: + - paths/login.yaml + - paths/download.yaml + - paths/upload-by-label.yaml + - paths/upload-by-uid.yaml + - paths/upload-match-uid.yaml + - paths/clean-packfiles.yaml + - paths/engine.yaml + - paths/config.yaml + - paths/config-js.yaml + - paths/version.yaml + - paths/users.yaml + - paths/jobs.yaml + - paths/gears.yaml + - paths/devices.yaml + - paths/groups.yaml + - paths/collections.yaml securityDefinitions: ApiKey: diff --git a/swagger/paths/clean-packfiles.yaml b/swagger/paths/clean-packfiles.yaml index 4ea212c3a605e224b6591e065aa9a272afbef016..a92aefdcd9d7aaddacf16fed5956f692a103a243 100644 --- a/swagger/paths/clean-packfiles.yaml +++ b/swagger/paths/clean-packfiles.yaml @@ -1,4 +1,4 @@ -clean-packfiles: +/clean-packfiles: post: summary: Clean up expired upload tokens and invalid token directories. operationId: clean_packfiles diff --git a/swagger/paths/collections.yaml b/swagger/paths/collections.yaml index e858f4366514e5c3957a201ee6fa2a388516dc1b..b92831fbc20b3f8ba2fbf6a4ee0bb0abfb4d7f47 100644 --- a/swagger/paths/collections.yaml +++ b/swagger/paths/collections.yaml @@ -1,10 +1,5 @@ # Global template arguments for collection -collection_tmpl_args: - resource: collection - tag: collections - parameter: CollectionId - -collections: +/collections: get: summary: List all collections. operationId: get_all_collections @@ -37,7 +32,7 @@ collections: '400': $ref: '#/responses/400:invalid-body-json' -collections-curators: +/collections/curators: get: summary: List all curators of collections operationId: get_all_collections_curators @@ -50,7 +45,7 @@ collections-curators: examples: response: $ref: examples/output/collection-curators-list.json -collections-collection: +/collections/{CollectionId}: parameters: - required: true type: string @@ -92,7 +87,7 @@ collections-collection: '200': description: Collection was deleted -collections-collection-sessions: +/collections/{CollectionId}/sessions: parameters: - required: true type: string @@ -112,7 +107,7 @@ collections-collection-sessions: response: $ref: examples/output/session-list.json -collections-collection-acquisitions: +/collections/{CollectionId}/acquisitions: parameters: - required: true type: string @@ -133,82 +128,116 @@ collections-collection-acquisitions: $ref: examples/output/acquisition-list.json # ===== Tags ===== -collections-collection-tags: +/collections/{CollectionId}/tags: $template: templates/tags.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-tags-tag: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/tags/{TagValue}: $template: templates/tags-tag.yaml arguments: - $ref: '#/collection_tmpl_args' + resource: collection + tag: collections + parameter: CollectionId # ===== Packfile ===== -collections-collection-packfile-start: +/collections/{CollectionId}/packfile-start: $template: templates/packfile-start.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-packfile: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/packfile: $template: templates/packfile.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-packfile-end: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/packfile-end: $template: templates/packfile-end.yaml arguments: - $ref: '#/collection_tmpl_args' + resource: collection + tag: collections + parameter: CollectionId # ===== Files ===== -collections-collection-files: +/collections/{CollectionId}/files: $template: templates/file-list-upload.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-files-file: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/files/{FileName}: $template: templates/file-item.yaml arguments: - $ref: '#/collection_tmpl_args' + resource: collection + tag: collections + parameter: CollectionId # ===== Permissions ===== -collections-collection-permissions: +/collections/{CollectionId}/permissions: $template: templates/permissions.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-permissions-user: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/permissions/{UserId}: $template: templates/permissions-user.yaml arguments: - $ref: '#/collection_tmpl_args' + resource: collection + tag: collections + parameter: CollectionId # ===== Notes ===== -collections-collection-notes: +/collections/{CollectionId}/notes: $template: templates/notes.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-notes-note: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/notes/{NoteId}: $template: templates/notes-note.yaml arguments: - $ref: '#/collection_tmpl_args' + resource: collection + tag: collections + parameter: CollectionId # ===== Analyses ===== -collections-collection-analyses: +/collections/{CollectionId}/analyses: $template: templates/analyses-list.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-analyses-analysis: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/analyses/{AnalysisId}: $template: templates/analysis-item.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-analyses-analysis-files: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/analyses/{AnalysisId}/files: $template: templates/analysis-files.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-analyses-analysis-files-filename: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/analyses/{AnalysisId}/files/{Filename}: $template: templates/analysis-files-create-ticket-filename.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-analyses-analysis-notes: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/analyses/{AnalysisId}/notes: $template: templates/analysis-notes.yaml arguments: - $ref: '#/collection_tmpl_args' -collections-collection-analyses-analysis-notes-note: + resource: collection + tag: collections + parameter: CollectionId +/collections/{CollectionId}/analyses/{AnalysisId}/notes/{NoteId}: $template: templates/analysis-notes-item.yaml arguments: - $ref: '#/collection_tmpl_args' + resource: collection + tag: collections + parameter: CollectionId \ No newline at end of file diff --git a/swagger/paths/config-js.yaml b/swagger/paths/config-js.yaml index 8456e325113f33ad2d02d2c7125736fef6551345..09ffa6a754ccf10ff83ac5349f9f98ca5f953021 100644 --- a/swagger/paths/config-js.yaml +++ b/swagger/paths/config-js.yaml @@ -1,4 +1,4 @@ -config-js: +/config.js: get: summary: Return public Scitran configuration information in javascript format. operationId: get_config_js diff --git a/swagger/paths/config.yaml b/swagger/paths/config.yaml index 74c3fdd914251900d1daaa76747783723719e6db..dfaf4a5d95d747b8f52338178b50cb89ddcf3113 100644 --- a/swagger/paths/config.yaml +++ b/swagger/paths/config.yaml @@ -1,4 +1,4 @@ -config: +/config: get: summary: Return public Scitran configuration information operationId: get_config diff --git a/swagger/paths/devices.yaml b/swagger/paths/devices.yaml index 767f52adcba6d29c6d997193e4b1332629346594..08f5edbaadd9c189d599ca3db6801a1d2525884e 100644 --- a/swagger/paths/devices.yaml +++ b/swagger/paths/devices.yaml @@ -1,4 +1,4 @@ -devices: +/devices: get: summary: List all devices. description: Requires login. @@ -32,7 +32,7 @@ devices: in: body schema: $ref: schemas/input/device.json -devices-self: +/devices/self: get: summary: Get device document for device making the request. description: Request must be a drone request. @@ -47,7 +47,7 @@ devices-self: examples: response: $ref: examples/output/device.json -devices-status: +/devices/status: get: summary: Get status for all known devices. description: ok - missing - error - unknown @@ -62,7 +62,7 @@ devices-status: examples: response: $ref: examples/output/device-status.json -devices-device: +/devices/{DeviceId}: parameters: - required: true type: string diff --git a/swagger/paths/download.yaml b/swagger/paths/download.yaml index 98cffd7900a97fe2ac8a2c200570e6c5993f3ce9..cf709334a05e238e3fa34de332b2fc2261662e90 100644 --- a/swagger/paths/download.yaml +++ b/swagger/paths/download.yaml @@ -1,4 +1,4 @@ -download: +/download: post: summary: Create a download ticket description: | diff --git a/swagger/paths/engine.yaml b/swagger/paths/engine.yaml index ddd947e636c219fa3f7176ee412284ed65d65f19..f44655e0ed60a88067aedf5c07ba9fdadd42214d 100644 --- a/swagger/paths/engine.yaml +++ b/swagger/paths/engine.yaml @@ -1,4 +1,4 @@ -engine: +/engine: post: summary: Upload a list of file fields. description: | diff --git a/swagger/paths/gears.yaml b/swagger/paths/gears.yaml index bda09189b88348c2f7befcd04d23f46074fd5d90..4a4ac88d37f067ff38d23d5cbb2c6248795239c4 100644 --- a/swagger/paths/gears.yaml +++ b/swagger/paths/gears.yaml @@ -1,4 +1,4 @@ -gears: +/gears: get: summary: List all gears operationId: get_all_gears @@ -7,7 +7,7 @@ gears: responses: default: description: '' -gears-gear-by-name: +/gears/{GearName}: parameters: - required: true description: Name of the gear to interact with @@ -25,7 +25,7 @@ gears-gear-by-name: responses: default: description: '' -gears-gear: +gears/{GearId}: parameters: - required: true description: Id of the gear to interact with diff --git a/swagger/paths/groups.yaml b/swagger/paths/groups.yaml index fa5f734e9cca77df25ecb9b60f1617f0ee7d8c9f..4c70539e03a055f3cdc5076f76de0942525bedb1 100644 --- a/swagger/paths/groups.yaml +++ b/swagger/paths/groups.yaml @@ -1,9 +1,4 @@ -group_tmpl_args: - resource: group - tag: groups - parameter: GroupId - -groups: +/groups: get: summary: List all groups operationId: get_all_groups @@ -34,7 +29,7 @@ groups: $ref: schemas/output/group-new.json '400': $ref: '#/responses/400:invalid-body-json' -groups-group: +/groups/{GroupId}: parameters: - required: true type: string @@ -76,26 +71,34 @@ groups-group: $ref: '#/responses/200:deleted-with-count' # ===== Permissions ===== -groups-group-permissions: +/groups/{GroupId}/permissions: $template: templates/permissions.yaml arguments: - $ref: '#/group_tmpl_args' -groups-group-permissions-user: + resource: group + tag: groups + parameter: GroupId +/groups/{GroupId}/permissions/{UserId}: $template: templates/permissions-user.yaml arguments: - $ref: '#/group_tmpl_args' + resource: group + tag: groups + parameter: GroupId # ===== Tags ===== -groups-group-tags: +/groups/{GroupId}/tags: $template: templates/tags.yaml arguments: - $ref: '#/group_tmpl_args' -groups-group-tags-tag: + resource: group + tag: groups + parameter: GroupId +/groups/{GroupId}/tags/{TagValue}: $template: templates/tags-tag.yaml arguments: - $ref: '#/group_tmpl_args' + resource: group + tag: groups + parameter: GroupId -groups-group-projects: +/groups/{GroupId}/projects: parameters: - required: true type: string diff --git a/swagger/paths/index.yaml b/swagger/paths/index.yaml deleted file mode 100644 index 4e0c5a37e8fb39780eb33dc1bbdf256c4adf2959..0000000000000000000000000000000000000000 --- a/swagger/paths/index.yaml +++ /dev/null @@ -1,134 +0,0 @@ -/login: - $ref: login.yaml#/login -/logout: - $ref: login.yaml#/logout -/download: - $ref: download.yaml#/download -/upload/label: - $ref: upload-by-label.yaml#/upload-by-label -/upload/uid: - $ref: upload-by-uid.yaml#/upload-by-uid -/upload/uid-match: - $ref: upload-match-uid.yaml#/upload-match-uid -/clean-packfiles: - $ref: clean-packfiles.yaml#/clean-packfiles -/engine: - $ref: engine.yaml#/engine -/config: - $ref: config.yaml#/config -/config-js: - $ref: config-js.yaml#/config-js -/version: - $ref: version.yaml#/version - -/users: - $ref: users.yaml#/users -/users/self: - $ref: users.yaml#/users-self -/users/self/avatar: - $ref: users.yaml#/users-self-avatar -'/users/{UserId}': - $ref: users.yaml#/users-user -'/users/{UserId}/groups': - $ref: users.yaml#/users-user-groups -'/users/{UserId}/acquisitions': - $ref: users.yaml#/users-user-acquisitions -'/users/{UserId}/collections': - $ref: users.yaml#/users-user-collections -'/users/{UserId}/projects': - $ref: users.yaml#/users-user-projects -'/users/{UserId}/sessions': - $ref: users.yaml#/users-user-sessions - -/jobs/add: - $ref: jobs.yaml#/jobs-add -/jobs/next: - $ref: jobs.yaml#/jobs-next -/jobs/stats: - $ref: jobs.yaml#/jobs-stats -/jobs/reap: - $ref: jobs.yaml#/jobs-reap -'/jobs/{JobId}': - $ref: jobs.yaml#/jobs-job -'/jobs/{JobId}/retry': - $ref: jobs.yaml#/jobs-job-retry -'/jobs/{JobId}/config.json': - $ref: jobs.yaml#/jobs-job-config-json - -/gears: - $ref: gears.yaml#/gears -'/gears/{GearName}': - $ref: gears.yaml#/gears-gear-by-name -'/gears/{GearId}': - $ref: gears.yaml#/gears-gear - -/devices: - $ref: devices.yaml#/devices -/devices/self: - $ref: devices.yaml#/devices-self -/devices/status: - $ref: devices.yaml#/devices-status -'/devices/{DeviceId}': - $ref: devices.yaml#/devices-device - -/groups: - $ref: groups.yaml#/groups -'/groups/{GroupId}': - $ref: groups.yaml#/groups-group -'/groups/{GroupId}/permissions': - $ref: groups.yaml#/groups-group-permissions -'/groups/{GroupId}/permissions/{UserId}': - $ref: groups.yaml#/groups-group-permissions-user -'/groups/{GroupId}/tags': - $ref: groups.yaml#/groups-group-tags -'/groups/{GroupId}/tags/{TagValue}': - $ref: groups.yaml#/groups-group-tags-tag -'/groups/{GroupId}/projects': - $ref: groups.yaml#/groups-group-projects - -/collections: - $ref: collections.yaml#/collections -/collections/curators: - $ref: collections.yaml#/collections-curators -'/collections/{CollectionId}': - $ref: collections.yaml#/collections-collection -'/collections/{CollectionId}/sessions': - $ref: collections.yaml#/collections-collection-sessions -'/collections/{CollectionId}/acquisitions': - $ref: collections.yaml#/collections-collection-acquisitions -'/collections/{CollectionId}/tags': - $ref: collections.yaml#/collections-collection-tags -'/collections/{CollectionId}/tags/{TagValue}': - $ref: collections.yaml#/collections-collection-tags-tag -'/collections/{CollectionId}/packfile-start': - $ref: collections.yaml#/collections-collection-packfile-start -'/collections/{CollectionId}/packfile': - $ref: collections.yaml#/collections-collection-packfile -'/collections/{CollectionId}/packfile-end': - $ref: collections.yaml#/collections-collection-packfile-end -'/collections/{CollectionId}/files': - $ref: collections.yaml#/collections-collection-files -'/collections/{CollectionId}/files/{FileName}': - $ref: collections.yaml#/collections-collection-files-file -'/collections/{CollectionId}/permissions': - $ref: collections.yaml#/collections-collection-permissions -'/collections/{CollectionId}/permissions/{UserId}': - $ref: collections.yaml#/collections-collection-permissions-user -'/collections/{CollectionId}/notes': - $ref: collections.yaml#/collections-collection-notes -'/collections/{CollectionId}/notes/{NoteId}': - $ref: collections.yaml#/collections-collection-notes-note -'/collections/{CollectionId}/analyses': - $ref: collections.yaml#/collections-collection-analyses -'/collections/{CollectionId}/analyses/{AnalysisId}': - $ref: collections.yaml#/collections-collection-analyses-analysis -'/collections/{CollectionId}/analyses/{AnalysisId}/files': - $ref: collections.yaml#/collections-collection-analyses-analysis-files -'/collections/{CollectionId}/analyses/{AnalysisId}/files/{Filename}': - $ref: collections.yaml#/collections-collection-analyses-analysis-files-filename -'/collections/{CollectionId}/analyses/{AnalysisId}/notes': - $ref: collections.yaml#/collections-collection-analyses-analysis-notes -'/collections/{CollectionId}/analyses/{AnalysisId}/notes/{NoteId}': - $ref: collections.yaml#/collections-collection-analyses-analysis-notes-note - - diff --git a/swagger/paths/jobs.yaml b/swagger/paths/jobs.yaml index 7e4f6e0f9ad9d5462d8728fbfb06cee7381e19a8..b65e2e513286cb476485fd9f2372a0cf5ab02beb 100644 --- a/swagger/paths/jobs.yaml +++ b/swagger/paths/jobs.yaml @@ -1,4 +1,4 @@ -jobs-add: +/jobs/add: post: summary: Add a job operationId: add_job @@ -18,7 +18,7 @@ jobs-add: examples: response: _id: 573cb66b135d87002660597c -jobs-next: +/jobs/next: get: summary: Get the next job in the queue description: Used by the engine. @@ -28,7 +28,7 @@ jobs-next: responses: default: description: '' -jobs-stats: +/jobs/stats: get: summary: Get stats about all current jobs operationId: get_jobs_stats @@ -40,7 +40,7 @@ jobs-stats: schema: example: $ref: examples/job_stats.json -jobs-reap: +/jobs/reap: post: summary: Reap stale jobs operationId: reap_jobs @@ -52,7 +52,7 @@ jobs-reap: schema: example: orphaned: 3 -jobs-job: +/jobs/{JobId}: parameters: - required: true type: string @@ -96,7 +96,7 @@ jobs-job: schema: example: $ref: examples/input/job-update.json -jobs-job-retry: +/jobs/{JobId}/retry: parameters: - required: true type: string @@ -120,7 +120,7 @@ jobs-job-retry: schema: example: _id: 57a35c118120be0e8d1f3f5f -jobs-job-config-json: +/jobs/{JobId}/config.json: parameters: - required: true type: string diff --git a/swagger/paths/login.yaml b/swagger/paths/login.yaml index b328f12cfd3046b40512148a3dd873da18d346de..85ec8f7959e2b7e8fa4a1b69bca6bb802e545975 100644 --- a/swagger/paths/login.yaml +++ b/swagger/paths/login.yaml @@ -1,4 +1,4 @@ -login: +/login: post: summary: Login description: Scitran Authentication @@ -9,7 +9,7 @@ login: schema: example: success: true -logout: +/logout: post: summary: Log Out description: Remove authtokens for user diff --git a/swagger/paths/upload-by-label.yaml b/swagger/paths/upload-by-label.yaml index f4427bcee64825599e69e9ba37fcf6080a23fff8..427650988f12a6dbd18c0f5b6db4bbea0641ca98 100644 --- a/swagger/paths/upload-by-label.yaml +++ b/swagger/paths/upload-by-label.yaml @@ -1,4 +1,4 @@ -upload-by-label: +/upload/label: post: summary: Multipart form upload with N file fields, each with their desired filename. description: > diff --git a/swagger/paths/upload-by-uid.yaml b/swagger/paths/upload-by-uid.yaml index 1642564d99dfe7f68b800611b67facedf1645bf0..c5b0076c82777407762000a207268f466e8c06a7 100644 --- a/swagger/paths/upload-by-uid.yaml +++ b/swagger/paths/upload-by-uid.yaml @@ -1,4 +1,4 @@ -upload-by-uid: +/upload/uid: post: summary: Multipart form upload with N file fields, each with their desired filename. description: > diff --git a/swagger/paths/upload-match-uid.yaml b/swagger/paths/upload-match-uid.yaml index f09868bf622502b4378024f30356efffe5b26ffa..83615e7766ba1175b7b049e0bb057cf84453a934 100644 --- a/swagger/paths/upload-match-uid.yaml +++ b/swagger/paths/upload-match-uid.yaml @@ -1,4 +1,4 @@ -upload-match-uid: +/upload/uid-match: post: summary: Multipart form upload with N file fields, each with their desired filename. description: > diff --git a/swagger/paths/users.yaml b/swagger/paths/users.yaml index c8e8885d4644e14adfb5fbffa43a34eaa4542179..dcccc30a454f265ab61f5ffad0d751bea6b7621d 100644 --- a/swagger/paths/users.yaml +++ b/swagger/paths/users.yaml @@ -1,4 +1,4 @@ -users: +/users: get: summary: Return a list of all users operationId: get_all_users @@ -26,7 +26,7 @@ users: $ref: schemas/output/user-new.json '400': $ref: '#/responses/400:invalid-body-json' -users-self: +/users/self: get: summary: Get information about the current user operationId: get_current_user @@ -41,7 +41,7 @@ users-self: examples: response: $ref: examples/user_jane_doe.json -users-self-avatar: +/users/self/avatar: get: summary: Get the avatar of the current user operationId: get_current_user_avatar @@ -51,7 +51,7 @@ users-self-avatar: '307': description: | Redirects to the image file of the current user's avatar -users-user: +/users/{UserId}: parameters: - required: true type: string @@ -109,7 +109,7 @@ users-user: $ref: examples/output/user-delete.json '404': description: User not found -users-user-groups: +/users/{UserId}/groups: parameters: - required: true type: string @@ -128,7 +128,7 @@ users-user-groups: examples: response: $ref: examples/output/groups-list.json -users-user-avatar: +/users/{UserId}/avatar: parameters: - required: true type: string @@ -143,7 +143,7 @@ users-user-avatar: '307': description: | Redirects to the image file of the specified user's avatar -users-user-acquisitions: +/users/{UserId}/acquisitions: parameters: - required: true type: string @@ -162,7 +162,7 @@ users-user-acquisitions: examples: response: $ref: examples/output/acquisition-list.json -users-user-collections: +/users/{UserId}/collections: parameters: - required: true type: string @@ -181,7 +181,7 @@ users-user-collections: examples: response: $ref: examples/output/collection-list.json -users-user-projects: +/users/{UserId}/projects: parameters: - required: true type: string @@ -200,7 +200,7 @@ users-user-projects: examples: response: $ref: examples/output/project-list.json -users-user-sessions: +/users/{UserId}/sessions: parameters: - required: true type: string diff --git a/swagger/paths/version.yaml b/swagger/paths/version.yaml index 67d4b09b8bbde21a25f2b55ddb1a8b1acda0f1e2..3203682073e4fef733e06952d9996e8914f21548 100644 --- a/swagger/paths/version.yaml +++ b/swagger/paths/version.yaml @@ -1,4 +1,4 @@ -version: +/version: get: description: Get database schema version info operationId: get_version diff --git a/swagger/support/tasks/resolve-templates.js b/swagger/support/tasks/resolve-templates.js index 66f93a181c93979d17dbf5298e44af5717f998ce..0f0c3848dc611fffd988bd6f9fc91cb7e289fca5 100644 --- a/swagger/support/tasks/resolve-templates.js +++ b/swagger/support/tasks/resolve-templates.js @@ -19,7 +19,7 @@ module.exports = function(grunt) { tmplpath = path.join(templates, obj['$template']); if( !loaded_templates[tmplpath] ) { if( !fs.existsSync(tmplpath) ) { - throw 'Template file does note exist:' + tmplpath; + throw 'Template file does not exist: ' + tmplpath; } loaded_templates[tmplpath] = yaml.safeLoad(fs.readFileSync(tmplpath).toString()); } @@ -33,6 +33,29 @@ module.exports = function(grunt) { }; } + function resolveIncludesFunc(templates) { + return function(obj) { + return walk(obj, function(obj) { + var i, includes, incpath, inc; + + if( obj.hasOwnProperty('$include') ) { + includes = obj['$include']; + delete obj['$include']; + for( i = 0; i < includes.length; i++ ) { + incpath = path.join(templates, includes[i]); + if( !fs.existsSync(incpath) ) { + throw 'Included file does not exist: ' + incpath; + } + inc = yaml.safeLoad(fs.readFileSync(incpath).toString()); + _.extend(obj, inc); + } + } + + return obj; + }); + }; + } + function resolveParamsFunc(args) { return function(obj) { if( typeof obj === 'string' ) { @@ -47,6 +70,7 @@ module.exports = function(grunt) { var dest = this.data.dest; var templates = this.data.templates||process.cwd(); var resolveTemplates = resolveTemplatesFunc(templates); + var resolveIncludes = resolveIncludesFunc(templates); if(!fs.existsSync(src)) { grunt.log.writeln('Could not find:', src); @@ -55,6 +79,7 @@ module.exports = function(grunt) { var root = JSON.parse(fs.readFileSync(src).toString()); try { + root = resolveIncludes(root); root = resolveTemplates(root); } catch( e ) { grunt.log.writeln('Error resolving templates:', e);