geniespec 0.1.2.dev9__tar.gz → 0.1.2.dev12__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.
Files changed (22) hide show
  1. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/PKG-INFO +66 -2
  2. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/README.md +65 -1
  3. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/pyproject.toml +2 -6
  4. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/pyproject.toml.orig +2 -7
  5. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/api_schema.yaml +96 -0
  6. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/genie.py +82 -29
  7. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/languages.py +123 -20
  8. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/renderable_types.py +20 -1
  9. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/v{version}/api.py.j2 +15 -3
  10. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/v{version}/endpoints.py.j2 +14 -5
  11. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/v{version}/exceptions.py.j2 +13 -1
  12. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/v{version}/internal.py.j2 +11 -2
  13. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/v{version}/resources.py.j2 +15 -2
  14. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/typescript-client/{service}/v{version}/client.ts.j2 +6 -0
  15. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/typescript-client/{service}/v{version}/endpoints.ts.j2 +3 -1
  16. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/typescript-client/{service}/v{version}/index.ts.j2 +2 -0
  17. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/typescript-client/{service}/v{version}/resources.ts.j2 +5 -4
  18. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/types.py +39 -1
  19. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/__init__.py +0 -0
  20. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/cli.py +0 -0
  21. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/__init__.py.j2 +0 -0
  22. {geniespec-0.1.2.dev9 → geniespec-0.1.2.dev12}/src/geniespec/templates/python-server/{service}/v{version}/__init__.py.j2 +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geniespec
3
- Version: 0.1.2.dev9
3
+ Version: 0.1.2.dev12
4
4
  Summary: Generate API code from an api.yaml spec
5
5
  License-Expression: MIT
6
6
  Requires-Dist: jinja2>=3.1.6
@@ -68,6 +68,68 @@ resources:
68
68
 
69
69
  Fields use it like any other type (`type: ViewContent`, also inside `List` and `Mapping`). `python-server` generates a `ViewContentV1` pydantic discriminated union in `resources`; `typescript-client` generates a `ViewContentV1` union type and a `viewContentV1FromObject` function that builds the member class named by the discriminator (and throws for unknown values).
70
70
 
