@@ -349,6 +349,7 @@ class Schema {
349
349
350
350
Schema (SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) :
351
351
allocator_ (allocator),
352
+ uri_ (schemaDocument->GetURI (), *allocator),
352
353
pointer_(p),
353
354
typeless_(schemaDocument->GetTypeless ()),
354
355
enum_(),
@@ -597,6 +598,10 @@ class Schema {
597
598
#endif
598
599
}
599
600
601
+ const SValue& GetURI () const {
602
+ return uri_;
603
+ }
604
+
600
605
const PointerType& GetPointer () const {
601
606
return pointer_;
602
607
}
@@ -1220,6 +1225,7 @@ class Schema {
1220
1225
};
1221
1226
1222
1227
AllocatorType* allocator_;
1228
+ SValue uri_;
1223
1229
PointerType pointer_;
1224
1230
const SchemaType* typeless_;
1225
1231
uint64_t * enum_;
@@ -1330,6 +1336,7 @@ class GenericSchemaDocument {
1330
1336
typedef typename EncodingType::Ch Ch;
1331
1337
typedef internal::Schema<GenericSchemaDocument> SchemaType;
1332
1338
typedef GenericPointer<ValueType, Allocator> PointerType;
1339
+ typedef GenericValue<EncodingType, Allocator> URIType;
1333
1340
friend class internal ::Schema<GenericSchemaDocument>;
1334
1341
template <typename , typename , typename >
1335
1342
friend class GenericSchemaValidator ;
@@ -1339,10 +1346,13 @@ class GenericSchemaDocument {
1339
1346
Compile a JSON document into schema document.
1340
1347
1341
1348
\param document A JSON document as source.
1349
+ \param uri The base URI of this schema document for purposes of violation reporting.
1350
+ \param uriLength Length of \c name, in code points.
1342
1351
\param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null.
1343
1352
\param allocator An optional allocator instance for allocating memory. Can be null.
1344
1353
*/
1345
- explicit GenericSchemaDocument (const ValueType& document, IRemoteSchemaDocumentProviderType* remoteProvider = 0 , Allocator* allocator = 0 ) :
1354
+ explicit GenericSchemaDocument (const ValueType& document, const Ch* uri = 0 , SizeType uriLength = 0 ,
1355
+ IRemoteSchemaDocumentProviderType* remoteProvider = 0 , Allocator* allocator = 0 ) :
1346
1356
remoteProvider_(remoteProvider),
1347
1357
allocator_(allocator),
1348
1358
ownAllocator_(),
@@ -1354,8 +1364,11 @@ class GenericSchemaDocument {
1354
1364
if (!allocator_)
1355
1365
ownAllocator_ = allocator_ = RAPIDJSON_NEW (Allocator)();
1356
1366
1367
+ Ch noUri[1 ] = {0 };
1368
+ uri_.SetString (uri ? uri : noUri, uriLength, *allocator_);
1369
+
1357
1370
typeless_ = static_cast <SchemaType*>(allocator_->Malloc (sizeof (SchemaType)));
1358
- new (typeless_) SchemaType (this , PointerType (), ValueType (kObjectType ).Move (), ValueType (kObjectType ).Move (), 0 );
1371
+ new (typeless_) SchemaType (this , PointerType (), ValueType (kObjectType ).Move (), ValueType (kObjectType ).Move (), allocator_ );
1359
1372
1360
1373
// Generate root schema, it will call CreateSchema() to create sub-schemas,
1361
1374
// And call AddRefSchema() if there are $ref.
@@ -1393,7 +1406,8 @@ class GenericSchemaDocument {
1393
1406
root_(rhs.root_),
1394
1407
typeless_(rhs.typeless_),
1395
1408
schemaMap_(std::move(rhs.schemaMap_)),
1396
- schemaRef_(std::move(rhs.schemaRef_))
1409
+ schemaRef_(std::move(rhs.schemaRef_)),
1410
+ uri_(std::move(rhs.uri_))
1397
1411
{
1398
1412
rhs.remoteProvider_ = 0 ;
1399
1413
rhs.allocator_ = 0 ;
@@ -1415,6 +1429,8 @@ class GenericSchemaDocument {
1415
1429
RAPIDJSON_DELETE (ownAllocator_);
1416
1430
}
1417
1431
1432
+ const URIType& GetURI () const { return uri_; }
1433
+
1418
1434
// ! Get the root schema.
1419
1435
const SchemaType& GetRoot () const { return *root_; }
1420
1436
@@ -1545,6 +1561,7 @@ class GenericSchemaDocument {
1545
1561
SchemaType* typeless_;
1546
1562
internal::Stack<Allocator> schemaMap_; // Stores created Pointer -> Schemas
1547
1563
internal::Stack<Allocator> schemaRef_; // Stores Pointer from $ref and schema which holds the $ref
1564
+ URIType uri_;
1548
1565
};
1549
1566
1550
1567
// ! GenericSchemaDocument using Value type.
0 commit comments