Skip to content

Commit

Permalink
Added Swagger support for DMVCFramework nullable types. Fix #453
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoduarte19 committed Dec 29, 2020
1 parent 9c9edc2 commit 0f7c682
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion samples/swaggerdoc/MyController2U.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ interface
MVCFramework.Commons,
MVCFramework.Swagger.Commons,
MVCFramework.Serializer.Commons,
MVCFramework.Middleware.Authentication.RoleBasedAuthHandler;
MVCFramework.Middleware.Authentication.RoleBasedAuthHandler,
MVCFramework.Nullables;

type

Expand All @@ -18,10 +19,12 @@ TAddress = class
FStreet: string;
FNumber: Integer;
FCity: string;
FPostalCode: NullableString;
public
property Street: string read FStreet write FStreet;
property Number: Integer read FNumber write FNumber;
property City: string read FCity write FCity;
property PostalCode: NullableString read FPostalCode write FPostalCode;
end;

[MVCNameCase(ncLowerCase)]
Expand Down
31 changes: 31 additions & 0 deletions sources/MVCFramework.Swagger.Commons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ implementation
System.RegularExpressions,
System.TypInfo,
MVCFramework,
MVCFramework.Nullables,
MVCFramework.Serializer.Abstract,
MVCFramework.Serializer.Commons,
Swag.Doc.Path.Operation.Response,
Expand Down Expand Up @@ -638,6 +639,36 @@ class function TMVCSwagger.TypeKindToMVCSwagSchemaType(APropType: TRttiType): TM
begin
if APropType.Handle = TypeInfo(TGUID) then
Result := stGuid
else if APropType.Handle = TypeInfo(NullableString) then
Result := stString
else if APropType.Handle = TypeInfo(NullableCurrency) then
Result := stNumber
else if APropType.Handle = TypeInfo(NullableBoolean) then
Result := stBoolean
else if APropType.Handle = TypeInfo(NullableTDate) then
Result := stDate
else if APropType.Handle = TypeInfo(NullableTTime) then
Result := stTime
else if APropType.Handle = TypeInfo(NullableTDateTime) then
Result := stDateTime
else if APropType.Handle = TypeInfo(NullableSingle) then
Result := stNumber
else if APropType.Handle = TypeInfo(NullableDouble) then
Result := stNumber
else if APropType.Handle = TypeInfo(NullableExtended) then
Result := stNumber
else if APropType.Handle = TypeInfo(NullableInt16) then
Result := stInteger
else if APropType.Handle = TypeInfo(NullableUInt16) then
Result := stInteger
else if APropType.Handle = TypeInfo(NullableInt32) then
Result := stInteger
else if APropType.Handle = TypeInfo(NullableUInt32) then
Result := stInteger
else if APropType.Handle = TypeInfo(NullableInt64) then
Result := stInt64
else if APropType.Handle = TypeInfo(NullableUInt64) then
Result := stInt64;
end;
tkInteger:
Result := stInteger;
Expand Down

0 comments on commit 0f7c682

Please sign in to comment.