71
+ `type: Uuid` is a string that must be a valid UUID. It works anywhere `String` does, including as a primary attribute in paths. `python-server` types it as `uuid.UUID`, so pydantic rejects other strings with a 400, internal methods get `uuid.UUID` objects and responses write them in the standard lowercase hyphenated form; `typescript-client` types it as `string`.
72
+
73
+ `type: BigInt` is an integer of any size that travels as a JSON string, because JSON numbers past 2^53 lose precision in JavaScript. `python-server` types it as `int` (a `BigInt` alias in `resources`), accepts `"123"` or `123` in requests, always writes it as a string and documents it as `{"type": "string"}`; `typescript-client` types it as `bigint`, parsed with `BigInt(...)` and sent with `String(...)`.
74
+
75
+ ## Rate limits
76
+
77
+ Name rate limits at the top level, then pick one per transition with `rateLimit`. `defaultRateLimit` applies to every transition that doesn't set one, and `rateLimit: none` turns it off for a transition, the same way `defaultAuthentication` and `authentication` work:
78
+
79
+ ```yaml
80
+ rateLimits:
81
+ - name: standard-read
82
+ perMinute: 30
83
+ perHour: 300
84
+ - name: public-read
85
+ perMinute: 30
86
+ perHour: 300
87
+ keyBy: ip
88
+ defaultRateLimit: standard-read
89
+ transitions:
90
+ - action: GET-HEALTH
91
+ method: GET
92
+ authentication: none
93
+ rateLimit: public-read
94
+ ```
95
+
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.
97
+
98
+ ## API docs
99
+
100
+ Transitions can set `operationId`, `summary`, `description`, `tags` and `extensions`, and attributes, request fields and response fields can set a `description`:
101
+
102
+ ```yaml
103
+ resources:
104
+ - singleName: Member
105
+ collectionName: Members
106
+ attributes:
107
+ - name: member-id
108
+ type: Uuid
109
+ isPrimary: true
110
+ description: The member's id.
111
+ transitions:
112
+ - action: GET
113
+ operationId: getMember
114
+ summary: Get a member
115
+ description: Returns one member.
116
+ tags: [Members]
117
+ extensions: {deprecated: true}
118
+ ```
119
+
120
+ `python-server` passes the transition fields to kiba-core's `route`, whose `OpenApiSchemaGenerator` documents every route with an `operationId` (and skips the rest); `extensions` reach `OpenApiExtension`s as `metadata['extensions']`. Field descriptions become pydantic `Field(description=...)`, so they show up in the request and response schemas. Each `operationId` must be unique, so a transition that generates more than one route (for example `GET` on a resource with unique attributes) can't set one. `typescript-client` ignores these fields.
121
+
122
+ ## Unique attributes
123
+
124
+ Resources are addressed by their primary attribute. A `GET` transition also adds a lookup for each `isUnique` attribute (`/assets/address/{address}`), and, on a child resource, for each `isUniqueInParent` attribute: one that is only unique within its parent, like an asset's address on a chain. Those lookups only exist through the parent (`/chains/{chainId}/assets/address/{address}`), never from root or another ancestor.
125
+
126
+ ## Overrides
127
+
128
+ `overrides` keep an API that existed before genie working the same way once it moves to genie. They are meant to be dropped in the next major version of that API.
129
+
130
+ - `shouldPrefixParentName: false` on a child resource names it without its parent's name: `Agent` under `User` stays `Agent` (not `UserAgent`), so its primary attribute is `agent-id` rather than `user-agent-id` and its fields keep their names. Its path is unchanged (`/users/{userId}/agents/{agentId}`).
131
+ - `responseFieldName` on a `GET`, `LIST`, `CREATE` or `UPDATE` transition renames the field its response puts the resource in (for example `memories` instead of `agentMemories`). Custom transitions name it with `responseField`.
132
+
71
133
  # Development
72
134
 
73
135
  ```
@@ -82,7 +144,9 @@ make install-typescript-client
82
144
  make test-typescript-client
83
145
  ```
84
146
 
85
- Merges to `main` publish a dev version to PyPI. To release, bump `version` in `pyproject.toml` in a PR, then run the Release workflow on `main` (Actions → Release → Run workflow). It tags `vX.Y.Z` and the Publish workflow publishes it. Only the release workflow can push version tags.
147
+ Merges to `main` publish a dev version to PyPI, except for changes that only touch the landing page. To release, bump `version` in `pyproject.toml` in a PR, then run the Release workflow on `main` (Actions → Release → Run workflow). It tags `vX.Y.Z` and the Publish workflow publishes it. Only the release workflow can push version tags.
148
+
149
+ `landing/` is the static site for geniespec.com (plain HTML, CSS and JS, no build step). Preview it with `python3 -m http.server --directory landing`. Merges that touch it sync it to the kiba sites bucket and invalidate CloudFront (`.github/workflows/landing-deploy.yml`).
86
150
 
87
151
  # Things that need work
88
152
 
@@ -54,6 +54,68 @@ resources:
54
54
 
55
55
  Fields use it like any other type (`type: ViewContent`, also inside `List` and `Mapping`). `python-server` generates a `ViewContentV1` pydantic discriminated union in `resources`; `typescript-client` generates a `ViewContentV1` union type and a `viewContentV1FromObject` function that builds the member class named by the discriminator (and throws for unknown values).
56
56
 
