forked from loafle/openapi-generator-original
add enum name mapping to ada codegen (#17299)
This commit is contained in:
parent
6a43a371f1
commit
2c9fbf81a7
@ -13,3 +13,5 @@ parameterNameMappings:
|
|||||||
additionalProperties:
|
additionalProperties:
|
||||||
modelPackage: Samples.Petstore
|
modelPackage: Samples.Petstore
|
||||||
projectName: Petstore
|
projectName: Petstore
|
||||||
|
enumNameMappings:
|
||||||
|
sold: UNAVAILABLE
|
||||||
|
@ -428,6 +428,10 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumVarName(String value, String datatype) {
|
public String toEnumVarName(String value, String datatype) {
|
||||||
|
if (enumNameMapping.containsKey(value)) {
|
||||||
|
return enumNameMapping.get(value);
|
||||||
|
}
|
||||||
|
|
||||||
String var;
|
String var;
|
||||||
if (value.isEmpty()) {
|
if (value.isEmpty()) {
|
||||||
var = "EMPTY";
|
var = "EMPTY";
|
||||||
|
@ -784,3 +784,13 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
type_:
|
type_:
|
||||||
type: string
|
type: string
|
||||||
|
AnotherStatus:
|
||||||
|
type: string
|
||||||
|
description: pet status in the store
|
||||||
|
deprecated: true
|
||||||
|
enum:
|
||||||
|
- available
|
||||||
|
- pending
|
||||||
|
- sold
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,75 @@ package body Samples.Petstore.Models is
|
|||||||
|
|
||||||
use Swagger.Streams;
|
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;
|
procedure Serialize (Into : in out Swagger.Streams.Output_Stream'Class;
|
||||||
Name : in String;
|
Name : in String;
|
||||||
Value : in Samples.Petstore.Models.ApiResponse_Type) is
|
Value : in Samples.Petstore.Models.ApiResponse_Type) is
|
||||||
|
@ -14,6 +14,32 @@ package Samples.Petstore.Models is
|
|||||||
pragma Style_Checks ("-bmrIu");
|
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
|
-- An uploaded response
|
||||||
-- Describes the result of uploading an image resource
|
-- Describes the result of uploading an image resource
|
||||||
|
Loading…
x
Reference in New Issue
Block a user