swagger
Utilities for parsing a swagger doc.
SwaggerModelAdditionalProperty
Bases: BaseModel
An additional property of a model (data structure) used in the API.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerModelProperty
Bases: BaseModel
A property of a model (data structure) used in the API.
This might also be referred to as a "field" or an "attribute" of the model.
See https://swagger.io/docs/specification/data-models/data-types/#objects
Source code in horde_sdk/generic_api/utils/swagger.py
format_
class-attribute
instance-attribute
additionalProperties
class-attribute
instance-attribute
SwaggerModelRef
Bases: BaseModel
A reference to a model (data structure) used in the API.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerModelEntry
Bases: BaseModel, ABC
An entry in the definitions section of the swagger doc.
This could be a model definition, or a schema validation method object.
See SwaggerModelDefinitionSchemaValidationMethods for more info.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerModelDefinition
Bases: SwaggerModelEntry
A definition of a model (data structure) used in the API.
Source code in horde_sdk/generic_api/utils/swagger.py
properties
class-attribute
instance-attribute
SwaggerSchemaValidationMethod
Bases: StrEnum
The type of schema validation method used in the Swagger doc.
Source code in horde_sdk/generic_api/utils/swagger.py
allOf
class-attribute
instance-attribute
The model must match all of the schemas in this list.
oneOf
class-attribute
instance-attribute
The model must match exactly one of the schemas in this list.
SwaggerModelDefinitionSchemaValidation
Bases: SwaggerModelEntry
When used instead of a SwaggerModelDefinition, it means that the model is validated against one or more schemas.
See the allOf, oneOf, and anyOf properties of the Swagger spec:
https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
Source code in horde_sdk/generic_api/utils/swagger.py
allOf
class-attribute
instance-attribute
The model must match all of the schemas in this list.
oneOf
class-attribute
instance-attribute
The model must match exactly one of the schemas in this list.
anyOf
class-attribute
instance-attribute
The model must match at least one of the schemas in this list.
validate_schema_validation_methods
Ensure that only one of the validation methods is specified.
Source code in horde_sdk/generic_api/utils/swagger.py
get_validation_method
Get the schema validation method used for this model.
Source code in horde_sdk/generic_api/utils/swagger.py
get_model_definitions
get_model_definitions() -> tuple[
SwaggerSchemaValidationMethod,
list[SwaggerModelDefinition | SwaggerModelRef],
]
Get the model definitions used for this model.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerDocTagsItem
Bases: BaseModel
A description of a tag in the swagger doc.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerDocResponseItem
Bases: BaseModel
A description of a response in the swagger doc.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerDocInfo
Bases: BaseModel
The info section of the swagger doc.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointMethodParameterSchemaRef
Bases: BaseModel
A schema definition of an endpoint method parameter that is a reference to another model.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointMethodParameterSchemaProperty
Bases: BaseModel
A property definition of an endpoint method parameter schema.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointMethodParameterSchema
Bases: BaseModel
A schema definition of an endpoint method parameter.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointMethodParameter
Bases: BaseModel
A parameter definition of an endpoint method.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointResponseSchemaItem
Bases: BaseModel
A response item definition pointing to a schema ("$ref").
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointResponseSchema
Bases: BaseModel
A response schema definition of an endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointResponse
Bases: BaseModel
A response definition of an endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpointMethod
Bases: BaseModel
A method definition of an endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
operation_id
class-attribute
instance-attribute
parameters
class-attribute
instance-attribute
responses
class-attribute
instance-attribute
SwaggerEndpointParameter
Bases: BaseModel
A parameter definition of an endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerEndpoint
Bases: BaseModel
An endpoint definition of the API.
Source code in horde_sdk/generic_api/utils/swagger.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
parameters
class-attribute
instance-attribute
get_endpoint_method_from_http_method
get_endpoint_method_from_http_method(
http_method: HTTPMethod | str,
) -> SwaggerEndpointMethod | None
Get the endpoint method for the given HTTP method.
Source code in horde_sdk/generic_api/utils/swagger.py
get_defined_endpoints
Get the endpoints that are specified in the swagger doc.
Source code in horde_sdk/generic_api/utils/swagger.py
get_all_request_models
Get all the request models for the endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
get_all_response_models
Get all the response models for the endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
at_least_one_method_specified
Ensure at least one method is specified.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerDoc
Bases: BaseModel
The swagger doc for an API, represented as an object.
Source code in horde_sdk/generic_api/utils/swagger.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | |
basePath
instance-attribute
The base path (after the top level domain) of the API. IE, /api.
paths
instance-attribute
The endpoints of the API. IE, /api/v2/generate/async.
produces
instance-attribute
The content types that the API can produce in responses.
consumes
instance-attribute
The content types that the API can consume in payloads.
tags
class-attribute
instance-attribute
Metadata about the document.
responses
class-attribute
instance-attribute
Unknown
definitions
instance-attribute
The definitions of the models (data structures) used in the API.
get_all_response_examples
get_all_response_examples() -> dict[
str,
dict[
HTTPMethod,
dict[
HTTPStatusCode,
dict[str, object] | list[Any],
],
],
]
Extract all response examples from the swagger doc.
This in the form of:
dict[endpoint_path, dict[http_method, dict[http_status_code, example_response]]]
Source code in horde_sdk/generic_api/utils/swagger.py
get_endpoint_examples
get_endpoint_examples(
endpoint: SwaggerEndpoint,
) -> dict[
HTTPMethod,
dict[HTTPStatusCode, dict[str, object] | list[Any]],
]
Extract response examples for a single endpoint.
Parameters:
-
endpoint(SwaggerEndpoint) –The SwaggerEndpoint object to extract response examples from.
Returns:
-
dict[HTTPMethod, dict[HTTPStatusCode, dict[str, object] | list[Any]]]–A dictionary of response examples for the endpoint in the form of:
-
dict[HTTPMethod, dict[HTTPStatusCode, dict[str, object] | list[Any]]]–dict[http_method, dict[http_status_code, example_response]]
Source code in horde_sdk/generic_api/utils/swagger.py
get_endpoint_method_examples
get_endpoint_method_examples(
endpoint_method_definition: SwaggerEndpointMethod,
) -> dict[HTTPStatusCode, dict[str, object] | list[Any]]
Extract response examples for a single HTTP method used by an endpoint.
Parameters:
-
endpoint_method_definition(SwaggerEndpointMethod) –The SwaggerEndpointMethod object to extract response examples from.
Returns:
-
dict[HTTPStatusCode, dict[str, object] | list[Any]]–A dictionary of response examples for the HTTP method in the form of:
-
dict[HTTPStatusCode, dict[str, object] | list[Any]]–dict[http_status_code, example_response]
Source code in horde_sdk/generic_api/utils/swagger.py
get_response_example
get_response_example(
response_definition: SwaggerEndpointResponse,
) -> dict[str, object] | list[Any]
Extract an example response for a single HTTP response definition.
Parameters:
-
response_definition(SwaggerEndpointResponse) –The SwaggerEndpointResponse object to extract an example response from.
Returns:
-
dict[str, object] | list[Any]–A dictionary or list representing an example response for the HTTP response definition.
Source code in horde_sdk/generic_api/utils/swagger.py
get_all_payload_examples
Extract all examples from the swagger doc.
This in the form of:
dict[endpoint_path, dict[param_name, param_example_value]]]
Source code in horde_sdk/generic_api/utils/swagger.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
filename_from_endpoint_path
staticmethod
filename_from_endpoint_path(
endpoint_path: str,
http_method: HTTPMethod,
*,
http_status_code: HTTPStatusCode | None = None
) -> str
Get the filename for the given endpoint path.
Parameters:
-
endpoint_path(str) –The path of the endpoint.
-
http_method(HTTPMethod) –The HTTP method used by the endpoint.
-
http_status_code(HTTPStatusCode | None, default:None) –The HTTP status code of the response (optional).
Returns:
-
str–A string representing the filename for the given endpoint path.
Source code in horde_sdk/generic_api/utils/swagger.py
get_all_verbs_for_endpoint
Get all HTTP methods defined for a given endpoint path.
Parameters:
-
endpoint_path(str) –The path of the endpoint.
Returns:
-
list[HTTPMethod]–A list of HTTPMethod objects representing the HTTP methods defined for the endpoint.
Source code in horde_sdk/generic_api/utils/swagger.py
write_all_payload_examples_to_file
Write all example payloads to a file in the test_data directory.
Parameters:
-
directory(str | Path) –The directory to write the files to.
Returns:
-
bool–A boolean indicating whether the operation succeeded.
Source code in horde_sdk/generic_api/utils/swagger.py
write_all_response_examples_to_file
write_all_response_examples_to_file(
directory: str | Path, *, error_responses: bool = False
) -> bool
Write all example responses to a file in the test_data directory.
Parameters:
-
directory(str | Path) –The directory to write the files to.
-
error_responses(bool, default:False) –Whether to include error responses. Defaults to False.
Returns:
-
bool–A boolean indicating whether the operation succeeded.
Source code in horde_sdk/generic_api/utils/swagger.py
get_default_with_constraint
get_default_with_constraint(
model_property: SwaggerModelProperty,
prop_name: str | None = None,
) -> object
Get the example value, defaulting to a a value appropriate to the type with any constraints applied.
Source code in horde_sdk/generic_api/utils/swagger.py
SwaggerParser
Parse a swagger doc from a URL or a local file.
Source code in horde_sdk/generic_api/utils/swagger.py
__init__
__init__(
*,
swagger_doc_url: str | None = None,
swagger_doc_path: str | Path | None = None
) -> None
Parse a swagger doc from a URL or a local file.
Parameters:
-
swagger_doc_url(str | None, default:None) –The URL of the Swagger doc to parse. Defaults to None.
-
swagger_doc_path(str | Path | None, default:None) –The path to the Swagger doc to parse. Defaults to None.
Raises:
-
RuntimeError–If the Swagger doc cannot be found or loaded.