forked from loafle/openapi-generator-original
add property, parameter name mapping to php generators (#16206)
This commit is contained in:
parent
243b5569ef
commit
f3b3de2a29
@ -1,4 +1,11 @@
|
||||
generatorName: php
|
||||
outputDir: samples/client/petstore/php/OpenAPIClient-php
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/php
|
||||
nameMappings:
|
||||
_type: underscore_type
|
||||
type_: type_with_underscore
|
||||
type-: type_with_dash
|
||||
parameterNameMappings:
|
||||
_type: underscore_type
|
||||
type_: type_with_underscore
|
||||
|
@ -460,6 +460,11 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// obtain the name from nameMapping directly if provided
|
||||
if (nameMapping.containsKey(name)) {
|
||||
return nameMapping.get(name);
|
||||
}
|
||||
|
||||
// translate @ for properties (like @type) to at_.
|
||||
// Otherwise an additional "type" property will leed to duplcates
|
||||
name = name.replaceAll("^@", "at_");
|
||||
@ -490,6 +495,11 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// obtain the name from parameterNameMapping directly if provided
|
||||
if (parameterNameMapping.containsKey(name)) {
|
||||
return parameterNameMapping.get(name);
|
||||
}
|
||||
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -52,6 +52,7 @@ docs/Model/OuterEnumInteger.md
|
||||
docs/Model/OuterEnumIntegerDefaultValue.md
|
||||
docs/Model/OuterObjectWithEnumProperty.md
|
||||
docs/Model/Pet.md
|
||||
docs/Model/PropertyNameMapping.md
|
||||
docs/Model/ReadOnlyFirst.md
|
||||
docs/Model/SingleRefType.md
|
||||
docs/Model/SpecialModelName.md
|
||||
@ -111,6 +112,7 @@ lib/Model/OuterEnumInteger.php
|
||||
lib/Model/OuterEnumIntegerDefaultValue.php
|
||||
lib/Model/OuterObjectWithEnumProperty.php
|
||||
lib/Model/Pet.php
|
||||
lib/Model/PropertyNameMapping.php
|
||||
lib/Model/ReadOnlyFirst.php
|
||||
lib/Model/SingleRefType.php
|
||||
lib/Model/SpecialModelName.php
|
||||
|
@ -82,6 +82,7 @@ Class | Method | HTTP request | Description
|
||||
*FakeApi* | [**fakeOuterNumberSerialize**](docs/Api/FakeApi.md#fakeouternumberserialize) | **POST** /fake/outer/number |
|
||||
*FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string |
|
||||
*FakeApi* | [**fakePropertyEnumIntegerSerialize**](docs/Api/FakeApi.md#fakepropertyenumintegerserialize) | **POST** /fake/property/enum-int |
|
||||
*FakeApi* | [**getParameterNameMapping**](docs/Api/FakeApi.md#getparameternamemapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test
|
||||
*FakeApi* | [**testBodyWithBinary**](docs/Api/FakeApi.md#testbodywithbinary) | **PUT** /fake/body-with-binary |
|
||||
*FakeApi* | [**testBodyWithFileSchema**](docs/Api/FakeApi.md#testbodywithfileschema) | **PUT** /fake/body-with-file-schema |
|
||||
*FakeApi* | [**testBodyWithQueryParams**](docs/Api/FakeApi.md#testbodywithqueryparams) | **PUT** /fake/body-with-query-params |
|
||||
@ -159,6 +160,7 @@ Class | Method | HTTP request | Description
|
||||
- [OuterEnumIntegerDefaultValue](docs/Model/OuterEnumIntegerDefaultValue.md)
|
||||
- [OuterObjectWithEnumProperty](docs/Model/OuterObjectWithEnumProperty.md)
|
||||
- [Pet](docs/Model/Pet.md)
|
||||
- [PropertyNameMapping](docs/Model/PropertyNameMapping.md)
|
||||
- [ReadOnlyFirst](docs/Model/ReadOnlyFirst.md)
|
||||
- [SingleRefType](docs/Model/SingleRefType.md)
|
||||
- [SpecialModelName](docs/Model/SpecialModelName.md)
|
||||
|
@ -12,6 +12,7 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati
|
||||
| [**fakeOuterNumberSerialize()**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | |
|
||||
| [**fakeOuterStringSerialize()**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | |
|
||||
| [**fakePropertyEnumIntegerSerialize()**](FakeApi.md#fakePropertyEnumIntegerSerialize) | **POST** /fake/property/enum-int | |
|
||||
| [**getParameterNameMapping()**](FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test |
|
||||
| [**testBodyWithBinary()**](FakeApi.md#testBodyWithBinary) | **PUT** /fake/body-with-binary | |
|
||||
| [**testBodyWithFileSchema()**](FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema | |
|
||||
| [**testBodyWithQueryParams()**](FakeApi.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params | |
|
||||
@ -467,6 +468,67 @@ No authorization required
|
||||
[[Back to Model list]](../../README.md#models)
|
||||
[[Back to README]](../../README.md)
|
||||
|
||||
## `getParameterNameMapping()`
|
||||
|
||||
```php
|
||||
getParameterNameMapping($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option)
|
||||
```
|
||||
|
||||
parameter name mapping test
|
||||
|
||||
### Example
|
||||
|
||||
```php
|
||||
<?php
|
||||
require_once(__DIR__ . '/vendor/autoload.php');
|
||||
|
||||
|
||||
|
||||
$apiInstance = new OpenAPI\Client\Api\FakeApi(
|
||||
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
|
||||
// This is optional, `GuzzleHttp\Client` will be used as default.
|
||||
new GuzzleHttp\Client()
|
||||
);
|
||||
$underscore_type = 56; // int | _type
|
||||
$type = 'type_example'; // string | type
|
||||
$type_with_underscore = 'type_with_underscore_example'; // string | type_
|
||||
$type_with_dash = 'type_with_dash_example'; // string | type-
|
||||
$http_debug_option = 'http_debug_option_example'; // string | http debug option (to test parameter naming option)
|
||||
|
||||
try {
|
||||
$apiInstance->getParameterNameMapping($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option);
|
||||
} catch (Exception $e) {
|
||||
echo 'Exception when calling FakeApi->getParameterNameMapping: ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
| Name | Type | Description | Notes |
|
||||
| ------------- | ------------- | ------------- | ------------- |
|
||||
| **underscore_type** | **int**| _type | |
|
||||
| **type** | **string**| type | |
|
||||
| **type_with_underscore** | **string**| type_ | |
|
||||
| **type_with_dash** | **string**| type- | |
|
||||
| **http_debug_option** | **string**| http debug option (to test parameter naming option) | |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: Not defined
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../../README.md#endpoints)
|
||||
[[Back to Model list]](../../README.md#models)
|
||||
[[Back to README]](../../README.md)
|
||||
|
||||
## `testBodyWithBinary()`
|
||||
|
||||
```php
|
||||
|
@ -0,0 +1,12 @@
|
||||
# # PropertyNameMapping
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**http_debug_operation** | **string** | | [optional]
|
||||
**underscore_type** | **string** | | [optional]
|
||||
**type** | **string** | | [optional]
|
||||
**type_with_underscore** | **string** | | [optional]
|
||||
|
||||
[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)
|
@ -96,6 +96,9 @@ class FakeApi
|
||||
'fakePropertyEnumIntegerSerialize' => [
|
||||
'application/json',
|
||||
],
|
||||
'getParameterNameMapping' => [
|
||||
'application/json',
|
||||
],
|
||||
'testBodyWithBinary' => [
|
||||
'image/png',
|
||||
],
|
||||
@ -2291,6 +2294,305 @@ class FakeApi
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getParameterNameMapping
|
||||
*
|
||||
* parameter name mapping test
|
||||
*
|
||||
* @param int $underscore_type _type (required)
|
||||
* @param string $type type (required)
|
||||
* @param string $type_with_underscore type_ (required)
|
||||
* @param string $type_with_dash type- (required)
|
||||
* @param string $http_debug_option http debug option (to test parameter naming option) (required)
|
||||
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getParameterNameMapping'] to see the possible values for this operation
|
||||
*
|
||||
* @throws \OpenAPI\Client\ApiException on non-2xx response
|
||||
* @throws \InvalidArgumentException
|
||||
* @return void
|
||||
*/
|
||||
public function getParameterNameMapping($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, string $contentType = self::contentTypes['getParameterNameMapping'][0])
|
||||
{
|
||||
$this->getParameterNameMappingWithHttpInfo($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getParameterNameMappingWithHttpInfo
|
||||
*
|
||||
* parameter name mapping test
|
||||
*
|
||||
* @param int $underscore_type _type (required)
|
||||
* @param string $type type (required)
|
||||
* @param string $type_with_underscore type_ (required)
|
||||
* @param string $type_with_dash type- (required)
|
||||
* @param string $http_debug_option http debug option (to test parameter naming option) (required)
|
||||
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getParameterNameMapping'] to see the possible values for this operation
|
||||
*
|
||||
* @throws \OpenAPI\Client\ApiException on non-2xx response
|
||||
* @throws \InvalidArgumentException
|
||||
* @return array of null, HTTP status code, HTTP response headers (array of strings)
|
||||
*/
|
||||
public function getParameterNameMappingWithHttpInfo($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, string $contentType = self::contentTypes['getParameterNameMapping'][0])
|
||||
{
|
||||
$request = $this->getParameterNameMappingRequest($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, $contentType);
|
||||
|
||||
try {
|
||||
$options = $this->createHttpClientOption();
|
||||
try {
|
||||
$response = $this->client->send($request, $options);
|
||||
} catch (RequestException $e) {
|
||||
throw new ApiException(
|
||||
"[{$e->getCode()}] {$e->getMessage()}",
|
||||
(int) $e->getCode(),
|
||||
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
||||
$e->getResponse() ? (string) $e->getResponse()->getBody() : null
|
||||
);
|
||||
} catch (ConnectException $e) {
|
||||
throw new ApiException(
|
||||
"[{$e->getCode()}] {$e->getMessage()}",
|
||||
(int) $e->getCode(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
if ($statusCode < 200 || $statusCode > 299) {
|
||||
throw new ApiException(
|
||||
sprintf(
|
||||
'[%d] Error connecting to the API (%s)',
|
||||
$statusCode,
|
||||
(string) $request->getUri()
|
||||
),
|
||||
$statusCode,
|
||||
$response->getHeaders(),
|
||||
(string) $response->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
return [null, $statusCode, $response->getHeaders()];
|
||||
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getParameterNameMappingAsync
|
||||
*
|
||||
* parameter name mapping test
|
||||
*
|
||||
* @param int $underscore_type _type (required)
|
||||
* @param string $type type (required)
|
||||
* @param string $type_with_underscore type_ (required)
|
||||
* @param string $type_with_dash type- (required)
|
||||
* @param string $http_debug_option http debug option (to test parameter naming option) (required)
|
||||
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getParameterNameMapping'] to see the possible values for this operation
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return \GuzzleHttp\Promise\PromiseInterface
|
||||
*/
|
||||
public function getParameterNameMappingAsync($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, string $contentType = self::contentTypes['getParameterNameMapping'][0])
|
||||
{
|
||||
return $this->getParameterNameMappingAsyncWithHttpInfo($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, $contentType)
|
||||
->then(
|
||||
function ($response) {
|
||||
return $response[0];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getParameterNameMappingAsyncWithHttpInfo
|
||||
*
|
||||
* parameter name mapping test
|
||||
*
|
||||
* @param int $underscore_type _type (required)
|
||||
* @param string $type type (required)
|
||||
* @param string $type_with_underscore type_ (required)
|
||||
* @param string $type_with_dash type- (required)
|
||||
* @param string $http_debug_option http debug option (to test parameter naming option) (required)
|
||||
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getParameterNameMapping'] to see the possible values for this operation
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return \GuzzleHttp\Promise\PromiseInterface
|
||||
*/
|
||||
public function getParameterNameMappingAsyncWithHttpInfo($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, string $contentType = self::contentTypes['getParameterNameMapping'][0])
|
||||
{
|
||||
$returnType = '';
|
||||
$request = $this->getParameterNameMappingRequest($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, $contentType);
|
||||
|
||||
return $this->client
|
||||
->sendAsync($request, $this->createHttpClientOption())
|
||||
->then(
|
||||
function ($response) use ($returnType) {
|
||||
return [null, $response->getStatusCode(), $response->getHeaders()];
|
||||
},
|
||||
function ($exception) {
|
||||
$response = $exception->getResponse();
|
||||
$statusCode = $response->getStatusCode();
|
||||
throw new ApiException(
|
||||
sprintf(
|
||||
'[%d] Error connecting to the API (%s)',
|
||||
$statusCode,
|
||||
$exception->getRequest()->getUri()
|
||||
),
|
||||
$statusCode,
|
||||
$response->getHeaders(),
|
||||
(string) $response->getBody()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create request for operation 'getParameterNameMapping'
|
||||
*
|
||||
* @param int $underscore_type _type (required)
|
||||
* @param string $type type (required)
|
||||
* @param string $type_with_underscore type_ (required)
|
||||
* @param string $type_with_dash type- (required)
|
||||
* @param string $http_debug_option http debug option (to test parameter naming option) (required)
|
||||
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getParameterNameMapping'] to see the possible values for this operation
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return \GuzzleHttp\Psr7\Request
|
||||
*/
|
||||
public function getParameterNameMappingRequest($underscore_type, $type, $type_with_underscore, $type_with_dash, $http_debug_option, string $contentType = self::contentTypes['getParameterNameMapping'][0])
|
||||
{
|
||||
|
||||
// verify the required parameter 'underscore_type' is set
|
||||
if ($underscore_type === null || (is_array($underscore_type) && count($underscore_type) === 0)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Missing the required parameter $underscore_type when calling getParameterNameMapping'
|
||||
);
|
||||
}
|
||||
|
||||
// verify the required parameter 'type' is set
|
||||
if ($type === null || (is_array($type) && count($type) === 0)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Missing the required parameter $type when calling getParameterNameMapping'
|
||||
);
|
||||
}
|
||||
|
||||
// verify the required parameter 'type_with_underscore' is set
|
||||
if ($type_with_underscore === null || (is_array($type_with_underscore) && count($type_with_underscore) === 0)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Missing the required parameter $type_with_underscore when calling getParameterNameMapping'
|
||||
);
|
||||
}
|
||||
|
||||
// verify the required parameter 'type_with_dash' is set
|
||||
if ($type_with_dash === null || (is_array($type_with_dash) && count($type_with_dash) === 0)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Missing the required parameter $type_with_dash when calling getParameterNameMapping'
|
||||
);
|
||||
}
|
||||
|
||||
// verify the required parameter 'http_debug_option' is set
|
||||
if ($http_debug_option === null || (is_array($http_debug_option) && count($http_debug_option) === 0)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Missing the required parameter $http_debug_option when calling getParameterNameMapping'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$resourcePath = '/fake/parameter-name-mapping';
|
||||
$formParams = [];
|
||||
$queryParams = [];
|
||||
$headerParams = [];
|
||||
$httpBody = '';
|
||||
$multipart = false;
|
||||
|
||||
// query params
|
||||
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
|
||||
$type,
|
||||
'type', // param base name
|
||||
'string', // openApiType
|
||||
'form', // style
|
||||
true, // explode
|
||||
true // required
|
||||
) ?? []);
|
||||
// query params
|
||||
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
|
||||
$http_debug_option,
|
||||
'http_debug_option', // param base name
|
||||
'string', // openApiType
|
||||
'form', // style
|
||||
true, // explode
|
||||
true // required
|
||||
) ?? []);
|
||||
|
||||
// header params
|
||||
if ($underscore_type !== null) {
|
||||
$headerParams['_type'] = ObjectSerializer::toHeaderValue($underscore_type);
|
||||
}
|
||||
// header params
|
||||
if ($type_with_underscore !== null) {
|
||||
$headerParams['type_'] = ObjectSerializer::toHeaderValue($type_with_underscore);
|
||||
}
|
||||
// header params
|
||||
if ($type_with_dash !== null) {
|
||||
$headerParams['type-'] = ObjectSerializer::toHeaderValue($type_with_dash);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
[],
|
||||
$contentType,
|
||||
$multipart
|
||||
);
|
||||
|
||||
// for model (json/xml)
|
||||
if (count($formParams) > 0) {
|
||||
if ($multipart) {
|
||||
$multipartContents = [];
|
||||
foreach ($formParams as $formParamName => $formParamValue) {
|
||||
$formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
|
||||
foreach ($formParamValueItems as $formParamValueItem) {
|
||||
$multipartContents[] = [
|
||||
'name' => $formParamName,
|
||||
'contents' => $formParamValueItem
|
||||
];
|
||||
}
|
||||
}
|
||||
// for HTTP post (form)
|
||||
$httpBody = new MultipartStream($multipartContents);
|
||||
|
||||
} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
|
||||
# if Content-Type contains "application/json", json_encode the form parameters
|
||||
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
|
||||
} else {
|
||||
// for HTTP post (form)
|
||||
$httpBody = ObjectSerializer::buildQuery($formParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$defaultHeaders = [];
|
||||
if ($this->config->getUserAgent()) {
|
||||
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
|
||||
}
|
||||
|
||||
$headers = array_merge(
|
||||
$defaultHeaders,
|
||||
$headerParams,
|
||||
$headers
|
||||
);
|
||||
|
||||
$operationHost = $this->config->getHost();
|
||||
$query = ObjectSerializer::buildQuery($queryParams);
|
||||
return new Request(
|
||||
'GET',
|
||||
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
|
||||
$headers,
|
||||
$httpBody
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation testBodyWithBinary
|
||||
*
|
||||
|
@ -0,0 +1,511 @@
|
||||
<?php
|
||||
/**
|
||||
* PropertyNameMapping
|
||||
*
|
||||
* PHP version 7.4
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Client
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://openapi-generator.tech
|
||||
* OpenAPI Generator version: 7.0.0-SNAPSHOT
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace OpenAPI\Client\Model;
|
||||
|
||||
use \ArrayAccess;
|
||||
use \OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
* PropertyNameMapping Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Client
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
* @implements \ArrayAccess<string, mixed>
|
||||
*/
|
||||
class PropertyNameMapping implements ModelInterface, ArrayAccess, \JsonSerializable
|
||||
{
|
||||
public const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $openAPIModelName = 'PropertyNameMapping';
|
||||
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $openAPITypes = [
|
||||
'http_debug_operation' => 'string',
|
||||
'underscore_type' => 'string',
|
||||
'type' => 'string',
|
||||
'type_with_underscore' => 'string'
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of property to format mappings. Used for (de)serialization
|
||||
*
|
||||
* @var string[]
|
||||
* @phpstan-var array<string, string|null>
|
||||
* @psalm-var array<string, string|null>
|
||||
*/
|
||||
protected static $openAPIFormats = [
|
||||
'http_debug_operation' => null,
|
||||
'underscore_type' => null,
|
||||
'type' => null,
|
||||
'type_with_underscore' => null
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of nullable properties. Used for (de)serialization
|
||||
*
|
||||
* @var boolean[]
|
||||
*/
|
||||
protected static array $openAPINullables = [
|
||||
'http_debug_operation' => false,
|
||||
'underscore_type' => false,
|
||||
'type' => false,
|
||||
'type_with_underscore' => false
|
||||
];
|
||||
|
||||
/**
|
||||
* If a nullable field gets set to null, insert it here
|
||||
*
|
||||
* @var boolean[]
|
||||
*/
|
||||
protected array $openAPINullablesSetToNull = [];
|
||||
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function openAPITypes()
|
||||
{
|
||||
return self::$openAPITypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of property to format mappings. Used for (de)serialization
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function openAPIFormats()
|
||||
{
|
||||
return self::$openAPIFormats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of nullable properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function openAPINullables(): array
|
||||
{
|
||||
return self::$openAPINullables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of nullable field names deliberately set to null
|
||||
*
|
||||
* @return boolean[]
|
||||
*/
|
||||
private function getOpenAPINullablesSetToNull(): array
|
||||
{
|
||||
return $this->openAPINullablesSetToNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter - Array of nullable field names deliberately set to null
|
||||
*
|
||||
* @param boolean[] $openAPINullablesSetToNull
|
||||
*/
|
||||
private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
|
||||
{
|
||||
$this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a property is nullable
|
||||
*
|
||||
* @param string $property
|
||||
* @return bool
|
||||
*/
|
||||
public static function isNullable(string $property): bool
|
||||
{
|
||||
return self::openAPINullables()[$property] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a nullable property is set to null.
|
||||
*
|
||||
* @param string $property
|
||||
* @return bool
|
||||
*/
|
||||
public function isNullableSetToNull(string $property): bool
|
||||
{
|
||||
return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name,
|
||||
* and the value is the original name
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $attributeMap = [
|
||||
'http_debug_operation' => 'http_debug_operation',
|
||||
'underscore_type' => '_type',
|
||||
'type' => 'type',
|
||||
'type_with_underscore' => 'type_'
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $setters = [
|
||||
'http_debug_operation' => 'setHttpDebugOperation',
|
||||
'underscore_type' => 'setUnderscoreType',
|
||||
'type' => 'setType',
|
||||
'type_with_underscore' => 'setTypeWithUnderscore'
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $getters = [
|
||||
'http_debug_operation' => 'getHttpDebugOperation',
|
||||
'underscore_type' => 'getUnderscoreType',
|
||||
'type' => 'getType',
|
||||
'type_with_underscore' => 'getTypeWithUnderscore'
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name,
|
||||
* and the value is the original name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function attributeMap()
|
||||
{
|
||||
return self::$attributeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setters()
|
||||
{
|
||||
return self::$setters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getters()
|
||||
{
|
||||
return self::$getters;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModelName()
|
||||
{
|
||||
return self::$openAPIModelName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Associative array for storing property values
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $container = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param mixed[] $data Associated array of property values
|
||||
* initializing the model
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
$this->setIfExists('http_debug_operation', $data ?? [], null);
|
||||
$this->setIfExists('underscore_type', $data ?? [], null);
|
||||
$this->setIfExists('type', $data ?? [], null);
|
||||
$this->setIfExists('type_with_underscore', $data ?? [], null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
|
||||
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
|
||||
* $this->openAPINullablesSetToNull array
|
||||
*
|
||||
* @param string $variableName
|
||||
* @param array $fields
|
||||
* @param mixed $defaultValue
|
||||
*/
|
||||
private function setIfExists(string $variableName, array $fields, $defaultValue): void
|
||||
{
|
||||
if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
|
||||
$this->openAPINullablesSetToNull[] = $variableName;
|
||||
}
|
||||
|
||||
$this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all the invalid properties with reasons.
|
||||
*
|
||||
* @return array invalid properties with reasons
|
||||
*/
|
||||
public function listInvalidProperties()
|
||||
{
|
||||
$invalidProperties = [];
|
||||
|
||||
return $invalidProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate all the properties in the model
|
||||
* return true if all passed
|
||||
*
|
||||
* @return bool True if all properties are valid
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return count($this->listInvalidProperties()) === 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets http_debug_operation
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getHttpDebugOperation()
|
||||
{
|
||||
return $this->container['http_debug_operation'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets http_debug_operation
|
||||
*
|
||||
* @param string|null $http_debug_operation http_debug_operation
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setHttpDebugOperation($http_debug_operation)
|
||||
{
|
||||
if (is_null($http_debug_operation)) {
|
||||
throw new \InvalidArgumentException('non-nullable http_debug_operation cannot be null');
|
||||
}
|
||||
$this->container['http_debug_operation'] = $http_debug_operation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets underscore_type
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUnderscoreType()
|
||||
{
|
||||
return $this->container['underscore_type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets underscore_type
|
||||
*
|
||||
* @param string|null $underscore_type underscore_type
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setUnderscoreType($underscore_type)
|
||||
{
|
||||
if (is_null($underscore_type)) {
|
||||
throw new \InvalidArgumentException('non-nullable underscore_type cannot be null');
|
||||
}
|
||||
$this->container['underscore_type'] = $underscore_type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets type
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->container['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets type
|
||||
*
|
||||
* @param string|null $type type
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
if (is_null($type)) {
|
||||
throw new \InvalidArgumentException('non-nullable type cannot be null');
|
||||
}
|
||||
$this->container['type'] = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets type_with_underscore
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTypeWithUnderscore()
|
||||
{
|
||||
return $this->container['type_with_underscore'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets type_with_underscore
|
||||
*
|
||||
* @param string|null $type_with_underscore type_with_underscore
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setTypeWithUnderscore($type_with_underscore)
|
||||
{
|
||||
if (is_null($type_with_underscore)) {
|
||||
throw new \InvalidArgumentException('non-nullable type_with_underscore cannot be null');
|
||||
}
|
||||
$this->container['type_with_underscore'] = $type_with_underscore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Returns true if offset exists. False otherwise.
|
||||
*
|
||||
* @param integer $offset Offset
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return isset($this->container[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets offset.
|
||||
*
|
||||
* @param integer $offset Offset
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->container[$offset] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value based on offset.
|
||||
*
|
||||
* @param int|null $offset Offset
|
||||
* @param mixed $value Value to be set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if (is_null($offset)) {
|
||||
$this->container[] = $value;
|
||||
} else {
|
||||
$this->container[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets offset.
|
||||
*
|
||||
* @param integer $offset Offset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
unset($this->container[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the object to a value that can be serialized natively by json_encode().
|
||||
* @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
*
|
||||
* @return mixed Returns data which can be serialized by json_encode(), which is a value
|
||||
* of any type other than a resource.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return ObjectSerializer::sanitizeForSerialization($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string presentation of the object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return json_encode(
|
||||
ObjectSerializer::sanitizeForSerialization($this),
|
||||
JSON_PRETTY_PRINT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a header-safe presentation of the object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toHeaderValue()
|
||||
{
|
||||
return json_encode(ObjectSerializer::sanitizeForSerialization($this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* PropertyNameMappingTest
|
||||
*
|
||||
* PHP version 7.4
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Client
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://openapi-generator.tech
|
||||
* OpenAPI Generator version: 7.0.0-SNAPSHOT
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Please update the test case below to test the model.
|
||||
*/
|
||||
|
||||
namespace OpenAPI\Client\Test\Model;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* PropertyNameMappingTest Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @description PropertyNameMapping
|
||||
* @package OpenAPI\Client
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
class PropertyNameMappingTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running any test case
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running all test cases
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test "PropertyNameMapping"
|
||||
*/
|
||||
public function testPropertyNameMapping()
|
||||
{
|
||||
// TODO: implement
|
||||
$this->markTestIncomplete('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "http_debug_operation"
|
||||
*/
|
||||
public function testPropertyHttpDebugOperation()
|
||||
{
|
||||
// TODO: implement
|
||||
$this->markTestIncomplete('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "underscore_type"
|
||||
*/
|
||||
public function testPropertyUnderscoreType()
|
||||
{
|
||||
// TODO: implement
|
||||
$this->markTestIncomplete('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "type"
|
||||
*/
|
||||
public function testPropertyType()
|
||||
{
|
||||
// TODO: implement
|
||||
$this->markTestIncomplete('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "type_with_underscore"
|
||||
*/
|
||||
public function testPropertyTypeWithUnderscore()
|
||||
{
|
||||
// TODO: implement
|
||||
$this->markTestIncomplete('Not implemented');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user