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; diff --git a/parse-base.openapi.json b/parse-base.openapi.json index c68ffa3..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", @@ -12,7 +12,7 @@ ], "security": [ { - "API Key": [], + "ParseSessionToken": [], "ParseApplicationId": [] } ], @@ -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); } 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) {