Skip to content

Commit e8c93bb

Browse files
Start adding docstrings
1 parent 9b5e5d8 commit e8c93bb

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.2] - 2025-04-27
9+
10+
- Add OpenAPI Specification v3.1 objects, by @tyzhnenko.
11+
812
## [1.1.1] - 2025-03-20
913

1014
- Fix bug in `MARKDOWN` view for `servers` (displaying twice the `description`

openapidocs/v31.py

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class SecuritySchemeType(Enum):
7373

7474
@dataclass
7575
class Contact(OpenAPIElement):
76+
"""
77+
Represents a Contact object in OpenAPI.
78+
79+
Attributes:
80+
name (Optional[str]): The identifying name of the contact person/organization.
81+
url (Optional[str]): The URL pointing to the contact information.
82+
email (Optional[str]): The email address of the contact person/organization.
83+
"""
7684
name: Optional[str] = None
7785
url: Optional[str] = None
7886
email: Optional[str] = None
@@ -93,6 +101,18 @@ class License(OpenAPIElement):
93101

94102
@dataclass
95103
class Info(OpenAPIElement):
104+
"""
105+
Represents the Info object in OpenAPI.
106+
107+
Attributes:
108+
title (str): The title of the API.
109+
version (str): The version of the API.
110+
summary (Optional[str]): A short summary of the API.
111+
description (Optional[str]): A detailed description of the API.
112+
terms_of_service (Optional[str]): A URL to the terms of service for the API.
113+
contact (Optional[Contact]): Contact information for the API.
114+
license (Optional[License]): License information for the API.
115+
"""
96116
title: str
97117
version: str
98118
summary: Optional[str] = None
@@ -118,6 +138,16 @@ class Server(OpenAPIElement):
118138

119139
@dataclass
120140
class XML(OpenAPIElement):
141+
"""
142+
Represents an XML object in OpenAPI.
143+
144+
Attributes:
145+
name (Optional[str]): The name of the XML element.
146+
namespace (Optional[str]): The namespace of the XML element.
147+
prefix (Optional[str]): The prefix to be used for the XML element.
148+
attribute (Optional[bool]): Whether the property is an attribute.
149+
wrapped (Optional[bool]): Whether the array is wrapped.
150+
"""
121151
name: Optional[str] = None
122152
namespace: Optional[str] = None
123153
prefix: Optional[str] = None
@@ -133,6 +163,61 @@ class Discriminator(OpenAPIElement):
133163

134164
@dataclass
135165
class Schema(OpenAPIElement):
166+
"""
167+
Represents a Schema object in OpenAPI.
168+
169+
Attributes:
170+
type (Union[None, str, ValueType, List[Union[None, str, ValueType]]]):
171+
The type of the schema (e.g., string, object, array).
172+
format (Union[None, str, ValueFormat]):
173+
The format of the schema (e.g., date-time, uuid).
174+
required (Optional[List[str]]):
175+
A list of required property names.
176+
properties (Optional[Dict[str, Union["Schema", "Reference"]]]):
177+
A dictionary of property names to their schemas or references.
178+
default (Optional[Any]):
179+
The default value for the schema.
180+
deprecated (Optional[bool]):
181+
Indicates if the schema is deprecated.
182+
example (Any):
183+
An example value for the schema.
184+
external_docs (Optional[ExternalDocs]):
185+
Additional external documentation for the schema.
186+
ref (Optional[str]):
187+
A reference to another schema.
188+
title (Optional[str]):
189+
The title of the schema.
190+
description (Optional[str]):
191+
A description of the schema.
192+
content_encoding (Optional[str]):
193+
The content encoding for the schema.
194+
content_media_type (Optional[str]):
195+
The content media type for the schema.
196+
max_length (Optional[float]):
197+
The maximum length for string values.
198+
min_length (Optional[float]):
199+
The minimum length for string values.
200+
maximum (Optional[float]):
201+
The maximum value for numeric values.
202+
minimum (Optional[float]):
203+
The minimum value for numeric values.
204+
xml (Optional[XML]):
205+
Additional metadata for XML representation.
206+
items (Union[None, "Schema", "Reference"]):
207+
The schema for items in an array.
208+
enum (Optional[List[str]]):
209+
A list of allowed values for the schema.
210+
discriminator (Optional[Discriminator]):
211+
The discriminator for polymorphism.
212+
all_of (Optional[List[Union["Schema", "Reference"]]]):
213+
A list of schemas that must all apply.
214+
any_of (Optional[List[Union["Schema", "Reference"]]]):
215+
A list of schemas where at least one must apply.
216+
one_of (Optional[List[Union["Schema", "Reference"]]]):
217+
A list of schemas where exactly one must apply.
218+
not_ (Optional[List[Union["Schema", "Reference"]]]):
219+
A schema that must not apply.
220+
"""
136221
type: Union[None, str, ValueType, List[Union[None, str, ValueType]]] = None
137222
format: Union[None, str, ValueFormat] = None
138223
required: Optional[List[str]] = None
@@ -345,8 +430,39 @@ class OpenIdConnectSecurity(SecurityScheme):
345430
description: Optional[str] = None
346431

347432

433+
@dataclass
434+
class MutualTLSSecurity(SecurityScheme):
435+
type: SecuritySchemeType = SecuritySchemeType.MUTUALTLS
436+
description: Optional[str] = None
437+
438+
348439
@dataclass
349440
class Components(OpenAPIElement):
441+
"""
442+
Represents the reusable components of an OpenAPI document.
443+
444+
Attributes:
445+
schemas (Optional[Dict[str, Union[Schema, Reference]]]):
446+
A dictionary of reusable Schema Objects or references to them.
447+
responses (Optional[Dict[str, Union[Response, Reference]]]):
448+
A dictionary of reusable Response Objects or references to them.
449+
parameters (Optional[Dict[str, Union[Parameter, Reference]]]):
450+
A dictionary of reusable Parameter Objects or references to them.
451+
examples (Optional[Dict[str, Union[Example, Reference]]]):
452+
A dictionary of reusable Example Objects or references to them.
453+
request_bodies (Optional[Dict[str, Union[RequestBody, Reference]]]):
454+
A dictionary of reusable RequestBody Objects or references to them.
455+
headers (Optional[Dict[str, Union[Header, Reference]]]):
456+
A dictionary of reusable Header Objects or references to them.
457+
security_schemes (Optional[Dict[str, Union[SecurityScheme, Reference]]]):
458+
A dictionary of reusable SecurityScheme Objects or references to them.
459+
links (Optional[Dict[str, Union[Link, Reference]]]):
460+
A dictionary of reusable Link Objects or references to them.
461+
callbacks (Optional[Dict[str, Union[Callback, Reference]]]):
462+
A dictionary of reusable Callback Objects or references to them.
463+
path_items (Optional[Dict[str, Union[PathItem, Reference]]]):
464+
A dictionary of reusable PathItem Objects or references to them.
465+
"""
350466
schemas: Optional[Dict[str, Union[Schema, Reference]]] = None
351467
responses: Optional[Dict[str, Union[Response, Reference]]] = None
352468
parameters: Optional[Dict[str, Union[Parameter, Reference]]] = None
@@ -380,7 +496,7 @@ def to_obj(self):
380496

381497
@dataclass
382498
class OpenAPI(OpenAPIRoot):
383-
openapi: str = "3.1.0"
499+
openapi: str = "3.1.1"
384500
info: Optional[Info] = None
385501
json_schema_dialect: str = "https://json-schema.org/draft/2020-12/schema"
386502
paths: Optional[Dict[str, PathItem]] = None

0 commit comments

Comments
 (0)