Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhendumadhukar committed May 17, 2021
1 parent 6ee1e0b commit 4e90d0c
Show file tree
Hide file tree
Showing 29 changed files with 2,681 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# camoswag
# Camoswag

Camoswag is a Camouflage extension which allows you to generate your mockfiles using an OpenAPI Specification.

For more information on Camouflage, see [documentation](https://fauxauldrich.github.io/camouflage/)

# Getting Started

- To use `camoswag`, you would need your OpenAPI specification file in either .json or .yaml format.
- You don't need to install `camoswag` in order to run, you can simply run it using `npx`
- Run the command: `npx camoswag --spec ./swagger.yaml` or `npx camoswag --spec ./swagger.json`. (Replace file location with your spec file location)
- This would create a new folder with the name `camouflage-${current_timestamp}` containing the required folder structure and mock files corresponding to each endpoint defined in your spec file.
- You can either delete or modify the dummy responses placed in the mockfiles as per your expectations. Once you are satisfied with the modifications, you can move the contents of the folder to your original ${MOCK_DIR} of your running Camouflage server.
- Note that if your spec file doesn't contain a response defined for a given endpoint, `camoswag` would put following default response in the mock file.

```json
{
"message": "More Configuration Needed"
}
```

Note: camoswag currenty supports JSON responses only.


- To install `camoswag` locally, run command `npm i -g camoswag`
- Run conversion command using `camoswag --spec ./swagger.yaml` or `camoswag --spec ./swagger.json`. (Replace file location with your spec file location)
33 changes: 33 additions & 0 deletions bin/camoswag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node
const argv = require("yargs").argv;
const specFile = argv.s || argv.spec;
const winston = require("winston");
const fs = require("fs");
const path = require("path");
const createMocks = require("../index");

const logger = winston.createLogger({
level: "info",
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple(),
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
winston.format.printf((log) => `${log.timestamp} ${log.level}: ${log.message}` + (log.splat !== undefined ? `${log.splat}` : " "))
),
transports: [new winston.transports.Console()],
});

if (!specFile) {
logger.error("Please specify at least one of the input parameters.");
logger.info("Available options are: -s/--spec");
process.exit(1);
}
if (specFile) {
const specFilePath = path.resolve(specFile);
if (typeof specFile !== "string" || !fs.existsSync(specFilePath)) {
logger.error(`${specFile} is not a valid file. Please provide a valid OpenAPI Specification file to proceed.`);
process.exit(1);
} else {
createMocks(specFilePath);
}
}
7 changes: 7 additions & 0 deletions camouflage-1621269198958/pet/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 405 Method Not Allowed
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
21 changes: 21 additions & 0 deletions camouflage-1621269198958/pet/PUT.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 405 Method Not Allowed
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
14 changes: 14 additions & 0 deletions camouflage-1621269198958/pet/__/DELETE.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
36 changes: 36 additions & 0 deletions camouflage-1621269198958/pet/__/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"id": 3639836862840832,
"category": {
"id": -6904188336340992,
"name": "msL"
},
"name": "fWDXeudI",
"photoUrls": [
"ZvvFZM"
],
"tags": [
{
"id": -5443327017091072,
"name": "Ynsqh"
}
],
"status": "pending"
}
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
7 changes: 7 additions & 0 deletions camouflage-1621269198958/pet/__/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 405 Method Not Allowed
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
9 changes: 9 additions & 0 deletions camouflage-1621269198958/pet/__/uploadImage/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"code": 5688478750736384,
"type": "L",
"message": "Hr"
}
====
31 changes: 31 additions & 0 deletions camouflage-1621269198958/pet/findByStatus/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
HTTP/1.1 200 OK
Content-Type: application/json

[
{
"id": -6258476816793600,
"category": {
"id": -3109826385149952,
"name": "mMRMXoHJnLD"
},
"name": "PWejWKffNW",
"photoUrls": [
"GvG"
],
"tags": [
{
"id": -5412031372984320,
"name": "Aj"
}
],
"status": "pending"
}
]
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
31 changes: 31 additions & 0 deletions camouflage-1621269198958/pet/findByTags/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
HTTP/1.1 200 OK
Content-Type: application/json

[
{
"id": 2527916277628928,
"category": {
"id": -6686392331534336,
"name": "pd"
},
"name": "nAxaUOtwWFJ",
"photoUrls": [
"qrpe"
],
"tags": [
{
"id": -4633484505120768,
"name": "yFswVK"
}
],
"status": "sold"
}
]
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
7 changes: 7 additions & 0 deletions camouflage-1621269198958/store/inventory/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"kocakos": 830884307533824
}
====
19 changes: 19 additions & 0 deletions camouflage-1621269198958/store/order/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"id": 5770442103062528,
"petId": -1120756788363264,
"quantity": -2879783742472192,
"shipDate": "2021-05-17T16:33:19.023Z",
"status": "placed",
"complete": false
}
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
14 changes: 14 additions & 0 deletions camouflage-1621269198958/store/order/__/DELETE.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
26 changes: 26 additions & 0 deletions camouflage-1621269198958/store/order/__/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"id": -1220053982773248,
"petId": -6279841993195520,
"quantity": 6676552519516160,
"shipDate": "2021-05-17T16:33:19.024Z",
"status": "approved",
"complete": false
}
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
7 changes: 7 additions & 0 deletions camouflage-1621269198958/user/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 default undefined
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
14 changes: 14 additions & 0 deletions camouflage-1621269198958/user/__/DELETE.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
28 changes: 28 additions & 0 deletions camouflage-1621269198958/user/__/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"id": 8407667567493120,
"username": "yTOe",
"firstName": "vLR",
"lastName": "oiOmvG",
"email": "AfLU",
"password": "Hct",
"phone": "ZUmmf",
"userStatus": 7517871211020288
}
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
14 changes: 14 additions & 0 deletions camouflage-1621269198958/user/__/PUT.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
7 changes: 7 additions & 0 deletions camouflage-1621269198958/user/createWithArray/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 default undefined
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
7 changes: 7 additions & 0 deletions camouflage-1621269198958/user/createWithList/POST.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 default undefined
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
12 changes: 12 additions & 0 deletions camouflage-1621269198958/user/login/GET.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Content-Type: application/json

"ghsVE"
====
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"message": "More Configuration Needed"
}
====
Loading

0 comments on commit 4e90d0c

Please sign in to comment.