Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit 2324482

Browse files
committed
feat: Enhance ConfluenceParameters model with additional confluence_kwargs field and clean up API generation script
1 parent d725fb2 commit 2324482

File tree

3 files changed

+70
-87
lines changed

3 files changed

+70
-87
lines changed

admin-api-lib/src/admin_api_lib/extractor_api_client/openapi_client/models/confluence_parameters.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,23 @@
2020
from typing import Any, ClassVar, Dict, List, Optional, Set
2121

2222
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
23+
from typing import Any, ClassVar, Dict, List, Optional
24+
from admin_api_lib.extractor_api_client.openapi_client.models.key_value_pair import KeyValuePair
25+
from typing import Optional, Set
2326
from typing_extensions import Self
2427

25-
2628
class ConfluenceParameters(BaseModel):
2729
""" """ # noqa: E501
2830

2931
url: StrictStr = Field(description="url of the confluence space.")
3032
token: StrictStr = Field(description="api key to access confluence.")
3133
space_key: StrictStr = Field(description="the space key of the confluence pages.")
32-
include_attachments: Optional[StrictBool] = Field(
33-
default=False,
34-
description="whether to include file attachments (e.g., images, documents) in the parsed content. Default is `false`.",
35-
)
36-
keep_markdown_format: Optional[StrictBool] = Field(
37-
default=True, description="whether to preserve markdown formatting in the output. Default is `true`."
38-
)
39-
keep_newlines: Optional[StrictBool] = Field(
40-
default=True,
41-
description="whether to retain newline characters in the output for better readability. Default is `true`.",
42-
)
43-
document_name: StrictStr = Field(
44-
description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document)."
45-
)
46-
__properties: ClassVar[List[str]] = [
47-
"url",
48-
"token",
49-
"space_key",
50-
"include_attachments",
51-
"keep_markdown_format",
52-
"keep_newlines",
53-
"document_name",
54-
]
34+
include_attachments: Optional[StrictBool] = Field(default=False, description="whether to include file attachments (e.g., images, documents) in the parsed content. Default is `false`.")
35+
keep_markdown_format: Optional[StrictBool] = Field(default=True, description="whether to preserve markdown formatting in the output. Default is `true`.")
36+
keep_newlines: Optional[StrictBool] = Field(default=True, description="whether to retain newline characters in the output for better readability. Default is `true`.")
37+
document_name: StrictStr = Field(description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document).")
38+
confluence_kwargs: Optional[List[KeyValuePair]] = Field(default=None, description="Additional kwargs like verify_ssl")
39+
__properties: ClassVar[List[str]] = ["url", "token", "space_key", "include_attachments", "keep_markdown_format", "keep_newlines", "document_name", "confluence_kwargs"]
5540

5641
model_config = ConfigDict(
5742
populate_by_name=True,
@@ -89,6 +74,13 @@ def to_dict(self) -> Dict[str, Any]:
8974
exclude=excluded_fields,
9075
exclude_none=True,
9176
)
77+
# override the default output from pydantic by calling `to_dict()` of each item in confluence_kwargs (list)
78+
_items = []
79+
if self.confluence_kwargs:
80+
for _item_confluence_kwargs in self.confluence_kwargs:
81+
if _item_confluence_kwargs:
82+
_items.append(_item_confluence_kwargs.to_dict())
83+
_dict['confluence_kwargs'] = _items
9284
return _dict
9385

9486
@classmethod
@@ -100,19 +92,16 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
10092
if not isinstance(obj, dict):
10193
return cls.model_validate(obj)
10294

