Swagger docs improved (#2607)
* fix: adds servers in openapi, remove hack in snippets, update deps, make dynamic import to use latests swagger ui deps * fix: remove unneded import * fix: adds yarn dev commands for api and swagger Co-authored-by: Agusti Fernandez Pardo <git@agusti.me> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									95dfb5b538
								
							
						
					
					
						commit
						e260ba0e49
					
				
					 4 changed files with 26 additions and 50 deletions
				
			
		|  | @ -77,7 +77,7 @@ export const SnippedGenerator = { | |||
|               //             method,
 | ||||
|               //             targets
 | ||||
|               //             // Since I don't know why hostname was undefinedundefined, I harcoded it here
 | ||||
|               //           ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com");
 | ||||
|               //           ).snippets[0].content;
 | ||||
|               //         } catch (err) {
 | ||||
|               //           // set to error in case it happens the npm package has some flaws
 | ||||
|               //           snippet = JSON.stringify(snippet);
 | ||||
|  | @ -104,12 +104,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  | @ -136,12 +132,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  | @ -168,12 +160,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  | @ -200,12 +188,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  | @ -237,7 +221,7 @@ export const SnippedGenerator = { | |||
|               //             path,
 | ||||
|               //             method,
 | ||||
|               //             targets
 | ||||
|               //           ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com");
 | ||||
|               //           ).snippets[0].content;
 | ||||
|               //         } catch (err) {
 | ||||
|               //           // set to error in case it happens the npm package has some flaws
 | ||||
|               //           snippet = JSON.stringify(snippet);
 | ||||
|  | @ -269,7 +253,7 @@ export const SnippedGenerator = { | |||
|               //             path,
 | ||||
|               //             method,
 | ||||
|               //             targets
 | ||||
|               //           ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com");
 | ||||
|               //           ).snippets[0].content;
 | ||||
|               //         } catch (err) {
 | ||||
|               //           // set to error in case it happens the npm package has some flaws
 | ||||
|               //           snippet = JSON.stringify(snippet);
 | ||||
|  | @ -296,12 +280,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  | @ -328,12 +308,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  | @ -360,12 +336,8 @@ export const SnippedGenerator = { | |||
|                     let snippet; | ||||
|                     try { | ||||
|                       // set request snippet content
 | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets( | ||||
|                         spec, | ||||
|                         path, | ||||
|                         method, | ||||
|                         targets | ||||
|                       ).snippets[0].content.replaceAll("undefinedundefined", "https://api.cal.com"); | ||||
|                       snippet = OpenAPISnippet.getEndpointSnippets(spec, path, method, targets).snippets[0] | ||||
|                         .content; | ||||
|                     } catch (err) { | ||||
|                       // set to error in case it happens the npm package has some flaws
 | ||||
|                       snippet = JSON.stringify(snippet); | ||||
|  |  | |||
|  | @ -10,14 +10,14 @@ | |||
|   "dependencies": { | ||||
|     "highlight.js": "^11.5.1", | ||||
|     "isarray": "2.0.5", | ||||
|     "next": "12.1.4", | ||||
|     "next": "12.1.5", | ||||
|     "openapi-snippet": "^0.13.0", | ||||
|     "react": "17.0.2", | ||||
|     "react-dom": "17.0.2", | ||||
|     "swagger-ui-react": "4.8.1" | ||||
|     "swagger-ui-react": "4.10.3" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@types/node": "16.11.26", | ||||
|     "@types/node": "17.0.27", | ||||
|     "@types/react": "17.0.43", | ||||
|     "@types/react-dom": "17.0.14", | ||||
|     "typescript": "4.6.3" | ||||
|  |  | |||
|  | @ -1,12 +1,14 @@ | |||
| import SwaggerUI from "swagger-ui-react"; | ||||
| import dynamic from "next/dynamic"; | ||||
| 
 | ||||
| import { SnippedGenerator, requestSnippets } from "@lib/snippets"; | ||||
| 
 | ||||
| const SwaggerUI: any = dynamic(() => import("swagger-ui-react"), { ssr: false }); | ||||
| 
 | ||||
| export default function APIDocs() { | ||||
|   return ( | ||||
|     <SwaggerUI | ||||
|       url={process.env.NEXT_PUBLIC_SWAGGER_DOCS_URL || "https://api.cal.com/docs"} | ||||
|       supportedSubmitMethods={["get", "post", "put", "delete", "patch"]} | ||||
|       supportedSubmitMethods={["get", "post", "delete", "patch"]} | ||||
|       requestSnippetsEnabled={true} | ||||
|       requestSnippets={requestSnippets} | ||||
|       plugins={[SnippedGenerator]} | ||||
|  |  | |||
|  | @ -17,6 +17,8 @@ | |||
|     "deploy": "turbo run deploy", | ||||
|     "dev": "turbo run dev --scope=\"@calcom/web\"", | ||||
|     "dev:website": "yarn predev && turbo run dev --scope=\"@calcom/web\" --scope=\"@calcom/website\"", | ||||
|     "dev:api": "yarn predev && turbo run dev --scope=\"@calcom/web\" --scope=\"@calcom/api\"", | ||||
|     "dev:swagger": "yarn predev && turbo run dev --scope=\"@calcom/api\" --scope=\"@calcom/swagger\"", | ||||
|     "dev:console": "yarn predev && turbo run dev --scope=\"@calcom/web\" --scope=\"@calcom/console\"", | ||||
|     "docs-dev": "yarn predev && turbo run dev --scope=\"@calcom/docs\"", | ||||
|     "docs-build": "turbo run build --scope=\"@calcom/docs\" --include-dependencies", | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Agusti Fernandez
						Agusti Fernandez