57
+ `type: Uuid` is a string that must be a valid UUID. It works anywhere `String` does, including as a primary attribute in paths. `python-server` types it as `uuid.UUID`, so pydantic rejects other strings with a 400, internal methods get `uuid.UUID` objects and responses write them in the standard lowercase hyphenated form; `typescript-client` types it as `string`.
58
+
59
+ `type: BigInt` is an integer of any size that travels as a JSON string, because JSON numbers past 2^53 lose precision in JavaScript. `python-server` types it as `int` (a `BigInt` alias in `resources`), accepts `"123"` or `123` in requests, always writes it as a string and documents it as `{"type": "string"}`; `typescript-client` types it as `bigint`, parsed with `BigInt(...)` and sent with `String(...)`.
60
+
61
+ ## Rate limits
62
+
63
+ Name rate limits at the top level, then pick one per transition with `rateLimit`. `defaultRateLimit` applies to every transition that doesn't set one, and `rateLimit: none` turns it off for a transition, the same way `defaultAuthentication` and `authentication` work:
64
+
65
+ ```yaml
66
+ rateLimits:
67
+ - name: standard-read
68
+ perMinute: 30
69
+ perHour: 300
70
+ - name: public-read
71
+ perMinute: 30
72
+ perHour: 300
73
+ keyBy: ip
74
+ defaultRateLimit: standard-read
75
+ transitions:
76
+ - action: GET-HEALTH
77
+ method: GET
78
+ authentication: none
79
+ rateLimit: public-read
80
+ ```
81
+
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.
83
+
84
+ ## API docs
85
+
86
+ Transitions can set `operationId`, `summary`, `description`, `tags` and `extensions`, and attributes, request fields and response fields can set a `description`:
87
+
88
+ ```yaml
89
+ resources:
90
+ - singleName: Member
91
+ collectionName: Members
92
+ attributes:
93
+ - name: member-id
94
+ type: Uuid
95
+ isPrimary: true
96
+ description: The member's id.
97
+ transitions:
98
+ - action: GET
99
+ operationId: getMember
100
+ summary: Get a member
101
+ description: Returns one member.
102
+ tags: [Members]
103
+ extensions: {deprecated: true}
104
+ ```
105
+
106
+ `python-server` passes the transition fields to kiba-core's `route`, whose `OpenApiSchemaGenerator` documents every route with an `operationId` (and skips the rest); `extensions` reach `OpenApiExtension`s as `metadata['extensions']`. Field descriptions become pydantic `Field(description=...)`, so they show up in the request and response schemas. Each `operationId` must be unique, so a transition that generates more than one route (for example `GET` on a resource with unique attributes) can't set one. `typescript-client` ignores these fields.
107
+
108
+ ## Unique attributes
109
+
110
+ Resources are addressed by their primary attribute. A `GET` transition also adds a lookup for each `isUnique` attribute (`/assets/address/{address}`), and, on a child resource, for each `isUniqueInParent` attribute: one that is only unique within its parent, like an asset's address on a chain. Those lookups only exist through the parent (`/chains/{chainId}/assets/address/{address}`), never from root or another ancestor.
111
+
112
+ ## Overrides
113
+
114
+ `overrides` keep an API that existed before genie working the same way once it moves to genie. They are meant to be dropped in the next major version of that API.
115
+
116
+ - `shouldPrefixParentName: false` on a child resource names it without its parent's name: `Agent` under `User` stays `Agent` (not `UserAgent`), so its primary attribute is `agent-id` rather than `user-agent-id` and its fields keep their names. Its path is unchanged (`/users/{userId}/agents/{agentId}`).
117
+ - `responseFieldName` on a `GET`, `LIST`, `CREATE` or `UPDATE` transition renames the field its response puts the resource in (for example `memories` instead of `agentMemories`). Custom transitions name it with `responseField`.
118
+
57
119
  # Development
58
120
 
59
121
  ```
@@ -68,7 +130,9 @@ make install-typescript-client
68
130
  make test-typescript-client
69
131
  ```
70
132
 
