Skip to content

Commit 94c0871

Browse files
📝 Document compatibility with OpenAPI. Extend dummy OpenAPI doc with examples.
1 parent 4150f37 commit 94c0871

File tree

11 files changed

+147
-4
lines changed

11 files changed

+147
-4
lines changed

‎config/mkdocs.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ docs_dir: ../docs
55

66
nav:
77
- index.md
8+
- openapi.md

‎docs/openapi.md‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# OpenAPI compatibility
2+
3+
- openapi: validated (3.0.* accepted)
4+
- info
5+
- license: Not usable. It's up to the user to verify the accepted use.
6+
- title and other fields: planned as part of project readme
7+
- externalDocs: planned as part of the project readme
8+
- servers: first server is used
9+
- url: used as the base URL
10+
- variables: default values are used to evaluate the server URL
11+
- security: implemented
12+
- tags: ignored, not planned
13+
- components
14+
- schemas:
15+
- title: planned as part of class docstr
16+
- type
17+
- [no value]: planned as primitive JSON-compatible object.
18+
- object: implemented as pydantic models
19+
- array: implemented as list
20+
- string, integer, number, boolean: implemented as str, int, float and bool
21+
- format: planned, including custom formats
22+
- validation keyword: supported by pydantic
23+
- allOf: needs improvement
24+
- oneOf and anyOf: implemented as union
25+
- not: planned for objects
26+
- required: non-required properties are turned to `Union[None, $type]`
27+
- additionalProperties:
28+
- boolean: supported as pydantic `extra: 'allow'` or `'forbid'`
29+
- schema: planned as a `Mapping` field
30+
- patternProperties: planned as `Mapping` field
31+
- enum: ignored; might be implemented for simple types as `Literal`
32+
- description: planned as part of docstr
33+
- default: if present, the property type turned to `Union[None, $type]` and has default value `None`
34+
- caveat: default values are not to be sent between Web API client and server, instead they are implied be the receiving side. Lapidary could potentially fill such values in response models, but it might be expensive, so it's not planned.
35+
- nullable: if true, the property type is turned to `Union[None, $type]`
36+
- readOnly & writeOnly: if either is true, the property type is turned to `Union[None, $type]` and has default value `None`; planned as part of docstr
37+
- caveat: readOnly properties are only to be sent to API server, and writeOnly only to be received by the client. A property might be both required one way, and invalid the other way, which could not be directly represented in Python.
38+
- discriminator: ignored
39+
- example: might be used as part of docstr
40+
- externalDocs: planned as part of docstr
41+
- deprecated: planned
42+
- xml: ignored, currently not planned
43+
- responses
44+
- description: planned as part of docstr
45+
- headers: if present, used as fields in the response envelope class
46+
- content: implemented; used as operation method return type, and a way to resolve model type for a response
47+
- links: ignored; might be used to generate methods in the response envelope
48+
- parameters: used in-line in operations
49+
- examples: ignored
50+
- requestBodies
51+
- description: planned as part of docstr
52+
- content: implemented
53+
- required: planned
54+
- headers: implemented
55+
- securitySchemes: implemented with httpx_auth
56+
- refreshUrl: not supported
57+
- links: planned
58+
- callbacks: not planned
59+
- paths
60+
- summary, description: planned as parts of docstr
61+
- servers: ignored
62+
- parameters
63+
- name: OpenAPI parameter names are not unique and might contain characters invalid for python names, therefore they're escaped and suffix-hungarian notation is used to distinguish between cookie, header, path and query parameters
64+
- in: implemented, suffix-hungarian notation is used to separate parameters
65+
- required: non-required parameters are optional with default value `None`
66+
- deprecated: planned
67+
- allowEmtyValue: planned
68+
- content: key: planned, value: processed as schema
69+
- style: partially implemented
70+
- allowReserved: planned
71+
- schema: implemented
72+
- example & examples: planned
73+
- x-lapidary-name: name of a parameter in the python
74+
- x-lapidary-responses-global: responses that might come from any operation
75+
- x-lapidary-headers-global: headers accepted by any operation

