Skip to content

Commit

Permalink
OpenApi.Summary & OpenApi.Deprecated annotations (#3944)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhraksMamtsov authored Nov 14, 2024
1 parent 7807f50 commit 3aff4d3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-wolves-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

`OpenApi.Summary` & `OpenApi.Deprecated` annotations have been added
4 changes: 3 additions & 1 deletion packages/platform-node/test/HttpApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ class UsersApi extends HttpApiGroup.make("users")
}))
.addSuccess(Schema.Array(User))
.addError(NoStatusError)
.annotate(OpenApi.Deprecated, true)
.annotate(OpenApi.Summary, "test summary")
.annotateContext(OpenApi.annotations({ identifier: "listUsers" }))
)
.add(
Expand All @@ -302,7 +304,7 @@ class Api extends HttpApi.empty
.addHttpApi(AnotherApi)
.add(UsersApi.prefix("/users"))
.addError(GlobalError, { status: 413 })
.annotateContext(OpenApi.annotations({ title: "API" }))
.annotateContext(OpenApi.annotations({ title: "API", summary: "test api summary" }))
{}

// impl
Expand Down
9 changes: 7 additions & 2 deletions packages/platform-node/test/fixtures/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"openapi": "3.0.3",
"info": {
"title": "API",
"version": "0.0.1"
"version": "0.0.1",
"summary": "test api summary"
},
"paths": {
"/groups/{id}": {
Expand Down Expand Up @@ -247,7 +248,11 @@
}
},
"get": {
"tags": ["Users API"],
"tags": [
"Users API"
],
"deprecated": true,
"summary": "test summary",
"operationId": "listUsers",
"parameters": [
{
Expand Down
24 changes: 24 additions & 0 deletions packages/platform/src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ export class Servers
*/
export class Format extends Context.Tag("@effect/platform/OpenApi/Format")<Format, string>() {}

/**
* @since 1.0.0
* @category annotations
*/
export class Summary extends Context.Tag("@effect/platform/OpenApi/Summary")<Summary, string>() {}

/**
* @since 1.0.0
* @category annotations
*/
export class Deprecated extends Context.Tag("@effect/platform/OpenApi/Deprecated")<Deprecated, boolean>() {}

/**
* @since 1.0.0
* @category annotations
Expand Down Expand Up @@ -98,6 +110,7 @@ export const annotations: (
options: {
readonly identifier?: string | undefined
readonly title?: string | undefined
readonly summary?: string | undefined
readonly version?: string | undefined
readonly description?: string | undefined
readonly license?: OpenAPISpecLicense | undefined
Expand All @@ -112,6 +125,7 @@ export const annotations: (
version: Version,
description: Description,
license: License,
summary: Summary,
externalDocs: ExternalDocs,
servers: Servers,
format: Format,
Expand Down Expand Up @@ -166,6 +180,9 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
Option.map(Context.getOption(api.annotations, License), (license) => {
spec.info.license = license
})
Option.map(Context.getOption(api.annotations, Summary), (summary) => {
spec.info.summary = summary as any
})
Option.map(Context.getOption(api.annotations, Servers), (servers) => {
spec.servers = servers as any
})
Expand Down Expand Up @@ -214,6 +231,12 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
Option.map(Context.getOption(endpoint.annotations, Description), (description) => {
op.description = description
})
Option.map(Context.getOption(endpoint.annotations, Summary), (summary) => {
op.summary = summary
})
Option.map(Context.getOption(endpoint.annotations, Deprecated), (deprecated) => {
op.deprecated = deprecated
})
Option.map(Context.getOption(endpoint.annotations, ExternalDocs), (externalDocs) => {
op.externalDocs = externalDocs
})
Expand Down Expand Up @@ -413,6 +436,7 @@ export interface OpenAPISpecInfo {
readonly version: string
readonly description?: string
readonly license?: OpenAPISpecLicense
readonly summary?: string
}

/**
Expand Down

0 comments on commit 3aff4d3

Please sign in to comment.