Skip to content

V1 release: major (internal) refactor and interface / terminology corrections #55

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

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ae80e1e
Annotation / defaults updates
robinmackaij Feb 11, 2025
20c8225
New submodule placeholders
robinmackaij Feb 11, 2025
8f0b74b
Merge branch 'main' into 48_split_up_openapi_libcore
robinmackaij Feb 11, 2025
7ebeccc
autoformat after changing to ruff
robinmackaij Feb 11, 2025
99c5bc3
Default Python in Dockerfile is lowest supported version
robinmackaij Feb 11, 2025
721c3ea
Address pylance issue
robinmackaij Feb 11, 2025
6719ee7
RequestData class extracted
robinmackaij Feb 11, 2025
71f7ff2
get_request_data extracted (incl. large scale cascade)
robinmackaij Feb 16, 2025
ee933ba
Fixed tests after major refactor
robinmackaij Feb 16, 2025
0da657a
documentation update after refactor / renames
robinmackaij Feb 16, 2025
c50092c
get_valid_url moved to path_functions, reordered keywords into regions
robinmackaij Mar 4, 2025
26ba206
get_ids_from_url extracted, RequestData and RequestValues extracted
robinmackaij Mar 4, 2025
d31b225
autoformat change
robinmackaij Mar 4, 2025
e0e4769
extracted get_invalidated_url
robinmackaij Mar 4, 2025
cc9bdc0
get_invalid_json_data extracted
robinmackaij Mar 4, 2025
c54a9f0
use the logger from robot.api
robinmackaij Mar 4, 2025
244f7aa
get_invalidated_parameters extracted
robinmackaij Mar 4, 2025
97dfc8c
ensure_in_use extracted / updated module imports
robinmackaij Mar 4, 2025
85b0b51
ensure_in_use moved to new region
robinmackaij Mar 4, 2025
b6ebe15
get_json_data_with_conflict extracted
robinmackaij Mar 4, 2025
8801586
multiple validation keywords extracted
robinmackaij Mar 7, 2025
29d70fd
removed duplicate docstrings
robinmackaij Mar 7, 2025
81fb221
validate_send_response extracted
robinmackaij Mar 7, 2025
d6feaa1
Use Protocol to address typing issues
robinmackaij Mar 7, 2025
fddde82
Fix indentation error
robinmackaij Mar 7, 2025
cfc6d7d
Fix (& refactor) incorrect comprehension, fixed related test
robinmackaij Mar 10, 2025
06b3e91
Updated test that passed due to implementation error
robinmackaij Mar 10, 2025
e309af0
poetry config update
robinmackaij Mar 14, 2025
ac610cf
Updated dependencies
robinmackaij Mar 14, 2025
3048f5f
pylint config update
robinmackaij Mar 14, 2025
67db7ec
linting issues in RF tests addressed
robinmackaij Mar 14, 2025
7dc3b30
Addressed most typing and linting issues
robinmackaij Mar 14, 2025
7f65591
robotcode analyze added to type-check task
robinmackaij Mar 14, 2025
8b40ef0
get_valid_url and related keywords no longer require method
robinmackaij Mar 14, 2025
c2de248
Merge pull request #54 from MarketSquare/48_split_up_openapi_libcore
robinmackaij Mar 14, 2025
40661de
Correct use of endpoint terminology
robinmackaij Mar 14, 2025
854c10b
Merge pull request #56 from MarketSquare/47_correct_incorrect_use_of_…
robinmackaij Mar 14, 2025
950c4cd
Updated testserver / tests for nested Dto implementation, added debug…
robinmackaij Mar 18, 2025
f0814d3
Refactor of data_generation to support nested Dtos
robinmackaij Mar 18, 2025
b4c9b07
Fixed historically incorrect test
robinmackaij Mar 18, 2025
573ec9f
changed imports
robinmackaij Mar 18, 2025
bbdce62
remove commented line
robinmackaij Mar 18, 2025
e710770
auto-format changes
robinmackaij Mar 18, 2025
c595bf3
Updated linting settings
robinmackaij Mar 18, 2025
86627e9
address "magic numbers"
robinmackaij Mar 18, 2025
7671caf
suppress some warnings
robinmackaij Mar 18, 2025
a86749b
Annotation improvements
robinmackaij Mar 18, 2025
d75f2ec
recursion_default handling changed, Any annotations changed to JSON o…
robinmackaij Mar 21, 2025
9a307d0
Updated docs / libspecs
robinmackaij Mar 21, 2025
0270c27
Merge pull request #61 from MarketSquare/49_support_nesting_of_dtos_i…
robinmackaij Mar 25, 2025
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
9 changes: 4 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.13-slim-bookworm
FROM python:3.10-slim-bookworm

