Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from MarketSquare/fix/get_valid_id_for_endpoin…
Browse files Browse the repository at this point in the history
…t_can_be_non-string

Fix/get valid id for endpoint can be non string
  • Loading branch information
robinmackaij authored Jun 22, 2023
2 parents 8f62ca8 + fc1f65a commit cfaddc2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/openapi_libcore.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name="robotframework-openapi-libcore"
version = "1.9.0"
version = "1.9.1"
description = "A Robot Framework library to facilitate library development for OpenAPI / Swagger APIs."
license = "Apache-2.0"
authors = ["Robin Mackaij <[email protected]>"]
Expand Down
24 changes: 12 additions & 12 deletions src/OpenApiLibCore/openapi_libcore.libspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<keywordspec name="OpenApiLibCore" type="LIBRARY" format="HTML" scope="SUITE" generated="2023-06-09T13:40:53+00:00" specversion="4" source="C:\GitHub\robotframework-openapi-libcore\src\OpenApiLibCore\openapi_libcore.py" lineno="379">
<version>1.9.0</version>
<keywordspec name="OpenApiLibCore" type="LIBRARY" format="HTML" scope="SUITE" generated="2023-06-22T08:04:13+00:00" specversion="4" source="C:\GitHub\robotframework-openapi-libcore\src\OpenApiLibCore\openapi_libcore.py" lineno="379">
<version>1.9.1</version>
<doc>&lt;p&gt;Main class providing the keywords and core logic to interact with an OpenAPI server.&lt;/p&gt;
&lt;p&gt;Visit the &lt;a href="https://github.com/MarketSquare/robotframework-openapi-libcore"&gt;library page&lt;/a&gt; for an introduction.&lt;/p&gt;</doc>
<tags>
Expand Down Expand Up @@ -156,7 +156,7 @@
</init>
</inits>
<keywords>
<kw name="Authorized Request" lineno="1395">
<kw name="Authorized Request" lineno="1397">
<arguments repr="url: str, method: str, params: Dict[str, Any] | None = None, headers: Dict[str, str] | None = None, json_data: Dict[str, Dict[str, ForwardRef('JSON')] | List[ForwardRef('JSON')] | str | int | float | bool | None] | List[Dict[str, ForwardRef('JSON')] | List[ForwardRef('JSON')] | str | int | float | bool | None] | str | int | float | bool | None = None">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="url: str">
<name>url</name>
Expand Down Expand Up @@ -194,7 +194,7 @@
&lt;p&gt;&amp;gt; Note: provided username / password or auth objects take precedence over token based security&lt;/p&gt;</doc>
<shortdoc>Perform a request using the security token or authentication set in the library.</shortdoc>
</kw>
<kw name="Ensure In Use" lineno="1299">
<kw name="Ensure In Use" lineno="1301">
<arguments repr="url: str, resource_relation: IdReference">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="url: str">
<name>url</name>
Expand All @@ -208,7 +208,7 @@
<doc>&lt;p&gt;Ensure that the (right-most) &lt;span class="name"&gt;id&lt;/span&gt; of the resource referenced by the &lt;span class="name"&gt;url&lt;/span&gt; is used by the resource defined by the &lt;span class="name"&gt;resource_relation&lt;/span&gt;.&lt;/p&gt;</doc>
<shortdoc>Ensure that the (right-most) `id` of the resource referenced by the `url` is used by the resource defined by the `resource_relation`.</shortdoc>
</kw>
<kw name="Get Ids From Url" lineno="734">
<kw name="Get Ids From Url" lineno="736">
<arguments repr="url: str">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="url: str">
<name>url</name>
Expand All @@ -218,7 +218,7 @@
<doc>&lt;p&gt;Perform a GET request on the &lt;span class="name"&gt;url&lt;/span&gt; and return the list of resource &lt;span class="name"&gt;ids&lt;/span&gt; from the response.&lt;/p&gt;</doc>
<shortdoc>Perform a GET request on the `url` and return the list of resource `ids` from the response.</shortdoc>
</kw>
<kw name="Get Invalid Json Data" lineno="1078">
<kw name="Get Invalid Json Data" lineno="1080">
<arguments repr="url: str, method: str, status_code: int, request_data: RequestData">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="url: str">
<name>url</name>
Expand All @@ -241,7 +241,7 @@
&lt;p&gt;&amp;gt; Note: applicable UniquePropertyValueConstraint and IdReference Relations are considered before changes to &lt;span class="name"&gt;json_data&lt;/span&gt; are made.&lt;/p&gt;</doc>
<shortdoc>Return `json_data` based on the `dto` on the `request_data` that will cause the provided `status_code` for the `method` operation on the `url`.</shortdoc>
</kw>
<kw name="Get Invalidated Parameters" lineno="1126">
<kw name="Get Invalidated Parameters" lineno="1128">
<arguments repr="status_code: int, request_data: RequestData">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="status_code: int">
<name>status_code</name>
Expand All @@ -255,7 +255,7 @@
<doc>&lt;p&gt;Returns a version of &lt;span class="name"&gt;params, headers&lt;/span&gt; as present on &lt;span class="name"&gt;request_data&lt;/span&gt; that has been modified to cause the provided &lt;span class="name"&gt;status_code&lt;/span&gt;.&lt;/p&gt;</doc>
<shortdoc>Returns a version of `params, headers` as present on `request_data` that has been modified to cause the provided `status_code`.</shortdoc>
</kw>
<kw name="Get Invalidated Url" lineno="1044">
<kw name="Get Invalidated Url" lineno="1046">
<arguments repr="valid_url: str">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="valid_url: str">
<name>valid_url</name>
Expand All @@ -266,7 +266,7 @@
&lt;p&gt;Raises ValueError if the valid_url cannot be invalidated.&lt;/p&gt;</doc>
<shortdoc>Return an url with all the path parameters in the `valid_url` replaced by a random UUID.</shortdoc>
</kw>
<kw name="Get Json Data For Dto Class" lineno="954">
<kw name="Get Json Data For Dto Class" lineno="956">
<arguments repr="schema: Dict[str, Any], dto_class: Dto | Type[Dto], operation_id: str = ">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="schema: Dict[str, Any]">
<name>schema</name>
Expand All @@ -286,7 +286,7 @@
<doc>&lt;p&gt;Generate a valid (json-compatible) dict for all the &lt;span class="name"&gt;dto_class&lt;/span&gt; properties.&lt;/p&gt;</doc>
<shortdoc>Generate a valid (json-compatible) dict for all the `dto_class` properties.</shortdoc>
</kw>
<kw name="Get Json Data With Conflict" lineno="1343">
<kw name="Get Json Data With Conflict" lineno="1345">
<arguments repr="url: str, method: str, dto: Dto, conflict_status_code: int">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="url: str">
<name>url</name>
Expand All @@ -308,7 +308,7 @@
<doc>&lt;p&gt;Return &lt;span class="name"&gt;json_data&lt;/span&gt; based on the &lt;span class="name"&gt;UniquePropertyValueConstraint&lt;/span&gt; that must be returned by the &lt;span class="name"&gt;get_relations&lt;/span&gt; implementation on the &lt;span class="name"&gt;dto&lt;/span&gt; for the given &lt;span class="name"&gt;conflict_status_code&lt;/span&gt;.&lt;/p&gt;</doc>
<shortdoc>Return `json_data` based on the `UniquePropertyValueConstraint` that must be returned by the `get_relations` implementation on the `dto` for the given `conflict_status_code`.</shortdoc>
</kw>
<kw name="Get Parameterized Endpoint From Url" lineno="1066">
<kw name="Get Parameterized Endpoint From Url" lineno="1068">
<arguments repr="url: str">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="url: str">
<name>url</name>
Expand All @@ -318,7 +318,7 @@
<doc>&lt;p&gt;Return the endpoint as found in the &lt;span class="name"&gt;paths&lt;/span&gt; section based on the given &lt;span class="name"&gt;url&lt;/span&gt;.&lt;/p&gt;</doc>
<shortdoc>Return the endpoint as found in the `paths` section based on the given `url`.</shortdoc>
</kw>
<kw name="Get Request Data" lineno="774">
<kw name="Get Request Data" lineno="776">
<arguments repr="endpoint: str, method: str">
<arg kind="POSITIONAL_OR_NAMED" required="true" repr="endpoint: str">
<name>endpoint</name>
Expand Down
8 changes: 5 additions & 3 deletions src/OpenApiLibCore/openapi_libcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,18 @@ def get_valid_url(self, endpoint: str, method: str) -> str:
if part.startswith("{") and part.endswith("}"):
type_endpoint_parts = endpoint_parts[slice(index)]
type_endpoint = "/".join(type_endpoint_parts)
existing_id: str = run_keyword(
existing_id: Union[str, int, float] = run_keyword(
"get_valid_id_for_endpoint", type_endpoint, method
)
endpoint_parts[index] = existing_id
endpoint_parts[index] = str(existing_id)
resolved_endpoint = "/".join(endpoint_parts)
url = f"{self.base_url}{resolved_endpoint}"
return url

@keyword
def get_valid_id_for_endpoint(self, endpoint: str, method: str) -> str:
def get_valid_id_for_endpoint(
self, endpoint: str, method: str
) -> Union[str, int, float]:
"""
Support keyword that returns the `id` for an existing resource at `endpoint`.
Expand Down
4 changes: 2 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def tests(context):

@task
def lint(context):
subprocess.run(f"mypy {ROOT}", shell=True, check=False)
subprocess.run(f"pylint {ROOT}/src/OpenApiLibCore", shell=True, check=False)
subprocess.run(f"mypy {ROOT}/src", shell=True, check=False)
subprocess.run(f"pylint {ROOT}/src", shell=True, check=False)
subprocess.run(f"robocop {ROOT}/tests/suites", shell=True, check=False)


Expand Down

0 comments on commit cfaddc2

Please sign in to comment.