Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Latest commit

 

History

History
187 lines (160 loc) · 7.59 KB

File metadata and controls

187 lines (160 loc) · 7.59 KB

petstore_api.paths.pet.operation

Operation Method Name

Method Name Api Class Notes
add_pet PetApi This api is only for tag=pet
post ApiForPost This api is only for this endpoint
post Pet This api is only for path=/pet

Table of Contents

General Info

Field Value
Summary Add a new pet to the store
Description Add a new pet to the store
Path "/pet"
HTTP Method post

Arguments

Name Type Description Notes
body typing.Union[pet.PetDictInput, pet.PetDict, pet.PetDictInput, pet.PetDict] required
content_type str optional, default is 'application/json' Selects the schema and serialization of the request body. value must be one of ['application/json', 'application/xml']
security_index typing.Optional[int] default is None Allows one to select a different security definition. If not None, must be one of [0, 1, 2]
server_index typing.Optional[int] default is None Allows one to select a different server. If not None, must be one of [0, 1, 2]
stream bool default is False if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout typing.Optional[typing.Union[int, typing.Tuple]] default is None the timeout used by the rest client
skip_deserialization bool default is False when True, headers and body will be unset and an instance of api_response.ApiResponseWithoutDeserialization will be returned

Return Types

HTTP Status Code Class Description
n/a api_response.ApiResponseWithoutDeserialization When skip_deserialization is True this response is returned
200 SuccessDescriptionOnly.ApiResponse Success
405 ResponseFor405.ApiResponse Invalid input

ResponseFor405

Description

Invalid input

ResponseFor405 ApiResponse

Name Type Description Notes
response urllib3.HTTPResponse Raw response
body Unset body was not defined
headers Unset headers were not defined

Security

Set auth info by setting ApiConfiguration.security_scheme_info to a dict where the key is the below security scheme quoted name, and the value is an instance of the linked component security scheme class. Select the security index by setting ApiConfiguration.security_index_info or by passing in security_index into the endpoint method. See how to do this in the code sample.

  • these securities are specific to this to this endpoint
Security Index Security Scheme to Scope Names
0 "api_key" []
1 "http_signature_test" []
2 "petstore_auth" [write:pets, read:pets]

Servers

Set the available servers by defining your used servers in ApiConfiguration.server_info Then select your server by setting a server index in ApiConfiguration.server_index_info or by passing server_index in to the endpoint method.

server_index Class Description
0 Server0 petstore server
1 Server1 The local server
2 Server2 staging server with no variables

Code Sample

import petstore_api
from petstore_api.configurations import api_configuration
from petstore_api.apis.tags import pet_api
from pprint import pprint
# security_index 0
from petstore_api.components.security_schemes import security_scheme_api_key
# security_index 1
from petstore_api.components.security_schemes import security_scheme_http_signature_test
# security_index 2
from petstore_api.components.security_schemes import security_scheme_petstore_auth

# security_scheme_info for security_index 0
security_scheme_info: api_configuration.SecuritySchemeInfo = {
    "api_key": security_scheme_api_key.ApiKey(
        api_key='sampleApiKeyValue'
    ),
}


# security_scheme_info for security_index 1
security_scheme_info: api_configuration.SecuritySchemeInfo = {
    "http_signature_test": security_scheme_http_signature_test.HttpSignatureTest(
        signing_info=petstore_api.signing.HttpSigningConfiguration(
            key_id='my-key-id',
            private_key_path='rsa.pem',
            signing_scheme=petstore_api.signing.SCHEME_HS2019,
            signing_algorithm=petstore_api.signing.ALGORITHM_RSASSA_PSS,
            signed_headers=[
                petstore_api.signing.HEADER_REQUEST_TARGET,
                petstore_api.signing.HEADER_CREATED,
                petstore_api.signing.HEADER_EXPIRES,
                petstore_api.signing.HEADER_HOST,
                petstore_api.signing.HEADER_DATE,
                petstore_api.signing.HEADER_DIGEST,
                'Content-Type',
                'User-Agent'
            ],
            signature_max_validity=datetime.timedelta(minutes=5)
        )

    ),
}


# security_scheme_info for security_index 2
security_scheme_info: api_configuration.SecuritySchemeInfo = {
    "petstore_auth": security_scheme_petstore_auth.PetstoreAuth(
    ),
}

security_index_info: api_configuration.SecurityIndexInfo = {
    "security": 0,  # default value
    "paths//pet/post/security": 0,
    # only set one "paths//pet/post/security": 1,
    # only set one "paths//pet/post/security": 2,
}
used_configuration = api_configuration.ApiConfiguration(
    security_scheme_info=security_scheme_info,
    security_index_info=security_index_info
)
# Enter a context with an instance of the API client
with petstore_api.ApiClient(used_configuration) as api_client:
    # Create an instance of the API class
    api_instance = pet_api.PetApi(api_client)

    # example passing only required values which don't have defaults set
    body = pet.Pet.validate({
        "id": 1,
        "category": category.Category.validate({
            "id": 1,
            "name": "default-name",
        }),
        "name": "doggie",
        "photo_urls": [
            "photo_urls_example"
        ],
        "tags": [
            tag.Tag.validate({
                "id": 1,
                "name": "name_example",
            })
        ],
        "status": "available",
    })
    try:
        # Add a new pet to the store
        api_response = api_instance.add_pet(
            body=body,
        )
        pprint(api_response)
    except petstore_api.ApiException as e:
        print("Exception when calling PetApi->add_pet: %s\n" % e)

[Back to top] [Back to PetApi API] [Back to Endpoints] [Back to README]