Skip to content

Commit 9d632bf

Browse files
committed
changes
1 parent 1212bb3 commit 9d632bf

File tree

5 files changed

+226
-11
lines changed

5 files changed

+226
-11
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ node src/index.js --open-api-specification-folder-path /path/to/openapi/specs
3838

3939
Set `OPENAI_API_KEY` in the environment process, and provide folder path to OpenAPI specification with flag `--open-api-specification-folder-path` with the path to the folder containing your OpenAPI specs.
4040

41-
The package will read these input values and use the OpenAI key to interact with GPT 3.5 Turbo and provide OpenAPI spec to the AI. The AI will then generate mock responses in JSON format for the provided APIs.
41+
The package will read these input values, use the OpenAI key to interact with GPT 3.5 Turbo, and provide OpenAPI spec to the AI. The AI will then generate mock responses in JSON format for the provided APIs.
42+
43+
**Note:** As of now package supports JSON formatted API Specification. You can use https://editor.swagger.io/ to make sure your OpenAPI Specification is valid.
4244

4345
### License
4446

merged_openapi.json

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,117 @@
937937
}
938938
}
939939
}
940+
},
941+
"/api/v1/demo_error": {
942+
"get": {
943+
"description": "Api will return list of tasks for accountId",
944+
"parameters": [
945+
{
946+
"name": "account_id",
947+
"in": "query",
948+
"description": "Account Id",
949+
"required": true,
950+
"schema": {
951+
"type": "string",
952+
"minLength": 10,
953+
"maxLength": 10
954+
}
955+
},
956+
{
957+
"name": "err_id",
958+
"in": "query",
959+
"description": "Account Id",
960+
"required": false,
961+
"schema": {
962+
"type": "string",
963+
"minLength": 1,
964+
"maxLength": 100
965+
}
966+
},
967+
{
968+
"name": "err_id1",
969+
"in": "query",
970+
"description": "Account Id",
971+
"required": false,
972+
"schema": {
973+
"type": "number",
974+
"minimum": 1,
975+
"maximum": 100
976+
}
977+
}
978+
],
979+
"responses": {
980+
"200": {
981+
"description": "Success",
982+
"content": {
983+
"application/json": {
984+
"schema": {
985+
"type": "object",
986+
"properties": {
987+
"task_ids": {
988+
"type": "array",
989+
"items": {
990+
"type": "string",
991+
"example": "00U1e000003TUB8EAO"
992+
}
993+
},
994+
"task_map_by_id": {
995+
"type": "object",
996+
"properties": {
997+
"00U1e000003TUB8EAO": {
998+
"type": "object",
999+
"properties": null,
1000+
"$ref": "#/components/schemas/task"
1001+
}
1002+
}
1003+
}
1004+
}
1005+
}
1006+
}
1007+
}
1008+
},
1009+
"400": {
1010+
"description": "Bad Request",
1011+
"content": {
1012+
"application/json": {
1013+
"schema": {
1014+
"$ref": "#/components/schemas/response_400"
1015+
}
1016+
}
1017+
}
1018+
},
1019+
"401": {
1020+
"description": "Unauthorized access",
1021+
"content": {
1022+
"application/json": {
1023+
"schema": {
1024+
"$ref": "#/components/schemas/response_401"
1025+
}
1026+
}
1027+
}
1028+
},
1029+
"404": {
1030+
"description": "Not Found",
1031+
"content": {
1032+
"application/json": {
1033+
"schema": {
1034+
"$ref": "#/components/schemas/response_404"
1035+
}
1036+
}
1037+
}
1038+
},
1039+
"500": {
1040+
"description": "Something went wrong",
1041+
"content": {
1042+
"application/json": {
1043+
"schema": {
1044+
"$ref": "#/components/schemas/response_500"
1045+
}
1046+
}
1047+
}
1048+
}
1049+
}
1050+
}
9401051
}
9411052
},
9421053
"components": {

sampleSpecs/openapi_tasks.json

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,117 @@
596596
}
597597
}
598598
}
599+
},
600+
"/api/v1/demo_error": {
601+
"get": {
602+
"description": "Api will return list of tasks for accountId",
603+
"parameters": [
604+
{
605+
"name": "account_id",
606+
"in": "query",
607+
"description": "Account Id",
608+
"required": true,
609+
"schema": {
610+
"type": "string",
611+
"minLength": 10,
612+
"maxLength": 10
613+
}
614+
},
615+
{
616+
"name": "err_id",
617+
"in": "query",
618+
"description": "Account Id",
619+
"required": false,
620+
"schema": {
621+
"type": "string",
622+
"minLength": 1,
623+
"maxLength": 100
624+
}
625+
},
626+
{
627+
"name": "err_id1",
628+
"in": "query",
629+
"description": "Account Id",
630+
"required": false,
631+
"schema": {
632+
"type": "number",
633+
"minimum": 1,
634+
"maximum": 100
635+
}
636+
}
637+
],
638+
"responses": {
639+
"200": {
640+
"description": "Success",
641+
"content": {
642+
"application/json": {
643+
"schema": {
644+
"type": "object",
645+
"properties": {
646+
"task_ids": {
647+
"type": "array",
648+
"items": {
649+
"type": "string",
650+
"example": "00U1e000003TUB8EAO"
651+
}
652+
},
653+
"task_map_by_id": {
654+
"type": "object",
655+
"properties": {
656+
"00U1e000003TUB8EAO": {
657+
"type": "object",
658+
"properties": null,
659+
"$ref": "#/components/schemas/task"
660+
}
661+
}
662+
}
663+
}
664+
}
665+
}
666+
}
667+
},
668+
"400": {
669+
"description": "Bad Request",
670+
"content": {
671+
"application/json": {
672+
"schema": {
673+
"$ref": "#/components/schemas/response_400"
674+
}
675+
}
676+
}
677+
},
678+
"401": {
679+
"description": "Unauthorized access",
680+
"content": {
681+
"application/json": {
682+
"schema": {
683+
"$ref": "#/components/schemas/response_401"
684+
}
685+
}
686+
}
687+
},
688+
"404": {
689+
"description": "Not Found",
690+
"content": {
691+
"application/json": {
692+
"schema": {
693+
"$ref": "#/components/schemas/response_404"
694+
}
695+
}
696+
}
697+
},
698+
"500": {
699+
"description": "Something went wrong",
700+
"content": {
701+
"application/json": {
702+
"schema": {
703+
"$ref": "#/components/schemas/response_500"
704+
}
705+
}
706+
}
707+
}
708+
}
709+
}
599710
}
600711
}
601712
}

src/promptStrings.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// const askApiResponsePrompt = (route) =>
2-
// `Generate a mock response for the "${route}" endpoint using the above provided OpenAPI spec.` +
3-
// `Note: Provide response in JSON Only. Ensure it's valid JSON and includes all attributes.` +
4-
// `If an attribute is an array, include 5 to 10 elements.` +
5-
// `Generate a random "id" whanever present in any entity. Give real life human readable and unique strings` +
6-
// `If there is any query param given, use its value to generate response.` +
7-
// `Please map the relavent entities correctly in response.` +
8-
// `response json should be as per relavent OpenAPI spec provided in .` ;
9-
101
const askApiResponsePrompt = (route) =>
112
`Generate a mock response for the "${route}" endpoint using the above provided OpenAPI spec.`;
123

src/simulateResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function simulateResponse(
4141
let prompt =
4242
fileContent +
4343
"\n" +
44-
promptStrings.askApiResponsePrompt(routeKey);
44+
promptStrings.askApiResponsePrompt(method + " " + originalUrl);
4545

4646
console.log("Prompt:=========\n", prompt);
4747

0 commit comments

Comments
 (0)