jsonstat-validator 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -300,7 +300,7 @@ class Dimension(JSONStatBaseModel):
300
300
  default=None,
301
301
  description=(
302
302
  "It is used to provide a list of links related to a dataset or a dimension, "
303
- "sorted by relation (see relation ID)."
303
+ "sorted by relation (see https://json-stat.org/full/#relationid)."
304
304
  ),
305
305
  )
306
306
  note: Optional[List[str]] = Field(
@@ -344,6 +344,113 @@ class Dimension(JSONStatBaseModel):
344
344
  return v
345
345
 
346
346
 
347
+ class DatasetDimension(JSONStatBaseModel):
348
+ """Dataset dimension.
349
+
350
+ A dimension model for when the dimension is a child of a Dataset
351
+ as it has different validation rules than a root Dimension.
352
+ """
353
+
354
+ version: Optional[str] = Field(
355
+ default=None,
356
+ description=(
357
+ "It declares the JSON-stat version of the response. The goal "
358
+ "of this property is to help clients parsing that particular response."
359
+ ),
360
+ )
361
+ class_: Optional[str] = Field(
362
+ default="dataset_dimension",
363
+ alias="class",
364
+ description=(
365
+ "JSON-stat supports several classes of responses. "
366
+ "Possible values of class are: dataset, dimension and collection. "
367
+ "This is an addition to the standard JSON-stat classes to allow for "
368
+ "different validation rules for dataset dimensions."
369
+ ),
370
+ exclude=True,
371
+ init=False,
372
+ frozen=True,
373
+ )
374
+ label: Optional[str] = Field(
375
+ default=None,
376
+ description=(
377
+ "It is used to assign a very short (one line) descriptive text to IDs "
378
+ "at different levels of the response tree. It is language-dependent."
379
+ ),
380
+ )
381
+ category: Optional[Category] = Field(
382
+ default=None,
383
+ description=(
384
+ "It is used to describe the possible values of a dimension. "
385
+ "It is language-dependent."
386
+ ),
387
+ )
388
+ href: Optional[AnyUrl] = Field(
389
+ default=None,
390
+ description=(
391
+ "It specifies a URL. Providers can use this property to avoid "
392
+ "sending information that is shared between different requests "
393
+ "(for example, dimensions)."
394
+ ),
395
+ )
396
+ link: Optional[Dict[str, List[Union[Link, JSONStatSchema]]]] = Field(
397
+ default=None,
398
+ description=(
399
+ "It is used to provide a list of links related to a dataset or a dimension, "
400
+ "sorted by relation (see https://json-stat.org/full/#relationid)."
401
+ ),
402
+ )
403
+ note: Optional[List[str]] = Field(
404
+ default=None,
405
+ description=(
406
+ "Note allows to assign annotations to datasets (array), dimensions (array) "
407
+ "and categories (object)."
408
+ ),
409
+ )
410
+ updated: Optional[str] = Field(
411
+ default=None,
412
+ description=(
413
+ "It contains the update time of the dataset. It is a string representing "
414
+ "a date in an ISO 8601 format recognized by the Javascript Date.parse "
415
+ "method (see ECMA-262 Date Time String Format: "
416
+ "https://262.ecma-international.org/6.0/#sec-date-time-string-format)."
417
+ ),
418
+ )
419
+ source: Optional[str] = Field(
420
+ default=None,
421
+ description=(
422
+ "It contains a language-dependent short text describing the source "
423
+ "of the dataset."
424
+ ),
425
+ )
426
+ extension: Optional[Dict[str, Any]] = Field(
427
+ default=None,
428
+ description=(
429
+ "Extension allows JSON-stat to be extended for particular needs. "
430
+ "Providers are free to define where they include this property and "
431
+ "what children are allowed in each case."
432
+ ),
433
+ )
434
+
435
+ @field_validator("updated", mode="after")
436
+ @classmethod
437
+ def validate_updated_date(cls, v: Optional[str]):
438
+ """Validates the updated date is in ISO 8601 format."""
439
+ if v and not is_valid_iso_date(v):
440
+ raise ValueError(f"Updated date: '{v}' is an invalid ISO 8601 format.")
441
+ return v
442
+
443
+ @model_validator(mode="after")
444
+ def validate_dataset_dimension(self):
445
+ """Dataset dimension-wide validation checks."""
446
+ if not self.category and not self.href:
447
+ raise ValueError(
448
+ "A category is required if a reference (href) is not provided."
449
+ "For an example, see: https://json-stat.org/full/#href"
450
+ )
451
+ return self
452
+
453
+
347
454
  class DatasetRole(JSONStatBaseModel):
348
455
  """Role of a dataset."""
349
456
 
@@ -372,6 +479,13 @@ class DatasetRole(JSONStatBaseModel):
372
479
  ),
