Skip to content

Commit 92202dd

Browse files
committed
add test case in spec and update samples
1 parent 4a3bf4c commit 92202dd

55 files changed

Lines changed: 2009 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,38 @@ paths:
273273
- petstore_auth:
274274
- 'write:pets'
275275
- 'read:pets'
276+
put:
277+
tags:
278+
- pet
279+
summary: updates an existing image
280+
description: ''
281+
operationId: updateImageFile
282+
consumes:
283+
- image/jpeg
284+
produces:
285+
- application/json
286+
parameters:
287+
- name: petId
288+
in: path
289+
description: ID of pet to update
290+
required: true
291+
type: integer
292+
format: int64
293+
- name: imageData
294+
in: body
295+
description: file to upload
296+
required: false
297+
schema:
298+
$ref: '#/definitions/InputStream'
299+
responses:
300+
'200':
301+
description: successful operation
302+
schema:
303+
$ref: '#/definitions/ApiResponse'
304+
security:
305+
- petstore_auth:
306+
- 'write:pets'
307+
- 'read:pets'
276308
/store/inventory:
277309
get:
278310
tags:
@@ -1642,3 +1674,6 @@ definitions:
16421674
- 1
16431675
- 2
16441676
- 3
1677+
InputStream:
1678+
type: string
1679+
format: binary

samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,57 @@ open class PetAPI {
273273
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
274274
}
275275

