@@ -7,19 +7,14 @@ import {
77import  {  initServerServices  }  from  '@app-builder/services/init.server' ; 
88import  {  downloadFile  }  from  '@app-builder/utils/download-file' ; 
99import  {  getRoute  }  from  '@app-builder/utils/routes' ; 
10- import  {  json ,   type   LinksFunction ,   type  LoaderFunctionArgs  }  from  '@remix-run/node' ; 
10+ import  {  type  LoaderFunctionArgs  }  from  '@remix-run/node' ; 
1111import  {  useLoaderData  }  from  '@remix-run/react' ; 
1212import  {  type  Namespace  }  from  'i18next' ; 
13- import  *  as  React  from  'react' ; 
1413import  toast  from  'react-hot-toast' ; 
1514import  {  useTranslation  }  from  'react-i18next' ; 
16- import  *  as  R  from  'remeda' ; 
17- import  swaggercss  from  'swagger-ui-react/swagger-ui.css?url' ; 
1815import  {  Button  }  from  'ui-design-system' ; 
1916import  {  Icon  }  from  'ui-icons' ; 
2017
21- const  SwaggerUI  =  React . lazy ( ( )  =>  import ( 'swagger-ui-react' ) ) ; 
22- 
2318export  const  handle  =  { 
2419  i18n : [ 'common' ,  'navigation' ,  'api' ]  satisfies  Namespace , 
2520  BreadCrumbs : [ 
@@ -36,30 +31,26 @@ export const handle = {
3631  ] , 
3732} ; 
3833
39- export  const  links : LinksFunction  =  ( )  => 
40-   swaggercss  ? [ {  rel : 'stylesheet' ,  href : swaggercss  } ]  : [ ] ; 
41- 
4234export  async  function  loader ( {  request } : LoaderFunctionArgs )  { 
4335  const  {  authService }  =  initServerServices ( request ) ; 
4436  const  {  dataModelRepository }  =  await  authService . isAuthenticated ( request ,  { 
4537    failureRedirect : getRoute ( '/sign-in' ) , 
4638  } ) ; 
4739
48-   const  openapi  =  await  dataModelRepository . getOpenApiSpec ( ) ; 
49-   return  json ( {  openapi } ) ; 
40+   const  [ openapi ,  openapiV1 ]  =  await  Promise . all ( [ 
41+     dataModelRepository . getOpenApiSpec ( ) , 
42+     dataModelRepository . getOpenApiSpecOfVersion ( 'v1' ) , 
43+   ] ) ; 
44+ 
45+   return  Response . json ( {  openapi,  openapiV1 } ) ; 
5046} 
5147
5248export  default  function  Api ( )  { 
5349  const  {  t }  =  useTranslation ( handle . i18n ) ; 
54-   const  {  openapi }  =  useLoaderData < typeof  loader > ( ) ; 
50+   const  {  openapi,  openapiV1  }  =  useLoaderData < typeof  loader > ( ) ; 
5551
56-   // Remove those parts, because they are part of the proper openapi spec but we do not want them as input to SwaggerUI 
57-   const  openapiWithoutSomeParts  =  React . useMemo ( ( )  =>  { 
58-     const  openapiWithoutSomeParts  =  R . clone ( openapi ) ; 
59-     delete  openapiWithoutSomeParts . info ; 
60-     delete  openapiWithoutSomeParts . components ?. securitySchemes ; 
61-     return  openapiWithoutSomeParts ; 
62-   } ,  [ openapi ] ) ; 
52+   console . log ( 'openapi' ,  openapi ) ; 
53+   console . log ( 'openapiV1' ,  openapiV1 ) ; 
6354
6455  return  ( 
6556    < Page . Main > 
@@ -68,7 +59,24 @@ export default function Api() {
6859      </ Page . Header > 
6960      < Page . Container > 
7061        < Page . Content > 
71-           < div  className = "flex" > 
62+           < div  className = "flex flex-col gap-2  items-start" > 
63+             < Button 
64+               variant = "secondary" 
65+               onClick = { ( )  =>  { 
66+                 try  { 
67+                   const  blob  =  new  Blob ( [ JSON . stringify ( openapiV1 ) ] ,  { 
68+                     type : 'application/json;charset=utf-8,' , 
69+                   } ) ; 
70+                   const  url  =  URL . createObjectURL ( blob ) ; 
71+                   void  downloadFile ( url ,  'openapi-v1.json' ) ; 
72+                 }  catch  ( _error )  { 
73+                   toast . error ( t ( 'common:errors.unknown' ) ) ; 
74+                 } 
75+               } } 
76+             > 
77+               < Icon  icon = "download"  className = "me-2 size-6"  /> 
78+               { t ( 'api:download_openapi_spec_v1' ) } 
79+             </ Button > 
7280            < Button 
7381              variant = "secondary" 
7482              onClick = { ( )  =>  { 
@@ -87,17 +95,6 @@ export default function Api() {
8795              { t ( 'api:download_openapi_spec' ) } 
8896            </ Button > 
8997          </ div > 
90-           < div  className = "-mx-5" > 
91-             < React . Suspense  fallback = { t ( 'common:loading' ) } > 
92-               { /* Issue with UNSAFE_componentWillReceiveProps: https://github.com/swagger-api/swagger-ui/issues/5729 */ } 
93-               < SwaggerUI 
94-                 spec = { openapiWithoutSomeParts } 
95-                 supportedSubmitMethods = { [ ] } 
96-                 defaultModelExpandDepth = { 5 } 
97-                 defaultModelsExpandDepth = { 4 } 
98-               /> 
99-             </ React . Suspense > 
100-           </ div > 
10198        </ Page . Content > 
10299      </ Page . Container > 
103100    </ Page . Main > 
0 commit comments