103-
_obj = cls.model_validate(
104-
{
105-
"url": obj.get("url"),
106-
"token": obj.get("token"),
107-
"space_key": obj.get("space_key"),
108-
"include_attachments": obj.get("include_attachments")
109-
if obj.get("include_attachments") is not None
110-
else False,
111-
"keep_markdown_format": obj.get("keep_markdown_format")
112-
if obj.get("keep_markdown_format") is not None
113-
else True,
114-
"keep_newlines": obj.get("keep_newlines") if obj.get("keep_newlines") is not None else True,
115-
"document_name": obj.get("document_name"),
116-
}
117-
)
95+
_obj = cls.model_validate({
96+
"url": obj.get("url"),
97+
"token": obj.get("token"),
98+
"space_key": obj.get("space_key"),
99+
"include_attachments": obj.get("include_attachments") if obj.get("include_attachments") is not None else False,
100+
"keep_markdown_format": obj.get("keep_markdown_format") if obj.get("keep_markdown_format") is not None else True,
101+
"keep_newlines": obj.get("keep_newlines") if obj.get("keep_newlines") is not None else True,
102+
"document_name": obj.get("document_name"),
103+
"confluence_kwargs": [KeyValuePair.from_dict(_item) for _item in obj["confluence_kwargs"]] if obj.get("confluence_kwargs") is not None else None
104+
})
118105
return _obj
106+
107+

api-generator.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ case $api_name in
3232
;;
3333
"extractor-api-lib")
3434
docker run --user $(id -u):$(id -g) --rm -v $PWD:/local openapitools/openapi-generator-cli@sha256:b35aee2d0f6ffadadcdad9d8fc3c46e8d48360c20b5731a5f47c809d51f67a04 generate -i /local/extractor-api-lib/openapi.yaml -g python-fastapi -o /local/extractor-api-lib --additional-properties=packageName=extractor_api_lib,generateSourceCodeOnly=True
35+
rm -r extractor-api-lib/src/openapi_server
3536
cd ./extractor-api-lib
3637
black .
3738
cd ..
38-
docker run --user $(id -u):$(id -g) --rm -v $PWD:/local openapitools/openapi-generator-cli@sha256:b35aee2d0f6ffadadcdad9d8fc3c46e8d48360c20b5731a5f47c809d51f67a04 generate -i /local/extractor-api-lib/openapi.yaml -g python -o /local/admin-api-lib/src --additional-properties=generateSourceCodeOnly=True,packageName=admin_api_lib.extractor_api_client.openapi_client
39+
docker run --user $(id -u):$(id -g) --rm -v $PWD:/local openapitools/openapi-generator-cli@sha256:b35aee2d0f6ffadadcdad9d8fc3c46e8d48360c20b5731a5f47c809d51f67a04 generate -i /local/extractor-api-lib/openapi.yaml -g python -o /local/admin-api-lib/src --additional-properties=packageName=admin_api_lib.extractor_api_client.openapi_client,generateSourceCodeOnly=True,testOutput=false
3940
rm -r admin-api-lib/src/openapi_server
41+
find ./admin-api-lib/src/admin_api_lib/extractor_api_client -type f -name '*.md' -delete
4042
cd ./admin-api-lib
4143
black .
4244
cd ..

extractor-api-lib/src/extractor_api_lib/models/confluence_parameters.py

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,50 @@
1313

1414

1515
from __future__ import annotations
16-
17-
import json
1816
import pprint
1917
import re # noqa: F401
20-
from typing import Any, ClassVar, Dict, List, Optional
18+
import json
19+
2120

22-
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
2321

22+
23+
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
24+
from typing import Any, ClassVar, Dict, List, Optional
25+
from extractor_api_lib.models.key_value_pair import KeyValuePair
2426
try:
2527
from typing import Self
2628
except ImportError:
2729
from typing_extensions import Self
2830

