Skip to content

Commit 4ba56c1

Browse files
authored
[plugin][feat] Better docs and docs_url (#2210)
1 parent 5aee8cb commit 4ba56c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1184
-1037
lines changed

fixcore/fixcore/model/exportable_model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import List, Union
22

33
from fixcore.model.model import (
44
Model,
@@ -18,7 +18,7 @@ def json_export_simple_schema(
1818
model: Model,
1919
with_properties: bool = True,
2020
with_relatives: bool = True,
21-
with_metadata: bool = True,
21+
with_metadata: Union[bool, List[str]] = True,
2222
) -> List[Json]:
2323
def export_simple(kind: SimpleKind) -> Json:
2424
result = kind.as_json()
@@ -56,7 +56,10 @@ def export_complex(kind: ComplexKind) -> Json:
5656
aggregate_root=kind.aggregate_root,
5757
)
5858
if with_metadata:
59-
result["metadata"] = kind.metadata
59+
if isinstance(with_metadata, list):
60+
result["metadata"] = {k: v for k, v in kind.metadata.items() if k in with_metadata}
61+
else:
62+
result["metadata"] = kind.metadata
6063
if with_properties:
6164
result["allow_unknown_props"] = kind.allow_unknown_props
6265
result["properties"] = {prop.name: export_property(prop, kind) for prop, kind in kind.all_props_with_kind()}

fixcore/fixcore/model/model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,18 @@ def is_complex(self) -> bool:
945945

946946
def as_json(self, **kwargs: bool) -> Json:
947947
result: Json = {"fqn": self.fqn, "aggregate_root": self.aggregate_root}
948-
if kwargs.get("with_metadata", True):
949-
result["metadata"] = self.metadata
948+
if wm := kwargs.get("with_metadata", True):
949+
if isinstance(wm, list):
950+
result["metadata"] = {k: v for k, v in self.metadata.items() if k in wm}
951+
else:
952+
result["metadata"] = self.metadata
950953
if kwargs.get("with_properties", True):
951954
result["allow_unknown_props"] = self.allow_unknown_props
952955
result["properties"] = [to_js(prop) for prop in self.properties]
953956
if kwargs.get("with_relatives", True):
954-
result["bases"] = self.bases
955957
result["successor_kinds"] = self.successor_kinds
958+
if kwargs.get("with_bases", True):
959+
result["bases"] = self.bases
956960
return result
957961

958962
def copy(

fixcore/fixcore/static/api-doc.yaml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ paths:
5555
schema:
5656
type: boolean
5757
default: false
58+
- name: format
59+
description: "The format of the returned json"
60+
in: query
61+
schema:
62+
type: string
63+
enum:
64+
- schema
65+
- simple
66+
required: false
5867
- name: kind
5968
description: "Only return information about the defined kinds. Comma separated list."
6069
in: query
@@ -69,27 +78,48 @@ paths:
6978
schema:
7079
type: string
7180
default: null
72-
- name: with_bases
73-
description: "Render all base classes. Only together with kind or filter"
81+
- name: aggregate_roots_only
82+
description: "Only return aggregate roots."
7483
in: query
7584
schema:
7685
type: boolean
7786
default: false
78-
- name: format
79-
description: "The format of the returned json"
87+
- name: with_bases
88+
description: "Include base classes and render the base section"
8089
in: query
8190
schema:
82-
type: string
83-
enum:
84-
- schema
85-
- simple
86-
required: false
91+
type: boolean
92+
default: false
8793
- name: with_property_kinds
8894
description: "Render types of property values. Only together with kind or filter"
8995
in: query
9096
schema:
9197
type: boolean
9298
default: false
99+
- name: with_properties
100+
description: "Render the properties of complex kinds"
101+
in: query
102+
schema:
103+
type: boolean
104+
default: true
105+
- name: with_relatives
106+
description: "Include information about relationships to other kinds."
107+
in: query
108+
schema:
109+
type: boolean
110+
default: true
111+
- name: with_metadata
112+
description: "Include metadata information."
113+
in: query
114+
schema:
115+
oneOf:
116+
- type: boolean
117+
description: "If true, all metadata is included."
118+
- type: array
119+
description: "List of metadata keys to include."
120+
items:
121+
type: string
122+
default: true
93123

94124

95125
responses:

fixcore/fixcore/web/api.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,21 @@ async def model_uml(self, request: Request, deps: TenantDependencies) -> StreamR
961961
return response
962962

963963
async def get_model(self, request: Request, deps: TenantDependencies) -> StreamResponse:
964+
def parse_bool_or_list(s: str) -> Union[bool, List[str]]:
965+
lwr = s.lower()
966+
if lwr == "true":
967+
return True
968+
if lwr == "false":
969+
return False
970+
return s.split(",")
971+
964972
graph_id = GraphName(request.match_info.get("graph_id", "fix"))
965973
full_model = await deps.model_handler.load_model(graph_id)
966974
with_bases = if_set(request.query.get("with_bases"), lambda x: x.lower() == "true", False)
967975
with_property_kinds = if_set(request.query.get("with_property_kinds"), lambda x: x.lower() == "true", False)
968976
with_properties = if_set(request.query.get("with_properties"), lambda x: x.lower() == "true", True)
969977
with_relatives = if_set(request.query.get("with_relatives"), lambda x: x.lower() == "true", True)
970-
with_metadata = if_set(request.query.get("with_metadata"), lambda x: x.lower() == "true", True)
978+
with_metadata = if_set(request.query.get("with_metadata"), parse_bool_or_list, True)
971979
aggregate_roots_only = if_set(request.query.get("aggregate_roots_only"), lambda x: x.lower() == "true", False)
972980
md = full_model
973981
if kind := request.query.get("kind"):
@@ -990,7 +998,12 @@ async def get_model(self, request: Request, deps: TenantDependencies) -> StreamR
990998
)
991999
else:
9921000
json_model = [
993-
m.as_json(with_properties=with_properties, with_relatives=with_relatives, with_metadata=with_metadata)
1001+
m.as_json(
1002+
with_properties=with_properties,
1003+
with_relatives=with_relatives,
1004+
with_metadata=with_metadata,
1005+
with_bases=with_bases,
1006+
)
9941007
for m in md.kinds.values()
9951008
]
9961009
return await single_result(request, json.loads(json.dumps(json_model, sort_keys=True)))

fixlib/fixlib/baseresources.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,11 @@ class BaseResource(ABC):
268268
_metadata: ClassVar[Dict[str, Any]] = {"icon": "resource", "group": "misc"}
269269
# Categories of this resource kind.
270270
_categories: ClassVar[List[Category]] = []
271+
# Link to the cloud providers product documentation of this resource kind.
272+
_docs_url: ClassVar[Optional[str]] = None
271273

272274
################################################################################
273-
# InstanceVariables
275+
# Instance Variables
274276

275277
# Identifier of this resource. Does not need to be globally unique. chksum is used to compute a unique identifier.
276278
id: str

fixlib/fixlib/core/model_export.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def export_data_class(clazz: type) -> None:
257257
metadata["service"] = s
258258
if (slc := getattr(clazz, "categories", None)) and callable(slc) and (sl := slc()):
259259
metadata["categories"] = sl
260+
if (docs_url := getattr(clazz, "_docs_url", None)) and isinstance(docs_url, str):
261+
metadata["docs_url"] = docs_url
260262
if ( # only export kind description on aggregate roots
261263
with_kind_description
262264
and (ar := aggregate_root)

plugins/aws/fix_plugin_aws/collector.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ def add_accounts(parent: Union[AwsOrganizationalRoot, AwsOrganizationalUnit]) ->
461461
class AwsOrganizationalRoot(BaseOrganizationalRoot, AwsResource):
462462
kind: ClassVar[str] = "aws_organizational_root"
463463
_kind_display: ClassVar[str] = "AWS Organizational Root"
464-
_kind_description: ClassVar[str] = "An AWS Organizational Root is the root of an AWS Organization."
464+
_kind_description: ClassVar[str] = "AWS Organizational Root is the top-level entity in AWS Organizations. It serves as the starting point for creating and managing multiple AWS accounts within an organization. The root provides centralized control over billing, access management, and resource allocation across all member accounts, ensuring consistent policies and governance throughout the organizational structure." # fmt: skip
465+
_docs_url: ClassVar[str] = "https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_root.html"
465466
_kind_service = "organizations"
466467
_metadata: ClassVar[Dict[str, Any]] = {"icon": "group", "group": "management"}
467468

@@ -471,5 +472,6 @@ class AwsOrganizationalUnit(BaseOrganizationalUnit, AwsResource):
471472
kind: ClassVar[str] = "aws_organizational_unit"
472473
_kind_display: ClassVar[str] = "AWS Organizational Unit"
473474
_kind_description: ClassVar[str] = "An AWS Organizational Unit is a container for AWS Accounts."
475+
_docs_url: ClassVar[str] = "https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_ous.html"
474476
_kind_service = "organizations"
475477
_metadata: ClassVar[Dict[str, Any]] = {"icon": "group", "group": "management"}

plugins/aws/fix_plugin_aws/resource/acm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class AwsAcmCertificate(AwsResource, BaseCertificate):
7171
kind: ClassVar[str] = "aws_acm_certificate"
7272
_kind_display: ClassVar[str] = "AWS ACM Certificate"
7373
_aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/acm/home?region={region}#/certificates/{id}", "arn_tpl": "arn:{partition}:acm:{region}:{account}:certificate/{id}"} # fmt: skip
74-
_kind_description: ClassVar[str] = "An AWS ACM Certificate is used to provision, manage, and deploy Secure Sockets Layer/Transport Layer Security (SSL/TLS) certificates for secure web traffic on AWS services." # fmt: skip
74+
_kind_description: ClassVar[str] = "AWS ACM Certificate is a digital credential issued by Amazon Web Services Certificate Manager. It authenticates the identity of websites and secures connections between clients and servers. ACM Certificates encrypt data in transit, prevent unauthorized access, and establish trust for online services. They support various AWS services and can be deployed across multiple regions." # fmt: skip
75+
_docs_url: ClassVar[str] = "https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html"
7576
_kind_service: ClassVar[Optional[str]] = service_name
7677
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("acm", "describe-certificate", "Certificate")
7778
mapping: ClassVar[Dict[str, Bender]] = {

0 commit comments

Comments
 (0)