github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/etc/example_schema.yaml (about)

     1  # Pet Store Schema
     2  schemas:
     3  - description: base resource definition
     4    id: base
     5    plural: bases
     6    prefix: /v1.0
     7    type: abstract
     8    schema:
     9      properties:
    10        description:
    11          description: Description
    12          permission:
    13          - create
    14          - update
    15          title: Description
    16          type: string
    17        id:
    18          description: ID
    19          permission:
    20          - create
    21          title: ID
    22          type: string
    23          view:
    24          - detail
    25        name:
    26          description: Name
    27          permission:
    28          - create
    29          - update
    30          title: Name
    31          type: string
    32        tenant_id:
    33          description: Tenant ID
    34          permission:
    35          - create
    36          title: Tenant ID
    37          type: string
    38          view:
    39          - detail
    40      propertiesOrder:
    41      - id
    42      - name
    43      - tenant_id
    44      - description
    45      required: []
    46      type: object
    47    singular: base
    48    title: Base Resource
    49  - description: pet
    50    id: pet
    51    plural: pets
    52    extends:
    53    - base
    54    prefix: /v1.0/store
    55    schema:
    56      properties:
    57        status:
    58          description: Status
    59          permission:
    60          - create
    61          - update
    62          title: Status
    63          type: string
    64          enum:
    65          - available
    66          - pending
    67          - sold
    68      propertiesOrder:
    69      - status
    70      required: []
    71      type: object
    72    singular: pet
    73    title: Pet
    74  - description: order
    75    id: order
    76    plural: orders
    77    extends:
    78    - base
    79    prefix: /v1.0/store
    80    schema:
    81      properties:
    82        pet_id:
    83          description: Pet
    84          permission:
    85          - create
    86          title: Pet
    87          type: string
    88          relation: pet
    89          relation_property: pet
    90          indexed: true
    91        status:
    92          description: Status
    93          permission:
    94          - create
    95          - update
    96          title: Status
    97          type: string
    98          enum:
    99          - placed
   100          - approved
   101          - delivered
   102        complete:
   103          description: Complete
   104          permission:
   105          - create
   106          title: Complete
   107          type: boolean
   108      propertiesOrder:
   109      - pet_id
   110      - status
   111      - complete
   112      required: []
   113      type: object
   114    singular: pet
   115    title: Order
   116  # Policy
   117  policies:
   118  # Allow to read schema
   119  - action: read
   120    effect: allow
   121    id: policy1
   122    principal: Member
   123    resource:
   124      path: /gohan/v0.1/schemas*
   125  # Allow to read pets
   126  - action: read
   127    effect: allow
   128    id: policy2
   129    principal: Member
   130    resource:
   131      path: /v1.0/store/pets
   132  # Allow to read orders
   133  - action: read
   134    effect: allow
   135    id: policy3
   136    principal: Member
   137    condition:
   138    - is_owner
   139    resource:
   140      path: /v1.0/store/orders
   141  # Allow to place new order
   142  - action: create
   143    effect: allow
   144    id: policy4
   145    principal: Member
   146    resource:
   147      path: /v1.0/store/orders
   148    condition:
   149    - type: property
   150      action: create
   151      match:
   152        status: placed
   153  extensions:
   154  - id: order
   155    path: /v1.0/store/orders
   156    code_type: gohanscript
   157    code: |
   158      tasks:
   159      - when: event_type == "post_create_in_transaction"
   160        blocks:
   161        #  Try debugger
   162        # - debugger:
   163        - db_get:
   164            tx: $transaction
   165            schema_id: pet
   166            id: $resource.pet_id
   167            tenant_id: ""
   168          register: pet
   169        - when: pet.status != "available"
   170          blocks:
   171          - error:
   172              name: CustomException
   173              code: 400
   174              message: "Selected pet isn't available"
   175          else:
   176          - db_update:
   177              tx: $transaction
   178              schema_id: pet
   179              data:
   180                  id: $resource.pet_id
   181                  status: "pending"
   182      - when: event_type == "post_update_in_transaction"
   183        blocks:
   184        - when: resource.status == "approved"
   185          blocks:
   186          - db_update:
   187              tx: $transaction
   188              schema_id: pet
   189              data:
   190                id: $resource.pet_id
   191                status: "sold"