1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-08-10 22:41:43 +02:00

Main build (Jenkins)

This commit is contained in:
Vitaly the Alpaca (bot)
2025-02-05 21:10:03 +03:00
parent 8c12fd89d9
commit 7962bb1d0e
10 changed files with 9530 additions and 9086 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,7 @@
// Uncomment if OneScript is executed
#Use "./internal"
#Use "../../data"
#Use asserts
#Region Internal
@@ -537,6 +538,12 @@ Function ExecuteTestCLI(Val Library, Val Method, Val Options, Val Record = True)
If Record Then
WriteCLICall(Library, Method, Options);
Try
WriteSwaggerPage(Library, Method, Options);
Except
Message("Swagger: " + ErrorDescription());
EndTry;
EndIf;
Try
@@ -2479,12 +2486,217 @@ Procedure WriteSwaggerPage(Val Library, Val Method, Val Options)
EndIf;
PagesCatalog = SwaggerCatalog();
LibraryCatalog = PagesCatalog + Library + "/";
MethodFile = LibraryCatalog + Method + ".json";
SimplestMethod = DefineSimplestHttpMethod(Options);
OintComposition = New("LibraryComposition");
LibraryComposition = OintComposition.GetComposition(Library);
MethodContent = LibraryComposition.FindRows(New Structure("Method", Method));
OptionsTable = New ValueTable;
OptionsTable.Columns.Add("Key");
OptionsTable.Columns.Add("Value");
OptionsTable.Columns.Add("Description");
For Each ContentString In MethodContent Do
NewLine = OptionsTable.Add();
NewLine.Key = StrReplace(ContentString.Parameter, "--", "");
NewLine.Description = ContentString.Description;
OPI_Tools.CollectionFieldExist(Options, NewLine.Option, NewLine.Value);
EndDo;
DescriptionStructure = New Structure;
If SimplestMethod = "GET" Then
DescriptionStructure.Insert("get", MakeDescriptionGet(OptionsTable));
EndIf;
NeedJSONVariant = SimplestMethod = "GET" Or SimplestMethod = "POST";
DescriptionStructure.Insert("post", MakeDescriptionPost(OptionsTable, NeedJSONVariant));
OPI_Tools.WriteJSONFile(DescriptionStructure, MethodFile);
EndProcedure
Function DefineSimplestHttpMethod(Val Options)
BinaryExist = False;
FindJSON = False;
For Each Option In Options Do
Value = Option.Value;
Key = Option.Key;
If Key = "out" Then
Continue;
EndIf;
If TypeOf(Value) = Type("BinaryData") Then
BinaryExist = True;
Break;
ElsIf TypeOf(Value) = Type("String") Then
ValueFile = New File(Value);
If ValueFile.Exist() And ValueFile.IsFile() Then
BinaryExist = True;
Break;
Else
OPI_TypeConversion.GetCollection(Value);
EndIf;
EndIf;
CurrentType = TypeOf(Value);
If CurrentType = Type("Map") Or CurrentType = Type("Structure") Then
FindJSON = True;
EndIf;
EndDo;
If Not BinaryExist And Not FindJSON Then
Method = "GET";
ElsIf Not BinaryExist Then
Method = "POST";
Else
Method = "FORM";
EndIf;
Return Method;
EndFunction
Function MakeDescriptionGet(Val OptionsTable)
DescriptionStructure = New Structure;
DescriptionStructure.Insert("summary", "Execution via GET method");
ParameterArray = New Array;
TypesMap = SwaggerTypesMap();
For Each Option In OptionsTable Do
Key = Option.Key;
Value = Option.Value;
Description = Option.Description;
ParameterStructure = New Structure;
ParameterStructure.Insert("name", Key);
ParameterStructure.Insert("in" , "query");
SwaggerType = TypesMap.Get(TypeOf(Value));
SwaggerType = ?(ValueIsFilled(SwaggerType), SwaggerType, TypesMap.Get(Type("String")));
ParameterStructure.Insert("schema" , SwaggerType);
ParameterStructure.Insert("description", Description);
ParameterArray.Add(ParameterStructure);
EndDo;
DescriptionStructure.Insert("parameters", ParameterArray);
Return DescriptionStructure;
EndFunction
Function MakeDescriptionPost(Val OptionsTable, Val NeedJSONVariant)
Description = "Execution via POST method (%1)";
Description = StrTemplate(Description, ?(NeedJSONVariant, "JSON or form-data", "form-data"));
DescriptionStructure = New Structure;
DescriptionStructure.Insert("summary", Description);
BodyStructure = New Structure;
BodyStructure.Insert("required", True);
BodyVariantsMap = MakeBodyVariants(OptionsTable, NeedJSONVariant);
BodyStructure.Insert("content", BodyVariantsMap);
DescriptionStructure.Insert("requestBody", BodyStructure);
Return DescriptionStructure;
EndFunction
Function MakeBodyVariants(Val OptionsTable, Val NeedJSONVariant)
TypesMap = SwaggerTypesMap();
BodyStructure = New Structure;
SchemeStructure = New Structure;
SchemeStructure.Insert("type", "object");
PropertiesStructure = New Structure;
For Each Option In OptionsTable Do
Key = Option.Key;
Value = Option.Value;
Description = Option.Description;
PropertyStructure = New Structure;
SwaggerType = TypesMap.Get(TypeOf(Value));
SwaggerType = ?(ValueIsFilled(SwaggerType), SwaggerType, TypesMap.Get(Type("String")));
PropertyStructure.Insert("type" , SwaggerType);
PropertyStructure.Insert("description", Description);
PropertiesStructure.Insert(Key, PropertyStructure);
EndDo;
SchemeStructure.Insert("properties", PropertiesStructure);
BodyStructure.Insert("schema", SchemeStructure);
VariantsMap = New Map;
VariantsMap.Insert("multipart/form-data", BodyStructure);
If NeedJSONVariant Then
VariantsMap.Insert("application/json", BodyStructure);
EndIf;
Return VariantsMap;
EndFunction
Function SwaggerTypesMap()
TypesMap = New Map;
TypesMap.Insert(Type("String") , New Structure("type" , "string"));
TypesMap.Insert(Type("Date") , New Structure("type,format", "string", "date-time"));
TypesMap.Insert(Type("Number") , New Structure("type" , "number"));
TypesMap.Insert(Type("Boolean") , New Structure("type" , "boolean"));
TypesMap.Insert(Type("Array") , New Structure("type,items" , "array" , New Structure("type","string")));
TypesMap.Insert(Type("Structure") , New Structure("type" , "object"));
TypesMap.Insert(Type("Map") , New Structure("type" , "object"));
TypesMap.Insert(Type("BinaryData"), New Structure("type" , "file"));
Return TypesMap;
EndFunction
Function SwaggerCatalog()
Return "./docs/ru/openapi/"
Return "./docs/ru/openapi/";
EndFunction
#EndRegion

