mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-13 21:20:56 +00:00
* Updated to new nodejs packages, depending heavily on express-openapi-validator. Requires quite a change in code. Updated the business-logic in the controllers/Controller.js file. Logger now records also timestamp of events. Files are uploaded according to definition in config.js file * Removed commented-out code; Changed openApi document extensions to suit new express-openapi-validator definition; multipart and file uploading is supported now; Automatic response returns the values the were sent in the request * fixed README documentation, fixed a mistage in package.json/mustache * added generated files that were created when running the ./bin/test file
188 lines
4.0 KiB
JavaScript
188 lines
4.0 KiB
JavaScript
/* eslint-disable no-unused-vars */
|
|
const Service = require('./Service');
|
|
|
|
/**
|
|
* Add a new pet to the store
|
|
*
|
|
* body Pet Pet object that needs to be added to the store
|
|
* no response value expected for this operation
|
|
* */
|
|
const addPet = ({ body }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
body,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* Deletes a pet
|
|
*
|
|
* petId Long Pet id to delete
|
|
* apiUnderscorekey String (optional)
|
|
* no response value expected for this operation
|
|
* */
|
|
const deletePet = ({ petId, apiUnderscorekey }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
petId,
|
|
apiUnderscorekey,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* Finds Pets by status
|
|
* Multiple status values can be provided with comma separated strings
|
|
*
|
|
* status List Status values that need to be considered for filter
|
|
* returns List
|
|
* */
|
|
const findPetsByStatus = ({ status }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
status,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* Finds Pets by tags
|
|
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
*
|
|
* tags List Tags to filter by
|
|
* returns List
|
|
* */
|
|
const findPetsByTags = ({ tags }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
tags,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* Find pet by ID
|
|
* Returns a single pet
|
|
*
|
|
* petId Long ID of pet to return
|
|
* returns Pet
|
|
* */
|
|
const getPetById = ({ petId }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
petId,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* Update an existing pet
|
|
*
|
|
* body Pet Pet object that needs to be added to the store
|
|
* no response value expected for this operation
|
|
* */
|
|
const updatePet = ({ body }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
body,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* Updates a pet in the store with form data
|
|
*
|
|
* petId Long ID of pet that needs to be updated
|
|
* name String Updated name of the pet (optional)
|
|
* status String Updated status of the pet (optional)
|
|
* no response value expected for this operation
|
|
* */
|
|
const updatePetWithForm = ({ petId, name, status }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
petId,
|
|
name,
|
|
status,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
/**
|
|
* uploads an image
|
|
*
|
|
* petId Long ID of pet to update
|
|
* additionalMetadata String Additional data to pass to server (optional)
|
|
* file File file to upload (optional)
|
|
* returns ApiResponse
|
|
* */
|
|
const uploadFile = ({ petId, additionalMetadata, file }) => new Promise(
|
|
async (resolve, reject) => {
|
|
try {
|
|
resolve(Service.successResponse({
|
|
petId,
|
|
additionalMetadata,
|
|
file,
|
|
}));
|
|
} catch (e) {
|
|
reject(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
|
|
module.exports = {
|
|
addPet,
|
|
deletePet,
|
|
findPetsByStatus,
|
|
findPetsByTags,
|
|
getPetById,
|
|
updatePet,
|
|
updatePetWithForm,
|
|
uploadFile,
|
|
};
|