mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-29 13:00:51 +00:00
* create nodejs express esrver * 1st commit of the express.js module. Express server working, api-docs loads properly. No real paths yet * 1st commit of the express.js module. Express server working, api-docs loads properly. No real paths yet (#2839) * Working Express server with successful routing to controllers. * rewrote controllers and services. Haven't tested yet * controllers and services have passed tests successfully * Added documentation * Added documentation * Support for openApi v3, using 'express-openapi-validator' for parsing and validation, and an internal router to pass arguments to controllers and services. /controllers/Pet.js and /services/PetService.js should be used for reverse engineering for future codegen script * update generator and template * update samples * more update * update service, controller * add vendor extensions * some updates to adapt to changes in the generator (removing references to swager); some work on handling file uploads; some work on tests * Update NodeJS server generator and templates based on new output (#3261) * update generator and template * update samples * more update * update service, controller * add vendor extensions * update doc * Changed routing code to follow the following convention: Each path operation has a 'x-openapi-router-controller' and 'x-openapi-router-service'. Automated files will be placed under /controllers and /services respectively. Controller file names will end with 'Controller.js'. Removed swaggerRouter, replaced it with openapiRouter Routing works and simple tests show a return of 200 to requests. * [nodejs-express-server] various updates, fixes (#3319) * various fix * remove dot from service * add space * better method empty argument * remove test service (#3379) * add new doc * 1. routingTests.js runs through all operations described in openapi.yaml and tries calling them, expecting 200 in return. Currently not all tests pass - not supporting xml, and problems with formData 2. Removed old testing files. 3. Added model files - contain data and structure as defined in openapi.yaml. Model.js has static methods relevant to all model files. 4. Changed openapi.yaml to allow running tests easily. * 1. routingTests.js runs through all operations described in openapi.yaml and tries calling them, expecting 200 in return. Currently not all tests pass - not supporting xml, and problems with formData (#3442) 2. Removed old testing files. 3. Added model files - contain data and structure as defined in openapi.yaml. Model.js has static methods relevant to all model files. 4. Changed openapi.yaml to allow running tests easily. * added model classes. Currently as a concept only. Seems like won't be in use * Updated README.md to be a detailed description of the project. Removed test files that are not needed. Removed utils/writer.js which is not needed, and the references to it in the codegen files * Removed redundant file app.js - this file has no benefit at this point. index.js now calls ExpressServer.js directly. Updated files that used to call app.js. Updated README.md accordingly Added a path to call the openapi.yaml, and a test file for all endpoints that are not in the openapi.yaml, ensuring that they return 200. Updated README.md accordingly * Remove test controller (#3575) * remove test controller * add back changes to templates * remove app.js * update wording
185 lines
4.2 KiB
JavaScript
185 lines
4.2 KiB
JavaScript
/* eslint-disable no-unused-vars */
|
|
const Service = require('./Service');
|
|
|
|
class PetService {
|
|
|
|
/**
|
|
* 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
|
|
**/
|
|
static addPet({ body }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static deletePet({ petId, apiUnderscorekey }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static findPetsByStatus({ status }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static findPetsByTags({ tags }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static getPetById({ petId }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static updatePet({ body }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static updatePetWithForm({ petId, name, status }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(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
|
|
**/
|
|
static uploadFile({ petId, additionalMetadata, file }) {
|
|
return new Promise(
|
|
async (resolve) => {
|
|
try {
|
|
resolve(Service.successResponse(''));
|
|
} catch (e) {
|
|
resolve(Service.rejectResponse(
|
|
e.message || 'Invalid input',
|
|
e.status || 405,
|
|
));
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = PetService;
|