mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 22:51:08 +02:00
* Corrections when writing file: write in 3.1 format
This commit is contained in:
parent
4888442fb4
commit
86da0baf02
@ -39,7 +39,8 @@ Type
|
|||||||
Procedure WriteProperty(const aName : TJSONStringType; aValue : TJSONSchemaVocabularyList);
|
Procedure WriteProperty(const aName : TJSONStringType; aValue : TJSONSchemaVocabularyList);
|
||||||
Procedure WriteProperty(const aName : TJSONStringType; aValue : TSchemaSimpleTypes);
|
Procedure WriteProperty(const aName : TJSONStringType; aValue : TSchemaSimpleTypes);
|
||||||
procedure WriteProperty(const aName: TJSONStringType; aValue: TJSONSchema);
|
procedure WriteProperty(const aName: TJSONStringType; aValue: TJSONSchema);
|
||||||
procedure WriteProperty(const aName: TJSONStringType; aValue: TJSONSchemaList);
|
procedure WriteListAsObject(const aName: TJSONStringType; aValue: TJSONSchemaList);
|
||||||
|
procedure WriteProperty(const aName: TJSONStringType; aValue: TJSONSchemaList; AllowAsObject: Boolean = False);
|
||||||
Procedure DoWriteSchema(aSchema : TJSONSchema);
|
Procedure DoWriteSchema(aSchema : TJSONSchema);
|
||||||
Public
|
Public
|
||||||
Procedure Writeschema(aSchema : TJSONSchema; aWriter : TAbstractJSONWriter);
|
Procedure Writeschema(aSchema : TJSONSchema; aWriter : TAbstractJSONWriter);
|
||||||
@ -79,20 +80,39 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSONSchemaWriter.WriteProperty(const aName: TJSONStringType; aValue: TJSONSchemaList);
|
procedure TJSONSchemaWriter.WriteListAsObject(const aName: TJSONStringType; aValue: TJSONSchemaList);
|
||||||
|
var
|
||||||
|
I : Integer;
|
||||||
|
begin
|
||||||
|
FWriter.StartProperty(aName);
|
||||||
|
FWriter.StartObject;
|
||||||
|
for I:=0 to aValue.Count-1 do
|
||||||
|
begin
|
||||||
|
FWriter.NextElement;
|
||||||
|
FWriter.StartProperty(aValue.Schemas[i].Name);
|
||||||
|
DoWriteSchema(aValue.Schemas[i]);
|
||||||
|
end;
|
||||||
|
FWriter.EndObject;
|
||||||
|
FWriter.EndProperty;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSONSchemaWriter.WriteProperty(const aName: TJSONStringType; aValue: TJSONSchemaList; AllowAsObject: Boolean);
|
||||||
|
|
||||||
var
|
var
|
||||||
I : Integer;
|
I : Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
FWriter.StartProperty(aName);
|
FWriter.StartProperty(aName);
|
||||||
FWriter.StartArray;
|
if AllowAsObject and (aValue.Count=1) then
|
||||||
for I:=0 to aValue.Count-1 do
|
DoWriteSchema(aValue.Schemas[0])
|
||||||
begin
|
else
|
||||||
FWriter.NextElement;
|
for I:=0 to aValue.Count-1 do
|
||||||
DoWriteSchema(aValue.Schemas[i]);
|
begin
|
||||||
end;
|
FWriter.StartArray;
|
||||||
FWriter.EndArray;
|
FWriter.NextElement;
|
||||||
|
DoWriteSchema(aValue.Schemas[i]);
|
||||||
|
FWriter.EndArray;
|
||||||
|
end;
|
||||||
FWriter.EndProperty;
|
FWriter.EndProperty;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -148,19 +168,32 @@ end;
|
|||||||
procedure TJSONSchemaWriter.WriteProperty(const aName: TJSONStringType; aValue: TSchemaSimpleTypes);
|
procedure TJSONSchemaWriter.WriteProperty(const aName: TJSONStringType; aValue: TSchemaSimpleTypes);
|
||||||
|
|
||||||
var
|
var
|
||||||
St : TSchemaSimpleType;
|
lCount : Integer;
|
||||||
|
St,stVal : TSchemaSimpleType;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
lCount:=0;
|
||||||
|
for St in TSchemaSimpleType do
|
||||||
|
if st in aValue then
|
||||||
|
begin
|
||||||
|
inc(lCount);
|
||||||
|
stVal:=St;
|
||||||
|
end;
|
||||||
With FWriter do
|
With FWriter do
|
||||||
begin
|
begin
|
||||||
StartProperty(aName);
|
StartProperty(aName);
|
||||||
StartArray;
|
if lCount=1 then
|
||||||
For ST in aValue do
|
WriteValue(stVal.AsString)
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
NextElement;
|
StartArray;
|
||||||
WriteValue(ST.AsString);
|
For ST in aValue do
|
||||||
|
begin
|
||||||
|
NextElement;
|
||||||
|
WriteValue(ST.AsString);
|
||||||
|
end;
|
||||||
|
EndArray;
|
||||||
end;
|
end;
|
||||||
EndArray;
|
|
||||||
EndProperty;
|
EndProperty;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -201,7 +234,7 @@ begin
|
|||||||
jskMinLength : W.WriteProperty(PropName,aSchema.Validations.MinLength);
|
jskMinLength : W.WriteProperty(PropName,aSchema.Validations.MinLength);
|
||||||
jskPattern : W.WriteProperty(PropName,aSchema.Validations.Pattern);
|
jskPattern : W.WriteProperty(PropName,aSchema.Validations.Pattern);
|
||||||
// jskAdditionalItems : WriteProperty(PropName,aSchema.Validations.AdditionalItems);
|
// jskAdditionalItems : WriteProperty(PropName,aSchema.Validations.AdditionalItems);
|
||||||
jskItems : WriteProperty(PropName,aSchema.Items);
|
jskItems : WriteProperty(PropName,aSchema.Items,true);
|
||||||
jskPrefixItems : WriteProperty(PropName,aSchema.PrefixItems);
|
jskPrefixItems : WriteProperty(PropName,aSchema.PrefixItems);
|
||||||
jskMaxItems : W.WriteProperty(PropName,aSchema.Validations.MaxItems);
|
jskMaxItems : W.WriteProperty(PropName,aSchema.Validations.MaxItems);
|
||||||
jskMinItems : W.WriteProperty(PropName,aSchema.Validations.MinItems);
|
jskMinItems : W.WriteProperty(PropName,aSchema.Validations.MinItems);
|
||||||
@ -212,7 +245,7 @@ begin
|
|||||||
jskMinContains : W.WriteProperty(PropName,aSchema.Validations.MinContains);
|
jskMinContains : W.WriteProperty(PropName,aSchema.Validations.MinContains);
|
||||||
jskRequired : W.WriteProperty(PropName,aSchema.Validations.Required);
|
jskRequired : W.WriteProperty(PropName,aSchema.Validations.Required);
|
||||||
jskAdditionalProperties : WriteProperty(PropName,aSchema.AdditionalProperties);
|
jskAdditionalProperties : WriteProperty(PropName,aSchema.AdditionalProperties);
|
||||||
jskProperties : WriteProperty(PropName,aSchema.Properties);
|
jskProperties : WriteListAsObject(PropName,aSchema.Properties);
|
||||||
jskPatternProperties: WriteProperty(PropName,aSchema.PatternProperties);
|
jskPatternProperties: WriteProperty(PropName,aSchema.PatternProperties);
|
||||||
jskPropertyNames : WriteProperty(PropName,aSchema.PropertyNames);
|
jskPropertyNames : WriteProperty(PropName,aSchema.PropertyNames);
|
||||||
jskDependentSchemas : WriteProperty(PropName,aSchema.DependentSchemas);
|
jskDependentSchemas : WriteProperty(PropName,aSchema.DependentSchemas);
|
||||||
|
Loading…
Reference in New Issue
Block a user