-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSwag.Doc.Info.pas
120 lines (99 loc) · 4.25 KB
/
Swag.Doc.Info.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{******************************************************************************}
{ }
{ Delphi SwagDoc Library }
{ Copyright (c) 2018 Marcelo Jaloto }
{ https://github.com/marcelojaloto/SwagDoc }
{ }
{******************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (the "License"); }
{ you may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at }
{ }
{ http://www.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{******************************************************************************}
unit Swag.Doc.Info;
interface
uses
System.JSON,
Swag.Doc.Info.License,
Swag.Doc.Info.Contact;
type
TSwagInfo = class(TObject)
private
fVersion: string;
fTitle: string;
fDescription: string;
fContact: TSwagInfoContact;
fTermsOfService: string;
fLicense: TSwagInfoLicense;
public
constructor Create; reintroduce;
destructor Destroy; override;
function GenerateJsonObject: TJSONObject;
procedure Load(pJson: TJSONObject);
property Version: string read fVersion write fVersion;
property Title: string read fTitle write fTitle;
property TermsOfService: string read fTermsOfService write fTermsOfService;
property Description: string read fDescription write fDescription;
property Contact: TSwagInfoContact read fContact write fContact;
property License: TSwagInfoLicense read fLicense;
end;
implementation
uses
System.SysUtils;
const
c_SwagInfoVersion = 'version';
c_SwagInfoTitle = 'title';
c_SwagInfoDescription = 'description';
c_SwagInfoContact = 'contact';
c_SwagInfoTermsOfService = 'termsOfService';
c_SwagLicense = 'license';
{ TSwagInfo }
procedure TSwagInfo.Load(pJson: TJSONObject);
begin
if Assigned(pJson.Values[c_SwagInfoVersion]) then
fVersion := pJson.Values[c_SwagInfoVersion].Value;
if Assigned(pJson.Values[c_SwagInfoTitle]) then
fTitle := pJson.Values[c_SwagInfoTitle].Value;
if Assigned(pJson.Values[c_SwagInfoDescription]) then
fDescription := pJson.Values[c_SwagInfoDescription].Value;
if Assigned(pJson.Values[c_SwagInfoTermsOfService]) then
FTermsOfService := pJson.Values[c_SwagInfoTermsOfService].Value;
if Assigned(pJson.Values[c_SwagInfoContact]) then
fContact.Load(pJson.Values[c_SwagInfoContact] as TJSONObject);
fLicense.Load((pJson as TJSONObject).Values[c_SwagLicense] as TJSONObject);
end;
constructor TSwagInfo.Create;
begin
inherited Create;
fContact := TSwagInfoContact.Create;
fLicense := TSwagInfoLicense.Create;
end;
destructor TSwagInfo.Destroy;
begin
FreeAndNil(fContact);
FreeAndNil(fLicense);
inherited Destroy;
end;
function TSwagInfo.GenerateJsonObject: TJSONObject;
begin
Result := TJsonObject.Create;
Result.AddPair(c_SwagInfoVersion, fVersion);
Result.AddPair(c_SwagInfoTitle, fTitle);
Result.AddPair(c_SwagInfoDescription, fDescription);
if not fTermsOfService.IsEmpty then
Result.AddPair(c_SwagInfoTermsOfService, fTermsOfService);
if not fContact.IsEmpty then
Result.AddPair(c_SwagInfoContact, fContact.GenerateJsonObject);
if not fLicense.isEmpty then
Result.AddPair(c_SwagLicense,fLicense.GenerateJsonObject);
end;
end.