View File

@@ -520,6 +520,16 @@ Function ReadJSONFile(Val Path) Export
EndFunction
Procedure WriteJSONFile(Data, Path) Export
JSONWriter = New JSONWriter;
JSONWriter.OpenFile(Path, , , New JSONWriterSettings(, Chars.Tab));
WriteJSON(JSONWriter, Data);
JSONWriter.Close();
EndProcedure
#EndRegion
#Region XML

View File

@@ -42,6 +42,7 @@
// Uncomment if OneScript is executed
// #Use "./internal"
// #Use "../../data"
// #Use asserts
#Region Internal
@@ -537,6 +538,12 @@ Function ExecuteTestCLI(Val Library, Val Method, Val Options, Val Record = True)
If Record Then
WriteCLICall(Library, Method, Options);
Try
WriteSwaggerPage(Library, Method, Options);
Except
Message("Swagger: " + ErrorDescription());
EndTry;
EndIf;
Try
@@ -2479,12 +2486,217 @@ Procedure WriteSwaggerPage(Val Library, Val Method, Val Options)
EndIf;
PagesCatalog = SwaggerCatalog();
LibraryCatalog = PagesCatalog + Library + "/";
MethodFile = LibraryCatalog + Method + ".json";
SimplestMethod = DefineSimplestHttpMethod(Options);
OintComposition = New("LibraryComposition");
LibraryComposition = OintComposition.GetComposition(Library);
MethodContent = LibraryComposition.FindRows(New Structure("Method", Method));
OptionsTable = New ValueTable;
OptionsTable.Columns.Add("Key");
OptionsTable.Columns.Add("Value");
OptionsTable.Columns.Add("Description");
For Each ContentString In MethodContent Do
NewLine = OptionsTable.Add();
NewLine.Key = StrReplace(ContentString.Parameter, "--", "");
NewLine.Description = ContentString.Description;
OPI_Tools.CollectionFieldExists(Options, NewLine.Option, NewLine.Value);
EndDo;
DescriptionStructure = New Structure;
If SimplestMethod = "GET" Then
DescriptionStructure.Insert("get", MakeDescriptionGet(OptionsTable));
EndIf;
NeedJSONVariant = SimplestMethod = "GET" Or SimplestMethod = "POST";
DescriptionStructure.Insert("post", MakeDescriptionPost(OptionsTable, NeedJSONVariant));
OPI_Tools.WriteJSONFile(DescriptionStructure, MethodFile);
EndProcedure
Function DefineSimplestHttpMethod(Val Options)
BinaryExists = False;
FindJSON = False;
For Each Option In Options Do
Value = Option.Value;
Key = Option.Key;
If Key = "out" Then
Continue;
EndIf;
If TypeOf(Value) = Type("BinaryData") Then
BinaryExists = True;
Break;
ElsIf TypeOf(Value) = Type("String") Then
ValueFile = New File(Value);
If ValueFile.Exists() And ValueFile.IsFile() Then
BinaryExists = True;
Break;
Else
OPI_TypeConversion.GetCollection(Value);
EndIf;
EndIf;
CurrentType = TypeOf(Value);
If CurrentType = Type("Map") Or CurrentType = Type("Structure") Then
FindJSON = True;
EndIf;
EndDo;
If Not BinaryExists And Not FindJSON Then
Method = "GET";
ElsIf Not BinaryExists Then
Method = "POST";
Else
Method = "FORM";
EndIf;
Return Method;
EndFunction
Function MakeDescriptionGet(Val OptionsTable)
DescriptionStructure = New Structure;
DescriptionStructure.Insert("summary", "Execution via GET method");
ParameterArray = New Array;
TypesMap = SwaggerTypesMap();
For Each Option In OptionsTable Do
Key = Option.Key;
Value = Option.Value;
Description = Option.Description;
ParameterStructure = New Structure;
ParameterStructure.Insert("name", Key);
ParameterStructure.Insert("in" , "query");
SwaggerType = TypesMap.Get(TypeOf(Value));
SwaggerType = ?(ValueIsFilled(SwaggerType), SwaggerType, TypesMap.Get(Type("String")));
ParameterStructure.Insert("schema" , SwaggerType);
ParameterStructure.Insert("description", Description);
ParameterArray.Add(ParameterStructure);
EndDo;
DescriptionStructure.Insert("parameters", ParameterArray);
Return DescriptionStructure;
EndFunction
Function MakeDescriptionPost(Val OptionsTable, Val NeedJSONVariant)
Description = "Execution via POST method (%1)";
Description = StrTemplate(Description, ?(NeedJSONVariant, "JSON or form-data", "form-data"));
DescriptionStructure = New Structure;
DescriptionStructure.Insert("summary", Description);
BodyStructure = New Structure;
BodyStructure.Insert("required", True);
BodyVariantsMap = MakeBodyVariants(OptionsTable, NeedJSONVariant);
BodyStructure.Insert("content", BodyVariantsMap);
DescriptionStructure.Insert("requestBody", BodyStructure);
Return DescriptionStructure;
EndFunction
Function MakeBodyVariants(Val OptionsTable, Val NeedJSONVariant)
TypesMap = SwaggerTypesMap();
BodyStructure = New Structure;
SchemeStructure = New Structure;
SchemeStructure.Insert("type", "object");
PropertiesStructure = New Structure;
For Each Option In OptionsTable Do
Key = Option.Key;
Value = Option.Value;
Description = Option.Description;
PropertyStructure = New Structure;
SwaggerType = TypesMap.Get(TypeOf(Value));
SwaggerType = ?(ValueIsFilled(SwaggerType), SwaggerType, TypesMap.Get(Type("String")));
PropertyStructure.Insert("type" , SwaggerType);
PropertyStructure.Insert("description", Description);
PropertiesStructure.Insert(Key, PropertyStructure);
EndDo;
SchemeStructure.Insert("properties", PropertiesStructure);
BodyStructure.Insert("schema", SchemeStructure);
VariantsMap = New Map;
VariantsMap.Insert("multipart/form-data", BodyStructure);
If NeedJSONVariant Then
VariantsMap.Insert("application/json", BodyStructure);
EndIf;
Return VariantsMap;
EndFunction
Function SwaggerTypesMap()
TypesMap = New Map;
TypesMap.Insert(Type("String") , New Structure("type" , "string"));
TypesMap.Insert(Type("Date") , New Structure("type,format", "string", "date-time"));
TypesMap.Insert(Type("Number") , New Structure("type" , "number"));
TypesMap.Insert(Type("Boolean") , New Structure("type" , "boolean"));
TypesMap.Insert(Type("Array") , New Structure("type,items" , "array" , New Structure("type","string")));
TypesMap.Insert(Type("Structure") , New Structure("type" , "object"));
TypesMap.Insert(Type("Map") , New Structure("type" , "object"));
TypesMap.Insert(Type("BinaryData"), New Structure("type" , "file"));
Return TypesMap;
EndFunction
Function SwaggerCatalog()
Return "./docs/ru/openapi/"
Return "./docs/ru/openapi/";
EndFunction
#EndRegion

