From 1bc3e5369fdce8757ab8bd4d4a7a6d33611bf633 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Sep 2021 11:09:21 +0800 Subject: [PATCH 1/5] map BigDecimal to float --- .../org/openapitools/codegen/languages/AbstractPhpCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index 2805cd301eed..30e82109e000 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -109,6 +109,7 @@ public AbstractPhpCodegen() { typeMapping = new HashMap(); typeMapping.put("integer", "int"); typeMapping.put("long", "int"); + typeMapping.put("BigDecimal", "float"); typeMapping.put("number", "float"); typeMapping.put("float", "float"); typeMapping.put("double", "double"); From 6fccdb9e874af50fa20f14ae41ec3343248c4c9f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Sep 2021 11:52:58 +0800 Subject: [PATCH 2/5] enhance type mapping in php generators --- .../codegen/languages/AbstractPhpCodegen.java | 19 ++++++++++++++----- .../languages/PhpSymfonyServerCodegen.java | 5 ++++- .../src/App/DTO/InlineObject1.php | 3 +-- .../php-dt-modern/src/App/DTO/Order.php | 1 + .../php-dt/src/App/DTO/InlineObject1.php | 3 +-- .../petstore/php-dt/src/App/DTO/Order.php | 1 + .../docs/Model/FormatTest.md | 8 ++++---- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../docs/Model/NullableClass.md | 4 ++-- .../php/OpenAPIClient-php/docs/Model/Order.md | 2 +- .../lib/Model/FormatTest.php | 6 +++--- .../lib/ObjectSerializer.php | 4 ++-- .../php-laravel/lib/app/Models/FormatTest.php | 2 +- .../src/App/DTO/Order.php | 1 + .../php-mezzio-ph/src/App/DTO/Order.php | 1 + .../Resources/docs/Model/Order.md | 2 +- 16 files changed, 39 insertions(+), 25 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index 30e82109e000..9952c38656b2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -90,7 +90,8 @@ public AbstractPhpCodegen() { "string", "object", "array", - "DateTime", + "\\DateTime", + "\\SplFileObject", "mixed", "number", "void", @@ -109,9 +110,9 @@ public AbstractPhpCodegen() { typeMapping = new HashMap(); typeMapping.put("integer", "int"); typeMapping.put("long", "int"); - typeMapping.put("BigDecimal", "float"); typeMapping.put("number", "float"); typeMapping.put("float", "float"); + typeMapping.put("decimal", "float"); typeMapping.put("double", "double"); typeMapping.put("string", "string"); typeMapping.put("byte", "int"); @@ -342,19 +343,27 @@ public String getTypeDeclaration(String name) { public String getSchemaType(Schema p) { String openAPIType = super.getSchemaType(p); String type = null; + + if (openAPIType == null) { + LOGGER.error("OpenAPI Type for {} is null. Default to UNKNOWN_OPENAPI_TYPE instead.", p.getName()); + openAPIType = "UNKNOWN_OPENAPI_TYPE"; + } + if (typeMapping.containsKey(openAPIType)) { type = typeMapping.get(openAPIType); if (languageSpecificPrimitives.contains(type)) { return type; } else if (instantiationTypes.containsKey(type)) { return type; + } else { + throw new RuntimeException("OpenAPI type `" + openAPIType + "` defined but can't mapped to language type." + + " Please report the issue via OpenAPI Generator github repo." + + " (if you're not using custom format with proper type mappings provided to openapi-generator)"); } } else { type = openAPIType; } - if (type == null) { - return null; - } + return toModelName(type); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 705185cf2207..17d970d39c52 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -151,7 +151,9 @@ public PhpSymfonyServerCodegen() { "number", "void", "byte", - "array" + "array", + "\\DateTime", + "UploadedFile" ) ); @@ -174,6 +176,7 @@ public PhpSymfonyServerCodegen() { typeMapping = new HashMap(); typeMapping.put("integer", "int"); typeMapping.put("long", "int"); + typeMapping.put("decimal", "float"); typeMapping.put("number", "float"); typeMapping.put("float", "float"); typeMapping.put("double", "double"); diff --git a/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php b/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php index 791f4cf410b9..b278bcf03f0f 100644 --- a/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php +++ b/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php @@ -18,8 +18,7 @@ class InlineObject1 * file to upload */ #[DTA\Data(field: "file", nullable: true)] - #[DTA\Strategy("Object", ["type" => \SplFileObject::class])] - #[DTA\Validator("TypeCompliant", ["type" => \SplFileObject::class])] + #[DTA\Validator("Scalar", ["type" => "\SplFileObject"])] public \SplFileObject|null $file = null; } diff --git a/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php b/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php index 8dd384b4475d..3aba236fc409 100644 --- a/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php +++ b/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php @@ -23,6 +23,7 @@ class Order public int|null $quantity = null; #[DTA\Data(field: "shipDate", nullable: true)] + #[DTA\Validator("Scalar", ["type" => "\DateTime"])] #[DTA\Strategy("DateTime")] #[DTA\Validator("Date", ["format" => \DateTime::RFC3339])] public \DateTime|null $ship_date = null; diff --git a/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php b/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php index 611b567c40da..3c883ca7a30b 100644 --- a/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php +++ b/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php @@ -20,8 +20,7 @@ class InlineObject1 /** * file to upload * @DTA\Data(field="file", nullable=true) - * @DTA\Strategy(name="Object", options={"type":\SplFileObject::class}) - * @DTA\Validator(name="TypeCompliant", options={"type":\SplFileObject::class}) + * @DTA\Validator(name="Scalar", options={"type":"\SplFileObject"}) * @var \SplFileObject|null */ public $file; diff --git a/samples/client/petstore/php-dt/src/App/DTO/Order.php b/samples/client/petstore/php-dt/src/App/DTO/Order.php index 835bebf66721..8e76c5f7ad6d 100644 --- a/samples/client/petstore/php-dt/src/App/DTO/Order.php +++ b/samples/client/petstore/php-dt/src/App/DTO/Order.php @@ -33,6 +33,7 @@ class Order /** * @DTA\Data(field="shipDate", nullable=true) + * @DTA\Validator(name="Scalar", options={"type":"\DateTime"}) * @DTA\Strategy(name="DateTime") * @DTA\Validator(name="Date", options={"format": \DateTime::RFC3339}) * @var \DateTime|null diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/FormatTest.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/FormatTest.md index 28f426d0cf89..2ce2f9dcb85a 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/FormatTest.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/FormatTest.md @@ -10,12 +10,12 @@ Name | Type | Description | Notes **number** | **float** | | **float** | **float** | | [optional] **double** | **double** | | [optional] -**decimal** | [**Decimal**](Decimal.md) | | [optional] +**decimal** | **float** | | [optional] **string** | **string** | | [optional] **byte** | **string** | | -**binary** | [**\SplFileObject**](\SplFileObject.md) | | [optional] -**date** | [**\DateTime**](\DateTime.md) | | -**date_time** | [**\DateTime**](\DateTime.md) | | [optional] +**binary** | **\SplFileObject** | | [optional] +**date** | **\DateTime** | | +**date_time** | **\DateTime** | | [optional] **uuid** | **string** | | [optional] **password** | **string** | | **pattern_with_digits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional] diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md index cdc5e7093de7..d86cc9fccce2 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **uuid** | **string** | | [optional] -**date_time** | [**\DateTime**](\DateTime.md) | | [optional] +**date_time** | **\DateTime** | | [optional] **map** | [**array**](Animal.md) | | [optional] [[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/NullableClass.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/NullableClass.md index 14cacbbd4d3a..83b78eaa8193 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/NullableClass.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/NullableClass.md @@ -8,8 +8,8 @@ Name | Type | Description | Notes **number_prop** | **float** | | [optional] **boolean_prop** | **bool** | | [optional] **string_prop** | **string** | | [optional] -**date_prop** | [**\DateTime**](\DateTime.md) | | [optional] -**datetime_prop** | [**\DateTime**](\DateTime.md) | | [optional] +**date_prop** | **\DateTime** | | [optional] +**datetime_prop** | **\DateTime** | | [optional] **array_nullable_prop** | **object[]** | | [optional] **array_and_items_nullable_prop** | **object[]** | | [optional] **array_items_nullable** | **object[]** | | [optional] diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/Order.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/Order.md index 14c7ef9fbe5b..c6ec90a33c1d 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Model/Order.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Model/Order.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **pet_id** | **int** | | [optional] **quantity** | **int** | | [optional] -**ship_date** | [**\DateTime**](\DateTime.md) | | [optional] +**ship_date** | **\DateTime** | | [optional] **status** | **string** | Order Status | [optional] **complete** | **bool** | | [optional] [default to false] diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php index deed199f79aa..420170543350 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php @@ -65,7 +65,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable 'number' => 'float', 'float' => 'float', 'double' => 'double', - 'decimal' => 'Decimal', + 'decimal' => 'float', 'string' => 'string', 'byte' => 'string', 'binary' => '\SplFileObject', @@ -554,7 +554,7 @@ public function setDouble($double) /** * Gets decimal * - * @return Decimal|null + * @return float|null */ public function getDecimal() { @@ -564,7 +564,7 @@ public function getDecimal() /** * Sets decimal * - * @param Decimal|null $decimal decimal + * @param float|null $decimal decimal * * @return self */ diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index c82083b1c991..69188fda3ecf 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -86,7 +86,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n foreach ($data::openAPITypes() as $property => $openAPIType) { $getter = $data::getters()[$property]; $value = $data->$getter(); - if ($value !== null && !in_array($openAPIType, ['DateTime', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + if ($value !== null && !in_array($openAPIType, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { $callable = [$openAPIType, 'getAllowableEnumValues']; if (is_callable($callable)) { /** array $callable */ @@ -330,7 +330,7 @@ public static function deserialize($data, $class, $httpHeaders = null) } /** @psalm-suppress ParadoxicalCondition */ - if (in_array($class, ['DateTime', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + if (in_array($class, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { settype($data, $class); return $data; } diff --git a/samples/server/petstore/php-laravel/lib/app/Models/FormatTest.php b/samples/server/petstore/php-laravel/lib/app/Models/FormatTest.php index 32e11e6c107f..c7dbd850eb6d 100644 --- a/samples/server/petstore/php-laravel/lib/app/Models/FormatTest.php +++ b/samples/server/petstore/php-laravel/lib/app/Models/FormatTest.php @@ -27,7 +27,7 @@ class FormatTest { /** @var double $double */ private $double; - /** @var Decimal $decimal */ + /** @var float $decimal */ private $decimal; /** @var string $string */ diff --git a/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php b/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php index 8dd384b4475d..3aba236fc409 100644 --- a/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php +++ b/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php @@ -23,6 +23,7 @@ class Order public int|null $quantity = null; #[DTA\Data(field: "shipDate", nullable: true)] + #[DTA\Validator("Scalar", ["type" => "\DateTime"])] #[DTA\Strategy("DateTime")] #[DTA\Validator("Date", ["format" => \DateTime::RFC3339])] public \DateTime|null $ship_date = null; diff --git a/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php b/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php index 835bebf66721..8e76c5f7ad6d 100644 --- a/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php +++ b/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php @@ -33,6 +33,7 @@ class Order /** * @DTA\Data(field="shipDate", nullable=true) + * @DTA\Validator(name="Scalar", options={"type":"\DateTime"}) * @DTA\Strategy(name="DateTime") * @DTA\Validator(name="Date", options={"format": \DateTime::RFC3339}) * @var \DateTime|null diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md index ee823c472c35..63a984cd357b 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md @@ -6,7 +6,7 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **petId** | **int** | | [optional] **quantity** | **int** | | [optional] -**shipDate** | [**\DateTime**](\DateTime.md) | | [optional] +**shipDate** | **\DateTime** | | [optional] **status** | **string** | Order Status | [optional] **complete** | **bool** | | [optional] [default to false] From a37a4d520f7b01548a75dd108014829d9ed65102 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Sep 2021 13:12:17 +0800 Subject: [PATCH 3/5] update tests --- .../test/java/org/openapitools/codegen/php/PhpModelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java index ca12192f2788..926d90732b7b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpModelTest.java @@ -76,7 +76,7 @@ public void simpleModelTest() { final CodegenProperty property3 = cm.vars.get(2); Assert.assertEquals(property3.baseName, "createdAt"); - Assert.assertEquals(property3.complexType, "\\DateTime"); + Assert.assertEquals(property3.complexType, null); Assert.assertEquals(property3.dataType, "\\DateTime"); Assert.assertEquals(property3.name, "created_at"); Assert.assertEquals(property3.defaultValue, null); From 7bb78473bb36cd165c56013251ae0aa83097d9b4 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Sep 2021 15:03:22 +0800 Subject: [PATCH 4/5] update doc, samples --- docs/generators/php-dt.md | 3 ++- docs/generators/php-laravel.md | 3 ++- docs/generators/php-lumen.md | 3 ++- docs/generators/php-mezzio-ph.md | 3 ++- docs/generators/php-slim-deprecated.md | 3 ++- docs/generators/php-slim4.md | 3 ++- docs/generators/php-symfony.md | 2 ++ docs/generators/php.md | 3 ++- .../petstore/haskell-servant/lib/OpenAPIPetstore/Types.hs | 1 + .../server/petstore/haskell-yesod/src/OpenAPIPetstore/Types.hs | 1 + 10 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/generators/php-dt.md b/docs/generators/php-dt.md index a61f3cd351c3..f92c7ca794a3 100644 --- a/docs/generators/php-dt.md +++ b/docs/generators/php-dt.md @@ -40,7 +40,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
    -
  • DateTime
  • +
  • \DateTime
  • +
  • \SplFileObject
  • array
  • bool
  • boolean
  • diff --git a/docs/generators/php-laravel.md b/docs/generators/php-laravel.md index b28504c1d02a..fa6717217adf 100644 --- a/docs/generators/php-laravel.md +++ b/docs/generators/php-laravel.md @@ -39,7 +39,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
      -
    • DateTime
    • +
    • \DateTime
    • +
    • \SplFileObject
    • array
    • bool
    • boolean
    • diff --git a/docs/generators/php-lumen.md b/docs/generators/php-lumen.md index 28f4810873d3..1c39477ad47b 100644 --- a/docs/generators/php-lumen.md +++ b/docs/generators/php-lumen.md @@ -39,7 +39,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
        -
      • DateTime
      • +
      • \DateTime
      • +
      • \SplFileObject
      • array
      • bool
      • boolean
      • diff --git a/docs/generators/php-mezzio-ph.md b/docs/generators/php-mezzio-ph.md index 8460e439084d..64266f6e2416 100644 --- a/docs/generators/php-mezzio-ph.md +++ b/docs/generators/php-mezzio-ph.md @@ -40,7 +40,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
          -
        • DateTime
        • +
        • \DateTime
        • +
        • \SplFileObject
        • array
        • bool
        • boolean
        • diff --git a/docs/generators/php-slim-deprecated.md b/docs/generators/php-slim-deprecated.md index 838b14ab7c3b..d6f8b35c7f21 100644 --- a/docs/generators/php-slim-deprecated.md +++ b/docs/generators/php-slim-deprecated.md @@ -39,7 +39,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
            -
          • DateTime
          • +
          • \DateTime
          • +
          • \SplFileObject
          • array
          • bool
          • boolean
          • diff --git a/docs/generators/php-slim4.md b/docs/generators/php-slim4.md index 5e0ec649254b..ae6cc1cb6569 100644 --- a/docs/generators/php-slim4.md +++ b/docs/generators/php-slim4.md @@ -40,7 +40,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
              -
            • DateTime
            • +
            • \DateTime
            • +
            • \SplFileObject
            • array
            • bool
            • boolean
            • diff --git a/docs/generators/php-symfony.md b/docs/generators/php-symfony.md index 03112d4ff8b4..4d268ab389ee 100644 --- a/docs/generators/php-symfony.md +++ b/docs/generators/php-symfony.md @@ -45,6 +45,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
                +
              • UploadedFile
              • +
              • \DateTime
              • array
              • bool
              • byte
              • diff --git a/docs/generators/php.md b/docs/generators/php.md index 8a99d592df2c..dcee69588f4b 100644 --- a/docs/generators/php.md +++ b/docs/generators/php.md @@ -40,7 +40,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
                  -
                • DateTime
                • +
                • \DateTime
                • +
                • \SplFileObject
                • array
                • bool
                • boolean
                • diff --git a/samples/server/petstore/haskell-servant/lib/OpenAPIPetstore/Types.hs b/samples/server/petstore/haskell-servant/lib/OpenAPIPetstore/Types.hs index af002e481c96..9bb39c771ab6 100644 --- a/samples/server/petstore/haskell-servant/lib/OpenAPIPetstore/Types.hs +++ b/samples/server/petstore/haskell-servant/lib/OpenAPIPetstore/Types.hs @@ -184,6 +184,7 @@ removeFieldLabelPrefix forParsing prefix = , (".", "'Period") , ("/", "'Slash") , (":", "'Colon") + , (";", "'Semicolon") , ("{", "'Left_Curly_Bracket") , ("|", "'Pipe") , ("<", "'LessThan") diff --git a/samples/server/petstore/haskell-yesod/src/OpenAPIPetstore/Types.hs b/samples/server/petstore/haskell-yesod/src/OpenAPIPetstore/Types.hs index 44a78e76afd0..1ba7c5d14872 100644 --- a/samples/server/petstore/haskell-yesod/src/OpenAPIPetstore/Types.hs +++ b/samples/server/petstore/haskell-yesod/src/OpenAPIPetstore/Types.hs @@ -154,6 +154,7 @@ removeFieldLabelPrefix forParsing prefix = , (".", "'Period") , ("/", "'Slash") , (":", "'Colon") + , (";", "'Semicolon") , ("{", "'Left_Curly_Bracket") , ("|", "'Pipe") , ("<", "'LessThan") From 6ed7568d71e7260501c37b6f7eef9705fba7165a Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 23 Sep 2021 16:43:17 +0800 Subject: [PATCH 5/5] remove primitive types from phpdt, mezzio --- docs/generators/php-dt.md | 2 -- docs/generators/php-mezzio-ph.md | 2 -- .../openapitools/codegen/languages/AbstractPhpCodegen.java | 4 ++++ .../codegen/languages/PhpDataTransferClientCodegen.java | 4 ++++ .../codegen/languages/PhpMezzioPathHandlerServerCodegen.java | 4 ++++ .../petstore/php-dt-modern/src/App/DTO/InlineObject1.php | 3 ++- samples/client/petstore/php-dt-modern/src/App/DTO/Order.php | 1 - samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php | 3 ++- samples/client/petstore/php-dt/src/App/DTO/Order.php | 1 - .../petstore/php-mezzio-ph-modern/src/App/DTO/Order.php | 1 - samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php | 1 - 11 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/generators/php-dt.md b/docs/generators/php-dt.md index f92c7ca794a3..6f9dae638045 100644 --- a/docs/generators/php-dt.md +++ b/docs/generators/php-dt.md @@ -40,8 +40,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
                    -
                  • \DateTime
                  • -
                  • \SplFileObject
                  • array
                  • bool
                  • boolean
                  • diff --git a/docs/generators/php-mezzio-ph.md b/docs/generators/php-mezzio-ph.md index 64266f6e2416..35bedda05f9f 100644 --- a/docs/generators/php-mezzio-ph.md +++ b/docs/generators/php-mezzio-ph.md @@ -40,8 +40,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES
                      -
                    • \DateTime
                    • -
                    • \SplFileObject
                    • array
                    • bool
                    • boolean
                    • diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index 9952c38656b2..077555a5743d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -355,11 +355,15 @@ public String getSchemaType(Schema p) { return type; } else if (instantiationTypes.containsKey(type)) { return type; + } + /* + // comment out the following as php-dt, php-mezzio still need to treat DateTime, SplFileObject as objects } else { throw new RuntimeException("OpenAPI type `" + openAPIType + "` defined but can't mapped to language type." + " Please report the issue via OpenAPI Generator github repo." + " (if you're not using custom format with proper type mappings provided to openapi-generator)"); } + */ } else { type = openAPIType; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpDataTransferClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpDataTransferClientCodegen.java index 38fc3332ee18..d50c1326958f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpDataTransferClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpDataTransferClientCodegen.java @@ -95,6 +95,10 @@ public PhpDataTransferClientCodegen() { //no point to use double - http://php.net/manual/en/language.types.float.php , especially because of PHP 7+ float type declaration typeMapping.put("double", "float"); + // remove these from primitive types to make the output works + languageSpecificPrimitives.remove("\\DateTime"); + languageSpecificPrimitives.remove("\\SplFileObject"); + apiTemplateFiles.clear(); apiTestTemplateFiles.clear(); apiDocTemplateFiles.clear(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpMezzioPathHandlerServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpMezzioPathHandlerServerCodegen.java index 529c5a27e217..06388626d4c2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpMezzioPathHandlerServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpMezzioPathHandlerServerCodegen.java @@ -87,6 +87,10 @@ public PhpMezzioPathHandlerServerCodegen() { //no point to use double - http://php.net/manual/en/language.types.float.php , especially because of PHP 7+ float type declaration typeMapping.put("double", "float"); + // remove these from primitive types to make the output works + languageSpecificPrimitives.remove("\\DateTime"); + languageSpecificPrimitives.remove("\\SplFileObject"); + embeddedTemplateDir = templateDir = "php-mezzio-ph"; invokerPackage = "App"; srcBasePath = "src" + File.separator + "App"; diff --git a/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php b/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php index b278bcf03f0f..791f4cf410b9 100644 --- a/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php +++ b/samples/client/petstore/php-dt-modern/src/App/DTO/InlineObject1.php @@ -18,7 +18,8 @@ class InlineObject1 * file to upload */ #[DTA\Data(field: "file", nullable: true)] - #[DTA\Validator("Scalar", ["type" => "\SplFileObject"])] + #[DTA\Strategy("Object", ["type" => \SplFileObject::class])] + #[DTA\Validator("TypeCompliant", ["type" => \SplFileObject::class])] public \SplFileObject|null $file = null; } diff --git a/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php b/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php index 3aba236fc409..8dd384b4475d 100644 --- a/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php +++ b/samples/client/petstore/php-dt-modern/src/App/DTO/Order.php @@ -23,7 +23,6 @@ class Order public int|null $quantity = null; #[DTA\Data(field: "shipDate", nullable: true)] - #[DTA\Validator("Scalar", ["type" => "\DateTime"])] #[DTA\Strategy("DateTime")] #[DTA\Validator("Date", ["format" => \DateTime::RFC3339])] public \DateTime|null $ship_date = null; diff --git a/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php b/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php index 3c883ca7a30b..611b567c40da 100644 --- a/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php +++ b/samples/client/petstore/php-dt/src/App/DTO/InlineObject1.php @@ -20,7 +20,8 @@ class InlineObject1 /** * file to upload * @DTA\Data(field="file", nullable=true) - * @DTA\Validator(name="Scalar", options={"type":"\SplFileObject"}) + * @DTA\Strategy(name="Object", options={"type":\SplFileObject::class}) + * @DTA\Validator(name="TypeCompliant", options={"type":\SplFileObject::class}) * @var \SplFileObject|null */ public $file; diff --git a/samples/client/petstore/php-dt/src/App/DTO/Order.php b/samples/client/petstore/php-dt/src/App/DTO/Order.php index 8e76c5f7ad6d..835bebf66721 100644 --- a/samples/client/petstore/php-dt/src/App/DTO/Order.php +++ b/samples/client/petstore/php-dt/src/App/DTO/Order.php @@ -33,7 +33,6 @@ class Order /** * @DTA\Data(field="shipDate", nullable=true) - * @DTA\Validator(name="Scalar", options={"type":"\DateTime"}) * @DTA\Strategy(name="DateTime") * @DTA\Validator(name="Date", options={"format": \DateTime::RFC3339}) * @var \DateTime|null diff --git a/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php b/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php index 3aba236fc409..8dd384b4475d 100644 --- a/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php +++ b/samples/server/petstore/php-mezzio-ph-modern/src/App/DTO/Order.php @@ -23,7 +23,6 @@ class Order public int|null $quantity = null; #[DTA\Data(field: "shipDate", nullable: true)] - #[DTA\Validator("Scalar", ["type" => "\DateTime"])] #[DTA\Strategy("DateTime")] #[DTA\Validator("Date", ["format" => \DateTime::RFC3339])] public \DateTime|null $ship_date = null; diff --git a/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php b/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php index 8e76c5f7ad6d..835bebf66721 100644 --- a/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php +++ b/samples/server/petstore/php-mezzio-ph/src/App/DTO/Order.php @@ -33,7 +33,6 @@ class Order /** * @DTA\Data(field="shipDate", nullable=true) - * @DTA\Validator(name="Scalar", options={"type":"\DateTime"}) * @DTA\Strategy(name="DateTime") * @DTA\Validator(name="Date", options={"format": \DateTime::RFC3339}) * @var \DateTime|null