diff --git a/.mocharc.json b/.mocharc.json index 57f2300..95e14e3 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -8,6 +8,7 @@ "./test/test-setup.ts" ], "spec": [ - "src/**/*.spec.ts" + "src/**/*.spec.ts", + "test/*.spec.ts" ] } diff --git a/test/petstore-v3.json b/test/petstore-v3.json index 27156a2..56761c7 100644 --- a/test/petstore-v3.json +++ b/test/petstore-v3.json @@ -3,51 +3,61 @@ "info": { "version": "1.0.0", "title": "Swagger Petstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, "license": { - "name": "MIT" + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" } }, "servers": [ { - "url": "http://petstore.swagger.io/v1" + "url": "https://petstore.swagger.io/v2" } ], "paths": { "/pets": { "get": { - "summary": "List all pets", - "operationId": "listPets", - "tags": [ - "pets" - ], + "operationId": "findPets", "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "style": "form", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, { "name": "limit", "in": "query", - "description": "How many items to return at one time (max 100)", + "description": "maximum number of results to return", "required": false, "schema": { "type": "integer", - "maximum": 100, "format": "int32" } } ], "responses": { "200": { - "description": "A paged array of pets", - "headers": { - "x-next": { - "description": "A link to the next page of responses", - "schema": { - "type": "string" - } - } - }, + "description": "pet response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Pets" + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } } } } @@ -65,24 +75,29 @@ } }, "post": { - "summary": "Create a pet", - "operationId": "createPets", - "tags": [ - "pets" - ], + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", "requestBody": { + "description": "Pet to add to the store", + "required": true, "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Pet" + "$ref": "#/components/schemas/NewPet" } } - }, - "required": true + } }, "responses": { - "201": { - "description": "Null response" + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } }, "default": { "description": "unexpected error", @@ -97,27 +112,25 @@ } } }, - "/pets/{petId}": { + "/pets/{id}": { "get": { - "summary": "Info for a specific pet", - "operationId": "showPetById", - "tags": [ - "pets" - ], + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "find pet by id", "parameters": [ { - "name": "petId", + "name": "id", "in": "path", + "description": "ID of pet to fetch", "required": true, - "description": "The id of the pet to retrieve", "schema": { - "type": "string" + "type": "integer", + "format": "int64" } } ], "responses": { "200": { - "description": "Expected response to a valid request", + "description": "pet response", "content": { "application/json": { "schema": { @@ -137,22 +150,67 @@ } } } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } } } }, "components": { "schemas": { "Pet": { + "allOf": [ + { + "$ref": "#/components/schemas/NewPet" + }, + { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "NewPet": { "type": "object", "required": [ - "id", "name" ], "properties": { - "id": { - "type": "integer", - "format": "int64" - }, "name": { "type": "string" }, @@ -161,13 +219,6 @@ } } }, - "Pets": { - "type": "array", - "maxItems": 100, - "items": { - "$ref": "#/components/schemas/Pet" - } - }, "Error": { "type": "object", "required": [ diff --git a/test/petstore-v3.yml b/test/petstore-v3.yml index b01683d..f5271a5 100644 --- a/test/petstore-v3.yml +++ b/test/petstore-v3.yml @@ -1,119 +1,819 @@ -openapi: '3.0.0' +openapi: 3.0.2 +servers: + - url: /v3 info: - version: 1.0.0 - title: Swagger Petstore + description: |- + This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about + Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! + You can now help us improve the API whether it's by making changes to the definition itself or to the code. + That way, with time, we can improve the API in general, and expose some of the new features in OAS3. + + Some useful links: + - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) + - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) + version: 1.0.20-SNAPSHOT + title: Swagger Petstore - OpenAPI 3.0 + termsOfService: 'http://swagger.io/terms/' + contact: + email: apiteam@swagger.io license: - name: MIT -servers: - - url: http://petstore.swagger.io/v1 + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + externalDocs: + description: Find out more + url: 'http://swagger.io' + - name: store + description: Access to Petstore orders + externalDocs: + description: Find out more about our store + url: 'http://swagger.io' + - name: user + description: Operations about user paths: - /pets: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: Add a new pet to the store + operationId: addPet + responses: + '200': + description: Successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + description: Create a new pet in the store + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: Update an existing pet by Id + operationId: updatePet + responses: + '200': + description: Successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + description: Update an existent pet in the store + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: false + explode: true + schema: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + /pet/findByTags: get: - summary: List all pets - operationId: listPets tags: - - pets + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags parameters: - - name: limit + - name: tags in: query - description: How many items to return at one time (max 100) + description: Tags to filter by required: false + explode: true + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true schema: type: integer - maximum: 100 - format: int32 + format: int64 responses: '200': - description: A paged array of pets - headers: - x-next: - description: A link to the next page of responses + description: successful operation + content: + application/xml: schema: - type: string + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + - petstore_auth: + - 'write:pets' + - 'read:pets' + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + - name: name + in: query + description: Name of pet that needs to be updated + schema: + type: string + - name: status + in: query + description: Status of pet that needs to be updated + schema: + type: string + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + description: '' + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + - name: additionalMetadata + in: query + description: Additional Metadata + required: false + schema: + type: string + responses: + '200': + description: successful operation content: application/json: schema: - $ref: '#/components/schemas/Pets' - default: - description: unexpected error + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/octet-stream: + schema: + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: getInventory + x-swagger-router-controller: OrderController + responses: + '200': + description: successful operation content: application/json: schema: - $ref: '#/components/schemas/Error' + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: post: - summary: Create a pet - operationId: createPets tags: - - pets + - store + summary: Place an order for a pet + description: Place a new order in the store + operationId: placeOrder + x-swagger-router-controller: OrderController + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + '405': + description: Invalid input requestBody: content: application/json: schema: - $ref: '#/components/schemas/Pet' - required: true + $ref: '#/components/schemas/Order' + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/Order' + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + x-swagger-router-controller: OrderController + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generate exceptions. + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of order that needs to be fetched + required: true + schema: + type: integer + format: int64 responses: - '201': - description: Null response - default: - description: unexpected error + '200': + description: successful operation content: + application/xml: + schema: + $ref: '#/components/schemas/Order' application/json: schema: - $ref: '#/components/schemas/Error' - /pets/{petId}: - get: - summary: Info for a specific pet - operationId: showPetById + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: tags: - - pets + - store + summary: Delete purchase order by ID + x-swagger-router-controller: OrderController + description: >- + For valid response try integer IDs with value < 1000. Anything above + 1000 or nonintegers will generate API errors + operationId: deleteOrder parameters: - - name: petId + - name: orderId in: path + description: ID of the order that needs to be deleted required: true - description: The id of the pet to retrieve + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/User' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/User' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/User' + description: Created user object + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: 'Creates list of users with given input array' + x-swagger-router-controller: UserController + operationId: createUsersWithListInput + responses: + '200': + description: Successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + default: + description: successful operation + requestBody: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: false + schema: + type: string + - name: password + in: query + description: The password for login in clear text + required: false schema: type: string responses: '200': - description: Expected response to a valid request + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + X-Expires-After: + description: date in UTC when token expires + schema: + type: string + format: date-time content: + application/xml: + schema: + type: string application/json: schema: - $ref: '#/components/schemas/Pet' + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + parameters: [] + responses: default: - description: unexpected error + description: successful operation + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: 'The name that needs to be fetched. Use user1 for testing. ' + required: true + schema: + type: string + responses: + '200': + description: successful operation content: + application/xml: + schema: + $ref: '#/components/schemas/User' application/json: schema: - $ref: '#/components/schemas/Error' + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Update user + x-swagger-router-controller: UserController + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that needs to be updated + required: true + schema: + type: string + responses: + default: + description: successful operation + requestBody: + description: Update an existent user in the store + content: + application/json: + schema: + $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/User' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/User' + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' components: schemas: - Pet: + Order: + x-swagger-router-model: io.swagger.petstore.model.Order + properties: + id: + type: integer + format: int64 + example: 10 + petId: + type: integer + format: int64 + example: 198772 + quantity: + type: integer + format: int32 + example: 7 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + example: approved + complete: + type: boolean + xml: + name: order + type: object + Customer: + properties: + id: + type: integer + format: int64 + example: 100000 + username: + type: string + example: fehguy + address: + type: array + items: + $ref: '#/components/schemas/Address' + xml: + wrapped: true + name: addresses + xml: + name: customer + type: object + Address: + properties: + street: + type: string + example: 437 Lytton + city: + type: string + example: Palo Alto + state: + type: string + example: CA + zip: + type: string + example: 94301 + xml: + name: address + type: object + Category: + x-swagger-router-model: io.swagger.petstore.model.Category + properties: + id: + type: integer + format: int64 + example: 1 + name: + type: string + example: Dogs + xml: + name: category type: object + User: + x-swagger-router-model: io.swagger.petstore.model.User + properties: + id: + type: integer + format: int64 + example: 10 + username: + type: string + example: theUser + firstName: + type: string + example: John + lastName: + type: string + example: James + email: + type: string + example: john@email.com + password: + type: string + example: 12345 + phone: + type: string + example: 12345 + userStatus: + type: integer + format: int32 + example: 1 + description: User Status + xml: + name: user + type: object + Tag: + x-swagger-router-model: io.swagger.petstore.model.Tag + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: tag + type: object + Pet: + x-swagger-router-model: io.swagger.petstore.model.Pet required: - - id - name + - photoUrls properties: id: type: integer format: int64 + example: 10 name: type: string - tag: + example: doggie + category: + $ref: '#/components/schemas/Category' + photoUrls: + type: array + xml: + wrapped: true + items: + type: string + xml: + name: photoUrl + tags: + type: array + xml: + wrapped: true + items: + $ref: '#/components/schemas/Tag' + xml: + name: tag + status: type: string - Pets: - type: array - maxItems: 100 - items: - $ref: '#/components/schemas/Pet' - Error: + description: pet status in the store + enum: + - available + - pending + - sold + xml: + name: pet type: object - required: - - code - - message + ApiResponse: properties: code: type: integer format: int32 + type: + type: string message: type: string + xml: + name: '##default' + type: object + requestBodies: + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'https://petstore.swagger.io/oauth/authorize' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + api_key: + type: apiKey + name: api_key + in: header diff --git a/test/snapshots.spec.ts b/test/snapshots.spec.ts index e2d79d3..0d71daa 100644 --- a/test/snapshots.spec.ts +++ b/test/snapshots.spec.ts @@ -11,7 +11,7 @@ describe('petstore snapshots', () => { it(`should match existing ${template} snapshot`, async () => { const snapshotFile = `./test/snapshots/${template}.ts`; const parameters: FullAppOptions = { - src: './test/petstore-v3.json', + src: './test/petstore-v3.yml', out: './.tmp/test/', template, }; diff --git a/test/snapshots/axios.ts b/test/snapshots/axios.ts index 041567e..8330c13 100644 --- a/test/snapshots/axios.ts +++ b/test/snapshots/axios.ts @@ -21,10 +21,10 @@ export const petClient = { */ addPet(body: Pet , $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/pet'; - return axios.request({ + return axios.request({ url: url, method: 'POST', data: body, @@ -54,9 +54,9 @@ export const petClient = { }, /** - * @param status + * @param status (optional) */ - findPetsByStatus(status: ('available'|'pending'|'sold')[] , + findPetsByStatus(status: ("available" | "pending" | "sold") | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/pet/findByStatus'; @@ -72,9 +72,9 @@ export const petClient = { }, /** - * @param tags + * @param tags (optional) */ - findPetsByTags(tags: string[] , + findPetsByTags(tags: string[] | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/pet/findByTags'; @@ -110,10 +110,10 @@ export const petClient = { */ updatePet(body: Pet , $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/pet'; - return axios.request({ + return axios.request({ url: url, method: 'PUT', data: body, @@ -133,18 +133,14 @@ export const petClient = { ): AxiosPromise { let url = '/pet/{petId}'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!name) { - formDataBody.append("name", name); - } - if (!!status) { - formDataBody.append("status", status); - } return axios.request({ url: url, method: 'POST', - data: formDataBody, + params: { + 'name': serializeQueryParam(name), + 'status': serializeQueryParam(status), + }, ...$config, }); }, @@ -152,27 +148,20 @@ export const petClient = { /** * @param petId * @param additionalMetadata (optional) - * @param file (optional) */ uploadFile(petId: number , additionalMetadata: string | null | undefined, - file: File | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/pet/{petId}/uploadImage'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!additionalMetadata) { - formDataBody.append("additionalMetadata", additionalMetadata); - } - if (!!file) { - formDataBody.append("file", file); - } return axios.request({ url: url, method: 'POST', - data: formDataBody, + params: { + 'additionalMetadata': serializeQueryParam(additionalMetadata), + }, ...$config, }); }, @@ -226,9 +215,9 @@ export const storeClient = { }, /** - * @param body + * @param body (optional) */ - placeOrder(body: Order , + placeOrder(body: Order | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/store/order'; @@ -245,30 +234,14 @@ export const storeClient = { export const userClient = { /** - * @param body + * @param body (optional) */ - createUser(body: User , + createUser(body: User | null | undefined, $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/user'; - return axios.request({ - url: url, - method: 'POST', - data: body, - ...$config, - }); - }, - - /** - * @param body - */ - createUsersWithArrayInput(body: User[] , - $config?: AxiosRequestConfig - ): AxiosPromise { - let url = '/user/createWithArray'; - - return axios.request({ + return axios.request({ url: url, method: 'POST', data: body, @@ -277,14 +250,14 @@ export const userClient = { }, /** - * @param body + * @param body (optional) */ - createUsersWithListInput(body: User[] , + createUsersWithListInput(body: User[] | null | undefined, $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/user/createWithList'; - return axios.request({ + return axios.request({ url: url, method: 'POST', data: body, @@ -325,11 +298,11 @@ export const userClient = { }, /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) */ - loginUser(username: string , - password: string , + loginUser(username: string | null | undefined, + password: string | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/user/login'; @@ -359,11 +332,11 @@ export const userClient = { }, /** + * @param body (optional) * @param username - * @param body */ - updateUser(username: string , - body: User , + updateUser(body: User | null | undefined, + username: string , $config?: AxiosRequestConfig ): AxiosPromise { let url = '/user/{username}'; @@ -389,41 +362,29 @@ function serializeQueryParam(obj: any) { .join('&'); } -export interface ApiResponse { - code?: number; - type?: string; - message?: string; -} - -export interface Category { - id?: number; - name?: string; -} - -export interface Pet { - name: string; - photoUrls: string[]; - id?: number; - category?: Category; - tags?: Tag[]; - - status?: 'available'|'pending'|'sold'; -} - -export interface Tag { - id?: number; - name?: string; -} - export interface Order { id?: number; petId?: number; quantity?: number; shipDate?: Date; +// Order Status + status?: ("placed" | "approved" | "delivered"); + complete?: boolean;} - status?: 'placed'|'approved'|'delivered'; - complete?: boolean; -} +export interface Customer { + id?: number; + username?: string; + address?: Address[];} + +export interface Address { + street?: string; + city?: string; + state?: string; + zip?: string;} + +export interface Category { + id?: number; + name?: string;} export interface User { id?: number; @@ -433,6 +394,23 @@ export interface User { email?: string; password?: string; phone?: string; +// User Status + userStatus?: number;} - userStatus?: number; -} +export interface Tag { + id?: number; + name?: string;} + +export interface Pet { + id?: number; + name: string; + category?: Category; + photoUrls: string[]; + tags?: Tag[]; +// pet status in the store + status?: ("available" | "pending" | "sold");} + +export interface ApiResponse { + code?: number; + type?: string; + message?: string;} diff --git a/test/snapshots/fetch.ts b/test/snapshots/fetch.ts index c285865..53d1cda 100644 --- a/test/snapshots/fetch.ts +++ b/test/snapshots/fetch.ts @@ -19,14 +19,14 @@ export const petClient = { */ addPet(body: Pet , $config?: RequestInit - ): Promise { + ): Promise { let url = defaults.baseUrl + '/pet?'; return fetch(url, { method: 'POST', body: JSON.stringify(body), ...$config, - }).then((response) => response.json() as Promise); + }).then((response) => response.json() as Promise); }, /** @@ -50,14 +50,14 @@ export const petClient = { }, /** - * @param status + * @param status (optional) */ - findPetsByStatus(status: ('available'|'pending'|'sold')[] , + findPetsByStatus(status: ("available" | "pending" | "sold") | null | undefined, $config?: RequestInit ): Promise { let url = defaults.baseUrl + '/pet/findByStatus?'; if (status !== undefined) { - status.forEach(item => { url += 'status=' + serializeQueryParam(item) + "&"; }); + url += 'status=' + serializeQueryParam(status) + "&"; } return fetch(url, { @@ -67,14 +67,14 @@ export const petClient = { }, /** - * @param tags + * @param tags (optional) */ - findPetsByTags(tags: string[] , + findPetsByTags(tags: string[] | null | undefined, $config?: RequestInit ): Promise { let url = defaults.baseUrl + '/pet/findByTags?'; if (tags !== undefined) { - tags.forEach(item => { url += 'tags=' + serializeQueryParam(item) + "&"; }); + url += 'tags=' + serializeQueryParam(tags) + "&"; } return fetch(url, { @@ -103,14 +103,14 @@ export const petClient = { */ updatePet(body: Pet , $config?: RequestInit - ): Promise { + ): Promise { let url = defaults.baseUrl + '/pet?'; return fetch(url, { method: 'PUT', body: JSON.stringify(body), ...$config, - }).then((response) => response.json() as Promise); + }).then((response) => response.json() as Promise); }, /** @@ -125,7 +125,13 @@ export const petClient = { ): Promise { let url = defaults.baseUrl + '/pet/{petId}?'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - + if (name !== undefined) { + url += 'name=' + serializeQueryParam(name) + "&"; + } + if (status !== undefined) { + url += 'status=' + serializeQueryParam(status) + "&"; + } + return fetch(url, { method: 'POST', ...$config, @@ -135,16 +141,17 @@ export const petClient = { /** * @param petId * @param additionalMetadata (optional) - * @param file (optional) */ uploadFile(petId: number , additionalMetadata: string | null | undefined, - file: File | null | undefined, $config?: RequestInit ): Promise { let url = defaults.baseUrl + '/pet/{petId}/uploadImage?'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - + if (additionalMetadata !== undefined) { + url += 'additionalMetadata=' + serializeQueryParam(additionalMetadata) + "&"; + } + return fetch(url, { method: 'POST', ...$config, @@ -196,9 +203,9 @@ export const storeClient = { }, /** - * @param body + * @param body (optional) */ - placeOrder(body: Order , + placeOrder(body: Order | null | undefined, $config?: RequestInit ): Promise { let url = defaults.baseUrl + '/store/order?'; @@ -213,48 +220,33 @@ export const storeClient = { }; export const userClient = { /** - * @param body + * @param body (optional) */ - createUser(body: User , + createUser(body: User | null | undefined, $config?: RequestInit - ): Promise { + ): Promise { let url = defaults.baseUrl + '/user?'; return fetch(url, { method: 'POST', body: JSON.stringify(body), ...$config, - }).then((response) => response.json() as Promise); - }, - - /** - * @param body - */ - createUsersWithArrayInput(body: User[] , - $config?: RequestInit - ): Promise { - let url = defaults.baseUrl + '/user/createWithArray?'; - - return fetch(url, { - method: 'POST', - body: JSON.stringify(body), - ...$config, - }).then((response) => response.json() as Promise); + }).then((response) => response.json() as Promise); }, /** - * @param body + * @param body (optional) */ - createUsersWithListInput(body: User[] , + createUsersWithListInput(body: User[] | null | undefined, $config?: RequestInit - ): Promise { + ): Promise { let url = defaults.baseUrl + '/user/createWithList?'; return fetch(url, { method: 'POST', body: JSON.stringify(body), ...$config, - }).then((response) => response.json() as Promise); + }).then((response) => response.json() as Promise); }, /** @@ -288,11 +280,11 @@ export const userClient = { }, /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) */ - loginUser(username: string , - password: string , + loginUser(username: string | null | undefined, + password: string | null | undefined, $config?: RequestInit ): Promise { let url = defaults.baseUrl + '/user/login?'; @@ -322,11 +314,11 @@ export const userClient = { }, /** + * @param body (optional) * @param username - * @param body */ - updateUser(username: string , - body: User , + updateUser(body: User | null | undefined, + username: string , $config?: RequestInit ): Promise { let url = defaults.baseUrl + '/user/{username}?'; @@ -350,41 +342,29 @@ function serializeQueryParam(obj: any) { .join('&'); } -export interface ApiResponse { - code?: number; - type?: string; - message?: string; -} - -export interface Category { - id?: number; - name?: string; -} - -export interface Pet { - name: string; - photoUrls: string[]; - id?: number; - category?: Category; - tags?: Tag[]; - - status?: 'available'|'pending'|'sold'; -} - -export interface Tag { - id?: number; - name?: string; -} - export interface Order { id?: number; petId?: number; quantity?: number; shipDate?: Date; +// Order Status + status?: ("placed" | "approved" | "delivered"); + complete?: boolean;} - status?: 'placed'|'approved'|'delivered'; - complete?: boolean; -} +export interface Customer { + id?: number; + username?: string; + address?: Address[];} + +export interface Address { + street?: string; + city?: string; + state?: string; + zip?: string;} + +export interface Category { + id?: number; + name?: string;} export interface User { id?: number; @@ -394,6 +374,23 @@ export interface User { email?: string; password?: string; phone?: string; +// User Status + userStatus?: number;} - userStatus?: number; -} +export interface Tag { + id?: number; + name?: string;} + +export interface Pet { + id?: number; + name: string; + category?: Category; + photoUrls: string[]; + tags?: Tag[]; +// pet status in the store + status?: ("available" | "pending" | "sold");} + +export interface ApiResponse { + code?: number; + type?: string; + message?: string;} diff --git a/test/snapshots/ng1.ts b/test/snapshots/ng1.ts index a872340..29744d0 100644 --- a/test/snapshots/ng1.ts +++ b/test/snapshots/ng1.ts @@ -134,7 +134,7 @@ export class petService extends BaseService { */ addPet(body: Pet , config?: IRequestShortcutConfig - ): IPromise { + ): IPromise { let url = '/pet?'; return this.$post( @@ -163,15 +163,15 @@ export class petService extends BaseService { } /** - * @param status + * @param status (optional) * @return Success */ - findPetsByStatus(status: ('available'|'pending'|'sold')[] , + findPetsByStatus(status: ("available" | "pending" | "sold") | null | undefined, config?: IRequestShortcutConfig ): IPromise { let url = '/pet/findByStatus?'; if (status !== undefined) { - status.forEach(item => { url += serializeQueryParam(item, 'status') + "&"; }); + url += serializeQueryParam(status, 'status') + "&"; } return this.$get( @@ -181,15 +181,15 @@ export class petService extends BaseService { } /** - * @param tags + * @param tags (optional) * @return Success */ - findPetsByTags(tags: string[] , + findPetsByTags(tags: string[] | null | undefined, config?: IRequestShortcutConfig ): IPromise { let url = '/pet/findByTags?'; if (tags !== undefined) { - tags.forEach(item => { url += serializeQueryParam(item, 'tags') + "&"; }); + url += serializeQueryParam(tags, 'tags') + "&"; } return this.$get( @@ -220,7 +220,7 @@ export class petService extends BaseService { */ updatePet(body: Pet , config?: IRequestShortcutConfig - ): IPromise { + ): IPromise { let url = '/pet?'; return this.$put( @@ -239,21 +239,20 @@ export class petService extends BaseService { updatePetWithForm(petId: number , name: string | null | undefined, status: string | null | undefined, - config: IRequestShortcutConfig = {headers: {'Content-Type': undefined}} + config?: IRequestShortcutConfig ): IPromise { let url = '/pet/{petId}?'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!name) { - formDataBody.append("name", name); - } - if (!!status) { - formDataBody.append("status", status); - } - + if (name !== undefined) { + url += serializeQueryParam(name, 'name') + "&"; + } + if (status !== undefined) { + url += serializeQueryParam(status, 'status') + "&"; + } + return this.$post( url, - formDataBody, + null, config ); } @@ -261,27 +260,21 @@ export class petService extends BaseService { /** * @param petId * @param additionalMetadata (optional) - * @param file (optional) * @return Success */ uploadFile(petId: number , additionalMetadata: string | null | undefined, - file: File | null | undefined, - config: IRequestShortcutConfig = {headers: {'Content-Type': undefined}} + config?: IRequestShortcutConfig ): IPromise { let url = '/pet/{petId}/uploadImage?'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!additionalMetadata) { - formDataBody.append("additionalMetadata", additionalMetadata); - } - if (!!file) { - formDataBody.append("file", file); - } - + if (additionalMetadata !== undefined) { + url += serializeQueryParam(additionalMetadata, 'additionalMetadata') + "&"; + } + return this.$post( url, - formDataBody, + null, config ); } @@ -340,10 +333,10 @@ export class storeService extends BaseService { } /** - * @param body + * @param body (optional) * @return Success */ - placeOrder(body: Order , + placeOrder(body: Order | null | undefined, config?: IRequestShortcutConfig ): IPromise { let url = '/store/order?'; @@ -364,12 +357,12 @@ export class userService extends BaseService { } /** - * @param body + * @param body (optional) * @return Success */ - createUser(body: User , + createUser(body: User | null | undefined, config?: IRequestShortcutConfig - ): IPromise { + ): IPromise { let url = '/user?'; return this.$post( @@ -380,28 +373,12 @@ export class userService extends BaseService { } /** - * @param body + * @param body (optional) * @return Success */ - createUsersWithArrayInput(body: User[] , + createUsersWithListInput(body: User[] | null | undefined, config?: IRequestShortcutConfig - ): IPromise { - let url = '/user/createWithArray?'; - - return this.$post( - url, - body, - config - ); - } - - /** - * @param body - * @return Success - */ - createUsersWithListInput(body: User[] , - config?: IRequestShortcutConfig - ): IPromise { + ): IPromise { let url = '/user/createWithList?'; return this.$post( @@ -444,12 +421,12 @@ export class userService extends BaseService { } /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) * @return Success */ - loginUser(username: string , - password: string , + loginUser(username: string | null | undefined, + password: string | null | undefined, config?: IRequestShortcutConfig ): IPromise { let url = '/user/login?'; @@ -480,12 +457,12 @@ export class userService extends BaseService { } /** + * @param body (optional) * @param username - * @param body * @return Success */ - updateUser(username: string , - body: User , + updateUser(body: User | null | undefined, + username: string , config?: IRequestShortcutConfig ): IPromise { let url = '/user/{username}?'; @@ -536,41 +513,29 @@ function serializeQueryParam(obj: any, property: string): string { return ''; } } -export interface ApiResponse { - code?: number; - type?: string; - message?: string; -} - -export interface Category { - id?: number; - name?: string; -} - -export interface Pet { - name: string; - photoUrls: string[]; - id?: number; - category?: Category; - tags?: Tag[]; - - status?: 'available'|'pending'|'sold'; -} - -export interface Tag { - id?: number; - name?: string; -} - export interface Order { id?: number; petId?: number; quantity?: number; shipDate?: Date; +// Order Status + status?: ("placed" | "approved" | "delivered"); + complete?: boolean;} - status?: 'placed'|'approved'|'delivered'; - complete?: boolean; -} +export interface Customer { + id?: number; + username?: string; + address?: Address[];} + +export interface Address { + street?: string; + city?: string; + state?: string; + zip?: string;} + +export interface Category { + id?: number; + name?: string;} export interface User { id?: number; @@ -580,6 +545,23 @@ export interface User { email?: string; password?: string; phone?: string; +// User Status + userStatus?: number;} - userStatus?: number; -} +export interface Tag { + id?: number; + name?: string;} + +export interface Pet { + id?: number; + name: string; + category?: Category; + photoUrls: string[]; + tags?: Tag[]; +// pet status in the store + status?: ("available" | "pending" | "sold");} + +export interface ApiResponse { + code?: number; + type?: string; + message?: string;} diff --git a/test/snapshots/ng2.ts b/test/snapshots/ng2.ts index 99c7b84..d7b671a 100644 --- a/test/snapshots/ng2.ts +++ b/test/snapshots/ng2.ts @@ -82,7 +82,7 @@ export class petService extends BaseService { addPet( body: Pet, config?: any - ): Observable { + ): Observable { let url = '/pet?'; return this.$post( @@ -112,16 +112,16 @@ export class petService extends BaseService { } /** - * @param status + * @param status (optional) * @return Success */ findPetsByStatus( - status: ('available'|'pending'|'sold')[], + status: ("available" | "pending" | "sold") | null | undefined, config?: any ): Observable { let url = '/pet/findByStatus?'; if (status !== undefined) { - status.forEach(item => { url += 'status=' + encodeURIComponent("" + item) + "&"; }); + url += 'status=' + encodeURIComponent("" + status) + "&"; } return this.$get( @@ -131,16 +131,16 @@ export class petService extends BaseService { } /** - * @param tags + * @param tags (optional) * @return Success */ findPetsByTags( - tags: string[], + tags: string[] | null | undefined, config?: any ): Observable { let url = '/pet/findByTags?'; if (tags !== undefined) { - tags.forEach(item => { url += 'tags=' + encodeURIComponent("" + item) + "&"; }); + url += 'tags=' + encodeURIComponent("" + tags) + "&"; } return this.$get( @@ -173,7 +173,7 @@ export class petService extends BaseService { updatePet( body: Pet, config?: any - ): Observable { + ): Observable { let url = '/pet?'; return this.$put( @@ -197,17 +197,16 @@ export class petService extends BaseService { ): Observable { let url = '/pet/{petId}?'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!name) { - formDataBody.append("name", name); + if (name !== undefined) { + url += 'name=' + encodeURIComponent("" + name) + "&"; } - if (!!status) { - formDataBody.append("status", status); + if (status !== undefined) { + url += 'status=' + encodeURIComponent("" + status) + "&"; } - + return this.$post( url, - formDataBody, + null, config ); } @@ -215,28 +214,22 @@ export class petService extends BaseService { /** * @param petId * @param additionalMetadata (optional) - * @param file (optional) * @return Success */ uploadFile( petId: number, additionalMetadata: string | null | undefined, - file: File | null | undefined, config?: any ): Observable { let url = '/pet/{petId}/uploadImage?'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!additionalMetadata) { - formDataBody.append("additionalMetadata", additionalMetadata); + if (additionalMetadata !== undefined) { + url += 'additionalMetadata=' + encodeURIComponent("" + additionalMetadata) + "&"; } - if (!!file) { - formDataBody.append("file", file); - } - + return this.$post( url, - formDataBody, + null, config ); } @@ -303,11 +296,11 @@ export class storeService extends BaseService { } /** - * @param body + * @param body (optional) * @return Success */ placeOrder( - body: Order, + body: Order | null | undefined, config?: any ): Observable { let url = '/store/order?'; @@ -333,13 +326,13 @@ export class userService extends BaseService { } /** - * @param body + * @param body (optional) * @return Success */ createUser( - body: User, + body: User | null | undefined, config?: any - ): Observable { + ): Observable { let url = '/user?'; return this.$post( @@ -350,30 +343,13 @@ export class userService extends BaseService { } /** - * @param body - * @return Success - */ - createUsersWithArrayInput( - body: User[], - config?: any - ): Observable { - let url = '/user/createWithArray?'; - - return this.$post( - url, - body, - config - ); - } - -/** - * @param body + * @param body (optional) * @return Success */ createUsersWithListInput( - body: User[], + body: User[] | null | undefined, config?: any - ): Observable { + ): Observable { let url = '/user/createWithList?'; return this.$post( @@ -418,13 +394,13 @@ export class userService extends BaseService { } /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) * @return Success */ loginUser( - username: string, - password: string, + username: string | null | undefined, + password: string | null | undefined, config?: any ): Observable { let url = '/user/login?'; @@ -456,13 +432,13 @@ export class userService extends BaseService { } /** + * @param body (optional) * @param username - * @param body * @return Success */ updateUser( + body: User | null | undefined, username: string, - body: User, config?: any ): Observable { let url = '/user/{username}?'; @@ -477,41 +453,29 @@ export class userService extends BaseService { } -export interface ApiResponse { - code?: number; - type?: string; - message?: string; -} - -export interface Category { - id?: number; - name?: string; -} - -export interface Pet { - name: string; - photoUrls: string[]; - id?: number; - category?: Category; - tags?: Tag[]; - - status?: 'available'|'pending'|'sold'; -} - -export interface Tag { - id?: number; - name?: string; -} - export interface Order { id?: number; petId?: number; quantity?: number; shipDate?: Date; +// Order Status + status?: ("placed" | "approved" | "delivered"); + complete?: boolean;} - status?: 'placed'|'approved'|'delivered'; - complete?: boolean; -} +export interface Customer { + id?: number; + username?: string; + address?: Address[];} + +export interface Address { + street?: string; + city?: string; + state?: string; + zip?: string;} + +export interface Category { + id?: number; + name?: string;} export interface User { id?: number; @@ -521,6 +485,23 @@ export interface User { email?: string; password?: string; phone?: string; +// User Status + userStatus?: number;} - userStatus?: number; -} +export interface Tag { + id?: number; + name?: string;} + +export interface Pet { + id?: number; + name: string; + category?: Category; + photoUrls: string[]; + tags?: Tag[]; +// pet status in the store + status?: ("available" | "pending" | "sold");} + +export interface ApiResponse { + code?: number; + type?: string; + message?: string;} diff --git a/test/snapshots/swr-axios.ts b/test/snapshots/swr-axios.ts index 695e20e..5934d59 100644 --- a/test/snapshots/swr-axios.ts +++ b/test/snapshots/swr-axios.ts @@ -29,11 +29,11 @@ export const petClient = { */ addPet( body: Pet , $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/pet'; - return axios.request({ + return axios.request({ url: url, method: 'POST', data: body, @@ -64,9 +64,9 @@ export const petClient = { }, /** - * @param status + * @param status (optional) */ - findPetsByStatus( status: ('available'|'pending'|'sold')[] , + findPetsByStatus( status: ("available" | "pending" | "sold") | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/pet/findByStatus'; @@ -83,9 +83,9 @@ export const petClient = { }, /** - * @param tags + * @param tags (optional) */ - findPetsByTags( tags: string[] , + findPetsByTags( tags: string[] | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/pet/findByTags'; @@ -123,11 +123,11 @@ export const petClient = { */ updatePet( body: Pet , $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/pet'; - return axios.request({ + return axios.request({ url: url, method: 'PUT', data: body, @@ -148,18 +148,14 @@ export const petClient = { let url = '/pet/{petId}'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!name) { - formDataBody.append("name", name); - } - if (!!status) { - formDataBody.append("status", status); - } return axios.request({ url: url, method: 'POST', - data: formDataBody, + params: { + 'name': serializeQueryParam(name), + 'status': serializeQueryParam(status), + }, ...$config, }); }, @@ -167,28 +163,21 @@ export const petClient = { /** * @param petId * @param additionalMetadata (optional) - * @param file (optional) */ uploadFile( petId: number , additionalMetadata: string | null | undefined, - file: File | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/pet/{petId}/uploadImage'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!additionalMetadata) { - formDataBody.append("additionalMetadata", additionalMetadata); - } - if (!!file) { - formDataBody.append("file", file); - } return axios.request({ url: url, method: 'POST', - data: formDataBody, + params: { + 'additionalMetadata': serializeQueryParam(additionalMetadata), + }, ...$config, }); }, @@ -196,9 +185,9 @@ export const petClient = { }; /** - * @param status + * @param status (optional) */ -export function usepetfindPetsByStatus( status: ('available'|'pending'|'sold')[] , +export function usepetfindPetsByStatus( status: ("available" | "pending" | "sold") | null | undefined, $config?: SwrConfig ) { let url = '/pet/findByStatus'; @@ -231,9 +220,9 @@ export function usepetfindPetsByStatus( status: ('available'|'pending'|'sold')[ } /** - * @param tags + * @param tags (optional) */ -export function usepetfindPetsByTags( tags: string[] , +export function usepetfindPetsByTags( tags: string[] | null | undefined, $config?: SwrConfig ) { let url = '/pet/findByTags'; @@ -344,9 +333,9 @@ const { data, error, mutate } = useSWR( }, /** - * @param body + * @param body (optional) */ - placeOrder( body: Order , + placeOrder( body: Order | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/store/order'; @@ -419,32 +408,15 @@ const { data, error, mutate } = useSWR( export const userClient = { /** - * @param body + * @param body (optional) */ - createUser( body: User , + createUser( body: User | null | undefined, $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/user'; - return axios.request({ - url: url, - method: 'POST', - data: body, - ...$config, - }); - }, - - /** - * @param body - */ - createUsersWithArrayInput( body: User[] , - $config?: AxiosRequestConfig - ): AxiosPromise { - let url = '/user/createWithArray'; - - - return axios.request({ + return axios.request({ url: url, method: 'POST', data: body, @@ -453,15 +425,15 @@ const { data, error, mutate } = useSWR( }, /** - * @param body + * @param body (optional) */ - createUsersWithListInput( body: User[] , + createUsersWithListInput( body: User[] | null | undefined, $config?: AxiosRequestConfig - ): AxiosPromise { + ): AxiosPromise { let url = '/user/createWithList'; - return axios.request({ + return axios.request({ url: url, method: 'POST', data: body, @@ -504,11 +476,11 @@ const { data, error, mutate } = useSWR( }, /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) */ - loginUser( username: string , - password: string , + loginUser( username: string | null | undefined, + password: string | null | undefined, $config?: AxiosRequestConfig ): AxiosPromise { let url = '/user/login'; @@ -540,11 +512,11 @@ const { data, error, mutate } = useSWR( }, /** + * @param body (optional) * @param username - * @param body */ - updateUser( username: string , - body: User , + updateUser( body: User | null | undefined, + username: string , $config?: AxiosRequestConfig ): AxiosPromise { let url = '/user/{username}'; @@ -591,11 +563,11 @@ const { data, error, mutate } = useSWR( } /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) */ -export function useuserloginUser( username: string , - password: string , +export function useuserloginUser( username: string | null | undefined, + password: string | null | undefined, $config?: SwrConfig ) { let url = '/user/login'; @@ -667,41 +639,29 @@ function serializeQueryParam(obj: any) { .reduce((a: any, b) => a.push(b + '=' + obj[b]) && a, []) .join('&'); } -export interface ApiResponse { - code?: number; - type?: string; - message?: string; -} - -export interface Category { - id?: number; - name?: string; -} - -export interface Pet { - name: string; - photoUrls: string[]; - id?: number; - category?: Category; - tags?: Tag[]; - - status?: 'available'|'pending'|'sold'; -} - -export interface Tag { - id?: number; - name?: string; -} - export interface Order { id?: number; petId?: number; quantity?: number; shipDate?: Date; +// Order Status + status?: ("placed" | "approved" | "delivered"); + complete?: boolean;} - status?: 'placed'|'approved'|'delivered'; - complete?: boolean; -} +export interface Customer { + id?: number; + username?: string; + address?: Address[];} + +export interface Address { + street?: string; + city?: string; + state?: string; + zip?: string;} + +export interface Category { + id?: number; + name?: string;} export interface User { id?: number; @@ -711,6 +671,23 @@ export interface User { email?: string; password?: string; phone?: string; +// User Status + userStatus?: number;} - userStatus?: number; -} +export interface Tag { + id?: number; + name?: string;} + +export interface Pet { + id?: number; + name: string; + category?: Category; + photoUrls: string[]; + tags?: Tag[]; +// pet status in the store + status?: ("available" | "pending" | "sold");} + +export interface ApiResponse { + code?: number; + type?: string; + message?: string;} diff --git a/test/snapshots/xior.ts b/test/snapshots/xior.ts index 605dab6..9877aca 100644 --- a/test/snapshots/xior.ts +++ b/test/snapshots/xior.ts @@ -21,10 +21,10 @@ export const petClient = { */ addPet(body: Pet , $config?: XiorRequestConfig - ): Promise> { + ): Promise> { let url = '/pet'; - return http.request({ + return http.request({ url: url, method: 'POST', data: body, @@ -54,9 +54,9 @@ export const petClient = { }, /** - * @param status + * @param status (optional) */ - findPetsByStatus(status: ('available'|'pending'|'sold')[] , + findPetsByStatus(status: ("available" | "pending" | "sold") | null | undefined, $config?: XiorRequestConfig ): Promise> { let url = '/pet/findByStatus'; @@ -72,9 +72,9 @@ export const petClient = { }, /** - * @param tags + * @param tags (optional) */ - findPetsByTags(tags: string[] , + findPetsByTags(tags: string[] | null | undefined, $config?: XiorRequestConfig ): Promise> { let url = '/pet/findByTags'; @@ -110,10 +110,10 @@ export const petClient = { */ updatePet(body: Pet , $config?: XiorRequestConfig - ): Promise> { + ): Promise> { let url = '/pet'; - return http.request({ + return http.request({ url: url, method: 'PUT', data: body, @@ -133,18 +133,14 @@ export const petClient = { ): Promise> { let url = '/pet/{petId}'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!name) { - formDataBody.append("name", name); - } - if (!!status) { - formDataBody.append("status", status); - } return http.request({ url: url, method: 'POST', - data: formDataBody, + params: { + 'name': serializeQueryParam(name), + 'status': serializeQueryParam(status), + }, ...$config, }); }, @@ -152,27 +148,20 @@ export const petClient = { /** * @param petId * @param additionalMetadata (optional) - * @param file (optional) */ uploadFile(petId: number , additionalMetadata: string | null | undefined, - file: File | null | undefined, $config?: XiorRequestConfig ): Promise> { let url = '/pet/{petId}/uploadImage'; url = url.replace('{petId}', encodeURIComponent("" + petId)); - const formDataBody = new FormData(); - if (!!additionalMetadata) { - formDataBody.append("additionalMetadata", additionalMetadata); - } - if (!!file) { - formDataBody.append("file", file); - } return http.request({ url: url, method: 'POST', - data: formDataBody, + params: { + 'additionalMetadata': serializeQueryParam(additionalMetadata), + }, ...$config, }); }, @@ -226,9 +215,9 @@ export const storeClient = { }, /** - * @param body + * @param body (optional) */ - placeOrder(body: Order , + placeOrder(body: Order | null | undefined, $config?: XiorRequestConfig ): Promise> { let url = '/store/order'; @@ -245,30 +234,14 @@ export const storeClient = { export const userClient = { /** - * @param body + * @param body (optional) */ - createUser(body: User , + createUser(body: User | null | undefined, $config?: XiorRequestConfig - ): Promise> { + ): Promise> { let url = '/user'; - return http.request({ - url: url, - method: 'POST', - data: body, - ...$config, - }); - }, - - /** - * @param body - */ - createUsersWithArrayInput(body: User[] , - $config?: XiorRequestConfig - ): Promise> { - let url = '/user/createWithArray'; - - return http.request({ + return http.request({ url: url, method: 'POST', data: body, @@ -277,14 +250,14 @@ export const userClient = { }, /** - * @param body + * @param body (optional) */ - createUsersWithListInput(body: User[] , + createUsersWithListInput(body: User[] | null | undefined, $config?: XiorRequestConfig - ): Promise> { + ): Promise> { let url = '/user/createWithList'; - return http.request({ + return http.request({ url: url, method: 'POST', data: body, @@ -325,11 +298,11 @@ export const userClient = { }, /** - * @param username - * @param password + * @param username (optional) + * @param password (optional) */ - loginUser(username: string , - password: string , + loginUser(username: string | null | undefined, + password: string | null | undefined, $config?: XiorRequestConfig ): Promise> { let url = '/user/login'; @@ -359,11 +332,11 @@ export const userClient = { }, /** + * @param body (optional) * @param username - * @param body */ - updateUser(username: string , - body: User , + updateUser(body: User | null | undefined, + username: string , $config?: XiorRequestConfig ): Promise> { let url = '/user/{username}'; @@ -389,41 +362,29 @@ function serializeQueryParam(obj: any) { .join('&'); } -export interface ApiResponse { - code?: number; - type?: string; - message?: string; -} - -export interface Category { - id?: number; - name?: string; -} - -export interface Pet { - name: string; - photoUrls: string[]; - id?: number; - category?: Category; - tags?: Tag[]; - - status?: 'available'|'pending'|'sold'; -} - -export interface Tag { - id?: number; - name?: string; -} - export interface Order { id?: number; petId?: number; quantity?: number; shipDate?: Date; +// Order Status + status?: ("placed" | "approved" | "delivered"); + complete?: boolean;} - status?: 'placed'|'approved'|'delivered'; - complete?: boolean; -} +export interface Customer { + id?: number; + username?: string; + address?: Address[];} + +export interface Address { + street?: string; + city?: string; + state?: string; + zip?: string;} + +export interface Category { + id?: number; + name?: string;} export interface User { id?: number; @@ -433,6 +394,23 @@ export interface User { email?: string; password?: string; phone?: string; +// User Status + userStatus?: number;} - userStatus?: number; -} +export interface Tag { + id?: number; + name?: string;} + +export interface Pet { + id?: number; + name: string; + category?: Category; + photoUrls: string[]; + tags?: Tag[]; +// pet status in the store + status?: ("available" | "pending" | "sold");} + +export interface ApiResponse { + code?: number; + type?: string; + message?: string;}