276+
/**
277+
updates an existing image
278+
279+
- parameter petId: (path) ID of pet to update
280+
- parameter imageData: (body) file to upload (optional)
281+
- parameter apiResponseQueue: The queue on which api response is dispatched.
282+
- parameter completion: completion handler to receive the data and the error objects
283+
*/
284+
@discardableResult
285+
open class func updateImageFile(petId: Int64, imageData: URL? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: ApiResponse?, _ error: Error?) -> Void)) -> RequestTask {
286+
return updateImageFileWithRequestBuilder(petId: petId, imageData: imageData).execute(apiResponseQueue) { result in
287+
switch result {
288+
case let .success(response):
289+
completion(response.body, nil)
290+
case let .failure(error):
291+
completion(nil, error)
292+
}
293+
}
294+
}
295+
296+
/**
297+
updates an existing image
298+
- PUT /pet/{petId}/uploadImage
299+
- OAuth:
300+
- type: oauth2
301+
- name: petstore_auth
302+
- parameter petId: (path) ID of pet to update
303+
- parameter imageData: (body) file to upload (optional)
304+
- returns: RequestBuilder<ApiResponse>
305+
*/
306+
open class func updateImageFileWithRequestBuilder(petId: Int64, imageData: URL? = nil) -> RequestBuilder<ApiResponse> {
307+
var localVariablePath = "/pet/{petId}/uploadImage"
308+
let petIdPreEscape = "\(APIHelper.mapValueToPathItem(petId))"
309+
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
310+
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
311+
let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath
312+
let localVariableParameters = ["body": imageData]
313+
314+
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
315+
316+
let localVariableNillableHeaders: [String: Any?] = [
317+
"Content-Type": "image/jpeg",
318+
]
319+
320+
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
321+
322+
let localVariableRequestBuilder: RequestBuilder<ApiResponse>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
323+
324+
return localVariableRequestBuilder.init(method: "PUT", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
325+
}
326+
276327
/**
277328
Update an existing pet
278329

samples/client/petstore/swift5/alamofireLibrary/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Class | Method | HTTP request | Description
4545
*PetAPI* | [**findPetsByStatus**](docs/PetAPI.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
4646
*PetAPI* | [**findPetsByTags**](docs/PetAPI.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
4747
*PetAPI* | [**getPetById**](docs/PetAPI.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
48+
*PetAPI* | [**updateImageFile**](docs/PetAPI.md#updateimagefile) | **PUT** /pet/{petId}/uploadImage | updates an existing image
4849
*PetAPI* | [**updatePet**](docs/PetAPI.md#updatepet) | **PUT** /pet | Update an existing pet
4950
*PetAPI* | [**updatePetWithForm**](docs/PetAPI.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
5051
*PetAPI* | [**uploadFile**](docs/PetAPI.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image

samples/client/petstore/swift5/alamofireLibrary/docs/PetAPI.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Method | HTTP request | Description
99
[**findPetsByStatus**](PetAPI.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
1010
[**findPetsByTags**](PetAPI.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
1111
[**getPetById**](PetAPI.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
12+
[**updateImageFile**](PetAPI.md#updateimagefile) | **PUT** /pet/{petId}/uploadImage | updates an existing image
1213
[**updatePet**](PetAPI.md#updatepet) | **PUT** /pet | Update an existing pet
1314
[**updatePetWithForm**](PetAPI.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
1415
[**uploadFile**](PetAPI.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
@@ -263,6 +264,56 @@ Name | Type | Description | Notes
263264

264265
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
265266

267+
# **updateImageFile**
268+
```swift
269+
open class func updateImageFile(petId: Int64, imageData: URL? = nil, completion: @escaping (_ data: ApiResponse?, _ error: Error?) -> Void)
270+
```
271+
272+
updates an existing image
273+
274+
### Example
275+
```swift
276+
// The following code samples are still beta. For any issue, please report via http://github.com/OpenAPITools/openapi-generator/issues/new
277+
import PetstoreClient
278+
279+
let petId = 987 // Int64 | ID of pet to update
280+
let imageData = URL(string: "https://example.com")! // URL | file to upload (optional)
281+
282+
// updates an existing image
283+
PetAPI.updateImageFile(petId: petId, imageData: imageData) { (response, error) in
284+
guard error == nil else {
285+
print(error)
286+
return
287+
}
288+
289+
if (response) {
290+
dump(response)
291+
}
292+
}
293+
```
294+
295+
### Parameters
296+
297+
Name | Type | Description | Notes
298+
------------- | ------------- | ------------- | -------------
299+
**petId** | **Int64** | ID of pet to update |
300+
**imageData** | **URL** | file to upload | [optional]
301+
302+
### Return type
303+
304+
[**ApiResponse**](ApiResponse.md)
305+
306+
### Authorization
307+
308+
[petstore_auth](../README.md#petstore_auth)
309+
310+
### HTTP request headers
311+
312+
- **Content-Type**: image/jpeg
313+
- **Accept**: application/json
314+
315+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
316+
266317
# **updatePet**
267318
```swift
268319
open class func updatePet(body: Pet, completion: @escaping (_ data: Void?, _ error: Error?) -> Void)

samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,49 @@ open class PetAPI {
233233
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
234234
}
235235

236+
/**
237+
updates an existing image
238+
239+
- parameter petId: (path) ID of pet to update
240+
- parameter imageData: (body) file to upload (optional)
241+
- returns: ApiResponse
242+
*/
243+
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
244+
open class func updateImageFile(petId: Int64, imageData: URL? = nil) async throws -> ApiResponse {
245+
return try await updateImageFileWithRequestBuilder(petId: petId, imageData: imageData).execute().body
246+
}
247+
248+
/**
249+
updates an existing image
250+
- PUT /pet/{petId}/uploadImage
251+
- OAuth:
252+
- type: oauth2
253+
- name: petstore_auth
254+
- parameter petId: (path) ID of pet to update
255+
- parameter imageData: (body) file to upload (optional)
256+
- returns: RequestBuilder<ApiResponse>
257+
*/
258+
open class func updateImageFileWithRequestBuilder(petId: Int64, imageData: URL? = nil) -> RequestBuilder<ApiResponse> {
259+
var localVariablePath = "/pet/{petId}/uploadImage"
260+
let petIdPreEscape = "\(APIHelper.mapValueToPathItem(petId))"
261+
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
262+
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
263+
let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath
264+
let localVariableParameters = ["body": imageData]
265+
266+
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
267+
268+
let localVariableNillableHeaders: [String: Any?] = [
269+
"Content-Type": "image/jpeg",
270+
]
271+
272+
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
273+
274+
let localVariableRequestBuilder: RequestBuilder<ApiResponse>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
275+
276+
return localVariableRequestBuilder.init(method: "PUT", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
277+
}
278+
236279
/**
237280
Update an existing pet
238281

samples/client/petstore/swift5/asyncAwaitLibrary/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Class | Method | HTTP request | Description
4545
*PetAPI* | [**findPetsByStatus**](docs/PetAPI.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
4646
*PetAPI* | [**findPetsByTags**](docs/PetAPI.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
4747
*PetAPI* | [**getPetById**](docs/PetAPI.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
48+
*PetAPI* | [**updateImageFile**](docs/PetAPI.md#updateimagefile) | **PUT** /pet/{petId}/uploadImage | updates an existing image
4849
*PetAPI* | [**updatePet**](docs/PetAPI.md#updatepet) | **PUT** /pet | Update an existing pet
4950
*PetAPI* | [**updatePetWithForm**](docs/PetAPI.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
5051
*PetAPI* | [**uploadFile**](docs/PetAPI.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image

samples/client/petstore/swift5/asyncAwaitLibrary/docs/PetAPI.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Method | HTTP request | Description
99
[**findPetsByStatus**](PetAPI.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
1010
[**findPetsByTags**](PetAPI.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
1111
[**getPetById**](PetAPI.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
12+
[**updateImageFile**](PetAPI.md#updateimagefile) | **PUT** /pet/{petId}/uploadImage | updates an existing image
1213
[**updatePet**](PetAPI.md#updatepet) | **PUT** /pet | Update an existing pet
1314
[**updatePetWithForm**](PetAPI.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
1415
[**uploadFile**](PetAPI.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
@@ -263,6 +264,56 @@ Name | Type | Description | Notes
263264

264265
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
265266

267+
# **updateImageFile**
268+
```swift
269+
open class func updateImageFile(petId: Int64, imageData: URL? = nil, completion: @escaping (_ data: ApiResponse?, _ error: Error?) -> Void)
270+
```
271+
272+
updates an existing image
273+
274+
### Example
275+
```swift
276+
// The following code samples are still beta. For any issue, please report via http://github.com/OpenAPITools/openapi-generator/issues/new
277+
import PetstoreClient
278+
279+
let petId = 987 // Int64 | ID of pet to update
280+
let imageData = URL(string: "https://example.com")! // URL | file to upload (optional)
281+
282+
// updates an existing image
283+
PetAPI.updateImageFile(petId: petId, imageData: imageData) { (response, error) in
284+
guard error == nil else {
285+
print(error)
286+
return
287+
}
288+
289+
if (response) {
290+
dump(response)
291+
}
292+
}
293+
```
294+
295+
### Parameters
296+
297+
Name | Type | Description | Notes
298+
------------- | ------------- | ------------- | -------------
299+
**petId** | **Int64** | ID of pet to update |
300+
**imageData** | **URL** | file to upload | [optional]
301+
302+
### Return type
303+
304+
[**ApiResponse**](ApiResponse.md)
305+
306+
### Authorization
307+
308+
[petstore_auth](../README.md#petstore_auth)
309+
310+
### HTTP request headers
311+
312+
- **Content-Type**: image/jpeg
313+
- **Accept**: application/json
314+
315+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
316+
266317
# **updatePet**
267318
```swift
268319
open class func updatePet(body: Pet, completion: @escaping (_ data: Void?, _ error: Error?) -> Void)

samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,66 @@ open class PetAPI {
321321
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
322322
}
323323

324+
/**
325+
updates an existing image
326+
327+
- parameter petId: (path) ID of pet to update
328+
- parameter imageData: (body) file to upload (optional)
329+
- returns: AnyPublisher<ApiResponse, Error>
330+
*/
331+
#if canImport(Combine)
332+
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
333+
open class func updateImageFile(petId: Int64, imageData: URL? = nil) -> AnyPublisher<ApiResponse, Error> {
334+
let requestBuilder = updateImageFileWithRequestBuilder(petId: petId, imageData: imageData)
335+
let requestTask = requestBuilder.requestTask
336+
return Future<ApiResponse, Error> { promise in
337+
requestBuilder.execute { result in
338+
switch result {
339+
case let .success(response):
340+
promise(.success(response.body))
341+
case let .failure(error):
342+
promise(.failure(error))
343+
}
344+
}
345+
}
346+
.handleEvents(receiveCancel: {
347+
requestTask.cancel()
348+
})
349+
.eraseToAnyPublisher()
350+
}
351+
#endif
352+
353+
/**
354+
updates an existing image
355+
- PUT /pet/{petId}/uploadImage
356+
- OAuth:
357+
- type: oauth2
358+
- name: petstore_auth
359+
- parameter petId: (path) ID of pet to update
360+
- parameter imageData: (body) file to upload (optional)
361+
- returns: RequestBuilder<ApiResponse>
362+
*/
363+
open class func updateImageFileWithRequestBuilder(petId: Int64, imageData: URL? = nil) -> RequestBuilder<ApiResponse> {
364+
var localVariablePath = "/pet/{petId}/uploadImage"
365+
let petIdPreEscape = "\(APIHelper.mapValueToPathItem(petId))"
366+
let petIdPostEscape = petIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
367+
localVariablePath = localVariablePath.replacingOccurrences(of: "{petId}", with: petIdPostEscape, options: .literal, range: nil)
368+
let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath
369+
let localVariableParameters = ["body": imageData]
370+
371+
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
372+
373+
let localVariableNillableHeaders: [String: Any?] = [
374+
"Content-Type": "image/jpeg",
375+
]
376+
377+
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
378+
379+
let localVariableRequestBuilder: RequestBuilder<ApiResponse>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
380+
381+
return localVariableRequestBuilder.init(method: "PUT", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
382+
}
383+
324384
/**
325385
Update an existing pet
326386

samples/client/petstore/swift5/combineLibrary/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Class | Method | HTTP request | Description
4545
*PetAPI* | [**findPetsByStatus**](docs/PetAPI.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
4646
*PetAPI* | [**findPetsByTags**](docs/PetAPI.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
4747
*PetAPI* | [**getPetById**](docs/PetAPI.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
48+
*PetAPI* | [**updateImageFile**](docs/PetAPI.md#updateimagefile) | **PUT** /pet/{petId}/uploadImage | updates an existing image
4849
*PetAPI* | [**updatePet**](docs/PetAPI.md#updatepet) | **PUT** /pet | Update an existing pet
4950
*PetAPI* | [**updatePetWithForm**](docs/PetAPI.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
5051
*PetAPI* | [**uploadFile**](docs/PetAPI.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image

0 commit comments

Comments
 (0)