mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 22:40:27 +02:00
* Allow to read YAML using new FPC support for YAML
This commit is contained in:
parent
4efdbd6cbb
commit
93a20edba4
@ -11,7 +11,7 @@ procedure register;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses MenuIntf, frmopenapiwizard, forms, controls, fpopenapi.reader, fpopenapi.objects, fpopenapi.codegen;
|
uses MenuIntf, frmopenapiwizard, forms, controls, fpopenapi.reader, fpopenapi.objects, fpopenapi.codegen, fpjson, fpyaml.parser, fpyaml.data, fpyaml.json;
|
||||||
|
|
||||||
Resourcestring
|
Resourcestring
|
||||||
SCMDOpenAPIWizard = 'ShowOpenAPICodeGenerator';
|
SCMDOpenAPIWizard = 'ShowOpenAPICodeGenerator';
|
||||||
@ -25,18 +25,49 @@ Type
|
|||||||
Function ResolveFullFileName(aKind : TUnitKind) : String;
|
Function ResolveFullFileName(aKind : TUnitKind) : String;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function GetJSONFromYAML(const aOpenAPIFile : string) : TJSONStringType;
|
||||||
|
|
||||||
|
var
|
||||||
|
lParser : TYAMLParser;
|
||||||
|
lYAML : TYAMLStream;
|
||||||
|
lJSON : TJSONData;
|
||||||
|
|
||||||
|
begin
|
||||||
|
lYAML:=Nil;
|
||||||
|
lJSON:=Nil;
|
||||||
|
lParser:=TYAMLParser.Create(aOpenAPIFile);
|
||||||
|
try
|
||||||
|
lYAML:=lParser.Parse;
|
||||||
|
lJSON:=YamlToJSON(lYAML);
|
||||||
|
Result:=lJSON.FormatJSON();
|
||||||
|
finally
|
||||||
|
lYAML.Free;
|
||||||
|
lJSON.Free;
|
||||||
|
lParser.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Procedure GenerateFiles(const aOpenAPIFile, aBaseOutputFile : string; aGenerator : TLazOpenAPICodeGen);
|
Procedure GenerateFiles(const aOpenAPIFile, aBaseOutputFile : string; aGenerator : TLazOpenAPICodeGen);
|
||||||
|
|
||||||
var
|
var
|
||||||
Loader : TOpenAPIReader;
|
Loader : TOpenAPIReader;
|
||||||
API : TOpenAPI;
|
API : TOpenAPI;
|
||||||
|
lJSON : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Loader:=Nil;
|
Loader:=Nil;
|
||||||
API:=TOpenAPI.Create;
|
API:=TOpenAPI.Create;
|
||||||
try
|
try
|
||||||
Loader:=TOpenAPIReader.Create(Nil);
|
Loader:=TOpenAPIReader.Create(Nil);
|
||||||
Loader.ReadFromFile(API,aOpenAPIFile);
|
if (ExtractFileExt(aOpenAPIFile)='.yaml') then
|
||||||
|
begin
|
||||||
|
lJSON:=GetJSONFromYAML(aOpenAPIFile);
|
||||||
|
Loader.ReadFromString(API,lJSON);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
// Assume JSON
|
||||||
|
Loader.ReadFromFile(API,aOpenAPIFile);
|
||||||
|
|
||||||
aGenerator.API:=API;
|
aGenerator.API:=API;
|
||||||
aGenerator.BaseOutputFileName:=aBaseOutputFile;
|
aGenerator.BaseOutputFileName:=aBaseOutputFile;
|
||||||
aGenerator.Execute;
|
aGenerator.Execute;
|
||||||
|
Loading…
Reference in New Issue
Block a user