Skip to content

Commit 3aff4d3

Browse files
OpenApi.Summary & OpenApi.Deprecated annotations (#3944)
1 parent 7807f50 commit 3aff4d3

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

.changeset/chilled-wolves-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/platform": patch
3+
---
4+
5+
`OpenApi.Summary` & `OpenApi.Deprecated` annotations have been added

packages/platform-node/test/HttpApi.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ class UsersApi extends HttpApiGroup.make("users")
280280
}))
281281
.addSuccess(Schema.Array(User))
282282
.addError(NoStatusError)
283+
.annotate(OpenApi.Deprecated, true)
284+
.annotate(OpenApi.Summary, "test summary")
283285
.annotateContext(OpenApi.annotations({ identifier: "listUsers" }))
284286
)
285287
.add(
@@ -302,7 +304,7 @@ class Api extends HttpApi.empty
302304
.addHttpApi(AnotherApi)
303305
.add(UsersApi.prefix("/users"))
304306
.addError(GlobalError, { status: 413 })
305-
.annotateContext(OpenApi.annotations({ title: "API" }))
307+
.annotateContext(OpenApi.annotations({ title: "API", summary: "test api summary" }))
306308
{}
307309

308310
// impl

packages/platform-node/test/fixtures/openapi.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"openapi": "3.0.3",
33
"info": {
44
"title": "API",
5-
"version": "0.0.1"
5+
"version": "0.0.1",
6+
"summary": "test api summary"
67
},
78
"paths": {
89
"/groups/{id}": {
@@ -247,7 +248,11 @@
247248
}
248249
},
249250
"get": {
250-
"tags": ["Users API"],
251+
"tags": [
252+
"Users API"
253+
],
254+
"deprecated": true,
255+
"summary": "test summary",
251256
"operationId": "listUsers",
252257
"parameters": [
253258
{

packages/platform/src/OpenApi.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ export class Servers
6767
*/
6868
export class Format extends Context.Tag("@effect/platform/OpenApi/Format")<Format, string>() {}
6969

70+
/**
71+
* @since 1.0.0
72+
* @category annotations
73+
*/
74+
export class Summary extends Context.Tag("@effect/platform/OpenApi/Summary")<Summary, string>() {}
75+
76+
/**
77+
* @since 1.0.0
78+
* @category annotations
79+
*/
80+
export class Deprecated extends Context.Tag("@effect/platform/OpenApi/Deprecated")<Deprecated, boolean>() {}
81+
7082
/**
7183
* @since 1.0.0
7284
* @category annotations
@@ -98,6 +110,7 @@ export const annotations: (
98110
options: {
99111
readonly identifier?: string | undefined
100112
readonly title?: string | undefined
113+
readonly summary?: string | undefined
101114
readonly version?: string | undefined
102115
readonly description?: string | undefined
103116
readonly license?: OpenAPISpecLicense | undefined
@@ -112,6 +125,7 @@ export const annotations: (
112125
version: Version,
113126
description: Description,
114127
license: License,
128+
summary: Summary,
115129
externalDocs: ExternalDocs,
116130
servers: Servers,
117131
format: Format,
@@ -166,6 +180,9 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
166180
Option.map(Context.getOption(api.annotations, License), (license) => {
167181
spec.info.license = license
168182
})
183+
Option.map(Context.getOption(api.annotations, Summary), (summary) => {
184+
spec.info.summary = summary as any
185+
})
169186
Option.map(Context.getOption(api.annotations, Servers), (servers) => {
170187
spec.servers = servers as any
171188
})
@@ -214,6 +231,12 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
214231
Option.map(Context.getOption(endpoint.annotations, Description), (description) => {
215232
op.description = description
216233
})
234+
Option.map(Context.getOption(endpoint.annotations, Summary), (summary) => {
235+
op.summary = summary
236+
})
237+
Option.map(Context.getOption(endpoint.annotations, Deprecated), (deprecated) => {
238+
op.deprecated = deprecated
239+
})
217240
Option.map(Context.getOption(endpoint.annotations, ExternalDocs), (externalDocs) => {
218241
op.externalDocs = externalDocs
219242
})
@@ -413,6 +436,7 @@ export interface OpenAPISpecInfo {
413436
readonly version: string
414437
readonly description?: string
415438
readonly license?: OpenAPISpecLicense
439+
readonly summary?: string
416440
}
417441

418442
/**

0 commit comments

Comments
 (0)