Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for vendor specific content types #1631

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added support for no-content responses in python abstractions and http packages. [#1630](https://github.com/microsoft/kiota/issues/1459)
- Added support for vendor-specific content types in python. [#1631](https://github.com/microsoft/kiota/issues/1463)

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
from io import BytesIO
from typing import Dict

Expand Down Expand Up @@ -36,9 +37,16 @@ def get_root_parse_node(self, content_type: str, content: BytesIO) -> ParseNode:
if not content:
raise Exception("Content cannot be null")

factory = self.CONTENT_TYPE_ASSOCIATED_FACTORIES.get(content_type)
vendor_specific_content_type = content_type.split(';')[0]
factory = self.CONTENT_TYPE_ASSOCIATED_FACTORIES.get(vendor_specific_content_type)
if factory:
return factory.get_root_parse_node(content_type, content)
return factory.get_root_parse_node(vendor_specific_content_type, content)

cleaned_content_type = re.sub(r'[^/]+\+', '', vendor_specific_content_type)
factory = self.CONTENT_TYPE_ASSOCIATED_FACTORIES.get(cleaned_content_type)
if factory:
return factory.get_root_parse_node(cleaned_content_type, content)

raise Exception(
f"Content type {content_type} does not have a factory registered to be parsed"
f"Content type {cleaned_content_type} does not have a factory registered to be parsed"
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict

from .serialization_writer import SerializationWriter
Expand Down Expand Up @@ -32,9 +33,16 @@ def get_serialization_writer(self, content_type: str) -> SerializationWriter:
if not content_type:
raise Exception("Content type cannot be null")

factory = self.CONTENT_TYPE_ASSOCIATED_FACTORIES.get(content_type)
vendor_specific_content_type = content_type.split(';')[0]
factory = self.CONTENT_TYPE_ASSOCIATED_FACTORIES.get(vendor_specific_content_type)
if factory:
return factory.get_serialization_writer(content_type)
return factory.get_serialization_writer(vendor_specific_content_type)
cleaned_content_type = re.sub(r'[^/]+\+', '', vendor_specific_content_type)

factory = self.CONTENT_TYPE_ASSOCIATED_FACTORIES.get(cleaned_content_type)
if factory:
return factory.get_serialization_writer(cleaned_content_type)
raise Exception(
f"Content type {content_type} does not have a factory registered to be serialized"
f"Content type {cleaned_content_type} does not have a factory registered"
"to be serialized"
)