sailpoint-oss / python-sdk

MIT License
6 stars 3 forks source link

get_active_campaigns(): Unable to serialize unknown type: <class 'typing_extensions._LiteralGenericAlias'> #19

Closed scott-fehrman-sp closed 2 weeks ago

scott-fehrman-sp commented 4 months ago

Run: python3 test_CertificationCampaigns.py

from typing import List
import sailpoint.v3
import sailpoint.beta
import json
from sailpoint.configuration import Configuration
from pydantic import StrictStr

configuration = Configuration()

results: List[sailpoint.v3.GetActiveCampaigns200ResponseInner] = None
result: sailpoint.v3.GetActiveCampaigns200ResponseInner = None

with sailpoint.v3.ApiClient(configuration) as api_client:
    results = sailpoint.v3.CertificationCampaignsApi(api_client).get_active_campaigns() 
    result = results[0]
    data = result.model_dump_json(by_alias=True, indent=4) #ERROR
    print(data)

Output:

 Unable to serialize unknown type: <class 'typing_extensions._LiteralGenericAlias'>
   File "/Documents/Projects/Python/python-example/test_CertificationCampaigns.py", line 13, in <module>
     data = result.model_dump_json(by_alias=True, indent=4)
 pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'typing_extensions._LiteralGenericAlias'>
scott-fehrman-sp commented 3 weeks ago

Testing with version 1.1.8 ... getting a different error message:

Multiple matches found when deserializing the JSON string into GetActiveCampaigns200ResponseInner with oneOf schemas: Campaign, SlimCampaign.
tyler-mairose-sp commented 2 weeks ago

This one is fixed in https://github.com/sailpoint-oss/python-sdk/commit/4cb94f6e6840867ae7f872c1d4ffa812ba914ace and will be a part of the next release!

Here is an example code snippet that would function the same as yours above:

from typing import List
import sailpoint.v3
import sailpoint.beta
import json
from sailpoint.configuration import Configuration
from pydantic import StrictStr

configuration = Configuration()

results: List[sailpoint.v3.GetActiveCampaigns200ResponseInner] = None
result: sailpoint.v3.GetActiveCampaigns200ResponseInner = None

with sailpoint.v3.ApiClient(configuration) as api_client:
    results = sailpoint.v3.CertificationCampaignsApi(api_client).get_active_campaigns() 
    for campaign in results:
        instance = campaign.actual_instance

        str_camp = instance.model_dump_json(by_alias=True)
        json_camp = json.loads(str_camp)
        print(f"Json: {json.dumps(json_camp, indent=2)}")