File tree Expand file tree Collapse file tree 7 files changed +205
-27
lines changed Expand file tree Collapse file tree 7 files changed +205
-27
lines changed Original file line number Diff line number Diff line change 55- Laxer usage of ` ControllerMethodArgs ` decorator: now allowing ` queries ` ,
66 ` params ` , ` header ` as literal arguments, so that things still work even if
77 users accidentally / deliberately use the undocumented singular / plural forms
8+ - Support for Open API Spec v3.1
9+ - Support for ` operationId ` and ` tags ` in OAS path request declarations
10+ - Support for top-level ` tags ` in OAS document
811
912### Changed
1013
1114- switched from ` deps.ts ` and ` dev_deps.ts ` to ` deno.jsonc `
1215- revamped documentation (JSDoc)
1316- code format & code format settings for VS Code users
14- - upgraded dependencies (` zod@^3.24.1 ` )
17+ - upgraded dependencies (` zod@^3.24.1 ` , ` @std/assert@^1.0.10 ` ,
18+ ` @std/testing@^1.0.8 ` )
1519- updated typing for ` OakOpenApiSpec ` (added prop: ` request ` , untyped unproven
1620 prop: ` requestBody ` )
1721
Original file line number Diff line number Diff line change 11{
22 "name" : " @dklab/oak-routing-ctrl" ,
3- "version" : " 0.13.0-alpha.2 " ,
3+ "version" : " 0.13.0-rc.1 " ,
44 "exports" : {
55 "." : " ./mod.ts" ,
66 "./mod" : " ./mod.ts"
2222 "imports" : {
2323 "@asteasolutions/zod-to-openapi" : " npm:@asteasolutions/zod-to-openapi@^7.3.0" ,
2424 "@oak/oak" : " jsr:@oak/oak@^17.1.3" ,
25- "@std/assert" : " jsr:@std/assert@^1.0.9 " ,
25+ "@std/assert" : " jsr:@std/assert@^1.0.10 " ,
2626 "@std/io" : " jsr:@std/io@^0.225.0" ,
2727 "@std/path" : " jsr:@std/path@^1.0.8" ,
28- "@std/testing" : " jsr:@std/testing@^1.0.6 " ,
28+ "@std/testing" : " jsr:@std/testing@^1.0.8 " ,
2929 "zod" : " npm:zod@^3.24.1"
3030 },
3131 "fmt" : {
Original file line number Diff line number Diff line change 11export const snapshot = {};
22
3- snapshot [` useOas standard behavior > testApiDocSnapshot 1` ] = `
3+ snapshot [` useOas standard behavior - OpenApi v3.0 > testApiDocSnapshot 1` ] = `
44{
55 components : {
66 parameters: {},
@@ -15,6 +15,7 @@ snapshot[`useOas standard behavior > testApiDocSnapshot 1`] = `
1515 paths : {
1616 " /hello/{name}" : {
1717 post: {
18+ operationId: undefined ,
1819 parameters: [
1920 {
2021 in: " path" ,
@@ -26,6 +27,7 @@ snapshot[`useOas standard behavior > testApiDocSnapshot 1`] = `
2627 },
2728 ],
2829 responses: {},
30+ tags: undefined ,
2931 },
3032 },
3133 },
@@ -34,5 +36,65 @@ snapshot[`useOas standard behavior > testApiDocSnapshot 1`] = `
3436 url: " /mock/" ,
3537 },
3638 ],
39+ tags : [
40+ {
41+ description: " Example description for Example Section" ,
42+ externalDocs: {
43+ url: " http://localhost" ,
44+ },
45+ name: " Example Section" ,
46+ },
47+ ],
48+ }
49+ ` ;
50+
51+ snapshot [` useOas standard behavior - OpenApi v3.1 > testApiDocSnapshot 1` ] = `
52+ {
53+ components : {
54+ parameters: {},
55+ schemas: {},
56+ },
57+ info : {
58+ description: " this is a mock API" ,
59+ title: " mock API" ,
60+ version: " 0.1.0" ,
61+ },
62+ openapi : " 3.1.0" ,
63+ paths : {
64+ " /hello/{name}" : {
65+ post: {
66+ operationId: " my-unique-test-op-id" ,
67+ parameters: [
68+ {
69+ in: " path" ,
70+ name: " name" ,
71+ required: true ,
72+ schema: {
73+ type: " string" ,
74+ },
75+ },
76+ ],
77+ responses: {},
78+ tags: [
79+ " Example Section" ,
80+ ],
81+ },
82+ },
83+ },
84+ servers : [
85+ {
86+ url: " /mock/" ,
87+ },
88+ ],
89+ tags : [
90+ {
91+ description: " Example description for Example Section" ,
92+ externalDocs: {
93+ url: " http://localhost" ,
94+ },
95+ name: " Example Section" ,
96+ },
97+ ],
98+ webhooks : {},
3799}
38100` ;
Original file line number Diff line number Diff line change @@ -3,8 +3,12 @@ import type { OakOpenApiSpec } from "./utils/schema_utils.ts";
33import type { SupportedVerb } from "./Store.ts" ;
44import { debug } from "./utils/logger.ts" ;
55
6+ type TheRouteConfig = RouteConfig & {
7+ tags ?: string [ ] ;
8+ } ;
9+
610// fnName|method|path => OasRouteConfig
7- export const oasStore : Map < string , RouteConfig > = new Map ( ) ;
11+ export const oasStore : Map < string , TheRouteConfig > = new Map ( ) ;
812
913const getRouteId = (
1014 fnName : string ,
@@ -62,6 +66,8 @@ export const updateOas = (
6266 ...existing . responses ,
6367 ...specs ?. responses ,
6468 } ,
69+ operationId : specs ?. operationId ,
70+ tags : specs ?. tags ,
6571 } ;
6672
6773 debug ( `OpenApiSpec: recording for [${ method } ] ${ path } ` ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { Application } from "@oak/oak";
22import { oasStore } from "./oasStore.ts" ;
33import {
44 OpenApiGeneratorV3 ,
5+ OpenApiGeneratorV31 ,
56 OpenAPIRegistry ,
67 type RouteConfig ,
78} from "@asteasolutions/zod-to-openapi" ;
@@ -34,6 +35,11 @@ export type UseOasConfig = Partial<OpenAPIObjectConfig> & {
3435 jsonPath ?: string ;
3536 uiPath ?: string ;
3637 uiTemplate ?: string ;
38+ tags ?: {
39+ name : string ;
40+ description ?: string ;
41+ externalDocs ?: { url : string } ;
42+ } [ ] ;
3743} ;
3844
3945type UseOas = (
@@ -62,7 +68,11 @@ const _useOas: UseOas = (
6268 }
6369 } ) ;
6470
65- const generator = new OpenApiGeneratorV3 ( registry . definitions ) ;
71+ const OpenApiGenerator = oasCfg . openapi ?. startsWith ( "3.0" )
72+ ? OpenApiGeneratorV3
73+ : OpenApiGeneratorV31 ;
74+
75+ const generator = new OpenApiGenerator ( registry . definitions ) ;
6676 const apiDoc = generator . generateDocument ( {
6777 openapi : "3.0.0" ,
6878 info : {
You can’t perform that action at this time.
0 commit comments