Skip to content

Commit 7ae0845

Browse files
committed
Checking for style and explode parameter properties
1 parent f2a18b7 commit 7ae0845

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Source/OpenApiGen.V3.Analyzer.pas

+39
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,64 @@ function TOpenApiAnalyzer.BuildMetaMethod(Method: TMetaMethod; const Path: strin
159159
end;
160160

161161
procedure TOpenApiAnalyzer.BuildMetaParam(MetaParam: TMetaParam; Param: TParameter; const MethodName: string);
162+
163+
procedure DefineStyleAndExplode(DefaultStyle: TStyle; out Style: TStyle; out Explode: Boolean);
164+
begin
165+
if Param.Style.IsAssigned then
166+
Style := Param.Style
167+
else
168+
Style := DefaultStyle;
169+
if Param.Explode.IsAssigned then
170+
Explode := Param.Explode
171+
else
172+
Explode := Style = TStyle.Form;
173+
end;
174+
175+
var
176+
Style: TStyle;
177+
Explode: Boolean;
162178
begin
179+
if Param.Schema = nil then
180+
raise EOpenApiAnalyzerException.CreateFmt('%.%s: missing schema', [MethodName, Param.Name]);
181+
if Param.Content <> nil then
182+
raise EOpenApiAnalyzerException.CreateFmt('%.%s: content property not supported', [MethodName, Param.Name]);
183+
163184
MetaParam.RestName := Param.Name;
164185
MetaParam.CodeName := ProcessNaming(Param.Name, Options.ServiceOptions.ParamNaming);
165186
case Param.&In of
166187
Query:
167188
begin
189+
DefineStyleAndExplode(TStyle.Form, Style, Explode);
190+
if Style <> TStyle.Form then
191+
raise EOpenApiAnalyzerException.CreateFmt('%.%s: style not supported', [MethodName, Param.Name]);
192+
168193
MetaParam.ParamType := MetaTypeFromSchema(Param.Schema, MethodName + Param.Name, TListType.ltAuto);
169194
MetaParam.Location := TParamLocation.plQuery;
170195
end;
171196
Path:
172197
begin
198+
DefineStyleAndExplode(TStyle.Simple, Style, Explode);
199+
if Style <> TStyle.Simple then
200+
raise EOpenApiAnalyzerException.CreateFmt('%.%s: style not supported', [MethodName, Param.Name]);
201+
173202
MetaParam.ParamType := MetaTypeFromSchema(Param.Schema, MethodName + Param.Name, TListType.ltAuto);
174203
MetaParam.Location := TParamLocation.plUrl;
175204
end;
176205
Header:
177206
begin
207+
DefineStyleAndExplode(TStyle.Simple, Style, Explode);
208+
if Style <> TStyle.Simple then
209+
raise EOpenApiAnalyzerException.CreateFmt('%.%s: style not supported', [MethodName, Param.Name]);
210+
178211
MetaParam.ParamType := MetaTypeFromSchema(Param.Schema, MethodName + Param.Name, TListType.ltAuto);
179212
MetaParam.Location := TParamLocation.plHeader;
180213
end;
214+
// Cookie:
215+
// begin
216+
// DefineStyleAndExplode(TStyle.Form, Style, Explode);
217+
// MetaParam.ParamType := MetaTypeFromSchema(Param.Schema, MethodName + Param.Name, TListType.ltAuto);
218+
// MetaParam.Location := TParamLocation.plCookie;
219+
// end;
181220
else
182221
raise EOpenApiAnalyzerException.CreateFmt('Unsupported parameter type: %s', [GetEnumName(TypeInfo(TLocation), Ord(Param.&In))]);
183222
end;

0 commit comments

Comments
 (0)