71
- Merges to `main` publish a dev version to PyPI. To release, bump `version` in `pyproject.toml` in a PR, then run the Release workflow on `main` (Actions → Release → Run workflow). It tags `vX.Y.Z` and the Publish workflow publishes it. Only the release workflow can push version tags.
133
+ Merges to `main` publish a dev version to PyPI, except for changes that only touch the landing page. To release, bump `version` in `pyproject.toml` in a PR, then run the Release workflow on `main` (Actions → Release → Run workflow). It tags `vX.Y.Z` and the Publish workflow publishes it. Only the release workflow can push version tags.
134
+
135
+ `landing/` is the static site for geniespec.com (plain HTML, CSS and JS, no build step). Preview it with `python3 -m http.server --directory landing`. Merges that touch it sync it to the kiba sites bucket and invalidate CloudFront (`.github/workflows/landing-deploy.yml`).
72
136
 
73
137
  # Things that need work
74
138
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "geniespec"
3
- version = "0.1.2.dev9"
3
+ version = "0.1.2.dev12"
4
4
  description = "Generate API code from an api.yaml spec"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -21,7 +21,7 @@ repository = "https://github.com/kibalabs/genie"
21
21
 
22
22
  [dependency-groups]
23
23
  dev = [
24
- "kiba-build==0.1.11.dev15",
24
+ "kiba-build==0.1.11.dev24",
25
25
  "kiba-core[core-api,requester]>=0.5.3.dev87,<0.5.4",
26
26
  ]
27
27
 
@@ -31,7 +31,3 @@ build-backend = "uv_build"
31
31
 
32
32
  [tool.pytest.ini_options]
33
33
  pythonpath = ["src"]
34
-
35
- [tool.bumpversion]
36
- search = 'version = "{current_version}"'
37
- replace = 'version = "{new_version}"'
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "geniespec"
3
- version = "0.1.2.dev9"
3
+ version = "0.1.2.dev12"
4
4
  description = "Generate API code from an api.yaml spec"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -21,7 +21,7 @@ repository = "https://github.com/kibalabs/genie"
21
21
 
22
22
  [dependency-groups]
23
23
  dev = [
24
- "kiba-build==0.1.11.dev15",
24
+ "kiba-build==0.1.11.dev24",
25
25
  "kiba-core[core-api,requester]>=0.5.3.dev87,<0.5.4",
26
26
  ]
27
27
 
@@ -31,8 +31,3 @@ build-backend = "uv_build"
31
31
 
32
32
  [tool.pytest.ini_options]
33
33
  pythonpath = ["src"]
34
-
35
- # NOTE(krishan711): without this, bumping the version also rewrites dependency pins that contain it (e.g. 0.1.1 inside kiba-build==0.1.11.dev15)
36
- [tool.bumpversion]
37
- search = "version = \"{current_version}\""
38
- replace = "version = \"{new_version}\""
@@ -45,11 +45,46 @@ properties:
45
45
  items:
46
46
  type: string
47
47
  defaultAuthentication:
48
+ type:
49
+ - "null"
50
+ - string
51
+ pattern: '^[a-z][a-z0-9_-]*$'
52
+ rateLimits:
53
+ type: array
54
+ items:
55
+ $ref: '#/definitions/RateLimit'
56
+ defaultRateLimit:
48
57
  type:
49
58
  - "null"
50
59
  - string
51
60
  pattern: '^[a-z][a-z0-9-]*$'
52
61
  definitions:
62
+ RateLimit:
63
+ type: object
64
+ additionalProperties: false
65
+ required:
66
+ - name
67
+ properties:
68
+ name:
69
+ type: string
70
+ pattern: '^[a-z][a-z0-9-]*$'
71
+ perMinute:
72
+ type: integer
73
+ minimum: 1
74
+ perFiveMinutes:
75
+ type: integer
76
+ minimum: 1
77
+ perHour:
78
+ type: integer
79
+ minimum: 1
80
+ perDay:
81
+ type: integer
82
+ minimum: 1
83
+ keyBy:
84
+ type: string
85
+ enum:
86
+ - user
87
+ - ip
53
88
  EnumValues:
