Skip to content

Commit ec03403

Browse files
committed
Merge pull request #2393 from wing328/model_start_with_number
[PHP] better handling of model name starting with number
2 parents 4d19da4 + 4b5a0a4 commit ec03403

File tree

11 files changed

+332
-139
lines changed

11 files changed

+332
-139
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ public String toModelName(String name) {
407407
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
408408
}
409409

410+
// model name starts with number
411+
if (name.matches("^\\d.*")) {
412+
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name));
413+
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
414+
}
415+
410416
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
411417
if (!name.matches("^\\\\.*")) {
412418
name = modelNamePrefix + name + modelNameSuffix;

modules/swagger-codegen/src/test/resources/2_0/petstore.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,19 @@
13131313
}
13141314
},
13151315
"Name": {
1316-
"descripton": "Model for testing reserved words",
1316+
"descripton": "Model for testing model name same as property name",
1317+
"properties": {
1318+
"name": {
1319+
"type": "integer",
1320+
"format": "int32"
1321+
}
1322+
},
1323+
"xml": {
1324+
"name": "Name"
1325+
}
1326+
},
1327+
"200_response": {
1328+
"descripton": "Model for testing model name starting with number",
13171329
"properties": {
13181330
"name": {
13191331
"type": "integer",

samples/client/petstore/php/SwaggerClient-php/README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Class | Method | HTTP request | Description
7777

7878
- [Category](docs/Category.md)
7979
- [InlineResponse200](docs/InlineResponse200.md)
80+
- [Model200Response](docs/Model200Response.md)
8081
- [ModelReturn](docs/ModelReturn.md)
8182
- [Name](docs/Name.md)
8283
- [Order](docs/Order.md)
@@ -89,48 +90,48 @@ Class | Method | HTTP request | Description
8990
## Documentation For Authorization
9091

9192

92-
## petstore_auth
93+
## test_api_key_header
9394

94-
- **Type**: OAuth
95-
- **Flow**: implicit
96-
- **Authorizatoin URL**: http://petstore.swagger.io/api/oauth/dialog
97-
- **Scopes**:
98-
- **write:pets**: modify pets in your account
99-
- **read:pets**: read your pets
95+
- **Type**: API key
96+
- **API key parameter name**: test_api_key_header
97+
- **Location**: HTTP header
10098

101-
## test_api_client_id
99+
## api_key
102100

103101
- **Type**: API key
104-
- **API key parameter name**: x-test_api_client_id
102+
- **API key parameter name**: api_key
105103
- **Location**: HTTP header
106104

105+
## test_http_basic
106+
107+
- **Type**: HTTP basic authentication
108+
107109
## test_api_client_secret
108110

109111
- **Type**: API key
110112
- **API key parameter name**: x-test_api_client_secret
111113
- **Location**: HTTP header
112114

113-
## api_key
115+
## test_api_client_id
114116

115117
- **Type**: API key
116-
- **API key parameter name**: api_key
118+
- **API key parameter name**: x-test_api_client_id
117119
- **Location**: HTTP header
118120

119-
## test_http_basic
120-
121-
- **Type**: HTTP basic authentication
122-
123121
## test_api_key_query
124122

125123
- **Type**: API key
126124
- **API key parameter name**: test_api_key_query
127125
- **Location**: URL query string
128126

129-
## test_api_key_header
127+
## petstore_auth
130128

131-
- **Type**: API key
132-
- **API key parameter name**: test_api_key_header
133-
- **Location**: HTTP header
129+
- **Type**: OAuth
130+
- **Flow**: implicit
131+
- **Authorizatoin URL**: http://petstore.swagger.io/api/oauth/dialog
132+
- **Scopes**:
133+
- **write:pets**: modify pets in your account
134+
- **read:pets**: read your pets
134135

135136

136137
## Author

samples/client/petstore/php/SwaggerClient-php/docs/InlineResponse200.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**photo_urls** | **string[]** | | [optional]
7-
**name** | **string** | | [optional]
6+
**tags** | [**\Swagger\Client\Model\Tag[]**](Tag.md) | | [optional]
87
**id** | **int** | |
98
**category** | **object** | | [optional]
10-
**tags** | [**\Swagger\Client\Model\Tag[]**](Tag.md) | | [optional]
119
**status** | **string** | pet status in the store | [optional]
10+
**name** | **string** | | [optional]
11+
**photo_urls** | **string[]** | | [optional]
1212

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

samples/client/petstore/php/SwaggerClient-php/docs/PetApi.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error cond
268268
<?php
269269
require_once(__DIR__ . '/vendor/autoload.php');
270270

271-
// Configure OAuth2 access token for authorization: petstore_auth
272-
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
273271
// Configure API key authorization: api_key
274272
Swagger\Client::getDefaultConfiguration->setApiKey('api_key', 'YOUR_API_KEY');
275273
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
276274
// Swagger\Client::getDefaultConfiguration->setApiKeyPrefix('api_key', 'BEARER');
275+
// Configure OAuth2 access token for authorization: petstore_auth
276+
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
277277

278278
$api_instance = new Swagger\Client\PetApi();
279279
$pet_id = 789; // int | ID of pet that needs to be fetched
@@ -299,7 +299,7 @@ Name | Type | Description | Notes
299299

300300
### Authorization
301301

302-
[petstore_auth](../README.md#petstore_auth), [api_key](../README.md#api_key)
302+
[api_key](../README.md#api_key), [petstore_auth](../README.md#petstore_auth)
303303

304304
### HTTP reuqest headers
305305

@@ -320,12 +320,12 @@ Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error cond
320320
<?php
321321
require_once(__DIR__ . '/vendor/autoload.php');
322322

323-
// Configure OAuth2 access token for authorization: petstore_auth
324-
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
325323
// Configure API key authorization: api_key
326324
Swagger\Client::getDefaultConfiguration->setApiKey('api_key', 'YOUR_API_KEY');
327325
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
328326
// Swagger\Client::getDefaultConfiguration->setApiKeyPrefix('api_key', 'BEARER');
327+
// Configure OAuth2 access token for authorization: petstore_auth
328+
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
329329

330330
$api_instance = new Swagger\Client\PetApi();
331331
$pet_id = 789; // int | ID of pet that needs to be fetched
@@ -351,7 +351,7 @@ Name | Type | Description | Notes
351351

352352
### Authorization
353353

354-
[petstore_auth](../README.md#petstore_auth), [api_key](../README.md#api_key)
354+
[api_key](../README.md#api_key), [petstore_auth](../README.md#petstore_auth)
355355

356356
### HTTP reuqest headers
357357

@@ -372,12 +372,12 @@ Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error cond
372372
<?php
373373
require_once(__DIR__ . '/vendor/autoload.php');
374374

375-
// Configure OAuth2 access token for authorization: petstore_auth
376-
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
377375
// Configure API key authorization: api_key
378376
Swagger\Client::getDefaultConfiguration->setApiKey('api_key', 'YOUR_API_KEY');
379377
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
380378
// Swagger\Client::getDefaultConfiguration->setApiKeyPrefix('api_key', 'BEARER');
379+
// Configure OAuth2 access token for authorization: petstore_auth
380+
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
381381

382382
$api_instance = new Swagger\Client\PetApi();
383383
$pet_id = 789; // int | ID of pet that needs to be fetched
@@ -403,7 +403,7 @@ Name | Type | Description | Notes
403403

404404
### Authorization
405405

406-
[petstore_auth](../README.md#petstore_auth), [api_key](../README.md#api_key)
406+
[api_key](../README.md#api_key), [petstore_auth](../README.md#petstore_auth)
407407

408408
### HTTP reuqest headers
409409

samples/client/petstore/php/SwaggerClient-php/docs/StoreApi.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge
214214
<?php
215215
require_once(__DIR__ . '/vendor/autoload.php');
216216

217-
// Configure API key authorization: test_api_key_query
218-
Swagger\Client::getDefaultConfiguration->setApiKey('test_api_key_query', 'YOUR_API_KEY');
219-
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
220-
// Swagger\Client::getDefaultConfiguration->setApiKeyPrefix('test_api_key_query', 'BEARER');
221217
// Configure API key authorization: test_api_key_header
222218
Swagger\Client::getDefaultConfiguration->setApiKey('test_api_key_header', 'YOUR_API_KEY');
223219
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
224220
// Swagger\Client::getDefaultConfiguration->setApiKeyPrefix('test_api_key_header', 'BEARER');
221+
// Configure API key authorization: test_api_key_query
222+
Swagger\Client::getDefaultConfiguration->setApiKey('test_api_key_query', 'YOUR_API_KEY');
223+
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
224+
// Swagger\Client::getDefaultConfiguration->setApiKeyPrefix('test_api_key_query', 'BEARER');
225225

226226
$api_instance = new Swagger\Client\StoreApi();
227227
$order_id = "order_id_example"; // string | ID of pet that needs to be fetched
@@ -247,7 +247,7 @@ Name | Type | Description | Notes
247247

248248
### Authorization
249249

250-
[test_api_key_query](../README.md#test_api_key_query), [test_api_key_header](../README.md#test_api_key_header)
250+
[test_api_key_header](../README.md#test_api_key_header), [test_api_key_query](../README.md#test_api_key_query)
251251

252252
### HTTP reuqest headers
253253

samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,18 @@ public function getPetByIdWithHttpInfo($pet_id)
618618
$httpBody = $formParams; // for HTTP post (form)
619619
}
620620

621-
// this endpoint requires OAuth (access token)
622-
if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
623-
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
624-
}
625-
626621
// this endpoint requires API key authentication
627622
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
628623
if (strlen($apiKey) !== 0) {
629624
$headerParams['api_key'] = $apiKey;
630625
}
631626

632627

628+
// this endpoint requires OAuth (access token)
629+
if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
630+
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
631+
}
632+
633633
// make the API Call
634634
try {
635635
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
@@ -725,18 +725,18 @@ public function getPetByIdInObjectWithHttpInfo($pet_id)
725725
$httpBody = $formParams; // for HTTP post (form)
726726
}
727727

728-
// this endpoint requires OAuth (access token)
729-
if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
730-
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
731-
}
732-
733728
// this endpoint requires API key authentication
734729
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
735730
if (strlen($apiKey) !== 0) {
736731
$headerParams['api_key'] = $apiKey;
737732
}
738733

739734

735+
// this endpoint requires OAuth (access token)
736+
if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
737+
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
738+
}
739+
740740
// make the API Call
741741
try {
742742
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
@@ -832,18 +832,18 @@ public function petPetIdtestingByteArraytrueGetWithHttpInfo($pet_id)
832832
$httpBody = $formParams; // for HTTP post (form)
833833
}
834834

835-
// this endpoint requires OAuth (access token)
836-
if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
837-
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
838-
}
839-
840835
// this endpoint requires API key authentication
841836
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
842837
if (strlen($apiKey) !== 0) {
843838
$headerParams['api_key'] = $apiKey;
844839
}
845840

846841

842+
// this endpoint requires OAuth (access token)
843+
if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
844+
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
845+
}
846+
847847
// make the API Call
848848
try {
849849
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(

samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,16 @@ public function getOrderByIdWithHttpInfo($order_id)
525525
}
526526

527527
// this endpoint requires API key authentication
528-
$apiKey = $this->apiClient->getApiKeyWithPrefix('test_api_key_query');
528+
$apiKey = $this->apiClient->getApiKeyWithPrefix('test_api_key_header');
529529
if (strlen($apiKey) !== 0) {
530-
$queryParams['test_api_key_query'] = $apiKey;
530+
$headerParams['test_api_key_header'] = $apiKey;
531531
}
532532

533533

534534
// this endpoint requires API key authentication
535-
$apiKey = $this->apiClient->getApiKeyWithPrefix('test_api_key_header');
535+
$apiKey = $this->apiClient->getApiKeyWithPrefix('test_api_key_query');
536536
if (strlen($apiKey) !== 0) {
537-
$headerParams['test_api_key_header'] = $apiKey;
537+
$queryParams['test_api_key_query'] = $apiKey;
538538
}
539539

540540

0 commit comments

Comments
 (0)