‎tests/e2e/expected/dummy/dummy.yaml‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ paths:
1818
x-count:
1919
schema:
2020
type: integer
21+
'300':
22+
$ref: '#/components/responses/default'
2123
parameters:
2224
- name: param1
2325
in: query
@@ -34,7 +36,7 @@ paths:
3436
additionalProperties: false
3537
required:
3638
- prop1
37-
required: true
39+
required: false
3840
/inline_schema_properties/:
3941
get:
4042
operationId: inline_schema_properties
@@ -75,6 +77,8 @@ paths:
7577
- read
7678
/insecure:
7779
get:
80+
requestBody:
81+
$ref: '#/components/requestBodies/dummy'
7882
description: Operation with no security requirements
7983
operationId: insecure
8084
responses:
@@ -211,6 +215,20 @@ components:
211215
schema:
212216
$ref: '#/components/schemas/all'
213217
description: ''
218+
requestBodies:
219+
dummy:
220+
required: false
221+
description: ''
222+
content:
223+
application/json:
224+
schema:
225+
type: object
226+
properties:
227+
prop1:
228+
type: string
229+
additionalProperties: false
230+
required:
231+
- prop1
214232

215233
security:
216234
- oauth-refresh:

‎tests/e2e/expected/dummy/gen/test_dummy/client.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import typing_extensions as typing
1111
from lapidary.runtime import *
1212

13+
import test_dummy.components.requestBodies.dummy.content.applicationu_ljson.schema.schema
1314
import test_dummy.components.responses.default
1415
import test_dummy.components.schemas.schema1.schema
1516
import test_dummy.paths.u_lcustomu_jsecurity.get.responses.default
@@ -43,13 +44,16 @@ async def test_op(
4344
self: typing.Self,
4445
*,
4546
param1_q: typing.Annotated[test_dummy.components.schemas.schema1.schema.schema1, Query('param1', )],
46-
param2_q: typing.Annotated[test_dummy.paths.u_ltestu_l.get.parameters.u_n.schema.schema.schema, Query('param2', )],
47+
param2_q: typing.Annotated[typing.Union[None, test_dummy.paths.u_ltestu_l.get.parameters.u_n.schema.schema.schema], Query('param2', )] = None,
4748
) -> typing.Annotated[
48-
Awaitable[test_dummy.paths.u_ltestu_l.get.responses.default.Response],
49+
Awaitable[typing.Union[test_dummy.components.responses.default.Response, test_dummy.paths.u_ltestu_l.get.responses.default.Response]],
4950
Responses({
5051
'default': {
5152
'application/json': test_dummy.paths.u_ltestu_l.get.responses.default.Response,
5253
},
54+
'300': {
55+
'application/json': test_dummy.components.responses.default.Response,
56+
},
5357
})
5458
]:
5559
pass
@@ -83,6 +87,12 @@ async def customSecurity(
8387
@get('/insecure', security=[])
8488
async def insecure(
8589
self: typing.Self,
90+
request_body: typing.Annotated[
91+
test_dummy.components.requestBodies.dummy.content.applicationu_ljson.schema.schema.schema,
92+
RequestBody({
93+
'application/json': test_dummy.components.requestBodies.dummy.content.applicationu_ljson.schema.schema.schema,
94+
}),
95+
],
8696
) -> typing.Annotated[
8797
Awaitable[test_dummy.components.responses.default.Response],
8898
Responses({
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is automatically @generated by Lapidary and should not be changed by hand.
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is automatically @generated by Lapidary and should not be changed by hand.
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is automatically @generated by Lapidary and should not be changed by hand.
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is automatically @generated by Lapidary and should not be changed by hand.
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is automatically @generated by Lapidary and should not be changed by hand.
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is automatically @generated by Lapidary and should not be changed by hand.
2+
3+
from __future__ import annotations
4+
5+
import lapidary.runtime
6+
import pydantic
7+
import typing_extensions as typing
8+
9+
10+
class schema(lapidary.runtime.ModelBase):
11+
prop1: str

0 commit comments

Comments
 (0)