Skip to content

Commit 5bc4570

Browse files
committed
Merge pull request #2540 from wing328/bug/fix_issue2523
[ObjC] fix spec with no model for ObjC API client
2 parents c159239 + 8657720 commit 5bc4570

File tree

11 files changed

+36
-349
lines changed

11 files changed

+36
-349
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public ObjcClientCodegen() {
9595
//TODO binary should be mapped to byte array
9696
// mapped to String as a workaround
9797
typeMapping.put("binary", "NSString");
98-
98+
typeMapping.put("ByteArray", "NSString");
9999

100100
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
101101
setReservedWordsLowerCase(

modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
{{#models}}{{#model}}#import "{{classname}}.h"
1616
{{/model}}{{/models}}
17+
{{^models}}#import "{{classPrefix}}Object.h"{{/models}}
1718

1819
@class {{classPrefix}}Configuration;
1920

modules/swagger-codegen/src/main/resources/objc/api-body.mustache

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static {{classname}}* singletonAPI = nil;
4040
#pragma mark -
4141

4242
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
43-
4443
if (singletonAPI == nil) {
4544
singletonAPI = [[{{classname}} alloc] init];
4645
[singletonAPI addHeader:headerValue forKey:key];
@@ -49,7 +48,6 @@ static {{classname}}* singletonAPI = nil;
4948
}
5049

5150
+({{classname}}*) sharedAPI {
52-
5351
if (singletonAPI == nil) {
5452
singletonAPI = [[{{classname}} alloc] init];
5553
}
@@ -82,14 +80,15 @@ static {{classname}}* singletonAPI = nil;
8280
-(NSNumber*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
8381
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
8482
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler {
85-
86-
{{#allParams}}{{#required}}
83+
{{#allParams}}
84+
{{#required}}
8785
// verify the required parameter '{{paramName}}' is set
8886
if ({{paramName}} == nil) {
8987
[NSException raise:@"Invalid parameter" format:@"Missing the required parameter `{{paramName}}` when calling `{{nickname}}`"];
9088
}
91-
{{/required}}{{/allParams}}
9289

90+
{{/required}}
91+
{{/allParams}}
9392
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"{{path}}"];
9493

9594
// remove format in URL if needed
@@ -98,26 +97,29 @@ static {{classname}}* singletonAPI = nil;
9897
}
9998

10099
NSMutableDictionary *pathParams = [[NSMutableDictionary alloc] init];
101-
{{#pathParams}}if ({{paramName}} != nil) {
100+
{{#pathParams}}
101+
if ({{paramName}} != nil) {
102102
pathParams[@"{{baseName}}"] = {{paramName}};
103103
}
104104
{{/pathParams}}
105105

106106
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
107-
{{#queryParams}}if ({{paramName}} != nil) {
107+
{{#queryParams}}
108+
if ({{paramName}} != nil) {
108109
{{#collectionFormat}}
109110
queryParams[@"{{baseName}}"] = [[{{classPrefix}}QueryParamCollection alloc] initWithValuesAndFormat: {{baseName}} format: @"{{collectionFormat}}"];
110111
{{/collectionFormat}}
111112
{{^collectionFormat}}queryParams[@"{{baseName}}"] = {{paramName}};{{/collectionFormat}}
112113
}
113114
{{/queryParams}}
114115
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders];
115-
116-
{{#headerParams}}if ({{paramName}} != nil) {
116+
{{#headerParams}}
117+
118+
if ({{paramName}} != nil) {
117119
headerParams[@"{{baseName}}"] = {{paramName}};
118120
}
119-
{{/headerParams}}
120121

122+
{{/headerParams}}
121123
// HTTP header `Accept`
122124
headerParams[@"Accept"] = [{{classPrefix}}ApiClient selectHeaderAccept:@[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]];
123125
if ([headerParams[@"Accept"] length] == 0) {
@@ -144,25 +146,20 @@ static {{classname}}* singletonAPI = nil;
144146
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
145147
{{#bodyParam}}
146148
bodyParam = {{paramName}};
147-
{{/bodyParam}}{{^bodyParam}}
149+
{{/bodyParam}}
150+
{{^bodyParam}}
148151
{{#formParams}}
149152
{{#notFile}}
150153
if ({{paramName}}) {
151154
formParams[@"{{baseName}}"] = {{paramName}};
152155
}
153-
{{/notFile}}{{#isFile}}
156+
{{/notFile}}
157+
{{#isFile}}
154158
localVarFiles[@"{{paramName}}"] = {{paramName}};
155159
{{/isFile}}
156160
{{/formParams}}
157161
{{/bodyParam}}
158162

159-
{{#requiredParamCount}}
160-
{{#requiredParams}}
161-
if ({{paramName}} == nil) {
162-
// error
163-
}
164-
{{/requiredParams}}
165-
{{/requiredParamCount}}
166163
return [self.apiClient requestWithPath: resourcePath
167164
method: @"{{httpMethod}}"
168165
pathParams: pathParams

samples/client/petstore/objc/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This ObjC package is automatically generated by the [Swagger Codegen](https://gi
66

77
- API version: 1.0.0
88
- Package version:
9-
- Build date: 2016-04-05T23:29:02.396+08:00
9+
- Build date: 2016-04-10T18:34:45.604+08:00
1010
- Build package: class io.swagger.codegen.languages.ObjcClientCodegen
1111

1212
## Requirements
@@ -46,6 +46,7 @@ Import the following:
4646
#import <SwaggerClient/SWGCat.h>
4747
#import <SwaggerClient/SWGCategory.h>
4848
#import <SwaggerClient/SWGDog.h>
49+
#import <SwaggerClient/SWGFormatTest.h>
4950
#import <SwaggerClient/SWGInlineResponse200.h>
5051
#import <SwaggerClient/SWGName.h>
5152
#import <SwaggerClient/SWGOrder.h>
@@ -106,20 +107,20 @@ All URIs are relative to *http://petstore.swagger.io/v2*
106107
Class | Method | HTTP request | Description
107108
------------ | ------------- | ------------- | -------------
108109
*SWGPetApi* | [**addPet**](docs/SWGPetApi.md#addpet) | **POST** /pet | Add a new pet to the store
109-
*SWGPetApi* | [**addPetUsingByteArray**](docs/SWGPetApi.md#addpetusingbytearray) | **POST** /pet?testing_byte_array=true | Fake endpoint to test byte array in body parameter for adding a new pet to the store
110+
*SWGPetApi* | [**addPetUsingByteArray**](docs/SWGPetApi.md#addpetusingbytearray) | **POST** /pet?testing_byte_array&#x3D;true | Fake endpoint to test byte array in body parameter for adding a new pet to the store
110111
*SWGPetApi* | [**deletePet**](docs/SWGPetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
111112
*SWGPetApi* | [**findPetsByStatus**](docs/SWGPetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
112113
*SWGPetApi* | [**findPetsByTags**](docs/SWGPetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
113114
*SWGPetApi* | [**getPetById**](docs/SWGPetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
114-
*SWGPetApi* | [**getPetByIdInObject**](docs/SWGPetApi.md#getpetbyidinobject) | **GET** /pet/{petId}?response=inline_arbitrary_object | Fake endpoint to test inline arbitrary object return by &#39;Find pet by ID&#39;
115-
*SWGPetApi* | [**petPetIdtestingByteArraytrueGet**](docs/SWGPetApi.md#petpetidtestingbytearraytrueget) | **GET** /pet/{petId}?testing_byte_array=true | Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
115+
*SWGPetApi* | [**getPetByIdInObject**](docs/SWGPetApi.md#getpetbyidinobject) | **GET** /pet/{petId}?response&#x3D;inline_arbitrary_object | Fake endpoint to test inline arbitrary object return by &#39;Find pet by ID&#39;
116+
*SWGPetApi* | [**petPetIdtestingByteArraytrueGet**](docs/SWGPetApi.md#petpetidtestingbytearraytrueget) | **GET** /pet/{petId}?testing_byte_array&#x3D;true | Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
116117
*SWGPetApi* | [**updatePet**](docs/SWGPetApi.md#updatepet) | **PUT** /pet | Update an existing pet
117118
*SWGPetApi* | [**updatePetWithForm**](docs/SWGPetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
118119
*SWGPetApi* | [**uploadFile**](docs/SWGPetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
119120
*SWGStoreApi* | [**deleteOrder**](docs/SWGStoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
120121
*SWGStoreApi* | [**findOrdersByStatus**](docs/SWGStoreApi.md#findordersbystatus) | **GET** /store/findByStatus | Finds orders by status
121122
*SWGStoreApi* | [**getInventory**](docs/SWGStoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
122-
*SWGStoreApi* | [**getInventoryInObject**](docs/SWGStoreApi.md#getinventoryinobject) | **GET** /store/inventory?response=arbitrary_object | Fake endpoint to test arbitrary object return by &#39;Get inventory&#39;
123+
*SWGStoreApi* | [**getInventoryInObject**](docs/SWGStoreApi.md#getinventoryinobject) | **GET** /store/inventory?response&#x3D;arbitrary_object | Fake endpoint to test arbitrary object return by &#39;Get inventory&#39;
123124
*SWGStoreApi* | [**getOrderById**](docs/SWGStoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
124125
*SWGStoreApi* | [**placeOrder**](docs/SWGStoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
125126
*SWGUserApi* | [**createUser**](docs/SWGUserApi.md#createuser) | **POST** /user | Create user
@@ -139,6 +140,7 @@ Class | Method | HTTP request | Description
139140
- [SWGCat](docs/SWGCat.md)
140141
- [SWGCategory](docs/SWGCategory.md)
141142
- [SWGDog](docs/SWGDog.md)
143+
- [SWGFormatTest](docs/SWGFormatTest.md)
142144
- [SWGInlineResponse200](docs/SWGInlineResponse200.md)
143145
- [SWGName](docs/SWGName.md)
144146
- [SWGOrder](docs/SWGOrder.md)

samples/client/petstore/objc/SwaggerClient.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313

1414
s.summary = "Swagger Petstore"
1515
s.description = <<-DESC
16-
This is a sample server Petstore server. You can find out more about Swagger at &lt;a href=\&quot;http://swagger.io\&quot;&gt;http://swagger.io&lt;/a&gt; or on irc.freenode.net, #swagger. For this sample, you can use the api key \&quot;special-key\&quot; to test the authorization filters
16+
This is a sample server Petstore server. You can find out more about Swagger at &lt;a href&#x3D;\&quot;http://swagger.io\&quot;&gt;http://swagger.io&lt;/a&gt; or on irc.freenode.net, #swagger. For this sample, you can use the api key \&quot;special-key\&quot; to test the authorization filters
1717
DESC
1818

1919
s.platform = :ios, '7.0'

samples/client/petstore/objc/SwaggerClient/SWGApiClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "SWGCat.h"
1818
#import "SWGCategory.h"
1919
#import "SWGDog.h"
20+
#import "SWGFormatTest.h"
2021
#import "SWGInlineResponse200.h"
2122
#import "SWGName.h"
2223
#import "SWGOrder.h"
@@ -27,6 +28,7 @@
2728
#import "SWGUser.h"
2829

2930

31+
3032
@class SWGConfiguration;
3133

3234
/**

samples/client/petstore/objc/SwaggerClient/SWGName.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ + (JSONKeyMapper *)keyMapper
3030
*/
3131
+ (BOOL)propertyIsOptional:(NSString *)propertyName
3232
{
33-
NSArray *optionalProperties = @[@"name", @"snakeCase"];
33+
NSArray *optionalProperties = @[@"snakeCase"];
3434

3535
if ([optionalProperties containsObject:propertyName]) {
3636
return YES;

0 commit comments

Comments
 (0)