# Update the certificates
RUN apt-get update && \
Expand Down Expand Up @@ -32,10 +32,9 @@ ENV PATH="$PATH:$POETRY_HOME/bin"
RUN curl -sSL https://install.python-poetry.org | python3 -
RUN poetry self update

# Configure poetry to not create virtual environments.
# This is done to force package installation to the global Python install so that users
# other than the Docker root user have access to the installed packages.
RUN poetry config virtualenvs.create false
# Configure poetry to create virtual environments in the project.
# This is done to be compatible with how uv and PDM set up the venvs.
RUN poetry config virtualenvs.in-project true

EXPOSE 8888
ENTRYPOINT ["/bin/sh"]
20 changes: 20 additions & 0 deletions .vscode/example.launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: testserver",
"type": "debugpy",
"request": "launch",
"module": "uvicorn",
"args": [
"testserver:app",
"--app-dir=./tests/server",
"--host=0.0.0.0",
"--port=8000",
]
}
]
}
29 changes: 15 additions & 14 deletions docs/advanced_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
When working with APIs, there are often relations between resources or constraints on values.
The property on one resource may refer to the `id` of another resource.
The value for a certain property may have to be unique within a certain scope.
Perhaps an endpoint path contains parameters that must match values that are defined outside the API itself.
Perhaps an url contains parameters that must match values that are defined outside the API itself.

