@@ -17,11 +17,20 @@ import {
1717import { signatureResponseSchema } from "./signature/schemas" ;
1818
1919const doc = {
20- openapi : "3.0.0 " ,
20+ openapi : "3.0.3 " ,
2121 info : {
2222 title : "Medialit API" ,
2323 description : "Easy file uploads for serverless apps" ,
2424 version : "0.3.0" ,
25+ termsOfService : "https://medialit.cloud/p/terms" ,
26+ contact : {
27+ name : "Medialit Support" ,
28+ url : "https://medialit.cloud" ,
29+ } ,
30+ license : {
31+ name : "AGPL-3.0" ,
32+ url : "https://www.gnu.org/licenses/agpl-3.0.en.html" ,
33+ } ,
2534 } ,
2635 servers : [
2736 {
@@ -38,6 +47,16 @@ const doc = {
3847 } ,
3948 } ,
4049 ] ,
50+ tags : [
51+ {
52+ name : "Media" ,
53+ description : "Upload, list, and manage media resources." ,
54+ } ,
55+ {
56+ name : "Settings" ,
57+ description : "Manage media processing configuration." ,
58+ } ,
59+ ] ,
4160 components : {
4261 securitySchemes : {
4362 apiKeyAuth : {
@@ -57,6 +76,28 @@ swaggerAutogen()(outputFile, routes, doc).then(() => {
5776 // Post-process to inject Joi schemas directly (avoiding autogen inference)
5877 const content = JSON . parse ( fs . readFileSync ( outputFile , "utf8" ) ) ;
5978
79+ const operationIdByMethodAndPath : Record < string , string > = {
80+ "get /health" : "getHealth" ,
81+ "post /settings/media/create" : "updateMediaSettings" ,
82+ "post /settings/media/get" : "getMediaSettings" ,
83+ "post /media/signature/create" : "createUploadSignature" ,
84+ "post /media/create" : "uploadMedia" ,
85+ "post /media/get/count" : "getMediaCount" ,
86+ "post /media/get/size" : "getMediaSize" ,
87+ "post /media/get/{mediaId}" : "getMediaDetails" ,
88+ "post /media/get" : "listMedia" ,
89+ "post /media/seal/{mediaId}" : "sealMedia" ,
90+ "delete /media/delete/{mediaId}" : "deleteMedia" ,
91+ } ;
92+
93+ const errorDescriptionByStatus : Record < string , string > = {
94+ "400" : "Bad Request" ,
95+ "401" : "Unauthorized" ,
96+ "404" : "Not Found" ,
97+ "409" : "Conflict" ,
98+ "500" : "Internal Server Error" ,
99+ } ;
100+
60101 // Inject components.schemas manually
61102 content . components . schemas = {
62103 ...content . components . schemas ,
@@ -68,8 +109,93 @@ swaggerAutogen()(outputFile, routes, doc).then(() => {
68109 SignatureResponse : joiToSwagger ( signatureResponseSchema ) . swagger ,
69110 MediaCountResponse : joiToSwagger ( mediaCountResponseSchema ) . swagger ,
70111 MediaSizeResponse : joiToSwagger ( mediaSizeResponseSchema ) . swagger ,
112+ ErrorResponse : {
113+ type : "object" ,
114+ properties : {
115+ error : {
116+ type : "string" ,
117+ example : "Unauthorized" ,
118+ } ,
119+ } ,
120+ required : [ "error" ] ,
121+ additionalProperties : false ,
122+ } ,
71123 } ;
72124
125+ if ( content . paths ) {
126+ delete content . paths [ "/cleanup/temp" ] ;
127+ delete content . paths [ "/cleanup/tus" ] ;
128+ }
129+
130+ Object . entries ( content . paths || { } ) . forEach ( ( [ apiPath , pathItem ] : any ) => {
131+ Object . entries ( pathItem || { } ) . forEach ( ( [ method , operation ] : any ) => {
132+ if ( ! operation || typeof operation !== "object" ) {
133+ return ;
134+ }
135+
136+ const operationId =
137+ operationIdByMethodAndPath [ `${ method } ${ apiPath } ` ] ;
138+ if ( operationId ) {
139+ operation . operationId = operationId ;
140+ }
141+
142+ if ( Array . isArray ( operation . parameters ) ) {
143+ operation . parameters . forEach ( ( parameter : any ) => {
144+ if ( parameter && typeof parameter === "object" ) {
145+ delete parameter . type ;
146+ }
147+ } ) ;
148+ }
149+
150+ if ( apiPath === "/media/create" && method === "post" ) {
151+ operation . security = [ { apiKeyAuth : [ ] } ] ;
152+ }
153+
154+ if ( apiPath === "/health" && method === "get" ) {
155+ operation . security = [ ] ;
156+ }
157+
158+ if ( apiPath === "/media/get" && method === "post" ) {
159+ delete operation . parameters ;
160+ operation . requestBody = {
161+ required : false ,
162+ content : {
163+ "application/json" : {
164+ schema : {
165+ $ref : "#/components/schemas/GetMediaQuery" ,
166+ } ,
167+ } ,
168+ } ,
169+ } ;
170+ }
171+
172+ operation . responses = operation . responses || { } ;
173+ [ "400" , "401" , "404" , "409" , "500" ] . forEach ( ( statusCode ) => {
174+ const existingResponse = operation . responses [ statusCode ] ;
175+ if ( ! existingResponse || existingResponse . $ref ) {
176+ return ;
177+ }
178+
179+ operation . responses [ statusCode ] = {
180+ ...existingResponse ,
181+ description :
182+ existingResponse . description ||
183+ errorDescriptionByStatus [ statusCode ] ,
184+ content : existingResponse . content || {
185+ "application/json" : {
186+ schema : {
187+ $ref : "#/components/schemas/ErrorResponse" ,
188+ } ,
189+ example : {
190+ error : errorDescriptionByStatus [ statusCode ] ,
191+ } ,
192+ } ,
193+ } ,
194+ } ;
195+ } ) ;
196+ } ) ;
197+ } ) ;
198+
73199 if ( content . openapi && content . swagger ) {
74200 delete content . swagger ;
75201 }
0 commit comments