diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed758028737..f11b2f5bade 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,4 +58,4 @@ jobs: BRANCH: build FOLDER: ./docs/dist GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MESSAGE: "Build: ({sha}) {msg}" + MESSAGE: "Build: ({sha}) {msg}" \ No newline at end of file diff --git a/docs/pages/api/metadata/examples.json b/docs/pages/api/metadata/examples.json index 090862d3999..5b3362e3a91 100644 --- a/docs/pages/api/metadata/examples.json +++ b/docs/pages/api/metadata/examples.json @@ -2058,5 +2058,331 @@ }, "tag": ["secret"] } + ], + "/projects/{projectId}/collections/{collectionId}/assets/{assetId}/upload": [ + { + "request": { + "file": "YOUR_FILE_FORM_DATA_FILE" + }, + "response": { + "id": 4658, + "collectionId": 909, + "tokenId": "200", + "url": "https://metadata.sequence.app/projects/30957/collections/909/tokens/200/image.png", + "metadataField": "image", + "filename": "image.png", + "filesize": 27972, + "mimeType": "image/png", + "width": 1024, + "height": 683, + "updatedAt": "2024-11-01T04:13:34.729008063Z" + }, + "tag": ["secret"] + } + ], + "/projects/{projectId}/collections/{collectionId}/tokens/{tokenId}/upload/{assetIdOrAssetType}": [ + { + "request": { + "file": "YOUR_FILE_FORM_DATA_FILE" + }, + "response": { + "id": 4658, + "collectionId": 909, + "tokenId": "200", + "url": "https://metadata.sequence.app/projects/30957/collections/909/tokens/200/image.png", + "metadataField": "image", + "filename": "image.png", + "filesize": 27972, + "mimeType": "image/png", + "width": 1024, + "height": 683, + "updatedAt": "2024-11-01T04:13:34.729008063Z" + }, + "tag": ["secret"] + } + ], + "/rpc/Collections/CreateContractCollection": [ + { + "request": { + "projectId": 30957, + "contractCollection": { + "chainId": 80002, + "contractAddress": "0x477566e9ade2dfa69f066f909e36ad617a2adef7", + "collectionId": 819 + } + }, + "response": { + "contractCollection": { + "id": 460, + "chainId": 80002, + "contractAddress": "0x477566e9ade2dfa69f066f909e36ad617a2adef7", + "collectionId": 819 + } + }, + "tag": ["secret"] + } + ], + "/rpc/Collections/GetContractCollection": [ + { + "request": { + "projectId": 30957, + "chainId": 80002, + "contractAddress": "0x6325e304e6eea3c818f1eaf8924570d491e1f6d4" + }, + "response": { + "contractCollection": { + "id": 442, + "chainId": 80002, + "contractAddress": "0x6325e304e6eea3c818f1eaf8924570d491e1f6d4", + "collectionId": 908 + } + }, + "tag": ["secret"] + } + ], + "/rpc/Metadata/GetTokenMetadataBatch": [ + { + "request": { + "chainID": "80002", + "contractTokenMap": { + "0x8070c5b48b1ce7b3219660c79b23e8679bfd5041": ["0", "1"], + "0x70a2177079877e4aae639d1abb29ffa537b94970": [ + "0", + "1", + "2", + "3", + "4", + "5" + ] + } + }, + "response": { + "contractTokenMetadata": { + "0x70a2177079877e4aae639d1abb29ffa537b94970": [ + { + "tokenId": "0", + "name": "Divine Axe #160", + "description": "This legendary axe, blessed by ancient gods, capable of shattering mountains.", + "image": "https://metadata.sequence.app/projects/30957/collections/819/tokens/0/image.png", + "properties": null, + "attributes": [ + { + "sharpness": 1120 + }, + { + "attackPower": 463 + }, + { + "weight": 700 + }, + { + "criticalHitChance": 1218 + } + ], + "updatedAt": "2024-11-01T08:29:29.848063928Z" + }, + { + "tokenId": "1", + "name": "Divine Axe #724", + "description": "This powerful axe, blessed by ancient gods, with the power to summon storms.", + "image": "https://metadata.sequence.app/projects/30957/collections/819/tokens/1/image.png", + "properties": null, + "attributes": [ + { + "speed": 1491 + }, + { + "edgeRetention": 1198 + }, + { + "criticalHitChance": 370 + }, + { + "attackPower": 396 + } + ], + "updatedAt": "2024-11-01T08:29:29.848063928Z" + }, + { + "tokenId": "2", + "name": "Divine Axe #819", + "description": "This ancient axe, blessed by ancient gods, capable of shattering mountains.", + "image": "https://metadata.sequence.app/projects/30957/collections/819/tokens/2/image.png", + "properties": null, + "attributes": [ + { + "balance": 81 + }, + { + "edgeRetention": 283 + }, + { + "sharpness": 105 + }, + { + "durability": 338 + } + ], + "updatedAt": "2024-11-01T08:29:29.848063928Z" + }, + { + "tokenId": "3", + "name": "Divine Axe #948", + "description": "This enchanted axe, crafted by the hands of giants, which never dulls.", + "image": "https://metadata.sequence.app/projects/30957/collections/819/tokens/3/image.png", + "properties": null, + "attributes": [ + { + "speed": 1314 + }, + { + "balance": 1235 + }, + { + "weight": 48 + }, + { + "magic": 826 + } + ], + "updatedAt": "2024-11-01T08:29:29.848063928Z" + }, + { + "tokenId": "4", + "name": "Divine Axe #031", + "description": "This powerful axe, forged in the fires of a dying star, which never dulls.", + "image": "https://metadata.sequence.app/projects/30957/collections/819/tokens/4/image.png", + "properties": null, + "attributes": [ + { + "speed": 1144 + }, + { + "elementalAffinity": 1315 + }, + { + "edgeRetention": 1128 + }, + { + "sharpness": 1232 + } + ], + "updatedAt": "2024-11-01T08:29:29.848063928Z" + }, + { + "tokenId": "5", + "name": "Divine Axe #452", + "description": "This enchanted axe, crafted by the hands of giants, with the power to summon storms.", + "image": "https://metadata.sequence.app/projects/30957/collections/819/tokens/5/image.png", + "properties": null, + "attributes": [ + { + "elementalAffinity": 803 + }, + { + "durability": 83 + }, + { + "criticalHitChance": 268 + }, + { + "balance": 1039 + } + ], + "updatedAt": "2024-11-01T08:29:29.848063928Z" + } + ], + "0x8070c5b48b1ce7b3219660c79b23e8679bfd5041": [ + { + "tokenId": "0", + "name": "Test nft erc721", + "description": "Description", + "image": "https://metadata.sequence.app/projects/30957/collections/273/tokens/0/image.jpg", + "properties": { + "armor": "100" + }, + "attributes": null, + "updatedAt": "2024-11-01T08:18:33.514523974Z" + }, + { + "tokenId": "1", + "name": "NFT 2 Amoy", + "description": "Description", + "image": "https://metadata.sequence.app/projects/30957/collections/273/tokens/1/image.jpg", + "properties": null, + "attributes": null, + "updatedAt": "2024-11-01T08:18:33.514523974Z" + } + ] + } + }, + "tag": ["public"] + } + ], + "/rpc/Collections/ListContractCollections": [ + { + "request": { + "collectionId": 819, + "projectId": 30957 + }, + "response": { + "contractCollections": [ + { + "id": 370, + "chainId": 80002, + "contractAddress": "0x70a2177079877e4aae639d1abb29ffa537b94970", + "collectionId": 819 + } + ], + "collections": [ + { + "id": 819, + "projectId": 30957, + "metadata": { + "name": "Placeholders", + "description": "Placeholders collection", + "image": "https://metadata.sequence.app/projects/30957/collections/819/image.png" + }, + "private": false, + "createdAt": "2024-10-03T18:46:15.987375Z", + "updatedAt": "2024-10-03T18:46:18.25727Z" + } + ], + "page": { + "pageSize": 30, + "more": false + } + }, + "tag": ["secret"] + } + ], + "/rpc/Collections/UpdateContractCollection": [ + { + "request": { + "projectId": 30957, + "contractCollection": { + "chainId": 80002, + "contractAddress": "0x70a2177079877e4aae639d1abb29ffa537b94970", + "collectionId": 819 + } + }, + "response": { + "ok": true + }, + "tag": ["secret"] + } + ], + "/rpc/Collections/DeleteContractCollection": [ + { + "request": { + "projectId": 30957, + "chainId": 80002, + "contractAddress": "0x477566e9ade2dfa69f066f909e36ad617a2adef7" + }, + "response": { + "ok": true + }, + "tag": ["secret"] + } ] } diff --git a/libs/example_merger.js b/libs/example_merger.js index 690a992b9a7..bf7ba20fe77 100644 --- a/libs/example_merger.js +++ b/libs/example_merger.js @@ -52,23 +52,61 @@ const addExamplesToOpenAPI = (doc, examples) => { } for (const [exampleName, ex] of Object.entries(example)) { - if (ex.request && Object.keys(ex.request).length > 0) { - const response = path.post.requestBody - response.content['application/json'].example = ex.request - } - - if (ex.response && Object.keys(ex.response).length > 0) { - const response = path.post.responses['200'] - response.content['application/json'].example = ex.response - } - - if (ex.description && Object.keys(ex.description).length > 0) { - path.post.description = ex.description - } - - if (ex.tag && Object.keys(ex.tag).length > 0) { - path.post.tags = {} - path.post.tags = ex.tag + const methods = ['post', 'put']; + + for (const method of methods) { + if (path[method]) { + if (ex.request && Object.keys(ex.request).length > 0) { + const requestBody = path[method].requestBody; + + if (requestBody) { + if (requestBody.content['application/octet-stream']) { + // Remove content of application/octet-stream + delete requestBody.content['application/octet-stream']; + requestBody.content['multipart/form-data'] = requestBody.content['multipart/form-data'] || {}; + requestBody.content['multipart/form-data'].example = ex.request; + } + + if (requestBody.content['multipart/form-data']) { + requestBody.content['multipart/form-data'].example = ex.request; + } + + if (requestBody.content['application/json']) { + requestBody.content['application/json'].example = ex.request; + } + } + } + + if (ex.response && Object.keys(ex.response).length > 0) { + const response = path[method].responses['200']; + + if (response) { + if (!response.content) { + response.content = { + 'application/json': { + example: ex.response, + }, + }; + } else { + if (response.content['application/json']) { + response.content['application/json'].example = ex.response; + } else { + response.content['application/json'] = { + example: ex.response, + }; + } + } + } + } + + if (ex.description && Object.keys(ex.description).length > 0) { + path[method].description = ex.description; + } + + if (ex.tag && Object.keys(ex.tag).length > 0) { + path[method].tags = ex.tag; + } + } } } } diff --git a/package.json b/package.json index 9ba47c30cf5..d6cee00eb36 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vocs dev", + "dev": "pnpm run prepare-openapi-docs && vocs dev", "build": "pnpm run prepare-openapi-docs && vocs build --searchIndex false", "preview": "vocs preview", "format": "biome format . --write",