54
89
  type: array
55
90
  minItems: 1
@@ -113,6 +148,8 @@ definitions:
113
148
  type: boolean
114
149
  isUnique:
115
150
  type: boolean
151
+ isUniqueInParent:
152
+ type: boolean
116
153
  shouldDisableGetEndpoint:
117
154
  type: boolean
118
155
  isUnfilterable:
@@ -123,6 +160,8 @@ definitions:
123
160
  type: boolean
124
161
  isDeprecated:
125
162
  type: boolean
163
+ description:
164
+ type: string
126
165
  defaultValue:
127
166
  type:
128
167
  - string
@@ -171,6 +210,12 @@ definitions:
171
210
  type: array
172
211
  items:
173
212
  type: string
213
+ overrides:
214
+ type: object
215
+ additionalProperties: false
216
+ properties:
217
+ shouldPrefixParentName:
218
+ type: boolean
174
219
  BaseTransition:
175
220
  type: object
176
221
  additionalProperties: false
@@ -192,6 +237,11 @@ definitions:
192
237
  responseField:
193
238
  $ref: '#/definitions/ResponseField'
194
239
  authentication:
240
+ type:
241
+ - "null"
242
+ - string
243
+ pattern: '^[a-z][a-z0-9_-]*$'
244
+ rateLimit:
195
245
  type:
196
246
  - "null"
197
247
  - string
@@ -202,6 +252,21 @@ definitions:
202
252
  - json
203
253
  - stream
204
254
  - redirect
255
+ operationId:
256
+ type: string
257
+ pattern: '^[A-Za-z][A-Za-z0-9_]*$'
258
+ summary:
259
+ type: string
260
+ description:
261
+ type: string
262
+ tags:
263
+ type: array
264
+ items:
265
+ type: string
266
+ extensions:
267
+ type: object
268
+ overrides:
269
+ $ref: '#/definitions/TransitionOverrides'
205
270
  Transition:
206
271
  type: object
207
272
  additionalProperties: false
@@ -223,6 +288,11 @@ definitions:
223
288
  responseField:
224
289
  $ref: '#/definitions/ResponseField'
225
290
  authentication:
291
+ type:
292
+ - "null"
293
+ - string
294
+ pattern: '^[a-z][a-z0-9_-]*$'
295
+ rateLimit:
226
296
  type:
227
297
  - "null"
228
298
  - string
@@ -240,6 +310,28 @@ definitions:
240
310
  - collection
241
311
  isIndirectAction:
242
312
  type: boolean
313
+ operationId:
314
+ type: string
315
+ pattern: '^[A-Za-z][A-Za-z0-9_]*$'
316
+ summary:
317
+ type: string
318
+ description:
319
+ type: string
320
+ tags:
321
+ type: array
322
+ items:
323
+ type: string
324
+ extensions:
325
+ type: object
326
+ overrides:
327
+ $ref: '#/definitions/TransitionOverrides'
328
+ TransitionOverrides:
329
+ type: object
330
+ additionalProperties: false
331
+ properties:
332
+ responseFieldName:
333
+ type: string
334
+ pattern: '^[a-z][A-Za-z0-9-]*$'
243
335
  RootTransition:
244
336
  type: object
245
337
  allOf:
@@ -283,6 +375,8 @@ definitions:
283
375
  - 'null'
284
376
  isDeprecated:
285
377
  type: boolean
378
+ description:
379
+ type: string
286
380
  maxValue:
287
381
  type:
288
382
  - string
@@ -329,6 +423,8 @@ definitions:
329
423
  type: boolean
330
424
  isList:
331
425
  type: boolean
426
+ description:
427
+ type: string
332
428
  Exception:
333
429
  type: object
334
430
  additionalProperties: false