29-
3031
class ConfluenceParameters(BaseModel):
31-
""" """ # noqa: E501
32-
32+
"""
33+
34+
""" # noqa: E501
3335
url: StrictStr = Field(description="url of the confluence space.")
3436
token: StrictStr = Field(description="api key to access confluence.")
3537
space_key: StrictStr = Field(description="the space key of the confluence pages.")
36-
include_attachments: Optional[StrictBool] = Field(
37-
default=False,
38-
description="whether to include file attachments (e.g., images, documents) in the parsed content. Default is `false`.",
39-
)
40-
keep_markdown_format: Optional[StrictBool] = Field(
41-
default=True, description="whether to preserve markdown formatting in the output. Default is `true`."
42-
)
43-
keep_newlines: Optional[StrictBool] = Field(
44-
default=True,
45-
description="whether to retain newline characters in the output for better readability. Default is `true`.",
46-
)
47-
document_name: StrictStr = Field(
48-
description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document)."
49-
)
50-
__properties: ClassVar[List[str]] = [
51-
"url",
52-
"token",
53-
"space_key",
54-
"include_attachments",
55-
"keep_markdown_format",
56-
"keep_newlines",
57-
"document_name",
58-
]
38+
include_attachments: Optional[StrictBool] = Field(default=False, description="whether to include file attachments (e.g., images, documents) in the parsed content. Default is `false`.")
39+
keep_markdown_format: Optional[StrictBool] = Field(default=True, description="whether to preserve markdown formatting in the output. Default is `true`.")
40+
keep_newlines: Optional[StrictBool] = Field(default=True, description="whether to retain newline characters in the output for better readability. Default is `true`.")
41+
document_name: StrictStr = Field(description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document).")
42+
confluence_kwargs: Optional[List[KeyValuePair]] = Field(default=None, description="Additional kwargs like verify_ssl")
43+
__properties: ClassVar[List[str]] = ["url", "token", "space_key", "include_attachments", "keep_markdown_format", "keep_newlines", "document_name", "confluence_kwargs"]
5944

6045
model_config = {
6146
"populate_by_name": True,
6247
"validate_assignment": True,
6348
"protected_namespaces": (),
6449
}
6550

51+
6652
def to_str(self) -> str:
6753
"""Returns the string representation of the model using alias"""
6854
return pprint.pformat(self.model_dump(by_alias=True))
6955

7056
def to_json(self) -> str:
7157
"""Returns the JSON representation of the model using alias"""
72-
return self.model_dump_json(by_alias=True, exclude_unset=True)
58+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
59+
return json.dumps(self.to_dict())
7360

7461
@classmethod
7562
def from_json(cls, json_str: str) -> Self:
@@ -88,9 +75,17 @@ def to_dict(self) -> Dict[str, Any]:
8875
"""
8976
_dict = self.model_dump(
9077
by_alias=True,
91-
exclude={},
78+
exclude={
79+
},
9280
exclude_none=True,
9381
)
82+
# override the default output from pydantic by calling `to_dict()` of each item in confluence_kwargs (list)
83+
_items = []
84+
if self.confluence_kwargs:
85+
for _item in self.confluence_kwargs:
86+
if _item:
87+
_items.append(_item.to_dict())
88+
_dict['confluence_kwargs'] = _items
9489
return _dict
9590

9691
@classmethod
@@ -102,19 +97,16 @@ def from_dict(cls, obj: Dict) -> Self:
10297
if not isinstance(obj, dict):
10398
return cls.model_validate(obj)
10499

105-
_obj = cls.model_validate(
106-
{
107-
"url": obj.get("url"),
108-
"token": obj.get("token"),
109-
"space_key": obj.get("space_key"),
110-
"include_attachments": obj.get("include_attachments")
111-
if obj.get("include_attachments") is not None
112-
else False,
113-
"keep_markdown_format": obj.get("keep_markdown_format")
114-
if obj.get("keep_markdown_format") is not None
115-
else True,
116-
"keep_newlines": obj.get("keep_newlines") if obj.get("keep_newlines") is not None else True,
117-
"document_name": obj.get("document_name"),
118-
}
119-
)
100+
_obj = cls.model_validate({
101+
"url": obj.get("url"),
102+
"token": obj.get("token"),
103+
"space_key": obj.get("space_key"),
104+
"include_attachments": obj.get("include_attachments") if obj.get("include_attachments") is not None else False,
105+
"keep_markdown_format": obj.get("keep_markdown_format") if obj.get("keep_markdown_format") is not None else True,
106+
"keep_newlines": obj.get("keep_newlines") if obj.get("keep_newlines") is not None else True,
107+
"document_name": obj.get("document_name"),
108+
"confluence_kwargs": [KeyValuePair.from_dict(_item) for _item in obj.get("confluence_kwargs")] if obj.get("confluence_kwargs") is not None else None
109+
})
120110
return _obj
111+
112+

0 commit comments

Comments
 (0)