View File

@@ -520,6 +520,16 @@ Function ReadJSONFile(Val Path) Export
EndFunction
Procedure WriteJSONFile(Data, Path) Export
JSONWriter = New JSONWriter;
JSONWriter.OpenFile(Path, , , New JSONWriterSettings(, Chars.Tab));
WriteJSON(JSONWriter, Data);
JSONWriter.Close();
EndProcedure
#EndRegion
#Region XML

View File

@@ -2682,14 +2682,14 @@
СоответствиеТипов = Новый Соответствие;
СоответствиеТипов.Вставить(Тип("Строка") , Новый Структура("type", "string"));
СоответствиеТипов.Вставить(Тип("Строка") , Новый Структура("type" , "string"));
СоответствиеТипов.Вставить(Тип("Дата") , Новый Структура("type,format", "string", "date-time"));
СоответствиеТипов.Вставить(Тип("Число") , Новый Структура("type", "number"));
СоответствиеТипов.Вставить(Тип("Булево") , Новый Структура("type", "boolean"));
СоответствиеТипов.Вставить(Тип("Массив") , Новый Структура("type,items", "array", Новый Структура("type","string")));
СоответствиеТипов.Вставить(Тип("Структура") , Новый Структура("type", "object"));
СоответствиеТипов.Вставить(Тип("Соответствие") , Новый Структура("type", "object"));
СоответствиеТипов.Вставить(Тип("ДвоичныеДанные"), Новый Структура("type", "file"));
СоответствиеТипов.Вставить(Тип("Число") , Новый Структура("type" , "number"));
СоответствиеТипов.Вставить(Тип("Булево") , Новый Структура("type" , "boolean"));
СоответствиеТипов.Вставить(Тип("Массив") , Новый Структура("type,items" , "array" , Новый Структура("type","string")));
СоответствиеТипов.Вставить(Тип("Структура") , Новый Структура("type" , "object"));
СоответствиеТипов.Вставить(Тип("Соответствие") , Новый Структура("type" , "object"));
СоответствиеТипов.Вставить(Тип("ДвоичныеДанные"), Новый Структура("type" , "file"));
Возврат СоответствиеТипов;

