Skip to content

Commit

Permalink
feat: hidden contracts with metadata hidden flag (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
puria authored Mar 7, 2024
1 parent fa16fc8 commit a9e86e3
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ Dir.ready(async () => {
const generateRoutes = (app: TemplatedApp) => {
Dir.files.forEach(async (endpoints) => {
const { contract, path, keys, conf, metadata } = endpoints;
if (metadata.hidden) return;

const LOG = L.getSubLogger({
stylePrettyLogs: true,
prettyLogTemplate:
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface Codec {
}

export interface Metadata {
hidden: boolean;
disableGet: boolean;
disablePost: boolean;

Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const newMetadata = (configRaw: JSON): Metadata => {
errorContentType: configRaw['error_content_type'] || 'plain/text',
examples: configRaw['examples'] || {},
tags: configRaw['tags'] || ['📑 Zencodes'],
hidden: configRaw['hidden'] || false,
};
};

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/broken_contracts/exec.keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"data_1": {}
}
10 changes: 10 additions & 0 deletions tests/fixtures/broken_contracts/exec.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"examples": {
"did": {
"value": {
"did_document": {"description": "sandbox_test_from_js_updated"},
"id": "did:dyne:sandbox.test:33ZZcaRLvdsvAKTkV8eAHZsvioZSgPcC4ReNXLup7Tj4#ethereum_address"
}
}
}
}
23 changes: 23 additions & 0 deletions tests/fixtures/broken_contracts/exec.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"properties": {
"data_1": {
"type": "object"
},
"id": {
"type": "string"
},
"did_document": {
"type": "object",
"properties": {
"description": {
"type": "string"
}
}
}
},
"required": [
"did_document",
"id"
]
}
3 changes: 3 additions & 0 deletions tests/fixtures/broken_contracts/exec.zen
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Given I send object 'data_1' and send sources 'did_document' and manipulate and merge and output into 'data'
Given I have a 'string dictionary' named 'data'
Then print the data
3 changes: 3 additions & 0 deletions tests/fixtures/meta/hidden.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hidden": true
}
2 changes: 2 additions & 0 deletions tests/fixtures/meta/hidden.zen
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Given nothing
Then print the string 'hidden'
31 changes: 30 additions & 1 deletion tests/workflow.stepci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,33 @@ tests:
status: 201
json:
output:
- "mimmolo"
- "mimmolo"

- name: HIDDEN POST
http:
url: http://${{env.host}}/meta/hidden
method: POST
json: {}
check:
status: 404

- name: HIDDEN RAW
http:
url: http://${{env.host}}/meta/hidden/raw
method: GET
check:
status: 404

- name: HIDDEN APP
http:
url: http://${{env.host}}/meta/hidden/app
method: GET
check:
status: 404

- name: HIDDEN GET
http:
url: http://${{env.host}}/meta/hidden
method: GET
check:
status: 404

0 comments on commit a9e86e3

Please sign in to comment.