These types of relations and limitations cannot be described / modeled within the openapi document.
To support automatic validation of API endpoints where such relations apply, OpenApiLibCore supports the usage of a custom mappings file.
Expand Down Expand Up @@ -42,7 +42,7 @@ from OpenApiLibCore import (


ID_MAPPING = {
"/myspecialendpoint", "special_thing_id",
"/myspecialpath", "special_thing_id",
}


Expand All @@ -54,7 +54,7 @@ class MyDtoThatDoesNothing(Dto):


DTO_MAPPING = {
("/myspecialendpoint", "post"): MyDtoThatDoesNothing
("/myspecialpath", "post"): MyDtoThatDoesNothing
}

```
Expand Down Expand Up @@ -88,16 +88,16 @@ def my_transformer(identifier_name: str) -> str:


ID_MAPPING = {
"/myspecialendpoint": ("special_thing_id", my_transformer),
"/myspecialpath": ("special_thing_id", my_transformer),
}

```

### The DTO_MAPPING
The `DTO_MAPPING` is a dictionary with a tuple as its key and a mappings Dto as its value.
The tuple must be in the form `("endpoint_from_the_paths_section", "method_supported_by_the_endpoint")`.
The `endpoint_from_the_paths_section` must be exactly as found in the openapi document.
The `method_supported_by_the_endpoint` must be one of the methods supported by the endpoint and must be in lowercase.
The tuple must be in the form `("path_from_the_paths_section", "method_supported_by_the_path")`.
The `path_from_the_paths_section` must be exactly as found in the openapi document.
The `method_supported_by_the_path` must be one of the methods supported by the path and must be in lowercase.


## Dto mapping classes
Expand All @@ -108,10 +108,10 @@ Each of these classes is designed to handle a relation or constraint commonly se

To explain the different mapping classes, we'll use the following example:

Imagine we have an API endpoint `/employees` where we can create (`post`) a new Employee resource.
Imagine we have an API path `/employees` where we can create (`post`) a new Employee resource.
The Employee has a number of required properties; name, employee_number, wagegroup_id, and date_of_birth.

There is also the the `/wagegroups` endpoint where a Wagegroup resource can be created.
There is also the the `/wagegroups` path where a Wagegroup resource can be created.
This Wagegroup also has a number of required properties: name and hourly rate.

---
Expand Down Expand Up @@ -159,7 +159,7 @@ This `error_code` should be described as one of the `responses` in the openapi d

If an Employee has been added to the system, this Employee refers to the `id` of a Wagegroup for its required `employee_number` property.

Now let's say there is also the `/wagegroups/${wagegroup_id}` endpoint that supports the `delete` operation.
Now let's say there is also the `/wagegroups/${wagegroup_id}` path that supports the `delete` operation.
If the Wagegroup refered to the Employee would be deleted, the Employee would be left with an invalid reference for one of its required properties.
To prevent this, an API typically returns an `error_code` when such a `delete` operation is attempted on a resource that is refered to in this fashion.
This `error_code` should be described as one of the `responses` in the openapi document for the `delete` operation of the `/wagegroups/${wagegroup_id}` path.
Expand Down Expand Up @@ -314,9 +314,9 @@ To be able to automatically perform endpoint validations, the OpenApiLibCore has
Often, such a `path` contains a reference to a resource id, e.g. `/employees/${employee_id}`.
When such an `id` is needed, the OpenApiLibCore tries to obtain a valid `id` by taking these steps:

1. Attempt a `post` on the "parent endpoint" and extract the `id` from the response.
In our example: perform a `post` request on the `/employees` endpoint and get the `id` from the response.
2. If 1. fails, perform a `get` request on the `/employees` endpoint. It is assumed that this will return a list of Employee objects with an `id`.
1. Attempt a `post` on the "parent path" and extract the `id` from the response.
In our example: perform a `post` request on the `/employees` path and get the `id` from the response.
2. If 1. fails, perform a `get` request on the `/employees` path. It is assumed that this will return a list of Employee objects with an `id`.
One item from the returned list is picked at rondom and its `id` is used.

This mechanism relies on the standard REST structure and patterns.
Expand All @@ -339,14 +339,15 @@ DTO_MAPPING = {
("/birthdays/{month}/{date}", "get"): BirthdaysDto
}
```
> Note: To take a `PathPropertiesConstraint` into use, the related Dto must be mapped to the `get` operation for the `path` in the `DTO_MAPPING` even if no such endpoint exists in the API.

---

### `IGNORE`
> *Never send this query parameter as part of a request*

Some optional query parameters have a range of valid values that depend on one or more path parameters.
Since path parameters are part of a url, they cannot be optional or empty so to extend the path parameters with optional parameters, query parameters can be used.
Since path parameters are part of an url, they cannot be optional or empty so to extend the path parameters with optional parameters, query parameters can be used.

To illustrate this, let's imagine an API where the energy label for a building can be requested: `/energylabel/${zipcode}/${home_number}`.
Some addresses however have an address extension, e.g. 1234AB 42 <sup>2.C</sup>.
Expand Down
8 changes: 4 additions & 4 deletions docs/driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The OpenAPI Specification (OAS) defines a standard, language-agnostic interface
to RESTful APIs, see https://swagger.io/specification/

The OpenApiDriver module implements a reader class that generates a test case for
each endpoint, method and response that is defined in an OpenAPI document, typically
each path, method and response that is defined in an OpenAPI document, typically
an openapi.json or openapi.yaml file.

> Note: OpenApiDriver is designed for APIs based on the OAS v3
Expand Down Expand Up @@ -88,13 +88,13 @@ Library OpenApiDriver
Test Template Validate Using Test Endpoint Keyword

*** Test Cases ***
Test Endpoint for ${method} on ${endpoint} where ${status_code} is expected
Test Endpoint for ${method} on ${path} where ${status_code} is expected

*** Keywords ***
Validate Using Test Endpoint Keyword
[Arguments] ${endpoint} ${method} ${status_code}
[Arguments] ${path} ${method} ${status_code}
Test Endpoint
... endpoint=${endpoint} method=${method} status_code=${status_code}
... path=${path} method=${method} status_code=${status_code}

```

Expand Down
4 changes: 2 additions & 2 deletions docs/libcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ recursion in them. See the `recursion_limit` and `recursion_default` parameters.

If the openapi document passes this validation, the next step is trying to do a test
run with a minimal test suite.
The example below can be used, with `source`, `origin` and 'endpoint' altered to
The example below can be used, with `source`, `origin` and `path` altered to
fit your situation.

``` robotframework
Expand All @@ -87,7 +87,7 @@ Library OpenApiLibCore

*** Test Cases ***
Getting Started
${url}= Get Valid Url endpoint=/employees/{employee_id} method=get
${url}= Get Valid Url path=/employees/{employee_id}

```

Expand Down
Loading
Loading