You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add `additionalPropertiesStrategy` option to `OpenApi.fromApi`, closes #4531.
7
+
8
+
This update introduces the `additionalPropertiesStrategy` option in `OpenApi.fromApi`, allowing control over how additional properties are handled in the generated OpenAPI schema.
9
+
10
+
- When `"strict"` (default), additional properties are disallowed (`"additionalProperties": false`).
11
+
- When `"allow"`, additional properties are allowed (`"additionalProperties": true`), making APIs more flexible.
12
+
13
+
The `additionalPropertiesStrategy` option has also been added to:
14
+
15
+
-`JSONSchema.fromAST`
16
+
-`OpenApiJsonSchema.makeWithDefs`
17
+
18
+
**Example**
19
+
20
+
```ts
21
+
import {
22
+
HttpApi,
23
+
HttpApiEndpoint,
24
+
HttpApiGroup,
25
+
OpenApi
26
+
} from"@effect/platform"
27
+
import { Schema } from"effect"
28
+
29
+
const api =HttpApi.make("api").add(
30
+
HttpApiGroup.make("group").add(
31
+
HttpApiEndpoint.get("get", "/").addSuccess(
32
+
Schema.Struct({ a: Schema.String })
33
+
)
34
+
)
35
+
)
36
+
37
+
const schema =OpenApi.fromApi(api, {
38
+
additionalPropertiesStrategy: "allow"
39
+
})
40
+
41
+
console.log(JSON.stringify(schema, null, 2))
42
+
/*
43
+
{
44
+
"openapi": "3.1.0",
45
+
"info": {
46
+
"title": "Api",
47
+
"version": "0.0.1"
48
+
},
49
+
"paths": {
50
+
"/": {
51
+
"get": {
52
+
"tags": [
53
+
"group"
54
+
],
55
+
"operationId": "group.get",
56
+
"parameters": [],
57
+
"security": [],
58
+
"responses": {
59
+
"200": {
60
+
"description": "Success",
61
+
"content": {
62
+
"application/json": {
63
+
"schema": {
64
+
"type": "object",
65
+
"required": [
66
+
"a"
67
+
],
68
+
"properties": {
69
+
"a": {
70
+
"type": "string"
71
+
}
72
+
},
73
+
"additionalProperties": true
74
+
}
75
+
}
76
+
}
77
+
},
78
+
"400": {
79
+
"description": "The request did not match the expected schema",
80
+
"content": {
81
+
"application/json": {
82
+
"schema": {
83
+
"$ref": "#/components/schemas/HttpApiDecodeError"
84
+
}
85
+
}
86
+
}
87
+
}
88
+
}
89
+
}
90
+
}
91
+
},
92
+
"components": {
93
+
"schemas": {
94
+
"HttpApiDecodeError": {
95
+
"type": "object",
96
+
"required": [
97
+
"issues",
98
+
"message",
99
+
"_tag"
100
+
],
101
+
"properties": {
102
+
"issues": {
103
+
"type": "array",
104
+
"items": {
105
+
"$ref": "#/components/schemas/Issue"
106
+
}
107
+
},
108
+
"message": {
109
+
"type": "string"
110
+
},
111
+
"_tag": {
112
+
"type": "string",
113
+
"enum": [
114
+
"HttpApiDecodeError"
115
+
]
116
+
}
117
+
},
118
+
"additionalProperties": true,
119
+
"description": "The request did not match the expected schema"
120
+
},
121
+
"Issue": {
122
+
"type": "object",
123
+
"required": [
124
+
"_tag",
125
+
"path",
126
+
"message"
127
+
],
128
+
"properties": {
129
+
"_tag": {
130
+
"type": "string",
131
+
"enum": [
132
+
"Pointer",
133
+
"Unexpected",
134
+
"Missing",
135
+
"Composite",
136
+
"Refinement",
137
+
"Transformation",
138
+
"Type",
139
+
"Forbidden"
140
+
],
141
+
"description": "The tag identifying the type of parse issue"
142
+
},
143
+
"path": {
144
+
"type": "array",
145
+
"items": {
146
+
"$ref": "#/components/schemas/PropertyKey"
147
+
},
148
+
"description": "The path to the property where the issue occurred"
149
+
},
150
+
"message": {
151
+
"type": "string",
152
+
"description": "A descriptive message explaining the issue"
153
+
}
154
+
},
155
+
"additionalProperties": true,
156
+
"description": "Represents an error encountered while parsing a value to match the schema"
157
+
},
158
+
"PropertyKey": {
159
+
"anyOf": [
160
+
{
161
+
"type": "string"
162
+
},
163
+
{
164
+
"type": "number"
165
+
},
166
+
{
167
+
"type": "object",
168
+
"required": [
169
+
"_tag",
170
+
"key"
171
+
],
172
+
"properties": {
173
+
"_tag": {
174
+
"type": "string",
175
+
"enum": [
176
+
"symbol"
177
+
]
178
+
},
179
+
"key": {
180
+
"type": "string"
181
+
}
182
+
},
183
+
"additionalProperties": true,
184
+
"description": "an object to be decoded into a globally shared symbol"
0 commit comments