amati 0.1.1__py3-none-any.whl → 0.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.
@@ -28,7 +28,7 @@ from pydantic import (
28
28
  model_validator,
29
29
  )
30
30
 
31
- from amati import AmatiValueError, Reference
31
+ from amati import AmatiValueError
32
32
  from amati import model_validators as mv
33
33
  from amati.fields import (
34
34
  URI,
@@ -42,7 +42,7 @@ from amati.fields import (
42
42
  from amati.fields.commonmark import CommonMark
43
43
  from amati.fields.json import JSON
44
44
  from amati.fields.oas import OpenAPI, RuntimeExpression
45
- from amati.logging import Log, LogMixin
45
+ from amati.logging import LogMixin
46
46
  from amati.validators.generic import GenericObject, allow_extra_fields
47
47
 
48
48
  type JSONPrimitive = str | int | float | bool | None
@@ -67,10 +67,8 @@ class ContactObject(GenericObject):
67
67
  name: Optional[str] = None
68
68
  url: Optional[URI] = None
69
69
  email: Optional[Email] = None
70
- _reference: ClassVar[Reference] = Reference(
71
- title=TITLE,
72
- url="https://spec.openapis.org/oas/3.0.4.html#contact-object",
73
- section="Contact Object",
70
+ _reference_uri: ClassVar[str] = (
71
+ "https://spec.openapis.org/oas/3.0.4.html#contact-object"
74
72
  )
75
73
 
76
74
 
@@ -82,10 +80,8 @@ class LicenceObject(GenericObject):
82
80
 
83
81
  name: str = Field(min_length=1)
84
82
  url: Optional[URI] = None
85
- _reference: ClassVar[Reference] = Reference(
86
- title=TITLE,
87
- url="https://spec.openapis.org/oas/v3.0.4.html#license-object",
88
- section="License Object",
83
+ _reference_uri: ClassVar[str] = (
84
+ "https://spec.openapis.org/oas/v3.0.4.html#license-object"
89
85
  )
90
86
 
91
87
 
@@ -102,10 +98,8 @@ class ReferenceObject(GenericObject):
102
98
  model_config = ConfigDict(extra="forbid", populate_by_name=True)
103
99
 
104
100
  ref: URI = Field(alias="$ref")
105
- _reference: ClassVar[Reference] = Reference(
106
- title=TITLE,
107
- url="https://spec.openapis.org/oas/v3.0.4.html#reference-object",
108
- section="Reference Object",
101
+ _reference_uri: ClassVar[str] = (
102
+ "https://spec.openapis.org/oas/v3.0.4.html#reference-object"
109
103
  )
110
104
 
111
105
 
@@ -121,10 +115,8 @@ class InfoObject(GenericObject):
121
115
  contact: Optional[ContactObject] = None
122
116
  license: Optional[LicenceObject] = None
123
117
  version: str
124
- _reference: ClassVar[Reference] = Reference(
125
- title=TITLE,
126
- url="https://spec.openapis.org/oas/3.0.4.html#info-object",
127
- section="Info Object",
118
+ _reference_uri: ClassVar[str] = (
119
+ "https://spec.openapis.org/oas/3.0.4.html#info-object"
128
120
  )
129
121
 
130
122
 
@@ -138,10 +130,8 @@ class DiscriminatorObject(GenericObject):
138
130
  # properly.
139
131
  propertyName: str
140
132
  mapping: Optional[dict[str, str | URI]] = None
141
- _reference: ClassVar[Reference] = Reference(
142
- title=TITLE,
143
- url="https://spec.openapis.org/oas/v3.0.4.html#discriminator-object",
144
- section="Security Scheme Object",
133
+ _reference_uri: ClassVar[str] = (
134
+ "https://spec.openapis.org/oas/v3.0.4.html#discriminator-object"
145
135
  )
146
136
 
147
137
 
@@ -155,13 +145,13 @@ class ExampleObject(GenericObject):
155
145
  description: Optional[str | CommonMark] = None
156
146
  value: Optional[JSONValue] = None
157
147
  externalValue: Optional[URI] = None
158
- _reference: ClassVar[Reference] = Reference(
159
- title=TITLE,
160
- url="https://spec.openapis.org/oas/v3.0.4.html#example-object",
161
- section="Example Object",
148
+ _reference_uri: ClassVar[str] = (
149
+ "https://spec.openapis.org/oas/v3.0.4.html#example-object"
162
150
  )
163
151
 
164
- _not_value_and_external_value = mv.only_one_of(["value", "externalValue"])
152
+ _not_value_and_external_value = mv.only_one_of(
153
+ ["value", "externalValue"], "warning"
154
+ )
165
155
 
166
156
 
167
157
  @specification_extensions("x-")
@@ -173,10 +163,8 @@ class ServerVariableObject(GenericObject):
173
163
  enum: Optional[list[str]] = Field(None, min_length=1)
174
164
  default: str = Field(min_length=1)
175
165
  description: Optional[str | CommonMark] = None
176
- _reference: ClassVar[Reference] = Reference(
177
- title=TITLE,
178
- url="https://spec.openapis.org/oas/v3.0.4.html#server-variable-object",
179
- section="Server Variable Object",
166
+ _reference_uri: ClassVar[str] = (
167
+ "https://spec.openapis.org/oas/v3.0.4.html#server-variable-object"
180
168
  )
181
169
 
182
170
  @model_validator(mode="after")
@@ -192,11 +180,13 @@ class ServerVariableObject(GenericObject):
192
180
 
193
181
  if self.default not in self.enum:
194
182
  LogMixin.log(
195
- Log(
196
- message=f"The default value {self.default} is not in the enum list {self.enum}", # pylint: disable=line-too-long
197
- type=Warning,
198
- reference=self._reference,
199
- )
183
+ {
184
+ "msg": f"The default value {self.default} is not in the enum list {self.enum}", # pylint: disable=line-too-long
185
+ "type": "warning",
186
+ "loc": (self.__class__.__name__,),
187
+ "input": {"default": self.default, "enum": self.enum},
188
+ "url": self._reference_uri,
189
+ }
200
190
  )
201
191
 
202
192
  return self
@@ -211,10 +201,8 @@ class ServerObject(GenericObject):
211
201
  url: URIWithVariables | URI
212
202
  description: Optional[str | CommonMark] = None
213
203
  variables: Optional[dict[str, ServerVariableObject]] = None
214
- _reference: ClassVar[Reference] = Reference(
215
- title=TITLE,
216
- url="https://spec.openapis.org/oas/v3.0.4.html#server-object",
217
- section="Server Object",
204
+ _reference_uri: ClassVar[str] = (
205
+ "https://spec.openapis.org/oas/v3.0.4.html#server-object"
218
206
  )
219
207
 
220
208
 
@@ -226,10 +214,8 @@ class ExternalDocumentationObject(GenericObject):
226
214
 
227
215
  description: Optional[str | CommonMark] = None
228
216
  url: URI
229
- _reference: ClassVar[Reference] = Reference(
230
- title=TITLE,
231
- url="https://spec.openapis.org/oas/v3.0.4.html#external-documentation-object",
232
- section="External Documentation Object",
217
+ _reference_uri: ClassVar[str] = (
218
+ "https://spec.openapis.org/oas/v3.0.4.html#external-documentation-object"
233
219
  )
234
220
 
235
221
 
@@ -280,10 +266,8 @@ class OperationObject(GenericObject):
280
266
  security: Optional[list["SecurityRequirementObject"]] = None
281
267
  servers: Optional[list[ServerObject]] = None
282
268
 
283
- _reference: ClassVar[Reference] = Reference(
284
- title=TITLE,
285
- url="https://spec.openapis.org/oas/v3.0.4.html#operation-object",
286
- section="Operation Object",
269
+ _reference_uri: ClassVar[str] = (
270
+ "https://spec.openapis.org/oas/v3.0.4.html#operation-object"
287
271
  )
288
272
 
289
273
 
@@ -298,6 +282,7 @@ PARAMETER_STYLES: set[str] = {
298
282
  }
299
283
 
300
284
 
285
+ @specification_extensions("x-")
301
286
  class ParameterObject(GenericObject):
302
287
  """Validates the OpenAPI Specification parameter object - §4.8.11"""
303
288
 
@@ -314,6 +299,9 @@ class ParameterObject(GenericObject):
314
299
  example: Optional[Any] = None
315
300
  examples: Optional[dict[str, "ExampleObject | ReferenceObject"]] = None
316
301
  content: Optional[dict[str, "MediaTypeObject"]] = None
302
+ _reference_uri: ClassVar[str] = (
303
+ "https://spec.openapis.org/oas/v3.0.4.html#parameter-object"
304
+ )
317
305
 
318
306
  _in_valid = mv.if_then(
319
307
  conditions={"in_": mv.UNKNOWN},
@@ -357,10 +345,8 @@ class RequestBodyObject(GenericObject):
357
345
  description: Optional[CommonMark | str] = None
358
346
  content: dict[str, "MediaTypeObject"]
359
347
  required: Optional[bool] = False
360
- _reference: ClassVar[Reference] = Reference(
361
- title=TITLE,
362
- url="https://spec.openapis.org/oas/v3.0.4.html#request-body-object",
363
- section="Request Body Object",
348
+ _reference_uri: ClassVar[str] = (
349
+ "https://spec.openapis.org/oas/v3.0.4.html#request-body-object"
364
350
  )
365
351
 
366
352
 
@@ -377,10 +363,8 @@ class MediaTypeObject(GenericObject):
377
363
  example: Optional[Any] = None
378
364
  examples: Optional[dict[str, ExampleObject | ReferenceObject]] = None
379
365
  encoding: Optional["EncodingObject"] = None
380
- _reference: ClassVar[Reference] = Reference(
381
- title=TITLE,
382
- url="https://spec.openapis.org/oas/v3.0.4.html#media-type-object",
383
- section="Tag Object",
366
+ _reference_uri: ClassVar[str] = (
367
+ "https://spec.openapis.org/oas/v3.0.4.html#media-type-object"
384
368
  )
385
369
 
386
370
 
@@ -392,10 +376,8 @@ class EncodingObject(GenericObject):
392
376
 
393
377
  contentType: Optional[str] = None
394
378
  headers: Optional[dict[str, "HeaderObject | ReferenceObject"]] = None
395
- _reference: ClassVar[Reference] = Reference(
396
- title=TITLE,
397
- url="https://spec.openapis.org/oas/v3.0.4.html#encoding object-object",
398
- section="Encoding Object",
379
+ _reference_uri: ClassVar[str] = (
380
+ "https://spec.openapis.org/oas/v3.0.4.html#encoding object-object"
399
381
  )
400
382
 
401
383
  @field_validator("contentType", mode="after")
@@ -417,7 +399,7 @@ class EncodingObject(GenericObject):
417
399
  type _ResponsesObjectReturnType = dict[str, "ReferenceObject | ResponseObject"]
418
400
 
419
401
 
420
- @specification_extensions("x-")
402
+ @specification_extensions(".*")
421
403
  class ResponsesObject(GenericObject):
422
404
  """
423
405
  Validates the OpenAPI Specification responses object - §4.8.16
@@ -428,10 +410,8 @@ class ResponsesObject(GenericObject):
428
410
  )
429
411
 
430
412
  default: Optional["ResponseObject | ReferenceObject"] = None
431
- _reference: ClassVar[Reference] = Reference(
432
- title=TITLE,
433
- url="https://spec.openapis.org/oas/v3.0.4.html#responses-object",
434
- section="Responses Object",
413
+ _reference_uri: ClassVar[str] = (
414
+ "https://spec.openapis.org/oas/v3.0.4.html#responses-object"
435
415
  )
436
416
 
437
417
  @classmethod
@@ -456,7 +436,7 @@ class ResponsesObject(GenericObject):
456
436
  try:
457
437
  return ReferenceObject.model_validate(value)
458
438
  except ValidationError as e:
459
- raise ValueError(message, ResponsesObject._reference) from e
439
+ raise ValueError(message, ResponsesObject._reference_uri) from e
460
440
 
461
441
  @model_validator(mode="before")
462
442
  @classmethod
@@ -511,10 +491,8 @@ class ResponseObject(GenericObject):
511
491
  headers: Optional[dict[str, "HeaderObject | ReferenceObject"]] = None
512
492
  content: Optional[dict[str, MediaTypeObject]] = None
513
493
  links: Optional[dict[str, "LinkObject | ReferenceObject"]] = None
514
- _reference: ClassVar[Reference] = Reference(
515
- title=TITLE,
516
- url="https://spec.openapis.org/oas/v3.0.4.html#response-object",
517
- section="Response Object",
494
+ _reference_uri: ClassVar[str] = (
495
+ "https://spec.openapis.org/oas/v3.0.4.html#response-object"
518
496
  )
519
497
 
520
498
 
@@ -528,10 +506,8 @@ class CallbackObject(GenericObject):
528
506
 
529
507
  # The keys are runtime expressions that resolve to a URL
530
508
  # The values are Response Objects or Reference Objects
531
- _reference: ClassVar[Reference] = Reference(
532
- title=TITLE,
533
- url="https://spec.openapis.org/oas/v3.0.4.html#callback-object",
534
- section="Callback Object",
509
+ _reference_uri: ClassVar[str] = (
510
+ "https://spec.openapis.org/oas/v3.0.4.html#callback-object"
535
511
  )
536
512
 
537
513
  @model_validator(mode="before")
@@ -571,7 +547,7 @@ class CallbackObject(GenericObject):
571
547
  except AmatiValueError as e:
572
548
  raise AmatiValueError(
573
549
  f"Invalid runtime expression '{match}' in field '{field_name}'",
574
- CallbackObject._reference,
550
+ CallbackObject._reference_uri,
575
551
  ) from e
576
552
 
577
553
  if matches:
@@ -592,10 +568,8 @@ class TagObject(GenericObject):
592
568
  name: str
593
569
  description: Optional[str | CommonMark] = None
594
570
  externalDocs: Optional[ExternalDocumentationObject] = None
595
- _reference: ClassVar[Reference] = Reference(
596
- title=TITLE,
597
- url="https://spec.openapis.org/oas/v3.0.4.html#tag-object",
598
- section="Tag Object",
571
+ _reference_uri: ClassVar[str] = (
572
+ "https://spec.openapis.org/oas/v3.0.4.html#tag-object"
599
573
  )
600
574
 
601
575
 
@@ -611,10 +585,8 @@ class LinkObject(GenericObject):
611
585
  requestBody: Optional[JSONValue | RuntimeExpression] = None
612
586
  description: Optional[str | CommonMark] = None
613
587
  server: Optional[ServerObject] = None
614
- _reference: ClassVar[Reference] = Reference(
615
- title=TITLE,
616
- url="https://spec.openapis.org/oas/v3.0.4.html#link-object",
617
- section="Link Object",
588
+ _reference_uri: ClassVar[str] = (
589
+ "https://spec.openapis.org/oas/v3.0.4.html#link-object"
618
590
  )
619
591
 
620
592
  _not_operationref_and_operationid = mv.only_one_of(
@@ -645,10 +617,8 @@ class HeaderObject(GenericObject):
645
617
  # Content fields
646
618
  content: Optional[dict[str, MediaTypeObject]] = None
647
619
 
648
- _reference: ClassVar[Reference] = Reference(
649
- title=TITLE,
650
- url="https://spec.openapis.org/oas/v3.0.4.html#link-object",
651
- section="Link Object",
620
+ _reference_uri: ClassVar[str] = (
621
+ "https://spec.openapis.org/oas/v3.0.4.html#link-object"
652
622
  )
653
623
 
654
624
  _not_schema_and_content = mv.only_one_of(["schema_", "content"])
@@ -665,19 +635,26 @@ class XMLObject(GenericObject):
665
635
  prefix: Optional[str] = None
666
636
  attribute: Optional[bool] = Field(default=False)
667
637
  wrapped: Optional[bool] = None
668
- _reference: ClassVar[Reference] = Reference(
669
- title=TITLE,
670
- url="https://spec.openapis.org/oas/v3.0.4.html#xml-object",
671
- section="Security Scheme Object",
638
+ _reference_uri: ClassVar[str] = (
639
+ "https://spec.openapis.org/oas/v3.0.4.html#xml-object"
672
640
  )
673
641
 
674
642
  @field_validator("namespace", mode="after")
675
643
  @classmethod
676
644
  def _validate_namespace(cls, value: URI) -> URI:
645
+ """
646
+ Validates that the namespace is not a relative URI.
647
+ """
677
648
  if value.type == URIType.RELATIVE:
678
649
  message = "XML namespace {value} cannot be a relative URI"
679
650
  LogMixin.log(
680
- Log(message=message, type=ValueError, reference=cls._reference)
651
+ {
652
+ "msg": message,
653
+ "type": "value_error",
654
+ "loc": (cls.__name__,),
655
+ "input": value,
656
+ "url": cls._reference_uri,
657
+ }
681
658
  )
682
659
 
683
660
  return value
@@ -713,10 +690,8 @@ class SchemaObject(GenericObject):
713
690
  default=None, alias="$ref"
714
691
  ) # Reference to another schema
715
692
 
716
- _reference: ClassVar[Reference] = Reference(
717
- title=TITLE,
718
- url="https://spec.openapis.org/oas/v3.0.4.html#schema-object",
719
- section="Link Object",
693
+ _reference_uri: ClassVar[str] = (
694
+ "https://spec.openapis.org/oas/v3.0.4.html#schema-object"
720
695
  )
721
696
 
722
697
  @model_validator(mode="after")
@@ -752,11 +727,13 @@ class SchemaObject(GenericObject):
752
727
  validator_cls(meta_schema).validate(schema_dict) # type: ignore
753
728
  except JSONVSchemeValidationError as e:
754
729
  LogMixin.log(
755
- Log(
756
- message=f"Invalid JSON Schema: {e.message}",
757
- type=ValueError,
758
- reference=self._reference,
759
- )
730
+ {
731
+ "msg": f"Invalid JSON Schema: {e.message}",
732
+ "type": "value_error",
733
+ "loc": (self.__class__.__name__,),
734
+ "input": schema_dict,
735
+ "url": self._reference_uri,
736
+ }
760
737
  )
761
738
 
762
739
  return self
@@ -781,10 +758,8 @@ class OAuthFlowObject(GenericObject):
781
758
  tokenUrl: Optional[URI] = None
782
759
  refreshUrl: Optional[URI] = None
783
760
  scopes: dict[str, str] = {}
784
- _reference: ClassVar[Reference] = Reference(
785
- title=TITLE,
786
- url="https://spec.openapis.org/oas/v3.0.4.html#oauth-flow-object",
787
- section="OAuth Flow Object",
761
+ _reference_uri: ClassVar[str] = (
762
+ "https://spec.openapis.org/oas/v3.0.4.html#oauth-flow-object"
788
763
  )
789
764
 
790
765
  _implicit_has_authorization_url = mv.if_then(
@@ -829,10 +804,8 @@ class OAuthFlowsObject(GenericObject):
829
804
  password: Optional[OAuthFlowObject] = None
830
805
  clientCredentials: Optional[OAuthFlowObject] = None
831
806
  authorizationCode: Optional[OAuthFlowObject] = None
832
- _reference: ClassVar[Reference] = Reference(
833
- title=TITLE,
834
- url="https://spec.openapis.org/oas/v3.0.4.html#oauth-flow-object",
835
- section="OAuth Flows Object",
807
+ _reference_uri: ClassVar[str] = (
808
+ "https://spec.openapis.org/oas/v3.0.4.html#oauth-flow-object"
836
809
  )
837
810
 
838
811
  @model_validator(mode="before")
@@ -875,10 +848,8 @@ class SecuritySchemeObject(GenericObject):
875
848
  "openIdConnect",
876
849
  }
877
850
 
878
- _reference: ClassVar[Reference] = Reference(
879
- title=TITLE,
880
- url="https://spec.openapis.org/oas/v3.0.4.html#security-scheme-object-0",
881
- section="Security Scheme Object",
851
+ _reference_uri: ClassVar[str] = (
852
+ "https://spec.openapis.org/oas/v3.0.4.html#security-scheme-object-0"
882
853
  )
883
854
 
884
855
  _type_in_enum = mv.if_then(
@@ -922,10 +893,8 @@ class SecurityRequirementObject(RootModel[list[_Requirement] | _Requirement]):
922
893
  # FIXME If the security scheme is of type "oauth2" or "openIdConnect", then the
923
894
  # value must be a list For other security scheme types, the array MAY contain a
924
895
  # list of role names which are required for the execution
925
- _reference: ClassVar[Reference] = Reference(
926
- title=TITLE,
927
- url="https://spec.openapis.org/oas/3.0.4.html#security-requirement-object",
928
- section="Security Requirement Object",
896
+ _reference_uri: ClassVar[str] = (
897
+ "https://spec.openapis.org/oas/3.0.4.html#security-requirement-object"
929
898
  )
930
899
 
931
900
 
@@ -946,10 +915,8 @@ class PathItemObject(GenericObject):
946
915
  trace: Optional[OperationObject] = None
947
916
  servers: Optional[list[ServerObject]] = None
948
917
  parameters: Optional[list[ParameterObject | ReferenceObject]] = None
949
- _reference: ClassVar[Reference] = Reference(
950
- title=TITLE,
951
- url="https://spec.openapis.org/oas/v3.0.4.html#path-item-object",
952
- section="Path Item Object",
918
+ _reference_uri: ClassVar[str] = (
919
+ "https://spec.openapis.org/oas/v3.0.4.html#path-item-object"
953
920
  )
954
921
 
955
922
 
@@ -961,17 +928,15 @@ class ComponentsObject(GenericObject):
961
928
 
962
929
  schemas: Optional[dict[str, SchemaObject]] = None
963
930
  responses: Optional[dict[str, ResponseObject | ReferenceObject]] = None
964
- paremeters: Optional[dict[str, ParameterObject | ReferenceObject]] = None
931
+ parameters: Optional[dict[str, ParameterObject | ReferenceObject]] = None
965
932
  examples: Optional[dict[str, ExampleObject | ReferenceObject]] = None
966
933
  requestBodies: Optional[dict[str, RequestBodyObject | ReferenceObject]] = None
967
934
  headers: Optional[dict[str, HeaderObject | ReferenceObject]] = None
968
935
  securitySchemes: Optional[dict[str, SecuritySchemeObject | ReferenceObject]] = None
969
936
  links: Optional[dict[str, LinkObject | ReferenceObject]] = None
970
937
  callbacks: Optional[dict[str, CallbackObject | ReferenceObject]] = None
971
- _reference: ClassVar[Reference] = Reference(
972
- title=TITLE,
973
- url="https://spec.openapis.org/oas/v3.0.4.html#components-object",
974
- section="Components Object",
938
+ _reference_uri: ClassVar[str] = (
939
+ "https://spec.openapis.org/oas/v3.0.4.html#components-object"
975
940
  )
976
941
 
977
942
  @model_validator(mode="before")
@@ -1024,8 +989,6 @@ class OpenAPIObject(GenericObject):
1024
989
  security: Optional[list[SecurityRequirementObject]] = None
1025
990
  tags: Optional[list[TagObject]] = None
1026
991
  externalDocs: Optional[ExternalDocumentationObject] = None
1027
- _reference: ClassVar[Reference] = Reference(
1028
- title=TITLE,
1029
- url="https://spec.openapis.org/oas/3.0.4.html#openapi-object",
1030
- section="OpenAPI Object",
992
+ _reference_uri: ClassVar[str] = (
993
+ "https://spec.openapis.org/oas/3.0.4.html#openapi-object"
1031
994
  )