Skip to content

Commit

Permalink
Add code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
phazonoverload committed Sep 16, 2024
1 parent 2407b8f commit c50ba37
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 45 deletions.
43 changes: 43 additions & 0 deletions api-spec/components/schemas/_index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Diff:
$ref: diff.yaml
Query:
$ref: query.yaml
Schema:
$ref: schema.yaml
x-metadata:
$ref: x-metadata.yaml

Activity:
$ref: activity.yaml
Collections:
$ref: collections.yaml
Extensions:
$ref: extensions.yaml
Fields:
$ref: fields.yaml
Files:
$ref: files.yaml
Flows:
$ref: flows.yaml
Folders:
$ref: folders.yaml
Operations:
$ref: operations.yaml
Permissions:
$ref: permissions.yaml
Presets:
$ref: presets.yaml
Relations:
$ref: relations.yaml
Revisions:
$ref: revisions.yaml
Roles:
$ref: roles.yaml
Settings:
$ref: settings.yaml
Users:
$ref: users.yaml
Versions:
$ref: versions.yaml
Webhooks:
$ref: webhooks.yaml
43 changes: 0 additions & 43 deletions api-spec/components/schemas/index.yaml

This file was deleted.

10 changes: 8 additions & 2 deletions api-spec/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ info:
servers:
- url: https://example.directus.app
description: Your current Directus project.
paths: {}

paths:
"/permissions":
$ref: paths/permissions/index.yaml
"/permissions/{id}":
$ref: paths/permissions/_id/index.yaml

components:
parameters:
$ref: components/parameters.yaml
Expand All @@ -18,7 +24,7 @@ components:
securitySchemes:
$ref: components/security.yaml
schemas:
$ref: components/schemas/index.yaml
$ref: components/schemas/_index.yaml
tags:
- name: Assets
description: Image typed files can be dynamically resized and transformed to fit any need.
Expand Down
39 changes: 39 additions & 0 deletions api-spec/paths/permissions/_id/getPermission.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
summary: Retrieve a Permission
description: Retrieve a single permissions object by unique identifier.
operationId: getPermission
parameters:
- "$ref": "../../../components/parameters.yaml#/Id"
- "$ref": "../../../components/parameters.yaml#/Fields"
- "$ref": "../../../components/parameters.yaml#/Meta"
responses:
"200":
description: Successful request
content:
application/json:
schema:
type: object
properties:
data:
"$ref": "../../../components/schemas/permissions.yaml"
"401":
"$ref": "../../../components/responses.yaml#/UnauthorizedError"
"404":
"$ref": "../../../components/responses.yaml#/NotFoundError"
tags:
- Permissions
x-codeSamples:
- label: Directus SDK
lang: JavaScript
source: |
import { createDirectus, rest, readPermission } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readPermission(permission_id, query_object));
- label: GraphQL
lang: GraphQL
source: |
GET /graphql/system
type Query {
permissions_by_id(id: ID!): directus_permissions
}
2 changes: 2 additions & 0 deletions api-spec/paths/permissions/_id/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
get:
$ref: getPermission.yaml
121 changes: 121 additions & 0 deletions api-spec/paths/permissions/createPermission.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
summary: Create a Permission
description: Create a new permission.
operationId: createPermission
parameters:
- "$ref": "../../components/parameters.yaml#/Meta"
requestBody:
content:
application/json:
schema:
properties:
collection:
description: What collection this permission applies to.
type: string
example: customers
comment:
description: If the user can post comments.
type: string
enum:
- none
- create
- update
- full
create:
description: If the user can create items.
type: string
enum:
- none
- full
delete:
description: If the user can update items.
type: string
enum:
- none
- mine
- role
- full
explain:
description:
If the user is required to leave a comment explaining
what was changed.
type: string
enum:
- none
- create
- update
- always
read:
description: If the user can read items.
type: string
enum:
- none
- mine
- role
- full
role:
description:
Unique identifier of the role this permission applies
to.
type: integer
example: 3
read_field_blacklist:
description: Explicitly denies read access for specific fields.
type: array
items:
type: string
example:
- featured_image
status:
description: What status this permission applies to.
type: string
status_blacklist:
description: Explicitly denies specific statuses to be used.
type: array
items:
type: string
update:
description: If the user can update items.
type: string
enum:
- none
- mine
- role
- full
write_field_blacklist:
description: Explicitly denies write access for specific fields.
type: array
items:
type: string
type: object
responses:
"200":
description: Successful request
content:
application/json:
schema:
type: object
properties:
data:
"$ref": "../../components/schemas/Permissions.yaml"
"401":
"$ref": "../../components/responses.yaml#/UnauthorizedError"
"404":
"$ref": "../../components/responses.yaml#/NotFoundError"
tags:
- Permissions
x-codeSamples:
- label: Directus SDK
lang: JavaScript
source: |
import { createDirectus, rest, createPermission } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(createPermission(permission_object));
- label: GraphQL
lang: GraphQL
source: |
POST /graphql/system
type Mutation {
create_permissions_item(data: create_directus_permissions_input!): directus_permissions
}
48 changes: 48 additions & 0 deletions api-spec/paths/permissions/getPermissions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
summary: List Permissions
description: List all permissions.
operationId: getPermissions
parameters:
- "$ref": "../../components/parameters.yaml#/Fields"
- "$ref": "../../components/parameters.yaml#/Limit"
- "$ref": "../../components/parameters.yaml#/Offset"
- "$ref": "../../components/parameters.yaml#/Meta"
- "$ref": "../../components/parameters.yaml#/Sort"
- "$ref": "../../components/parameters.yaml#/Filter"
- "$ref": "../../components/parameters.yaml#/Search"
- "$ref": "../../components/parameters.yaml#/Page"
responses:
"200":
description: Successful request
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
"$ref": "../../components/schemas/permissions.yaml"
meta:
"$ref": "../../components/schemas/x-metadata.yaml"
"401":
"$ref": "../../components/responses.yaml#/UnauthorizedError"
"404":
"$ref": "../../components/responses.yaml#/NotFoundError"
tags:
- Permissions
x-codeSamples:
- label: Directus SDK
lang: JavaScript
source: |
import { createDirectus, rest, readPermissions } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readPermissions(query_object));
- label: GraphQL
lang: GraphQL
source: |
POST /graphql/system
type Query {
permissions: directus_permissions
}
4 changes: 4 additions & 0 deletions api-spec/paths/permissions/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
get:
$ref: getPermissions.yaml
post:
$ref: createPermission.yaml

0 comments on commit c50ba37

Please sign in to comment.