diff --git a/bin/configs/ada.yaml b/bin/configs/ada.yaml index 176853b967c..39b9968d37f 100644 --- a/bin/configs/ada.yaml +++ b/bin/configs/ada.yaml @@ -13,3 +13,5 @@ parameterNameMappings: additionalProperties: modelPackage: Samples.Petstore projectName: Petstore +enumNameMappings: + sold: UNAVAILABLE diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java index 6411726d8c3..5087cf7240d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java @@ -428,6 +428,10 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg @Override public String toEnumVarName(String value, String datatype) { + if (enumNameMapping.containsKey(value)) { + return enumNameMapping.get(value); + } + String var; if (value.isEmpty()) { var = "EMPTY"; diff --git a/modules/openapi-generator/src/test/resources/3_0/ada/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/ada/petstore.yaml index 3137152533a..7e7b74ba418 100644 --- a/modules/openapi-generator/src/test/resources/3_0/ada/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/ada/petstore.yaml @@ -784,3 +784,13 @@ components: type: string type_: type: string + AnotherStatus: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + + diff --git a/samples/client/petstore/ada/src/model/samples-petstore-models.adb b/samples/client/petstore/ada/src/model/samples-petstore-models.adb index b8468b4f868..e8db8583586 100644 --- a/samples/client/petstore/ada/src/model/samples-petstore-models.adb +++ b/samples/client/petstore/ada/src/model/samples-petstore-models.adb @@ -15,6 +15,75 @@ package body Samples.Petstore.Models is use Swagger.Streams; + + function To_AnotherStatus_Type (Value : in String) return Samples.Petstore.Models.AnotherStatus_Type is + begin + if Value = "available" then + return AVAILABLE; + end if; + if Value = "pending" then + return PENDING; + end if; + if Value = "sold" then + return UNAVAILABLE; + end if; + raise Constraint_Error; + end To_AnotherStatus_Type; + + function To_String (Value : in Samples.Petstore.Models.AnotherStatus_Type) return String is + begin + case Value is + when AVAILABLE => + return "available"; + + when PENDING => + return "pending"; + + when UNAVAILABLE => + return "sold"; + + end case; + end To_String; + procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class; + Name : in String; + Value : in Samples.Petstore.Models.AnotherStatus_Type) is + begin + Into.Write_Entity (Name, To_String (Value)); end Serialize; + + procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class; + Name : in String; + Value : in AnotherStatus_Type_Vectors.Vector) is + begin + Into.Start_Array (Name); + for Item of Value loop + Serialize (Into, "", Item); + end loop; + Into.End_Array (Name); + end Serialize; + + procedure Deserialize (From : in Swagger.Value_Type; + Name : in String; + Value : out Samples.Petstore.Models.AnotherStatus_Type) is + Object : Swagger.Value_Type; + begin + Swagger.Streams.Deserialize (From, Name, Object); + Value := To_AnotherStatus_Type (Swagger.To_String (Object)); + end Deserialize; + + procedure Deserialize (From : in Swagger.Value_Type; + Name : in String; + Value : in out AnotherStatus_Type_Vectors.Vector) is + List : Swagger.Value_Array_Type; + Item : Samples.Petstore.Models.AnotherStatus_Type; + begin + Value.Clear; + Swagger.Streams.Deserialize (From, Name, List); + for Data of List loop + Deserialize (Data, "", Item); + Value.Append (Item); + end loop; + end Deserialize; + procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class; Name : in String; Value : in Samples.Petstore.Models.ApiResponse_Type) is diff --git a/samples/client/petstore/ada/src/model/samples-petstore-models.ads b/samples/client/petstore/ada/src/model/samples-petstore-models.ads index 2f299369bfb..af5399eac9c 100644 --- a/samples/client/petstore/ada/src/model/samples-petstore-models.ads +++ b/samples/client/petstore/ada/src/model/samples-petstore-models.ads @@ -14,6 +14,32 @@ package Samples.Petstore.Models is pragma Style_Checks ("-bmrIu"); + + type AnotherStatus_Type is (AVAILABLE,PENDING,UNAVAILABLE); + + function To_AnotherStatus_Type (Value : in String) return Samples.Petstore.Models.AnotherStatus_Type; + + function To_String (Value : in AnotherStatus_Type) return String; + + + package AnotherStatus_Type_Vectors is + new Ada.Containers.Vectors (Index_Type => Positive, + Element_Type => Samples.Petstore.Models.AnotherStatus_Type); + + procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class; + Name : in String; + Value : in Samples.Petstore.Models.AnotherStatus_Type); + procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class; + Name : in String; + Value : in AnotherStatus_Type_Vectors.Vector); + procedure Deserialize (From : in Swagger.Value_Type; + Name : in String; + Value : out Samples.Petstore.Models.AnotherStatus_Type); + procedure Deserialize (From : in Swagger.Value_Type; + Name : in String; + Value : in out AnotherStatus_Type_Vectors.Vector); + + -- ------------------------------ -- An uploaded response -- Describes the result of uploading an image resource