Are components definable in custom script services?

I’m writing a custom v8js script API to make a CouchDB API that can access views. I’m wondering if there is a way with Dreamfactory to allow user roles only access to certain tables? Are components in role definitions supported for custom scripts?

Thanks!

Yes, Role definitions can be added for scripts and remote web services down to the component level, but they require you to add swagger definitions for your service. Otherwise, DreamFactory doesn’t know that the components exist.

1 Like

Thanks for the response! I’ve written a swagger definition for my service
which populates the API Docs, but I haven’t used it to create components.
What type of data type or schema gets translated from the swagger
definition into a component as seen by DreamFactory?

1 Like

Any update on that topic?

Since I couldn’t find much information about it in the wiki, I have tried formatting a service definition by mimicking what I have found in the “native” Dreamfactory Services.

Here is an excerpt of the service definition for the service I created. This service accesses the database tables of a MySQL Service. In the example below, the service, when accessed through /api/v2/test-service/content would query the MySQL table and simply pass on the response.

I have tried adding descriptions for responses, and an operationId for each path. Yet it does not help making Dreamfactory see these paths as components, like for “native” services (see for example the user service at the bottom of this post).

Help or links to documentation would be appreciated :slight_smile:

swagger: '2.0'
basePath: "/api/v2"
info:
  version: "2.0"
  title: "Test Service"
consumes:
  - "application/json"
produces:
  - "application/json"
paths:
  /test-service/content:
    get:
      tags:
      - test-service
      operationId: "getContents"
      responses:
        '200':
          description: Success
          schema:
            $ref: '#/definitions/RecordsResponse'
        default:
          description: Error
          schema:
            $ref: '#/definitions/Error'
  /test-service/author:
    get:
      tags:
      - test-service
      operationId: "getAuthors"
      responses:
        '200':
          description: Success
          schema:
            $ref: '#/definitions/RecordsResponse'
        default:
          description: Error
          schema:
            $ref: '#/definitions/Error'
...
definitions:
  Success:
    type: object
    properties:
      success:
        type: boolean
        description: "True when API call was successful, false or error otherwise."
  Error:
    type: object
    properties:
      code:
        type: integer
        format: int32
        description: "Error code."
      message:
        type: string
        description: "String description of the error."
  RecordResponse:
    type: object
    properties:
      id:
        type: integer
        format: int32
        description: "Sample identifier of this record."
  RecordsResponse:
    type: object
    properties:
      resource:
        type: array
        description: "Array of system user records."
        items:
          "$ref": "#/definitions/RecordResponse"
tags:
  name: test-service
  description: "A test service"