View File

@@ -2682,14 +2682,14 @@
СоответствиеТипов = Новый Соответствие;
СоответствиеТипов.Вставить(Тип("Строка") , Новый Структура("type", "string"));
СоответствиеТипов.Вставить(Тип("Строка") , Новый Структура("type" , "string"));
СоответствиеТипов.Вставить(Тип("Дата") , Новый Структура("type,format", "string", "date-time"));
СоответствиеТипов.Вставить(Тип("Число") , Новый Структура("type", "number"));
СоответствиеТипов.Вставить(Тип("Булево") , Новый Структура("type", "boolean"));
СоответствиеТипов.Вставить(Тип("Массив") , Новый Структура("type,items", "array", Новый Структура("type","string")));
СоответствиеТипов.Вставить(Тип("Структура") , Новый Структура("type", "object"));
СоответствиеТипов.Вставить(Тип("Соответствие") , Новый Структура("type", "object"));
СоответствиеТипов.Вставить(Тип("ДвоичныеДанные"), Новый Структура("type", "file"));
СоответствиеТипов.Вставить(Тип("Число") , Новый Структура("type" , "number"));
СоответствиеТипов.Вставить(Тип("Булево") , Новый Структура("type" , "boolean"));
СоответствиеТипов.Вставить(Тип("Массив") , Новый Структура("type,items" , "array" , Новый Структура("type","string")));
СоответствиеТипов.Вставить(Тип("Структура") , Новый Структура("type" , "object"));
СоответствиеТипов.Вставить(Тип("Соответствие") , Новый Структура("type" , "object"));
СоответствиеТипов.Вставить(Тип("ДвоичныеДанные"), Новый Структура("type" , "file"));
Возврат СоответствиеТипов;