373
480
  )
374
481
 
482
+ @model_validator(mode="after")
483
+ def validate_dataset_role(self):
484
+ """Dataset role-wide validation checks."""
485
+ if not self.time and not self.geo and not self.metric:
486
+ raise ValueError("At least one role must be provided.")
487
+ return self
488
+
375
489
 
376
490
  class Dataset(JSONStatBaseModel):
377
491
  """JSON-stat dataset."""
@@ -430,12 +544,13 @@ class Dataset(JSONStatBaseModel):
430
544
  "and in the same order as in id."
431
545
  ),
432
546
  )
433
- role: Optional[DatasetRole] = Field(
547
+ role: DatasetRole = Field(
434
548
  default=None,
435
549
  description=(
436
550
  "It can be used to assign special roles to dimensions. "
437
551
  "At this moment, possible roles are: time, geo and metric. "
438
552
  "A role can be shared by several dimensions."
553
+ "We differ from the specification in that the role is required, not optional"
439
554
  ),
440
555
  )
441
556
  value: Union[
@@ -457,10 +572,11 @@ class Dataset(JSONStatBaseModel):
457
572
  ),
458
573
  )
459
574
 
460
- dimension: Dict[str, Dimension] = Field(
575
+ dimension: Dict[str, DatasetDimension] = Field(
461
576
  description=(
462
577
  "The dimension property contains information about the dimensions of "
463
- "the dataset. dimension must have properties (see dimension ID) with "
578
+ "the dataset. dimension must have properties "
579
+ "(see https://json-stat.org/full/#dimensionid) with "
464
580
  "the same names of each element in the id array."
465
581
  ),
466
582
  )
@@ -483,7 +599,7 @@ class Dataset(JSONStatBaseModel):
483
599
  default=None,
484
600
  description=(
485
601
  "It is used to provide a list of links related to a dataset or a dimension, "
486
- "sorted by relation (see relation ID)."
602
+ "sorted by relation (see https://json-stat.org/full/#relationid)."
487
603
  ),
488
604
  )
489
605
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jsonstat-validator
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
5
5
  Author-email: Ahmed Hassan <ahmedhassan.ahmed@fao.org>
6
6
  License: # MIT License
@@ -0,0 +1,7 @@
1
+ jsonstat_validator/__init__.py,sha256=hvsaEgQFH8vY_bPRDyrhroxjJd1c5nFjmZQ_lxzH0AQ,806
2
+ jsonstat_validator/validator.py,sha256=fhbJBfxq1xsTSuVJ2qBql1p_Y14-yOAgsOLEbubEMQM,27669
3
+ jsonstat_validator-0.1.2.dist-info/LICENSE,sha256=cyCvx3tHW8u9ZWGkTMrCKaB2ft4RonlMBVOEHDa2tEk,1091
4
+ jsonstat_validator-0.1.2.dist-info/METADATA,sha256=0PhHVXIpimgPc9-IeaKT4kittcAjydvczeIM7oZgV_M,7259
5
+ jsonstat_validator-0.1.2.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
6
+ jsonstat_validator-0.1.2.dist-info/top_level.txt,sha256=l6xoMFlWGRRbXMxl4MG-q0FA3In7rYZLBzVF8W7IhdU,19
7
+ jsonstat_validator-0.1.2.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- jsonstat_validator/__init__.py,sha256=hvsaEgQFH8vY_bPRDyrhroxjJd1c5nFjmZQ_lxzH0AQ,806
2
- jsonstat_validator/validator.py,sha256=X9UmAp1R_h1xisAHdls_wh4l99z5Uqk23P008ZPrbM0,23284
3
- jsonstat_validator-0.1.1.dist-info/LICENSE,sha256=cyCvx3tHW8u9ZWGkTMrCKaB2ft4RonlMBVOEHDa2tEk,1091
4
- jsonstat_validator-0.1.1.dist-info/METADATA,sha256=8Zz-W22W3NRA2opmKUvlxViByUCSvfwIiCk5j7-5AWE,7259
5
- jsonstat_validator-0.1.1.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
6
- jsonstat_validator-0.1.1.dist-info/top_level.txt,sha256=l6xoMFlWGRRbXMxl4MG-q0FA3In7rYZLBzVF8W7IhdU,19
7
- jsonstat_validator-0.1.1.dist-info/RECORD,,