From d65512dbe5de5c834086d821397aac43ea6d6b7a Mon Sep 17 00:00:00 2001 From: Krishna Kumar Date: Fri, 13 Jan 2023 05:50:47 +0530 Subject: [PATCH 1/5] Initialise Parse --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c9e58a6..07eda75 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,11 @@ function ParseOpenAPI(options) { ); app.use(openAPIEndpoint, this.renderOpenAPISpec.bind(this)); + + // initialise parse + Parse.serverURL = options.serverURL; + Parse.initialize(options.appId, options.javascriptKey); + Parse.masterKey = options.masterKey; return app; }; @@ -84,4 +89,4 @@ ParseOpenAPI.prototype.renderOpenAPISpec = async function (req, res) { res.json(openAPIObject); } -module.exports = ParseOpenAPI; \ No newline at end of file +module.exports = ParseOpenAPI; From 21c410d12916ab0fe0c93365dc9a3050c6e8ca3f Mon Sep 17 00:00:00 2001 From: raajon Date: Sat, 16 Sep 2023 11:12:47 +0200 Subject: [PATCH 2/5] bugfix and readme update --- parse-base.openapi.json | 4 ++-- readme.md | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/parse-base.openapi.json b/parse-base.openapi.json index c68ffa3..e7efb7d 100644 --- a/parse-base.openapi.json +++ b/parse-base.openapi.json @@ -143,7 +143,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Error" + "$ref": "#/components/schemas/ErrorResponse" } } } @@ -196,7 +196,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Error" + "$ref": "#/components/schemas/ErrorResponse" } } } diff --git a/readme.md b/readme.md index 567333f..f1bbe53 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,12 @@ const ParseSwagger = require('parse-server-swagger'); // Serve swagger API documentation if (CONFIG.swagger) { - const parseSwagger = new ParseSwagger(); + const parseSwagger = new ParseSwagger({ + serverURL: "https://yourServerUrl/parse", + appId: "yourAppId", + masterKey: "yourMasterKey", + + }); app.use(parseSwagger); } From 4decf42f8bfed2910a859348b418e1b85d22ed06 Mon Sep 17 00:00:00 2001 From: raajon Date: Tue, 19 Sep 2023 23:00:55 +0200 Subject: [PATCH 3/5] Update parse-base.openapi.json --- parse-base.openapi.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/parse-base.openapi.json b/parse-base.openapi.json index e7efb7d..8dfd8e6 100644 --- a/parse-base.openapi.json +++ b/parse-base.openapi.json @@ -10,12 +10,6 @@ "url": "/parse" } ], - "security": [ - { - "API Key": [], - "ParseApplicationId": [] - } - ], "components": { "securitySchemes": { "ParseSessionToken": { From 3d611790f077eef5af03472709119b53bf0c46a8 Mon Sep 17 00:00:00 2001 From: raajon Date: Tue, 19 Sep 2023 23:11:34 +0200 Subject: [PATCH 4/5] Update parse-base.openapi.json --- parse-base.openapi.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parse-base.openapi.json b/parse-base.openapi.json index 8dfd8e6..269f495 100644 --- a/parse-base.openapi.json +++ b/parse-base.openapi.json @@ -10,6 +10,12 @@ "url": "/parse" } ], + "security": [ + { + "ParseSessionToken": [], + "ParseApplicationId": [] + } + ], "components": { "securitySchemes": { "ParseSessionToken": { From fa1bc1c6d2a3e5022d169fb70fc7f3525d11380f Mon Sep 17 00:00:00 2001 From: raajon Date: Wed, 20 Sep 2023 22:29:39 +0200 Subject: [PATCH 5/5] update schema --- parse-base.openapi.json | 2 +- schema-to-openapi.js | 59 ++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/parse-base.openapi.json b/parse-base.openapi.json index 269f495..81a9865 100644 --- a/parse-base.openapi.json +++ b/parse-base.openapi.json @@ -1,5 +1,5 @@ { - "openapi": "3.0.2", + "openapi": "3.0.3", "info": { "title": "Parse API", "description": "Interact with the Parse API", diff --git a/schema-to-openapi.js b/schema-to-openapi.js index 622a5c4..6fc0462 100644 --- a/schema-to-openapi.js +++ b/schema-to-openapi.js @@ -19,7 +19,7 @@ const readOnlyFields = ["objectId", "createdAt", "updatedAt", "ACL"]; * @prop {boolean} [allowMasterKeyEndpoints] - Generate documentation for every possible endpoint, * regardless of CLPs * @prop {boolean} [allowParseClasses] - Generate documentation for special Parse classes (starting with "_") - * + * * Transform Parse Server schema to openapi.json * @param {ParseSchema[]} schemas * @param {Options} [options] - Opportunity to pass a full URL @@ -70,7 +70,30 @@ module.exports = function(schemas, options = {}) { * @param {object} classSchema server classes */ function transformClassToSchema(classSchema) { - const fieldSchema = { type: "object", properties: {} }; + const fieldSchema = { + type: "object", + required: ["objectId", "createdAt", "updatedAt", "ACL"], + properties: { + objectId: { + type: "string", + readOnly: true + }, + createdAt: { + type: "string", + format: "date-time", + readOnly: true + }, + updatedAt: { + type: "string", + format: "date-time", + readOnly: true + }, + ACL: { + type: "object", + readOnly: true + } + } + }; for (const fieldName in classSchema.fields) { const element = classSchema.fields[fieldName]; @@ -78,10 +101,7 @@ function transformClassToSchema(classSchema) { fieldSchema.properties[fieldName] = schemaTypeToOpenAPIType(element); } } - - return { - allOf: [fieldSchema, { $ref: "#/components/schemas/ParseObjectBase" }] - }; + return fieldSchema; } /** @@ -110,18 +130,21 @@ function schemaTypeToOpenAPIType(fieldDefinition) { case "Pointer": return { - allOf: [ - { $ref: "#/components/schemas/Pointer" }, - { - type: "object", - properties: { - className: { - type: "string", - enum: [fieldDefinition.targetClass] - } - } + type: "object", + required: ["__type", "className", "objectId"], + properties: { + __type: { + type: "string", + enum: ["Pointer"] + }, + objectId: { + type: "string" + }, + className: { + type: "string", + enum: [fieldDefinition.targetClass] } - ] + } }; case "Relation": return { type: "object" }; @@ -136,7 +159,7 @@ function schemaTypeToOpenAPIType(fieldDefinition) { /** * Get OpenAPI configuration for parse endpoint - * + * * @param {ParseSchema} classSchema */ function getParseClassActions(classSchema) {