geniespec 0.1.2.dev16__tar.gz → 0.1.2.dev17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- geniespec-0.1.2.dev16/README.md → geniespec-0.1.2.dev17/PKG-INFO +16 -0
- geniespec-0.1.2.dev16/PKG-INFO → geniespec-0.1.2.dev17/README.md +2 -14
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/pyproject.toml +2 -2
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/pyproject.toml.orig +2 -2
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/api_schema.yaml +3 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/genie.py +1 -1
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/languages.py +11 -1
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/renderable_types.py +1 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/v{version}/api.py.j2 +7 -2
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/types.py +1 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/__init__.py +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/cli.py +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/__init__.py.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/v{version}/__init__.py.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/v{version}/endpoints.py.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/v{version}/exceptions.py.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/v{version}/internal.py.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/python-server/{service}/v{version}/resources.py.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/typescript-client/{service}/v{version}/client.ts.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/typescript-client/{service}/v{version}/endpoints.ts.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/typescript-client/{service}/v{version}/index.ts.j2 +0 -0
- {geniespec-0.1.2.dev16 → geniespec-0.1.2.dev17}/src/geniespec/templates/typescript-client/{service}/v{version}/resources.ts.j2 +0 -0
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geniespec
|
|
3
|
+
Version: 0.1.2.dev17
|
|
4
|
+
Summary: Generate API code from an api.yaml spec
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Dist: jinja2>=3.1.6
|
|
7
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
8
|
+
Requires-Dist: jsonschema>=4.26.0
|
|
9
|
+
Requires-Dist: pydantic>=2.13.5
|
|
10
|
+
Requires-Dist: kiba-core>=0.5.3.dev81,<0.5.4
|
|
11
|
+
Requires-Python: >=3.13, <4
|
|
12
|
+
Project-URL: repository, https://github.com/kibalabs/genie
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
1
15
|
# Genie
|
|
2
16
|
|
|
3
17
|
Genie (`geniespec` on PyPI) generates API code from an `api.yaml` spec. Install it like any other tool and run it from your build scripts; the generated code is gitignored, not committed.
|
|
@@ -81,6 +95,8 @@ transitions:
|
|
|
81
95
|
|
|
82
96
|
A rate limit needs at least one of `perMinute`, `perFiveMinutes`, `perHour` and `perDay`. `keyBy` is `user` (the default) or `ip`. Requests over any window are rejected with a 429. Limits keyed by `user` count per authenticated user, so a transition using one needs `authentication`. `python-server` writes each rate limit as a `RATE_LIMIT_<NAME>` kiba-core `RateLimitConfig` and passes it to `route`; keying by `ip` needs kiba-core's `OriginIpMiddleware`. `typescript-client` ignores rate limits.
|
|
83
97
|
|
|
98
|
+
A rate limit can name an `exemption` (e.g. `exemption: integrator`) for requests it shouldn't count, such as integrators that call from their own servers and so share one IP. `python-server` adds it to the `RateLimitConfig`, and `create_routes` then takes a keyword-only `rateLimitExemptionResolver` (kiba-core's `RateLimitExemptionResolver`). Before counting a request against that limit, kiba-core asks the resolver's `is_rate_limit_exempt(exemption=..., request=...)`, after authentication, so it can use whatever auth set. Exempt requests aren't counted.
|
|
99
|
+
|
|
84
100
|
## API docs
|
|
85
101
|
|
|
86
102
|
Transitions can set `operationId`, `summary`, `description`, `tags` and `extensions`, and attributes, request fields and response fields can set a `description`:
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: geniespec
|
|
3
|
-
Version: 0.1.2.dev16
|
|
4
|
-
Summary: Generate API code from an api.yaml spec
|
|
5
|
-
License-Expression: MIT
|
|
6
|
-
Requires-Dist: jinja2>=3.1.6
|
|
7
|
-
Requires-Dist: pyyaml>=6.0.3
|
|
8
|
-
Requires-Dist: jsonschema>=4.26.0
|
|
9
|
-
Requires-Dist: pydantic>=2.13.5
|
|
10
|
-
Requires-Dist: kiba-core>=0.5.3.dev81,<0.5.4
|
|
11
|
-
Requires-Python: >=3.13, <4
|
|
12
|
-
Project-URL: repository, https://github.com/kibalabs/genie
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
|
|
15
1
|
# Genie
|
|
16
2
|
|
|
17
3
|
Genie (`geniespec` on PyPI) generates API code from an `api.yaml` spec. Install it like any other tool and run it from your build scripts; the generated code is gitignored, not committed.
|
|
@@ -95,6 +81,8 @@ transitions:
|
|
|
95
81
|
|
|
96
82
|
A rate limit needs at least one of `perMinute`, `perFiveMinutes`, `perHour` and `perDay`. `keyBy` is `user` (the default) or `ip`. Requests over any window are rejected with a 429. Limits keyed by `user` count per authenticated user, so a transition using one needs `authentication`. `python-server` writes each rate limit as a `RATE_LIMIT_<NAME>` kiba-core `RateLimitConfig` and passes it to `route`; keying by `ip` needs kiba-core's `OriginIpMiddleware`. `typescript-client` ignores rate limits.
|
|
97
83
|
|
|
84
|
+
A rate limit can name an `exemption` (e.g. `exemption: integrator`) for requests it shouldn't count, such as integrators that call from their own servers and so share one IP. `python-server` adds it to the `RateLimitConfig`, and `create_routes` then takes a keyword-only `rateLimitExemptionResolver` (kiba-core's `RateLimitExemptionResolver`). Before counting a request against that limit, kiba-core asks the resolver's `is_rate_limit_exempt(exemption=..., request=...)`, after authentication, so it can use whatever auth set. Exempt requests aren't counted.
|
|
85
|
+
|
|
98
86
|
## API docs
|
|
99
87
|
|
|
100
88
|
Transitions can set `operationId`, `summary`, `description`, `tags` and `extensions`, and attributes, request fields and response fields can set a `description`:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "geniespec"
|
|
3
|
-
version = "0.1.2.
|
|
3
|
+
version = "0.1.2.dev17"
|
|
4
4
|
description = "Generate API code from an api.yaml spec"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -22,7 +22,7 @@ repository = "https://github.com/kibalabs/genie"
|
|
|
22
22
|
[dependency-groups]
|
|
23
23
|
dev = [
|
|
24
24
|
"kiba-build==0.1.11.dev24",
|
|
25
|
-
"kiba-core[core-api,requester]>=0.5.3.
|
|
25
|
+
"kiba-core[core-api,requester]>=0.5.3.dev103,<0.5.4",
|
|
26
26
|
]
|
|
27
27
|
|
|
28
28
|
[build-system]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "geniespec"
|
|
3
|
-
version = "0.1.2.
|
|
3
|
+
version = "0.1.2.dev17"
|
|
4
4
|
description = "Generate API code from an api.yaml spec"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -22,7 +22,7 @@ repository = "https://github.com/kibalabs/genie"
|
|
|
22
22
|
[dependency-groups]
|
|
23
23
|
dev = [
|
|
24
24
|
"kiba-build==0.1.11.dev24",
|
|
25
|
-
"kiba-core[core-api,requester]>=0.5.3.
|
|
25
|
+
"kiba-core[core-api,requester]>=0.5.3.dev103,<0.5.4",
|
|
26
26
|
]
|
|
27
27
|
|
|
28
28
|
[build-system]
|
|
@@ -547,7 +547,7 @@ class Renderer:
|
|
|
547
547
|
enums=[RenderableEnum(name=RenderableString.from_pascal_case_string(string=enum.name), values=enum.values) for enum in api.enums],
|
|
548
548
|
oneOfs=renderableOneOfs,
|
|
549
549
|
rateLimits=[
|
|
550
|
-
RenderableRateLimit(name=RenderableString.from_kebab_case_string(string=rateLimit.name), perMinute=rateLimit.perMinute, perFiveMinutes=rateLimit.perFiveMinutes, perHour=rateLimit.perHour, perDay=rateLimit.perDay, keyBy=rateLimit.keyBy)
|
|
550
|
+
RenderableRateLimit(name=RenderableString.from_kebab_case_string(string=rateLimit.name), perMinute=rateLimit.perMinute, perFiveMinutes=rateLimit.perFiveMinutes, perHour=rateLimit.perHour, perDay=rateLimit.perDay, keyBy=rateLimit.keyBy, exemption=rateLimit.exemption)
|
|
551
551
|
for rateLimit in api.rateLimits
|
|
552
552
|
],
|
|
553
553
|
)
|
|
@@ -394,6 +394,15 @@ class PythonLanguageDefinition(BaseLanguageDefinition):
|
|
|
394
394
|
def route_rate_limit(operation: RenderableOperation) -> str | None:
|
|
395
395
|
return operation.rateLimit if operation.rateLimit not in (None, 'none') else None
|
|
396
396
|
|
|
397
|
+
@classmethod
|
|
398
|
+
def route_rate_limit_has_exemption(cls, api: RenderableApi, operation: RenderableOperation) -> bool:
|
|
399
|
+
rateLimitName = cls.route_rate_limit(operation=operation)
|
|
400
|
+
return any(rateLimit.name.kebabCaseString == rateLimitName and rateLimit.exemption is not None for rateLimit in api.rateLimits)
|
|
401
|
+
|
|
402
|
+
@classmethod
|
|
403
|
+
def requires_rate_limit_exemption_resolver(cls, api: RenderableApi) -> bool:
|
|
404
|
+
return any(cls.route_rate_limit_has_exemption(api=api, operation=operation) for operation in api.operations)
|
|
405
|
+
|
|
397
406
|
@staticmethod
|
|
398
407
|
def rate_limit_constant_name(name: str) -> str:
|
|
399
408
|
return f'RATE_LIMIT_{RenderableString.from_kebab_case_string(string=name).snakeCaseString.upper()}'
|
|
@@ -402,7 +411,8 @@ class PythonLanguageDefinition(BaseLanguageDefinition):
|
|
|
402
411
|
def rate_limit_config(rateLimit: RenderableRateLimit) -> str:
|
|
403
412
|
windows = {'perMinute': rateLimit.perMinute, 'perFiveMinutes': rateLimit.perFiveMinutes, 'perHour': rateLimit.perHour, 'perDay': rateLimit.perDay}
|
|
404
413
|
entries = [f"'{window}': {limit}" for window, limit in windows.items() if limit is not None]
|
|
405
|
-
|
|
414
|
+
exemption = [f"'exemption': '{rateLimit.exemption}'"] if rateLimit.exemption is not None else []
|
|
415
|
+
return '{' + ', '.join([*entries, f"'keyBy': '{rateLimit.keyBy}'", *exemption]) + '}'
|
|
406
416
|
|
|
407
417
|
def operation_name(self, operation: RenderableOperation) -> str:
|
|
408
418
|
return self.snake_name(name=self._operation_name(operation=operation))
|
|
@@ -6,6 +6,11 @@ import collections.abc
|
|
|
6
6
|
{% endif %}
|
|
7
7
|
{% if api.operations %}
|
|
8
8
|
from core.api.api_request import KibaApiRequest
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% if target.requires_rate_limit_exemption_resolver(api=api) %}
|
|
11
|
+
from core.api.rate_limit import RateLimitExemptionResolver
|
|
12
|
+
{% endif %}
|
|
13
|
+
{% if api.operations %}
|
|
9
14
|
from core.api.route import route
|
|
10
15
|
{% endif %}
|
|
11
16
|
from core.api.route_auth import RouteAuthResolver
|
|
@@ -27,7 +32,7 @@ from .internal import {{ target.internal_class_name(api=api) }}
|
|
|
27
32
|
{% for rateLimit in api.rateLimits %}
|
|
28
33
|
{{ target.rate_limit_constant_name(name=rateLimit.name.kebabCaseString) }}: RateLimitConfig = {{ target.rate_limit_config(rateLimit=rateLimit) }}
|
|
29
34
|
{% endfor %}
|
|
30
|
-
def create_routes(internal: {{ target.internal_class_name(api=api) }}, {% if target.requires_auth_resolver(api=api) %}authResolver: RouteAuthResolver{% else %}authResolver: RouteAuthResolver | None = None{% endif %}) -> list[BaseRoute]:
|
|
35
|
+
def create_routes(internal: {{ target.internal_class_name(api=api) }}, {% if target.requires_auth_resolver(api=api) %}authResolver: RouteAuthResolver{% else %}authResolver: RouteAuthResolver | None = None{% endif %}{% if target.requires_rate_limit_exemption_resolver(api=api) %}, *, rateLimitExemptionResolver: RateLimitExemptionResolver{% endif %}) -> list[BaseRoute]:
|
|
31
36
|
|
|
32
37
|
|
|
33
38
|
{% for operation in api.operations %}
|
|
@@ -35,7 +40,7 @@ def create_routes(internal: {{ target.internal_class_name(api=api) }}, {% if tar
|
|
|
35
40
|
{% set rate_limit = target.route_rate_limit(operation=operation) %}
|
|
36
41
|
{% set class_name = target.operation_class_name(operation=operation) %}
|
|
37
42
|
{% set result_name = target.identifier(name=operation.responseFields[0].name) if operation.responseFields else 'result' %}
|
|
38
|
-
@route(requestType=endpoints.{{ class_name }}Request, responseType=endpoints.{{ class_name }}Response{% if target.is_streaming(operation=operation) %}, isStreaming=True{% endif %}{% if auth is not none %}, authResolver=authResolver, auth='{{ auth }}'{% endif %}{% if rate_limit is not none %}, rateLimit={{ target.rate_limit_constant_name(name=rate_limit) }}{% endif %}{{ target.route_documentation_arguments(operation=operation) }})
|
|
43
|
+
@route(requestType=endpoints.{{ class_name }}Request, responseType=endpoints.{{ class_name }}Response{% if target.is_streaming(operation=operation) %}, isStreaming=True{% endif %}{% if auth is not none %}, authResolver=authResolver, auth='{{ auth }}'{% endif %}{% if rate_limit is not none %}, rateLimit={{ target.rate_limit_constant_name(name=rate_limit) }}{% endif %}{% if target.route_rate_limit_has_exemption(api=api, operation=operation) %}, rateLimitExemptionResolver=rateLimitExemptionResolver{% endif %}{{ target.route_documentation_arguments(operation=operation) }})
|
|
39
44
|
async def {{ target.operation_name(operation=operation) }}(request: KibaApiRequest[endpoints.{{ class_name }}Request]) -> {% if target.is_streaming(operation=operation) %}collections.abc.AsyncIterator[endpoints.{{ class_name }}Response]{% else %}endpoints.{{ class_name }}Response{% endif %}:
|
|
40
45
|
{% for parameter in target.request_parameters(operation=operation) %}
|
|
41
46
|
{% set param_name = target.identifier(name=parameter.name) %}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|