Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -84,4 +89,4 @@ ParseOpenAPI.prototype.renderOpenAPISpec = async function (req, res) {
res.json(openAPIObject);
}

module.exports = ParseOpenAPI;
module.exports = ParseOpenAPI;
8 changes: 4 additions & 4 deletions parse-base.openapi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openapi": "3.0.2",
"openapi": "3.0.3",
"info": {
"title": "Parse API",
"description": "Interact with the Parse API",
Expand All @@ -12,7 +12,7 @@
],
"security": [
{
"API Key": [],
"ParseSessionToken": [],
"ParseApplicationId": []
}
],
Expand Down Expand Up @@ -143,7 +143,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
59 changes: 41 additions & 18 deletions schema-to-openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,18 +70,38 @@ 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];
if (!readOnlyFields.includes(fieldName)) {
fieldSchema.properties[fieldName] = schemaTypeToOpenAPIType(element);
}
}

return {
allOf: [fieldSchema, { $ref: "#/components/schemas/ParseObjectBase" }]
};
return fieldSchema;
}

/**
Expand Down Expand Up @@ -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" };
Expand All @@ -136,7 +159,7 @@ function schemaTypeToOpenAPIType(fieldDefinition) {

/**
* Get OpenAPI configuration for parse endpoint
*
*
* @param {ParseSchema} classSchema
*/
function getParseClassActions(classSchema) {
Expand Down