fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #94 from nicolas-chaulet/fix/types-api

fix(types): add types for programmatic API

authored by

Lubos and committed by
GitHub
872cae22 94a13cf4

+81 -2382
-1
.eslintignore
··· 1 1 dist 2 2 node_modules 3 - samples 4 3 temp 5 4 test/e2e/generated 6 5 test/generated
-3
.gitignore
··· 11 11 *.iml 12 12 dist 13 13 coverage 14 - samples/generated 15 - samples/swagger-codegen-cli-v2.jar 16 - samples/swagger-codegen-cli-v3.jar 17 14 .env 18 15 19 16 # test files
+12 -1
README.md
··· 49 49 yarn add @nicolas-chaulet/openapi-typescript-codegen -D 50 50 ``` 51 51 52 - and add a script to your `package.json` file 52 + If you want to use `openapi-ts` with CLI, add a script to your `package.json` file 53 53 54 54 ```json 55 55 "scripts": { 56 56 "openapi-ts": "openapi-ts" 57 57 } 58 + ``` 59 + 60 + You can also generate your client programmatically by importing `openapi-ts` in a `.ts` file. 61 + 62 + ```ts 63 + import { createClient } from '@nicolas-chaulet/openapi-typescript-codegen' 64 + 65 + createClient({ 66 + input: 'path/to/openapi.json', 67 + output: 'src/client', 68 + }) 58 69 ``` 59 70 60 71 > ⚠️ You need to be running Node.js v18 or newer
+2 -5
bin/index.js
··· 39 39 40 40 async function start() { 41 41 try { 42 - const OpenAPI = await import(new URL('../dist/index.js', import.meta.url)); 43 - await OpenAPI.generate({ 44 - ...params, 45 - clientName: params.name, 46 - }); 42 + const { createClient } = await import(new URL('../dist/index.js', import.meta.url)); 43 + await createClient(params); 47 44 process.exit(0); 48 45 } catch (error) { 49 46 console.error(error);
+1 -1
package.json
··· 49 49 "build-types-check": "tsc --project tsconfig.check.json", 50 50 "build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp", 51 51 "build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node", 52 - "clean": "rimraf dist test/generated test/e2e/generated samples/generated coverage node_modules/.cache", 52 + "clean": "rimraf dist test/generated test/e2e/generated coverage node_modules/.cache", 53 53 "eslint:fix": "eslint . --fix", 54 54 "eslint": "eslint .", 55 55 "prepublishOnly": "npm run build",
-21
samples/codegen.sh
··· 1 - #!/bin/sh 2 - 3 - rm -rf dist 4 - rm swagger-codegen-cli-v2.jar 5 - rm swagger-codegen-cli-v3.jar 6 - 7 - curl https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.15/swagger-codegen-cli-2.4.15.jar -o swagger-codegen-cli-v2.jar 8 - curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.21/swagger-codegen-cli-3.0.21.jar -o swagger-codegen-cli-v3.jar 9 - 10 - java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-aurelia -o generated/v2/typescript-aurelia/ 11 - java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-angular -o generated/v2/typescript-angular/ 12 - java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-inversify -o generated/v2/typescript-inversify/ 13 - java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-fetch -o generated/v2/typescript-fetch/ 14 - java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-jquery -o generated/v2/typescript-jquery/ 15 - java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-node -o generated/v2/typescript-node/ 16 - 17 - java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-angular -o generated/v3/typescript-angular/ 18 - java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-fetch -o generated/v3/typescript-fetch/ 19 - 20 - node ../bin/index.js --input spec/v2.json --output generated/v2/openapi-typescript-codegen/ 21 - node ../bin/index.js --input spec/v3.json --output generated/v3/openapi-typescript-codegen/
-1061
samples/spec/v2.json
··· 1 - { 2 - "swagger": "2.0", 3 - "info": { 4 - "description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", 5 - "version": "1.0.5", 6 - "title": "Swagger Petstore", 7 - "termsOfService": "http://swagger.io/terms/", 8 - "contact": { 9 - "email": "apiteam@swagger.io" 10 - }, 11 - "license": { 12 - "name": "Apache 2.0", 13 - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 - } 15 - }, 16 - "host": "petstore.swagger.io", 17 - "basePath": "/v2", 18 - "tags": [ 19 - { 20 - "name": "pet", 21 - "description": "Everything about your Pets", 22 - "externalDocs": { 23 - "description": "Find out more", 24 - "url": "http://swagger.io" 25 - } 26 - }, 27 - { 28 - "name": "store", 29 - "description": "Access to Petstore orders" 30 - }, 31 - { 32 - "name": "user", 33 - "description": "Operations about user", 34 - "externalDocs": { 35 - "description": "Find out more about our store", 36 - "url": "http://swagger.io" 37 - } 38 - } 39 - ], 40 - "schemes": [ 41 - "https", 42 - "http" 43 - ], 44 - "paths": { 45 - "/pet/{petId}/uploadImage": { 46 - "post": { 47 - "tags": [ 48 - "pet" 49 - ], 50 - "summary": "uploads an image", 51 - "description": "", 52 - "operationId": "uploadFile", 53 - "consumes": [ 54 - "multipart/form-data" 55 - ], 56 - "produces": [ 57 - "application/json" 58 - ], 59 - "parameters": [ 60 - { 61 - "name": "petId", 62 - "in": "path", 63 - "description": "ID of pet to update", 64 - "required": true, 65 - "type": "integer", 66 - "format": "int64" 67 - }, 68 - { 69 - "name": "additionalMetadata", 70 - "in": "formData", 71 - "description": "Additional data to pass to server", 72 - "required": false, 73 - "type": "string" 74 - }, 75 - { 76 - "name": "file", 77 - "in": "formData", 78 - "description": "file to upload", 79 - "required": false, 80 - "type": "file" 81 - } 82 - ], 83 - "responses": { 84 - "200": { 85 - "description": "successful operation", 86 - "schema": { 87 - "$ref": "#/definitions/ApiResponse" 88 - } 89 - } 90 - }, 91 - "security": [ 92 - { 93 - "petstore_auth": [ 94 - "write:pets", 95 - "read:pets" 96 - ] 97 - } 98 - ] 99 - } 100 - }, 101 - "/pet": { 102 - "post": { 103 - "tags": [ 104 - "pet" 105 - ], 106 - "summary": "Add a new pet to the store", 107 - "description": "", 108 - "operationId": "addPet", 109 - "consumes": [ 110 - "application/json", 111 - "application/xml" 112 - ], 113 - "produces": [ 114 - "application/json", 115 - "application/xml" 116 - ], 117 - "parameters": [ 118 - { 119 - "in": "body", 120 - "name": "body", 121 - "description": "Pet object that needs to be added to the store", 122 - "required": true, 123 - "schema": { 124 - "$ref": "#/definitions/Pet" 125 - } 126 - } 127 - ], 128 - "responses": { 129 - "405": { 130 - "description": "Invalid input" 131 - } 132 - }, 133 - "security": [ 134 - { 135 - "petstore_auth": [ 136 - "write:pets", 137 - "read:pets" 138 - ] 139 - } 140 - ] 141 - }, 142 - "put": { 143 - "tags": [ 144 - "pet" 145 - ], 146 - "summary": "Update an existing pet", 147 - "description": "", 148 - "operationId": "updatePet", 149 - "consumes": [ 150 - "application/json", 151 - "application/xml" 152 - ], 153 - "produces": [ 154 - "application/json", 155 - "application/xml" 156 - ], 157 - "parameters": [ 158 - { 159 - "in": "body", 160 - "name": "body", 161 - "description": "Pet object that needs to be added to the store", 162 - "required": true, 163 - "schema": { 164 - "$ref": "#/definitions/Pet" 165 - } 166 - } 167 - ], 168 - "responses": { 169 - "400": { 170 - "description": "Invalid ID supplied" 171 - }, 172 - "404": { 173 - "description": "Pet not found" 174 - }, 175 - "405": { 176 - "description": "Validation exception" 177 - } 178 - }, 179 - "security": [ 180 - { 181 - "petstore_auth": [ 182 - "write:pets", 183 - "read:pets" 184 - ] 185 - } 186 - ] 187 - } 188 - }, 189 - "/pet/findByStatus": { 190 - "get": { 191 - "tags": [ 192 - "pet" 193 - ], 194 - "summary": "Finds Pets by status", 195 - "description": "Multiple status values can be provided with comma separated strings", 196 - "operationId": "findPetsByStatus", 197 - "produces": [ 198 - "application/json", 199 - "application/xml" 200 - ], 201 - "parameters": [ 202 - { 203 - "name": "status", 204 - "in": "query", 205 - "description": "Status values that need to be considered for filter", 206 - "required": true, 207 - "type": "array", 208 - "items": { 209 - "type": "string", 210 - "enum": [ 211 - "available", 212 - "pending", 213 - "sold" 214 - ], 215 - "default": "available" 216 - }, 217 - "collectionFormat": "multi" 218 - } 219 - ], 220 - "responses": { 221 - "200": { 222 - "description": "successful operation", 223 - "schema": { 224 - "type": "array", 225 - "items": { 226 - "$ref": "#/definitions/Pet" 227 - } 228 - } 229 - }, 230 - "400": { 231 - "description": "Invalid status value" 232 - } 233 - }, 234 - "security": [ 235 - { 236 - "petstore_auth": [ 237 - "write:pets", 238 - "read:pets" 239 - ] 240 - } 241 - ] 242 - } 243 - }, 244 - "/pet/findByTags": { 245 - "get": { 246 - "tags": [ 247 - "pet" 248 - ], 249 - "summary": "Finds Pets by tags", 250 - "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", 251 - "operationId": "findPetsByTags", 252 - "produces": [ 253 - "application/json", 254 - "application/xml" 255 - ], 256 - "parameters": [ 257 - { 258 - "name": "tags", 259 - "in": "query", 260 - "description": "Tags to filter by", 261 - "required": true, 262 - "type": "array", 263 - "items": { 264 - "type": "string" 265 - }, 266 - "collectionFormat": "multi" 267 - } 268 - ], 269 - "responses": { 270 - "200": { 271 - "description": "successful operation", 272 - "schema": { 273 - "type": "array", 274 - "items": { 275 - "$ref": "#/definitions/Pet" 276 - } 277 - } 278 - }, 279 - "400": { 280 - "description": "Invalid tag value" 281 - } 282 - }, 283 - "security": [ 284 - { 285 - "petstore_auth": [ 286 - "write:pets", 287 - "read:pets" 288 - ] 289 - } 290 - ], 291 - "deprecated": true 292 - } 293 - }, 294 - "/pet/{petId}": { 295 - "get": { 296 - "tags": [ 297 - "pet" 298 - ], 299 - "summary": "Find pet by ID", 300 - "description": "Returns a single pet", 301 - "operationId": "getPetById", 302 - "produces": [ 303 - "application/json", 304 - "application/xml" 305 - ], 306 - "parameters": [ 307 - { 308 - "name": "petId", 309 - "in": "path", 310 - "description": "ID of pet to return", 311 - "required": true, 312 - "type": "integer", 313 - "format": "int64" 314 - } 315 - ], 316 - "responses": { 317 - "200": { 318 - "description": "successful operation", 319 - "schema": { 320 - "$ref": "#/definitions/Pet" 321 - } 322 - }, 323 - "400": { 324 - "description": "Invalid ID supplied" 325 - }, 326 - "404": { 327 - "description": "Pet not found" 328 - } 329 - }, 330 - "security": [ 331 - { 332 - "api_key": [] 333 - } 334 - ] 335 - }, 336 - "post": { 337 - "tags": [ 338 - "pet" 339 - ], 340 - "summary": "Updates a pet in the store with form data", 341 - "description": "", 342 - "operationId": "updatePetWithForm", 343 - "consumes": [ 344 - "application/x-www-form-urlencoded" 345 - ], 346 - "produces": [ 347 - "application/json", 348 - "application/xml" 349 - ], 350 - "parameters": [ 351 - { 352 - "name": "petId", 353 - "in": "path", 354 - "description": "ID of pet that needs to be updated", 355 - "required": true, 356 - "type": "integer", 357 - "format": "int64" 358 - }, 359 - { 360 - "name": "name", 361 - "in": "formData", 362 - "description": "Updated name of the pet", 363 - "required": false, 364 - "type": "string" 365 - }, 366 - { 367 - "name": "status", 368 - "in": "formData", 369 - "description": "Updated status of the pet", 370 - "required": false, 371 - "type": "string" 372 - } 373 - ], 374 - "responses": { 375 - "405": { 376 - "description": "Invalid input" 377 - } 378 - }, 379 - "security": [ 380 - { 381 - "petstore_auth": [ 382 - "write:pets", 383 - "read:pets" 384 - ] 385 - } 386 - ] 387 - }, 388 - "delete": { 389 - "tags": [ 390 - "pet" 391 - ], 392 - "summary": "Deletes a pet", 393 - "description": "", 394 - "operationId": "deletePet", 395 - "produces": [ 396 - "application/json", 397 - "application/xml" 398 - ], 399 - "parameters": [ 400 - { 401 - "name": "api_key", 402 - "in": "header", 403 - "required": false, 404 - "type": "string" 405 - }, 406 - { 407 - "name": "petId", 408 - "in": "path", 409 - "description": "Pet id to delete", 410 - "required": true, 411 - "type": "integer", 412 - "format": "int64" 413 - } 414 - ], 415 - "responses": { 416 - "400": { 417 - "description": "Invalid ID supplied" 418 - }, 419 - "404": { 420 - "description": "Pet not found" 421 - } 422 - }, 423 - "security": [ 424 - { 425 - "petstore_auth": [ 426 - "write:pets", 427 - "read:pets" 428 - ] 429 - } 430 - ] 431 - } 432 - }, 433 - "/store/order": { 434 - "post": { 435 - "tags": [ 436 - "store" 437 - ], 438 - "summary": "Place an order for a pet", 439 - "description": "", 440 - "operationId": "placeOrder", 441 - "consumes": [ 442 - "application/json" 443 - ], 444 - "produces": [ 445 - "application/json", 446 - "application/xml" 447 - ], 448 - "parameters": [ 449 - { 450 - "in": "body", 451 - "name": "body", 452 - "description": "order placed for purchasing the pet", 453 - "required": true, 454 - "schema": { 455 - "$ref": "#/definitions/Order" 456 - } 457 - } 458 - ], 459 - "responses": { 460 - "200": { 461 - "description": "successful operation", 462 - "schema": { 463 - "$ref": "#/definitions/Order" 464 - } 465 - }, 466 - "400": { 467 - "description": "Invalid Order" 468 - } 469 - } 470 - } 471 - }, 472 - "/store/order/{orderId}": { 473 - "get": { 474 - "tags": [ 475 - "store" 476 - ], 477 - "summary": "Find purchase order by ID", 478 - "description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", 479 - "operationId": "getOrderById", 480 - "produces": [ 481 - "application/json", 482 - "application/xml" 483 - ], 484 - "parameters": [ 485 - { 486 - "name": "orderId", 487 - "in": "path", 488 - "description": "ID of pet that needs to be fetched", 489 - "required": true, 490 - "type": "integer", 491 - "maximum": 10, 492 - "minimum": 1, 493 - "format": "int64" 494 - } 495 - ], 496 - "responses": { 497 - "200": { 498 - "description": "successful operation", 499 - "schema": { 500 - "$ref": "#/definitions/Order" 501 - } 502 - }, 503 - "400": { 504 - "description": "Invalid ID supplied" 505 - }, 506 - "404": { 507 - "description": "Order not found" 508 - } 509 - } 510 - }, 511 - "delete": { 512 - "tags": [ 513 - "store" 514 - ], 515 - "summary": "Delete purchase order by ID", 516 - "description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors", 517 - "operationId": "deleteOrder", 518 - "produces": [ 519 - "application/json", 520 - "application/xml" 521 - ], 522 - "parameters": [ 523 - { 524 - "name": "orderId", 525 - "in": "path", 526 - "description": "ID of the order that needs to be deleted", 527 - "required": true, 528 - "type": "integer", 529 - "minimum": 1, 530 - "format": "int64" 531 - } 532 - ], 533 - "responses": { 534 - "400": { 535 - "description": "Invalid ID supplied" 536 - }, 537 - "404": { 538 - "description": "Order not found" 539 - } 540 - } 541 - } 542 - }, 543 - "/store/inventory": { 544 - "get": { 545 - "tags": [ 546 - "store" 547 - ], 548 - "summary": "Returns pet inventories by status", 549 - "description": "Returns a map of status codes to quantities", 550 - "operationId": "getInventory", 551 - "produces": [ 552 - "application/json" 553 - ], 554 - "parameters": [], 555 - "responses": { 556 - "200": { 557 - "description": "successful operation", 558 - "schema": { 559 - "type": "object", 560 - "additionalProperties": { 561 - "type": "integer", 562 - "format": "int32" 563 - } 564 - } 565 - } 566 - }, 567 - "security": [ 568 - { 569 - "api_key": [] 570 - } 571 - ] 572 - } 573 - }, 574 - "/user/createWithArray": { 575 - "post": { 576 - "tags": [ 577 - "user" 578 - ], 579 - "summary": "Creates list of users with given input array", 580 - "description": "", 581 - "operationId": "createUsersWithArrayInput", 582 - "consumes": [ 583 - "application/json" 584 - ], 585 - "produces": [ 586 - "application/json", 587 - "application/xml" 588 - ], 589 - "parameters": [ 590 - { 591 - "in": "body", 592 - "name": "body", 593 - "description": "List of user object", 594 - "required": true, 595 - "schema": { 596 - "type": "array", 597 - "items": { 598 - "$ref": "#/definitions/User" 599 - } 600 - } 601 - } 602 - ], 603 - "responses": { 604 - "default": { 605 - "description": "successful operation" 606 - } 607 - } 608 - } 609 - }, 610 - "/user/createWithList": { 611 - "post": { 612 - "tags": [ 613 - "user" 614 - ], 615 - "summary": "Creates list of users with given input array", 616 - "description": "", 617 - "operationId": "createUsersWithListInput", 618 - "consumes": [ 619 - "application/json" 620 - ], 621 - "produces": [ 622 - "application/json", 623 - "application/xml" 624 - ], 625 - "parameters": [ 626 - { 627 - "in": "body", 628 - "name": "body", 629 - "description": "List of user object", 630 - "required": true, 631 - "schema": { 632 - "type": "array", 633 - "items": { 634 - "$ref": "#/definitions/User" 635 - } 636 - } 637 - } 638 - ], 639 - "responses": { 640 - "default": { 641 - "description": "successful operation" 642 - } 643 - } 644 - } 645 - }, 646 - "/user/{username}": { 647 - "get": { 648 - "tags": [ 649 - "user" 650 - ], 651 - "summary": "Get user by user name", 652 - "description": "", 653 - "operationId": "getUserByName", 654 - "produces": [ 655 - "application/json", 656 - "application/xml" 657 - ], 658 - "parameters": [ 659 - { 660 - "name": "username", 661 - "in": "path", 662 - "description": "The name that needs to be fetched. Use user1 for testing. ", 663 - "required": true, 664 - "type": "string" 665 - } 666 - ], 667 - "responses": { 668 - "200": { 669 - "description": "successful operation", 670 - "schema": { 671 - "$ref": "#/definitions/User" 672 - } 673 - }, 674 - "400": { 675 - "description": "Invalid username supplied" 676 - }, 677 - "404": { 678 - "description": "User not found" 679 - } 680 - } 681 - }, 682 - "put": { 683 - "tags": [ 684 - "user" 685 - ], 686 - "summary": "Updated user", 687 - "description": "This can only be done by the logged in user.", 688 - "operationId": "updateUser", 689 - "consumes": [ 690 - "application/json" 691 - ], 692 - "produces": [ 693 - "application/json", 694 - "application/xml" 695 - ], 696 - "parameters": [ 697 - { 698 - "name": "username", 699 - "in": "path", 700 - "description": "name that need to be updated", 701 - "required": true, 702 - "type": "string" 703 - }, 704 - { 705 - "in": "body", 706 - "name": "body", 707 - "description": "Updated user object", 708 - "required": true, 709 - "schema": { 710 - "$ref": "#/definitions/User" 711 - } 712 - } 713 - ], 714 - "responses": { 715 - "400": { 716 - "description": "Invalid user supplied" 717 - }, 718 - "404": { 719 - "description": "User not found" 720 - } 721 - } 722 - }, 723 - "delete": { 724 - "tags": [ 725 - "user" 726 - ], 727 - "summary": "Delete user", 728 - "description": "This can only be done by the logged in user.", 729 - "operationId": "deleteUser", 730 - "produces": [ 731 - "application/json", 732 - "application/xml" 733 - ], 734 - "parameters": [ 735 - { 736 - "name": "username", 737 - "in": "path", 738 - "description": "The name that needs to be deleted", 739 - "required": true, 740 - "type": "string" 741 - } 742 - ], 743 - "responses": { 744 - "400": { 745 - "description": "Invalid username supplied" 746 - }, 747 - "404": { 748 - "description": "User not found" 749 - } 750 - } 751 - } 752 - }, 753 - "/user/login": { 754 - "get": { 755 - "tags": [ 756 - "user" 757 - ], 758 - "summary": "Logs user into the system", 759 - "description": "", 760 - "operationId": "loginUser", 761 - "produces": [ 762 - "application/json", 763 - "application/xml" 764 - ], 765 - "parameters": [ 766 - { 767 - "name": "username", 768 - "in": "query", 769 - "description": "The user name for login", 770 - "required": true, 771 - "type": "string" 772 - }, 773 - { 774 - "name": "password", 775 - "in": "query", 776 - "description": "The password for login in clear text", 777 - "required": true, 778 - "type": "string" 779 - } 780 - ], 781 - "responses": { 782 - "200": { 783 - "description": "successful operation", 784 - "headers": { 785 - "X-Expires-After": { 786 - "type": "string", 787 - "format": "date-time", 788 - "description": "date in UTC when token expires" 789 - }, 790 - "X-Rate-Limit": { 791 - "type": "integer", 792 - "format": "int32", 793 - "description": "calls per hour allowed by the user" 794 - } 795 - }, 796 - "schema": { 797 - "type": "string" 798 - } 799 - }, 800 - "400": { 801 - "description": "Invalid username/password supplied" 802 - } 803 - } 804 - } 805 - }, 806 - "/user/logout": { 807 - "get": { 808 - "tags": [ 809 - "user" 810 - ], 811 - "summary": "Logs out current logged in user session", 812 - "description": "", 813 - "operationId": "logoutUser", 814 - "produces": [ 815 - "application/json", 816 - "application/xml" 817 - ], 818 - "parameters": [], 819 - "responses": { 820 - "default": { 821 - "description": "successful operation" 822 - } 823 - } 824 - } 825 - }, 826 - "/user": { 827 - "post": { 828 - "tags": [ 829 - "user" 830 - ], 831 - "summary": "Create user", 832 - "description": "This can only be done by the logged in user.", 833 - "operationId": "createUser", 834 - "consumes": [ 835 - "application/json" 836 - ], 837 - "produces": [ 838 - "application/json", 839 - "application/xml" 840 - ], 841 - "parameters": [ 842 - { 843 - "in": "body", 844 - "name": "body", 845 - "description": "Created user object", 846 - "required": true, 847 - "schema": { 848 - "$ref": "#/definitions/User" 849 - } 850 - } 851 - ], 852 - "responses": { 853 - "default": { 854 - "description": "successful operation" 855 - } 856 - } 857 - } 858 - } 859 - }, 860 - "securityDefinitions": { 861 - "api_key": { 862 - "type": "apiKey", 863 - "name": "api_key", 864 - "in": "header" 865 - }, 866 - "petstore_auth": { 867 - "type": "oauth2", 868 - "authorizationUrl": "https://petstore.swagger.io/oauth/authorize", 869 - "flow": "implicit", 870 - "scopes": { 871 - "read:pets": "read your pets", 872 - "write:pets": "modify pets in your account" 873 - } 874 - } 875 - }, 876 - "definitions": { 877 - "ApiResponse": { 878 - "type": "object", 879 - "properties": { 880 - "code": { 881 - "type": "integer", 882 - "format": "int32" 883 - }, 884 - "type": { 885 - "type": "string" 886 - }, 887 - "message": { 888 - "type": "string" 889 - } 890 - } 891 - }, 892 - "Category": { 893 - "type": "object", 894 - "properties": { 895 - "id": { 896 - "type": "integer", 897 - "format": "int64" 898 - }, 899 - "name": { 900 - "type": "string" 901 - } 902 - }, 903 - "xml": { 904 - "name": "Category" 905 - } 906 - }, 907 - "Pet": { 908 - "type": "object", 909 - "required": [ 910 - "name", 911 - "photoUrls" 912 - ], 913 - "properties": { 914 - "id": { 915 - "type": "integer", 916 - "format": "int64" 917 - }, 918 - "category": { 919 - "$ref": "#/definitions/Category" 920 - }, 921 - "name": { 922 - "type": "string", 923 - "example": "doggie" 924 - }, 925 - "photoUrls": { 926 - "type": "array", 927 - "xml": { 928 - "wrapped": true 929 - }, 930 - "items": { 931 - "type": "string", 932 - "xml": { 933 - "name": "photoUrl" 934 - } 935 - } 936 - }, 937 - "tags": { 938 - "type": "array", 939 - "xml": { 940 - "wrapped": true 941 - }, 942 - "items": { 943 - "xml": { 944 - "name": "tag" 945 - }, 946 - "$ref": "#/definitions/Tag" 947 - } 948 - }, 949 - "status": { 950 - "type": "string", 951 - "description": "pet status in the store", 952 - "enum": [ 953 - "available", 954 - "pending", 955 - "sold" 956 - ] 957 - } 958 - }, 959 - "xml": { 960 - "name": "Pet" 961 - } 962 - }, 963 - "Tag": { 964 - "type": "object", 965 - "properties": { 966 - "id": { 967 - "type": "integer", 968 - "format": "int64" 969 - }, 970 - "name": { 971 - "type": "string" 972 - } 973 - }, 974 - "xml": { 975 - "name": "Tag" 976 - } 977 - }, 978 - "Order": { 979 - "type": "object", 980 - "properties": { 981 - "bool": { 982 - "description": "Simple boolean enum", 983 - "type": "boolean", 984 - "enum": [ 985 - true 986 - ] 987 - }, 988 - "id": { 989 - "type": "integer", 990 - "format": "int64" 991 - }, 992 - "petId": { 993 - "type": "integer", 994 - "format": "int64" 995 - }, 996 - "quantity": { 997 - "type": "integer", 998 - "format": "int32" 999 - }, 1000 - "shipDate": { 1001 - "type": "string", 1002 - "format": "date-time" 1003 - }, 1004 - "status": { 1005 - "type": "string", 1006 - "description": "Order Status", 1007 - "enum": [ 1008 - "placed", 1009 - "approved", 1010 - "delivered" 1011 - ] 1012 - }, 1013 - "complete": { 1014 - "type": "boolean" 1015 - } 1016 - }, 1017 - "xml": { 1018 - "name": "Order" 1019 - } 1020 - }, 1021 - "User": { 1022 - "type": "object", 1023 - "properties": { 1024 - "id": { 1025 - "type": "integer", 1026 - "format": "int64" 1027 - }, 1028 - "username": { 1029 - "type": "string" 1030 - }, 1031 - "firstName": { 1032 - "type": "string" 1033 - }, 1034 - "lastName": { 1035 - "type": "string" 1036 - }, 1037 - "email": { 1038 - "type": "string" 1039 - }, 1040 - "password": { 1041 - "type": "string" 1042 - }, 1043 - "phone": { 1044 - "type": "string" 1045 - }, 1046 - "userStatus": { 1047 - "type": "integer", 1048 - "format": "int32", 1049 - "description": "User Status" 1050 - } 1051 - }, 1052 - "xml": { 1053 - "name": "User" 1054 - } 1055 - } 1056 - }, 1057 - "externalDocs": { 1058 - "description": "Find out more about Swagger", 1059 - "url": "http://swagger.io" 1060 - } 1061 - }
-1225
samples/spec/v3.json
··· 1 - { 2 - "openapi": "3.0.2", 3 - "info": { 4 - "title": "Swagger Petstore - OpenAPI 3.0", 5 - "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) ", 6 - "termsOfService": "http://swagger.io/terms/", 7 - "contact": { 8 - "email": "apiteam@swagger.io" 9 - }, 10 - "license": { 11 - "name": "Apache 2.0", 12 - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 13 - }, 14 - "version": "1.0.4" 15 - }, 16 - "externalDocs": { 17 - "description": "Find out more about Swagger", 18 - "url": "http://swagger.io" 19 - }, 20 - "servers": [ 21 - { 22 - "url": "/api/v3" 23 - } 24 - ], 25 - "tags": [ 26 - { 27 - "name": "pet", 28 - "description": "Everything about your Pets", 29 - "externalDocs": { 30 - "description": "Find out more", 31 - "url": "http://swagger.io" 32 - } 33 - }, 34 - { 35 - "name": "store", 36 - "description": "Operations about user" 37 - }, 38 - { 39 - "name": "user", 40 - "description": "Access to Petstore orders", 41 - "externalDocs": { 42 - "description": "Find out more about our store", 43 - "url": "http://swagger.io" 44 - } 45 - } 46 - ], 47 - "paths": { 48 - "/pet": { 49 - "put": { 50 - "tags": [ 51 - "pet" 52 - ], 53 - "summary": "Update an existing pet", 54 - "description": "Update an existing pet by Id", 55 - "operationId": "updatePet", 56 - "requestBody": { 57 - "description": "Update an existent pet in the store", 58 - "content": { 59 - "application/json": { 60 - "schema": { 61 - "$ref": "#/components/schemas/Pet" 62 - } 63 - }, 64 - "application/xml": { 65 - "schema": { 66 - "$ref": "#/components/schemas/Pet" 67 - } 68 - }, 69 - "application/x-www-form-urlencoded": { 70 - "schema": { 71 - "$ref": "#/components/schemas/Pet" 72 - } 73 - } 74 - }, 75 - "required": true 76 - }, 77 - "responses": { 78 - "200": { 79 - "description": "Successful operation", 80 - "content": { 81 - "application/xml": { 82 - "schema": { 83 - "$ref": "#/components/schemas/Pet" 84 - } 85 - }, 86 - "application/json": { 87 - "schema": { 88 - "$ref": "#/components/schemas/Pet" 89 - } 90 - } 91 - } 92 - }, 93 - "400": { 94 - "description": "Invalid ID supplied" 95 - }, 96 - "404": { 97 - "description": "Pet not found" 98 - }, 99 - "405": { 100 - "description": "Validation exception" 101 - } 102 - }, 103 - "security": [ 104 - { 105 - "petstore_auth": [ 106 - "write:pets", 107 - "read:pets" 108 - ] 109 - } 110 - ] 111 - }, 112 - "post": { 113 - "tags": [ 114 - "pet" 115 - ], 116 - "summary": "Add a new pet to the store", 117 - "description": "Add a new pet to the store", 118 - "operationId": "addPet", 119 - "requestBody": { 120 - "description": "Create a new pet in the store", 121 - "content": { 122 - "application/json": { 123 - "schema": { 124 - "$ref": "#/components/schemas/Pet" 125 - } 126 - }, 127 - "application/xml": { 128 - "schema": { 129 - "$ref": "#/components/schemas/Pet" 130 - } 131 - }, 132 - "application/x-www-form-urlencoded": { 133 - "schema": { 134 - "$ref": "#/components/schemas/Pet" 135 - } 136 - } 137 - }, 138 - "required": true 139 - }, 140 - "responses": { 141 - "200": { 142 - "description": "Successful operation", 143 - "content": { 144 - "application/xml": { 145 - "schema": { 146 - "$ref": "#/components/schemas/Pet" 147 - } 148 - }, 149 - "application/json": { 150 - "schema": { 151 - "$ref": "#/components/schemas/Pet" 152 - } 153 - } 154 - } 155 - }, 156 - "405": { 157 - "description": "Invalid input" 158 - } 159 - }, 160 - "security": [ 161 - { 162 - "petstore_auth": [ 163 - "write:pets", 164 - "read:pets" 165 - ] 166 - } 167 - ] 168 - } 169 - }, 170 - "/pet/findByStatus": { 171 - "get": { 172 - "tags": [ 173 - "pet" 174 - ], 175 - "summary": "Finds Pets by status", 176 - "description": "Multiple status values can be provided with comma separated strings", 177 - "operationId": "findPetsByStatus", 178 - "parameters": [ 179 - { 180 - "name": "status", 181 - "in": "query", 182 - "description": "Status values that need to be considered for filter", 183 - "required": false, 184 - "explode": true, 185 - "schema": { 186 - "type": "string", 187 - "default": "available", 188 - "enum": [ 189 - "available", 190 - "pending", 191 - "sold" 192 - ] 193 - } 194 - } 195 - ], 196 - "responses": { 197 - "200": { 198 - "description": "successful operation", 199 - "content": { 200 - "application/xml": { 201 - "schema": { 202 - "type": "array", 203 - "items": { 204 - "$ref": "#/components/schemas/Pet" 205 - } 206 - } 207 - }, 208 - "application/json": { 209 - "schema": { 210 - "type": "array", 211 - "items": { 212 - "$ref": "#/components/schemas/Pet" 213 - } 214 - } 215 - } 216 - } 217 - }, 218 - "400": { 219 - "description": "Invalid status value" 220 - } 221 - }, 222 - "security": [ 223 - { 224 - "petstore_auth": [ 225 - "write:pets", 226 - "read:pets" 227 - ] 228 - } 229 - ] 230 - } 231 - }, 232 - "/pet/findByTags": { 233 - "get": { 234 - "tags": [ 235 - "pet" 236 - ], 237 - "summary": "Finds Pets by tags", 238 - "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", 239 - "operationId": "findPetsByTags", 240 - "parameters": [ 241 - { 242 - "name": "tags", 243 - "in": "query", 244 - "description": "Tags to filter by", 245 - "required": false, 246 - "explode": true, 247 - "schema": { 248 - "type": "array", 249 - "items": { 250 - "type": "string" 251 - } 252 - } 253 - } 254 - ], 255 - "responses": { 256 - "200": { 257 - "description": "successful operation", 258 - "content": { 259 - "application/xml": { 260 - "schema": { 261 - "type": "array", 262 - "items": { 263 - "$ref": "#/components/schemas/Pet" 264 - } 265 - } 266 - }, 267 - "application/json": { 268 - "schema": { 269 - "type": "array", 270 - "items": { 271 - "$ref": "#/components/schemas/Pet" 272 - } 273 - } 274 - } 275 - } 276 - }, 277 - "400": { 278 - "description": "Invalid tag value" 279 - } 280 - }, 281 - "security": [ 282 - { 283 - "petstore_auth": [ 284 - "write:pets", 285 - "read:pets" 286 - ] 287 - } 288 - ] 289 - } 290 - }, 291 - "/pet/{petId}": { 292 - "get": { 293 - "tags": [ 294 - "pet" 295 - ], 296 - "summary": "Find pet by ID", 297 - "description": "Returns a single pet", 298 - "operationId": "getPetById", 299 - "parameters": [ 300 - { 301 - "name": "petId", 302 - "in": "path", 303 - "description": "ID of pet to return", 304 - "required": true, 305 - "schema": { 306 - "type": "integer", 307 - "format": "int64" 308 - } 309 - } 310 - ], 311 - "responses": { 312 - "200": { 313 - "description": "successful operation", 314 - "content": { 315 - "application/xml": { 316 - "schema": { 317 - "$ref": "#/components/schemas/Pet" 318 - } 319 - }, 320 - "application/json": { 321 - "schema": { 322 - "$ref": "#/components/schemas/Pet" 323 - } 324 - } 325 - } 326 - }, 327 - "400": { 328 - "description": "Invalid ID supplied" 329 - }, 330 - "404": { 331 - "description": "Pet not found" 332 - } 333 - }, 334 - "security": [ 335 - { 336 - "api_key": [] 337 - }, 338 - { 339 - "petstore_auth": [ 340 - "write:pets", 341 - "read:pets" 342 - ] 343 - } 344 - ] 345 - }, 346 - "post": { 347 - "tags": [ 348 - "pet" 349 - ], 350 - "summary": "Updates a pet in the store with form data", 351 - "description": "", 352 - "operationId": "updatePetWithForm", 353 - "parameters": [ 354 - { 355 - "name": "petId", 356 - "in": "path", 357 - "description": "ID of pet that needs to be updated", 358 - "required": true, 359 - "schema": { 360 - "type": "integer", 361 - "format": "int64" 362 - } 363 - }, 364 - { 365 - "name": "name", 366 - "in": "query", 367 - "description": "Name of pet that needs to be updated", 368 - "schema": { 369 - "type": "string" 370 - } 371 - }, 372 - { 373 - "name": "status", 374 - "in": "query", 375 - "description": "Status of pet that needs to be updated", 376 - "schema": { 377 - "type": "string" 378 - } 379 - } 380 - ], 381 - "responses": { 382 - "405": { 383 - "description": "Invalid input" 384 - } 385 - }, 386 - "security": [ 387 - { 388 - "petstore_auth": [ 389 - "write:pets", 390 - "read:pets" 391 - ] 392 - } 393 - ] 394 - }, 395 - "delete": { 396 - "tags": [ 397 - "pet" 398 - ], 399 - "summary": "Deletes a pet", 400 - "description": "", 401 - "operationId": "deletePet", 402 - "parameters": [ 403 - { 404 - "name": "api_key", 405 - "in": "header", 406 - "description": "", 407 - "required": false, 408 - "schema": { 409 - "type": "string" 410 - } 411 - }, 412 - { 413 - "name": "petId", 414 - "in": "path", 415 - "description": "Pet id to delete", 416 - "required": true, 417 - "schema": { 418 - "type": "integer", 419 - "format": "int64" 420 - } 421 - } 422 - ], 423 - "responses": { 424 - "400": { 425 - "description": "Invalid pet value" 426 - } 427 - }, 428 - "security": [ 429 - { 430 - "petstore_auth": [ 431 - "write:pets", 432 - "read:pets" 433 - ] 434 - } 435 - ] 436 - } 437 - }, 438 - "/pet/{petId}/uploadImage": { 439 - "post": { 440 - "tags": [ 441 - "pet" 442 - ], 443 - "summary": "uploads an image", 444 - "description": "", 445 - "operationId": "uploadFile", 446 - "parameters": [ 447 - { 448 - "name": "petId", 449 - "in": "path", 450 - "description": "ID of pet to update", 451 - "required": true, 452 - "schema": { 453 - "type": "integer", 454 - "format": "int64" 455 - } 456 - }, 457 - { 458 - "name": "additionalMetadata", 459 - "in": "query", 460 - "description": "Additional Metadata", 461 - "required": false, 462 - "schema": { 463 - "type": "string" 464 - } 465 - } 466 - ], 467 - "requestBody": { 468 - "content": { 469 - "application/octet-stream": { 470 - "schema": { 471 - "type": "string", 472 - "format": "binary" 473 - } 474 - } 475 - } 476 - }, 477 - "responses": { 478 - "200": { 479 - "description": "successful operation", 480 - "content": { 481 - "application/json": { 482 - "schema": { 483 - "$ref": "#/components/schemas/ApiResponse" 484 - } 485 - } 486 - } 487 - } 488 - }, 489 - "security": [ 490 - { 491 - "petstore_auth": [ 492 - "write:pets", 493 - "read:pets" 494 - ] 495 - } 496 - ] 497 - } 498 - }, 499 - "/store/inventory": { 500 - "get": { 501 - "tags": [ 502 - "store" 503 - ], 504 - "summary": "Returns pet inventories by status", 505 - "description": "Returns a map of status codes to quantities", 506 - "operationId": "getInventory", 507 - "responses": { 508 - "200": { 509 - "description": "successful operation", 510 - "content": { 511 - "application/json": { 512 - "schema": { 513 - "type": "object", 514 - "additionalProperties": { 515 - "type": "integer", 516 - "format": "int32" 517 - } 518 - } 519 - } 520 - } 521 - } 522 - }, 523 - "security": [ 524 - { 525 - "api_key": [] 526 - } 527 - ] 528 - } 529 - }, 530 - "/store/order": { 531 - "post": { 532 - "tags": [ 533 - "store" 534 - ], 535 - "summary": "Place an order for a pet", 536 - "description": "Place a new order in the store", 537 - "operationId": "placeOrder", 538 - "requestBody": { 539 - "content": { 540 - "application/json": { 541 - "schema": { 542 - "$ref": "#/components/schemas/Order" 543 - } 544 - }, 545 - "application/xml": { 546 - "schema": { 547 - "$ref": "#/components/schemas/Order" 548 - } 549 - }, 550 - "application/x-www-form-urlencoded": { 551 - "schema": { 552 - "$ref": "#/components/schemas/Order" 553 - } 554 - } 555 - } 556 - }, 557 - "responses": { 558 - "200": { 559 - "description": "successful operation", 560 - "content": { 561 - "application/json": { 562 - "schema": { 563 - "$ref": "#/components/schemas/Order" 564 - } 565 - } 566 - } 567 - }, 568 - "405": { 569 - "description": "Invalid input" 570 - } 571 - } 572 - } 573 - }, 574 - "/store/order/{orderId}": { 575 - "get": { 576 - "tags": [ 577 - "store" 578 - ], 579 - "summary": "Find purchase order by ID", 580 - "description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", 581 - "operationId": "getOrderById", 582 - "parameters": [ 583 - { 584 - "name": "orderId", 585 - "in": "path", 586 - "description": "ID of order that needs to be fetched", 587 - "required": true, 588 - "schema": { 589 - "type": "integer", 590 - "format": "int64" 591 - } 592 - } 593 - ], 594 - "responses": { 595 - "200": { 596 - "description": "successful operation", 597 - "content": { 598 - "application/xml": { 599 - "schema": { 600 - "$ref": "#/components/schemas/Order" 601 - } 602 - }, 603 - "application/json": { 604 - "schema": { 605 - "$ref": "#/components/schemas/Order" 606 - } 607 - } 608 - } 609 - }, 610 - "400": { 611 - "description": "Invalid ID supplied" 612 - }, 613 - "404": { 614 - "description": "Order not found" 615 - } 616 - } 617 - }, 618 - "delete": { 619 - "tags": [ 620 - "store" 621 - ], 622 - "summary": "Delete purchase order by ID", 623 - "description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", 624 - "operationId": "deleteOrder", 625 - "parameters": [ 626 - { 627 - "name": "orderId", 628 - "in": "path", 629 - "description": "ID of the order that needs to be deleted", 630 - "required": true, 631 - "schema": { 632 - "type": "integer", 633 - "format": "int64" 634 - } 635 - } 636 - ], 637 - "responses": { 638 - "400": { 639 - "description": "Invalid ID supplied" 640 - }, 641 - "404": { 642 - "description": "Order not found" 643 - } 644 - } 645 - } 646 - }, 647 - "/user": { 648 - "post": { 649 - "tags": [ 650 - "user" 651 - ], 652 - "summary": "Create user", 653 - "description": "This can only be done by the logged in user.", 654 - "operationId": "createUser", 655 - "requestBody": { 656 - "description": "Created user object", 657 - "content": { 658 - "application/json": { 659 - "schema": { 660 - "$ref": "#/components/schemas/User" 661 - } 662 - }, 663 - "application/xml": { 664 - "schema": { 665 - "$ref": "#/components/schemas/User" 666 - } 667 - }, 668 - "application/x-www-form-urlencoded": { 669 - "schema": { 670 - "$ref": "#/components/schemas/User" 671 - } 672 - } 673 - } 674 - }, 675 - "responses": { 676 - "default": { 677 - "description": "successful operation", 678 - "content": { 679 - "application/json": { 680 - "schema": { 681 - "$ref": "#/components/schemas/User" 682 - } 683 - }, 684 - "application/xml": { 685 - "schema": { 686 - "$ref": "#/components/schemas/User" 687 - } 688 - } 689 - } 690 - } 691 - } 692 - } 693 - }, 694 - "/user/createWithList": { 695 - "post": { 696 - "tags": [ 697 - "user" 698 - ], 699 - "summary": "Creates list of users with given input array", 700 - "description": "Creates list of users with given input array", 701 - "operationId": "createUsersWithListInput", 702 - "requestBody": { 703 - "content": { 704 - "application/json": { 705 - "schema": { 706 - "type": "array", 707 - "items": { 708 - "$ref": "#/components/schemas/User" 709 - } 710 - } 711 - } 712 - } 713 - }, 714 - "responses": { 715 - "200": { 716 - "description": "Successful operation", 717 - "content": { 718 - "application/xml": { 719 - "schema": { 720 - "$ref": "#/components/schemas/User" 721 - } 722 - }, 723 - "application/json": { 724 - "schema": { 725 - "$ref": "#/components/schemas/User" 726 - } 727 - } 728 - } 729 - }, 730 - "default": { 731 - "description": "successful operation" 732 - } 733 - } 734 - } 735 - }, 736 - "/user/login": { 737 - "get": { 738 - "tags": [ 739 - "user" 740 - ], 741 - "summary": "Logs user into the system", 742 - "description": "", 743 - "operationId": "loginUser", 744 - "parameters": [ 745 - { 746 - "name": "username", 747 - "in": "query", 748 - "description": "The user name for login", 749 - "required": false, 750 - "schema": { 751 - "type": "string" 752 - } 753 - }, 754 - { 755 - "name": "password", 756 - "in": "query", 757 - "description": "The password for login in clear text", 758 - "required": false, 759 - "schema": { 760 - "type": "string" 761 - } 762 - } 763 - ], 764 - "responses": { 765 - "200": { 766 - "description": "successful operation", 767 - "headers": { 768 - "X-Rate-Limit": { 769 - "description": "calls per hour allowed by the user", 770 - "schema": { 771 - "type": "integer", 772 - "format": "int32" 773 - } 774 - }, 775 - "X-Expires-After": { 776 - "description": "date in UTC when token expires", 777 - "schema": { 778 - "type": "string", 779 - "format": "date-time" 780 - } 781 - } 782 - }, 783 - "content": { 784 - "application/xml": { 785 - "schema": { 786 - "type": "string" 787 - } 788 - }, 789 - "application/json": { 790 - "schema": { 791 - "type": "string" 792 - } 793 - } 794 - } 795 - }, 796 - "400": { 797 - "description": "Invalid username/password supplied" 798 - } 799 - } 800 - } 801 - }, 802 - "/user/logout": { 803 - "get": { 804 - "tags": [ 805 - "user" 806 - ], 807 - "summary": "Logs out current logged in user session", 808 - "description": "", 809 - "operationId": "logoutUser", 810 - "parameters": [], 811 - "responses": { 812 - "default": { 813 - "description": "successful operation" 814 - } 815 - } 816 - } 817 - }, 818 - "/user/{username}": { 819 - "get": { 820 - "tags": [ 821 - "user" 822 - ], 823 - "summary": "Get user by user name", 824 - "description": "", 825 - "operationId": "getUserByName", 826 - "parameters": [ 827 - { 828 - "name": "username", 829 - "in": "path", 830 - "description": "The name that needs to be fetched. Use user1 for testing. ", 831 - "required": true, 832 - "schema": { 833 - "type": "string" 834 - } 835 - } 836 - ], 837 - "responses": { 838 - "200": { 839 - "description": "successful operation", 840 - "content": { 841 - "application/xml": { 842 - "schema": { 843 - "$ref": "#/components/schemas/User" 844 - } 845 - }, 846 - "application/json": { 847 - "schema": { 848 - "$ref": "#/components/schemas/User" 849 - } 850 - } 851 - } 852 - }, 853 - "400": { 854 - "description": "Invalid username supplied" 855 - }, 856 - "404": { 857 - "description": "User not found" 858 - } 859 - } 860 - }, 861 - "put": { 862 - "tags": [ 863 - "user" 864 - ], 865 - "summary": "Update user", 866 - "description": "This can only be done by the logged in user.", 867 - "operationId": "updateUser", 868 - "parameters": [ 869 - { 870 - "name": "username", 871 - "in": "path", 872 - "description": "name that need to be deleted", 873 - "required": true, 874 - "schema": { 875 - "type": "string" 876 - } 877 - } 878 - ], 879 - "requestBody": { 880 - "description": "Update an existent user in the store", 881 - "content": { 882 - "application/json": { 883 - "schema": { 884 - "$ref": "#/components/schemas/User" 885 - } 886 - }, 887 - "application/xml": { 888 - "schema": { 889 - "$ref": "#/components/schemas/User" 890 - } 891 - }, 892 - "application/x-www-form-urlencoded": { 893 - "schema": { 894 - "$ref": "#/components/schemas/User" 895 - } 896 - } 897 - } 898 - }, 899 - "responses": { 900 - "default": { 901 - "description": "successful operation" 902 - } 903 - } 904 - }, 905 - "delete": { 906 - "tags": [ 907 - "user" 908 - ], 909 - "summary": "Delete user", 910 - "description": "This can only be done by the logged in user.", 911 - "operationId": "deleteUser", 912 - "parameters": [ 913 - { 914 - "name": "username", 915 - "in": "path", 916 - "description": "The name that needs to be deleted", 917 - "required": true, 918 - "schema": { 919 - "type": "string" 920 - } 921 - } 922 - ], 923 - "responses": { 924 - "400": { 925 - "description": "Invalid username supplied" 926 - }, 927 - "404": { 928 - "description": "User not found" 929 - } 930 - } 931 - } 932 - } 933 - }, 934 - "components": { 935 - "schemas": { 936 - "Order": { 937 - "type": "object", 938 - "properties": { 939 - "id": { 940 - "type": "integer", 941 - "format": "int64", 942 - "example": 10 943 - }, 944 - "petId": { 945 - "type": "integer", 946 - "format": "int64", 947 - "example": 198772 948 - }, 949 - "quantity": { 950 - "type": "integer", 951 - "format": "int32", 952 - "example": 7 953 - }, 954 - "shipDate": { 955 - "type": "string", 956 - "format": "date-time" 957 - }, 958 - "status": { 959 - "type": "string", 960 - "description": "Order Status", 961 - "example": "approved", 962 - "enum": [ 963 - "placed", 964 - "approved", 965 - "delivered" 966 - ] 967 - }, 968 - "complete": { 969 - "type": "boolean" 970 - } 971 - }, 972 - "xml": { 973 - "name": "order" 974 - } 975 - }, 976 - "Customer": { 977 - "type": "object", 978 - "properties": { 979 - "id": { 980 - "type": "integer", 981 - "format": "int64", 982 - "example": 100000 983 - }, 984 - "username": { 985 - "type": "string", 986 - "example": "fehguy" 987 - }, 988 - "address": { 989 - "type": "array", 990 - "xml": { 991 - "name": "addresses", 992 - "wrapped": true 993 - }, 994 - "items": { 995 - "$ref": "#/components/schemas/Address" 996 - } 997 - } 998 - }, 999 - "xml": { 1000 - "name": "customer" 1001 - } 1002 - }, 1003 - "Address": { 1004 - "type": "object", 1005 - "properties": { 1006 - "street": { 1007 - "type": "string", 1008 - "example": "437 Lytton" 1009 - }, 1010 - "city": { 1011 - "type": "string", 1012 - "example": "Palo Alto" 1013 - }, 1014 - "state": { 1015 - "type": "string", 1016 - "example": "CA" 1017 - }, 1018 - "zip": { 1019 - "type": "string", 1020 - "example": "94301" 1021 - } 1022 - }, 1023 - "xml": { 1024 - "name": "address" 1025 - } 1026 - }, 1027 - "Category": { 1028 - "type": "object", 1029 - "properties": { 1030 - "id": { 1031 - "type": "integer", 1032 - "format": "int64", 1033 - "example": 1 1034 - }, 1035 - "name": { 1036 - "type": "string", 1037 - "example": "Dogs" 1038 - } 1039 - }, 1040 - "xml": { 1041 - "name": "category" 1042 - } 1043 - }, 1044 - "User": { 1045 - "type": "object", 1046 - "properties": { 1047 - "id": { 1048 - "type": "integer", 1049 - "format": "int64", 1050 - "example": 10 1051 - }, 1052 - "username": { 1053 - "type": "string", 1054 - "example": "theUser" 1055 - }, 1056 - "firstName": { 1057 - "type": "string", 1058 - "example": "John" 1059 - }, 1060 - "lastName": { 1061 - "type": "string", 1062 - "example": "James" 1063 - }, 1064 - "email": { 1065 - "type": "string", 1066 - "example": "john@email.com" 1067 - }, 1068 - "password": { 1069 - "type": "string", 1070 - "example": "12345" 1071 - }, 1072 - "phone": { 1073 - "type": "string", 1074 - "example": "12345" 1075 - }, 1076 - "userStatus": { 1077 - "type": "integer", 1078 - "description": "User Status", 1079 - "format": "int32", 1080 - "example": 1 1081 - } 1082 - }, 1083 - "xml": { 1084 - "name": "user" 1085 - } 1086 - }, 1087 - "Tag": { 1088 - "type": "object", 1089 - "properties": { 1090 - "id": { 1091 - "type": "integer", 1092 - "format": "int64" 1093 - }, 1094 - "name": { 1095 - "type": "string" 1096 - } 1097 - }, 1098 - "xml": { 1099 - "name": "tag" 1100 - } 1101 - }, 1102 - "Pet": { 1103 - "required": [ 1104 - "name", 1105 - "photoUrls" 1106 - ], 1107 - "type": "object", 1108 - "properties": { 1109 - "id": { 1110 - "type": "integer", 1111 - "format": "int64", 1112 - "example": 10 1113 - }, 1114 - "name": { 1115 - "type": "string", 1116 - "example": "doggie" 1117 - }, 1118 - "category": { 1119 - "$ref": "#/components/schemas/Category" 1120 - }, 1121 - "photoUrls": { 1122 - "type": "array", 1123 - "xml": { 1124 - "wrapped": true 1125 - }, 1126 - "items": { 1127 - "type": "string", 1128 - "xml": { 1129 - "name": "photoUrl" 1130 - } 1131 - } 1132 - }, 1133 - "tags": { 1134 - "type": "array", 1135 - "xml": { 1136 - "wrapped": true 1137 - }, 1138 - "items": { 1139 - "$ref": "#/components/schemas/Tag" 1140 - } 1141 - }, 1142 - "status": { 1143 - "type": "string", 1144 - "description": "pet status in the store", 1145 - "enum": [ 1146 - "available", 1147 - "pending", 1148 - "sold" 1149 - ] 1150 - } 1151 - }, 1152 - "xml": { 1153 - "name": "pet" 1154 - } 1155 - }, 1156 - "ApiResponse": { 1157 - "type": "object", 1158 - "properties": { 1159 - "code": { 1160 - "type": "integer", 1161 - "format": "int32" 1162 - }, 1163 - "type": { 1164 - "type": "string" 1165 - }, 1166 - "message": { 1167 - "type": "string" 1168 - } 1169 - }, 1170 - "xml": { 1171 - "name": "##default" 1172 - } 1173 - } 1174 - }, 1175 - "requestBodies": { 1176 - "Pet": { 1177 - "description": "Pet object that needs to be added to the store", 1178 - "content": { 1179 - "application/json": { 1180 - "schema": { 1181 - "$ref": "#/components/schemas/Pet" 1182 - } 1183 - }, 1184 - "application/xml": { 1185 - "schema": { 1186 - "$ref": "#/components/schemas/Pet" 1187 - } 1188 - } 1189 - } 1190 - }, 1191 - "UserArray": { 1192 - "description": "List of user object", 1193 - "content": { 1194 - "application/json": { 1195 - "schema": { 1196 - "type": "array", 1197 - "items": { 1198 - "$ref": "#/components/schemas/User" 1199 - } 1200 - } 1201 - } 1202 - } 1203 - } 1204 - }, 1205 - "securitySchemes": { 1206 - "petstore_auth": { 1207 - "type": "oauth2", 1208 - "flows": { 1209 - "implicit": { 1210 - "authorizationUrl": "https://petstore3.swagger.io/oauth/authorize", 1211 - "scopes": { 1212 - "write:pets": "modify pets in your account", 1213 - "read:pets": "read your pets" 1214 - } 1215 - } 1216 - } 1217 - }, 1218 - "api_key": { 1219 - "type": "apiKey", 1220 - "name": "api_key", 1221 - "in": "header" 1222 - } 1223 - } 1224 - } 1225 - }
+5 -5
src/index.spec.ts
··· 1 - import { generate, parseOpenApiSpecification } from './index'; 1 + import { createClient, parseOpenApiSpecification } from './index'; 2 2 import * as parseV2 from './openApi/v2'; 3 3 import * as parseV3 from './openApi/v3'; 4 4 5 5 describe('index', () => { 6 6 it('parses v2 without issues', async () => { 7 - await generate({ 7 + await createClient({ 8 8 input: './test/spec/v2.json', 9 9 output: './generated/v2/', 10 10 write: false, ··· 12 12 }); 13 13 14 14 it('parses v3 without issues', async () => { 15 - await generate({ 15 + await createClient({ 16 16 input: './test/spec/v3.json', 17 17 output: './generated/v3/', 18 18 write: false, ··· 20 20 }); 21 21 22 22 it('downloads and parses v2 without issues', async () => { 23 - await generate({ 23 + await createClient({ 24 24 input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/spec/v2.json', 25 25 output: './generated/v2-downloaded/', 26 26 write: false, ··· 28 28 }); 29 29 30 30 it('downloads and parses v3 without issues', async () => { 31 - await generate({ 31 + await createClient({ 32 32 input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/spec/v3.json', 33 33 output: './generated/v3-downloaded/', 34 34 write: false,
+17 -7
src/index.ts
··· 4 4 5 5 import { sync } from 'cross-spawn'; 6 6 7 + import type { Client } from './client/interfaces/Client'; 7 8 import { parse as parseV2 } from './openApi/v2'; 8 9 import { parse as parseV3 } from './openApi/v3'; 9 10 import type { Config, UserConfig } from './types/config'; ··· 79 80 const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => { 80 81 const userConfigFromFile = await getConfigFromFile(); 81 82 if (userConfigFromFile) { 82 - userConfig = { ...userConfig, ...userConfigFromFile }; 83 + userConfig = { ...userConfigFromFile, ...userConfig }; 83 84 } 84 85 85 86 const { 86 87 autoformat = true, 87 88 base, 88 - clientName, 89 89 enums = false, 90 90 exportCore = true, 91 91 exportModels = true, 92 92 exportSchemas = false, 93 93 exportServices = true, 94 94 input, 95 + name, 95 96 operationId = true, 96 97 output, 97 98 postfixModels = '', ··· 109 110 autoformat, 110 111 base, 111 112 client, 112 - clientName, 113 113 enums, 114 114 exportCore, 115 115 exportModels, 116 116 exportSchemas, 117 117 exportServices, 118 118 input, 119 + name, 119 120 operationId, 120 121 output, 121 122 postfixModels, ··· 142 143 * Generate the OpenAPI client. This method will read the OpenAPI specification and based on the 143 144 * given language it will generate the client, including the typed models, validation schemas, 144 145 * service layer, etc. 145 - * @param userConfig {@link UserConfig} passed to the generate method 146 + * @param userConfig {@link UserConfig} passed to the `createClient()` method 146 147 */ 147 - export const generate = async (userConfig: UserConfig): Promise<void> => { 148 + export async function createClient(userConfig: UserConfig): Promise<Client> { 148 149 const pkg = JSON.parse(readFileSync(path.resolve(process.cwd(), 'package.json')).toString()); 149 150 150 151 const dependencies = [pkg.dependencies, pkg.devDependencies].reduce( ··· 172 173 } 173 174 174 175 console.log('✨ Done! Your client is located in:', config.output); 175 - }; 176 + return client; 177 + } 178 + 179 + /** 180 + * Type helper for openapi-ts.config.ts, returns {@link UserConfig} object 181 + */ 182 + export function defineConfig(config: UserConfig): UserConfig { 183 + return config; 184 + } 176 185 177 186 export default { 178 - generate, 187 + createClient, 188 + defineConfig, 179 189 };
+1 -9
src/node/index.ts
··· 1 - import type { UserConfig } from '../types/config'; 2 - 1 + export { createClient, defineConfig } from '../'; 3 2 export type { UserConfig } from '../types/config'; 4 - 5 - /** 6 - * Type helper for openapi-ts.config.ts, returns {@link UserConfig} object 7 - */ 8 - export function defineConfig(config: UserConfig): UserConfig { 9 - return config; 10 - }
+1 -1
src/openApi/v2/index.ts
··· 10 10 * Parse the OpenAPI specification to a Client model that contains 11 11 * all the models, services and schema's we should output. 12 12 * @param openApi The OpenAPI spec that we have loaded from disk. 13 - * @param options Options passed to the generate method 13 + * @param options {@link Config} passed to the `createClient()` method 14 14 */ 15 15 export const parse = (openApi: OpenApi, options: Config): Client => { 16 16 const version = getServiceVersion(openApi.info.version);
+1 -1
src/openApi/v3/index.ts
··· 10 10 * Parse the OpenAPI specification to a Client model that contains 11 11 * all the models, services and schema's we should output. 12 12 * @param openApi The OpenAPI spec that we have loaded from disk. 13 - * @param options Options passed to the generate method 13 + * @param options {@link Config} passed to the `createClient()` method 14 14 */ 15 15 export const parse = (openApi: OpenApi, options: Config): Client => { 16 16 const version = getServiceVersion(openApi.info.version);
+2 -2
src/templates/client.hbs
··· 45 45 {{/each}} 46 46 ] 47 47 }) 48 - export class {{{@root.$config.clientName}}} {} 48 + export class {{{@root.$config.name}}} {} 49 49 {{else}} 50 50 type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest; 51 51 52 - export class {{{@root.$config.clientName}}} { 52 + export class {{{@root.$config.name}}} { 53 53 54 54 {{#each services}} 55 55 public readonly {{{camelCase name}}}: {{{name}}}{{{@root.$config.postfixServices}}};
+4 -4
src/templates/exportService.hbs
··· 1 1 {{#equals @root.$config.client 'angular'}} 2 - {{#if @root.$config.clientName}} 2 + {{#if @root.$config.name}} 3 3 import { Injectable } from '@angular/core'; 4 4 import type { Observable } from 'rxjs'; 5 5 {{else}} ··· 15 15 {{#notEquals @root.$config.client 'angular'}} 16 16 import type { CancelablePromise } from '../core/CancelablePromise'; 17 17 {{/notEquals}} 18 - {{#if @root.$config.clientName}} 18 + {{#if @root.$config.name}} 19 19 {{#equals @root.$config.client 'angular'}} 20 20 import { BaseHttpRequest } from '../core/BaseHttpRequest'; 21 21 {{else}} ··· 45 45 }) 46 46 {{/equals}} 47 47 export class {{{name}}}{{{@root.$config.postfixServices}}} { 48 - {{#if @root.$config.clientName}} 48 + {{#if @root.$config.name}} 49 49 50 50 constructor(public readonly httpRequest: BaseHttpRequest) {} 51 51 {{else}} ··· 78 78 {{/each}} 79 79 * @throws ApiError 80 80 */ 81 - {{#if @root.$config.clientName}} 81 + {{#if @root.$config.name}} 82 82 {{#equals @root.$config.client 'angular'}} 83 83 public {{{name}}}{{>operationTypes}}({{>operationParameters}}): Observable<{{>operationResult}}> { 84 84 {{>dataDestructure}}
+3 -3
src/templates/index.hbs
··· 1 - {{#if @root.$config.clientName}} 2 - export { {{{@root.$config.clientName}}} } from './{{{@root.$config.clientName}}}'; 1 + {{#if @root.$config.name}} 2 + export { {{{@root.$config.name}}} } from './{{{@root.$config.name}}}'; 3 3 {{/if}} 4 4 5 5 {{#if @root.$config.exportCore}} 6 6 export { ApiError } from './core/ApiError'; 7 - {{#if @root.$config.clientName}} 7 + {{#if @root.$config.name}} 8 8 export { BaseHttpRequest } from './core/BaseHttpRequest'; 9 9 {{/if}} 10 10 export { CancelablePromise, CancelError } from './core/CancelablePromise';
+1 -1
src/templates/partials/dataDestructure.hbs
··· 1 - {{~#if @root.$config.clientName~}} 1 + {{~#if @root.$config.name~}} 2 2 {{#if @root.$config.useOptions~}} 3 3 {{#if parameters}} 4 4 const {
+1 -1
src/templates/partials/operationParameters.hbs
··· 1 1 {{#if @root.$config.useOptions~}} 2 - {{~#if @root.$config.clientName~}} 2 + {{~#if @root.$config.name~}} 3 3 {{#if parameters}}data: {{{nameOperationDataType name}}}{{#ifOperationDataOptional parameters}} = {}{{/ifOperationDataOptional}}{{/if}} 4 4 {{~else~}} 5 5 {{~#notEquals @root.$config.serviceResponse 'generics'~}}
+3 -3
src/templates/partials/operationResult.hbs
··· 2 2 {{~#notEquals @root.$config.serviceResponse 'generics'~}} 3 3 {{~#equals @root.$config.serviceResponse 'response'}}ApiResult<{{/equals~}} 4 4 {{~else~}} 5 - {{~#unless @root.$config.clientName}}TApiResponse<T, {{/unless~}} 5 + {{~#unless @root.$config.name}}TApiResponse<T, {{/unless~}} 6 6 {{~/notEquals~}} 7 7 {{~/if~}} 8 8 {{~#if results~}} ··· 14 14 {{~#notEquals @root.$config.serviceResponse 'generics'~}} 15 15 {{~#equals @root.$config.serviceResponse 'response'}}>{{/equals~}} 16 16 {{~else~}} 17 - {{~#unless @root.$config.clientName}}>{{/unless~}} 17 + {{~#unless @root.$config.name}}>{{/unless~}} 18 18 {{~/notEquals~}} 19 - {{~/if~}} 19 + {{~/if~}}
+1 -1
src/templates/partials/operationTypes.hbs
··· 1 1 {{#if @root.$config.useOptions~}} 2 2 {{#equals @root.$config.serviceResponse 'generics'}} 3 - {{~#unless @root.$config.clientName~}} 3 + {{~#unless @root.$config.name~}} 4 4 <T extends TResult> 5 5 {{~/unless~}} 6 6 {{/equals}}
+6 -6
src/types/config.ts
··· 14 14 */ 15 15 client?: 'angular' | 'axios' | 'fetch' | 'node' | 'xhr'; 16 16 /** 17 - * Custom client class name 18 - */ 19 - clientName?: string; 20 - /** 21 17 * Generate JavaScript objects from enum definitions 22 18 * @default false 23 19 */ ··· 46 42 * The relative location of the OpenAPI spec 47 43 */ 48 44 input: string | Record<string, unknown>; 45 + /** 46 + * Custom client class name 47 + */ 48 + name?: string; 49 49 /** 50 50 * Use operation ID to generate operation names? 51 51 * @default true ··· 91 91 write?: boolean; 92 92 } 93 93 94 - export type Config = Omit<Required<UserConfig>, 'base' | 'clientName' | 'request'> & 95 - Pick<UserConfig, 'base' | 'clientName' | 'request'>; 94 + export type Config = Omit<Required<UserConfig>, 'base' | 'name' | 'request'> & 95 + Pick<UserConfig, 'base' | 'name' | 'request'>;
+1 -1
src/utils/write/__tests__/class.spec.ts
··· 36 36 37 37 await writeClientClass(client, templates, './dist', { 38 38 client: 'fetch', 39 - clientName: 'AppClient', 40 39 enums: true, 40 + name: 'AppClient', 41 41 postfixServices: '', 42 42 }); 43 43
+2 -2
src/utils/write/class.ts
··· 20 20 client: Client, 21 21 templates: Templates, 22 22 outputPath: string, 23 - options: Pick<Required<UserConfig>, 'client' | 'clientName' | 'enums' | 'postfixServices'> 23 + options: Pick<Required<UserConfig>, 'client' | 'enums' | 'name' | 'postfixServices'> 24 24 ): Promise<void> => { 25 25 const templateResult = templates.client({ 26 26 $config: options, ··· 31 31 version: client.version, 32 32 }); 33 33 34 - await writeFileSync(path.resolve(outputPath, `${options.clientName}.ts`), templateResult); 34 + await writeFileSync(path.resolve(outputPath, `${options.name}.ts`), templateResult); 35 35 };
+3 -3
src/utils/write/client.ts
··· 16 16 * Write our OpenAPI client, using the given templates at the given output 17 17 * @param client Client containing models, schemas, and services 18 18 * @param templates Templates wrapper with all loaded Handlebars templates 19 - * @param options {@link Config} passed to the `generate()` function 19 + * @param options {@link Config} passed to the `createClient()` method 20 20 */ 21 21 export const writeClient = async (client: Client, templates: Templates, options: Config): Promise<void> => { 22 22 const outputPath = path.resolve(process.cwd(), options.output); ··· 83 83 await writeClientServices(client, templates, outputPathServices, options); 84 84 } 85 85 86 - if (options.clientName) { 86 + if (options.name) { 87 87 await mkdirSync(outputPath, { 88 88 recursive: true, 89 89 }); 90 90 await writeClientClass(client, templates, outputPath, { 91 91 ...options, 92 - clientName: options.clientName, 92 + name: options.name, 93 93 }); 94 94 } 95 95
+1 -1
src/utils/write/core.ts
··· 75 75 }) 76 76 ); 77 77 78 - if (options.clientName) { 78 + if (options.name) { 79 79 await writeFileSync( 80 80 path.resolve(outputPath, 'BaseHttpRequest.ts'), 81 81 templates.core.baseHttpRequest({
+1 -1
src/utils/write/index.ts
··· 29 29 | 'postfixServices' 30 30 | 'postfixModels' 31 31 > & 32 - Pick<UserConfig, 'clientName'> 32 + Pick<UserConfig, 'name'> 33 33 ): Promise<void> => { 34 34 const templateResult = templates.index({ 35 35 $config: options,
+1 -1
src/utils/write/services.ts
··· 10 10 * @param client Client containing models, schemas, and services 11 11 * @param templates The loaded handlebar templates 12 12 * @param outputPath Directory to write the generated files to 13 - * @param options {@link Config} passed to the `generate()` function 13 + * @param options {@link Config} passed to the `createClient()` method 14 14 */ 15 15 export const writeClientServices = async ( 16 16 client: Client,
+4 -4
test/e2e/scripts/generateClient.ts
··· 1 - import { generate as __generate } from '../../../'; 1 + import { createClient } from '../../../'; 2 2 3 3 export const generateClient = async ( 4 4 dir: string, 5 5 version: string, 6 6 client: 'fetch' | 'xhr' | 'node' | 'axios' | 'angular', 7 7 useOptions: boolean = false, 8 - clientName?: string 8 + name?: string 9 9 ) => { 10 - await __generate({ 10 + await createClient({ 11 11 client, 12 - clientName, 13 12 input: `./test/spec/${version}.json`, 13 + name, 14 14 output: `./test/e2e/generated/${dir}/`, 15 15 useOptions, 16 16 });
+5 -5
test/index.spec.ts
··· 2 2 3 3 import { sync } from 'glob'; 4 4 5 - import { generate } from '../'; 5 + import { createClient } from '../'; 6 6 7 7 describe('v2', () => { 8 8 it('should generate', async () => { 9 - await generate({ 9 + await createClient({ 10 10 client: 'fetch', 11 11 enums: true, 12 12 exportCore: true, ··· 27 27 28 28 describe('v3', () => { 29 29 it('should generate', async () => { 30 - await generate({ 30 + await createClient({ 31 31 client: 'fetch', 32 32 enums: true, 33 33 exportCore: true, ··· 46 46 }); 47 47 48 48 it('should generate Date types', async () => { 49 - await generate({ 49 + await createClient({ 50 50 client: 'fetch', 51 51 enums: true, 52 52 exportCore: false, ··· 66 66 }); 67 67 68 68 it('should generate optional argument', async () => { 69 - await generate({ 69 + await createClient({ 70 70 client: 'fetch', 71 71 enums: true, 72 72 exportCore: true,
+2 -2
test/sample.cjs
··· 11 11 useOptions: true, 12 12 }; 13 13 14 - const { generate } = await import(path.resolve(process.cwd(), 'dist/index.js')); 15 - await generate(config); 14 + const { createClient } = await import(path.resolve(process.cwd(), 'dist/index.js')); 15 + await createClient(config); 16 16 }; 17 17 18 18 main();