-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build swagger.json as part of webpack.make.js when running npm run bu…
…ild. Currently using hardcoded path that works only on my computer (WIP) (#535)
- Loading branch information
1 parent
34a388d
commit a534dc0
Showing
4 changed files
with
59 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,7 @@ | |
|
||
import errors from './components/errors'; | ||
import path from 'path'; | ||
import config from './config/environment'; | ||
|
||
const swaggerUi = require('swagger-ui-express'); | ||
var swaggerJSDoc = require('swagger-jsdoc'); | ||
// const swaggerDocument = require('./swagger/swagger.json'); | ||
// const YAML = require('yamljs'); | ||
// const swaggerDocument = YAML.load(path.join(__dirname, './swagger/swagger.yaml')); | ||
import swaggerUi from 'swagger-ui-express'; | ||
|
||
export default app => { | ||
// Insert routes below | ||
|
@@ -32,71 +26,15 @@ export default app => { | |
app.use('/api/provenance', require('./api/provenance')); | ||
app.use('/auth', require('./auth').default); | ||
|
||
console.log('domain', config.domain); | ||
|
||
// swagger definition | ||
// maps to https://swagger.io/specification/#oasObject | ||
var swaggerDefinition = { | ||
openapi: '3.0.2', | ||
info: { | ||
title: 'PHC Collaboration Portal API', | ||
version: '1.0.0', // TODO Get version from config | ||
description: `Personalized Health Care (PHC) Collaboration Portal | ||
developed by Sage Bionetworks and Roche/Genentech`, | ||
contact: { | ||
name: 'API Support', | ||
url: 'https://www.synapse.org', | ||
email: '[email protected]' | ||
}, | ||
license: { | ||
name: 'CC BY-NC 3.0', | ||
url: 'https://creativecommons.org/licenses/by-nc/3.0/' | ||
} | ||
}, | ||
servers: [{ | ||
url: `${config.domain}/api`, | ||
description: 'This app' | ||
}], | ||
components: { | ||
securitySchemes: { | ||
BearerAuth: { | ||
type: 'http', | ||
scheme: 'bearer', | ||
bearerFormat: 'JWT' | ||
} | ||
}, | ||
responses: { | ||
UnauthorizedError: { | ||
description: 'Access token is missing or invalid' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const swaggerOptions = { | ||
customSiteTitle: 'PHC Collaboration Portal API', | ||
customCss: '.topbar { display: none }', | ||
// docExpansion: 'none' | ||
}; | ||
|
||
// options for the swagger docs | ||
var swaggerJSDocOptions = { | ||
swaggerDefinition: swaggerDefinition, | ||
apis: [ | ||
'./**/api/**/index.js', | ||
'./**/auth/**/*.js', | ||
'./shared/interfaces/**/*.ts' | ||
// './**/swagger/**/*.ts' | ||
] | ||
}; | ||
|
||
// initialize swagger-jsdoc | ||
const swaggerSpec = swaggerJSDoc(swaggerJSDocOptions); | ||
const swaggerSpec = require('/Users/tschaffter/dev/PHCCollaborationPortal/dist/client/swagger.json'); | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, swaggerOptions)); | ||
|
||
// Swagger | ||
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); | ||
|
||
// All undefined asset or api routes should return a 404 | ||
app.route('/:url(api|auth|components|app|bower_components|assets|api-docs)/*') | ||
.get(errors[404]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
const path = require('path'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const webpack = require('webpack'); | ||
var GitRevisionPlugin = require('git-revision-webpack-plugin'); | ||
const GitRevisionPlugin = require('git-revision-webpack-plugin'); | ||
const MomentLocalesPlugin = require('moment-locales-webpack-plugin'); | ||
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | ||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | ||
const SwaggerJSDocWebpackPlugin = require('swagger-jsdoc-webpack-plugin'); | ||
const fs = require('fs'); | ||
|
||
module.exports = function makeWebpackConfig(options) { | ||
|
@@ -315,10 +316,54 @@ module.exports = function makeWebpackConfig(options) { | |
// ("en" is built into Moment and can’t be removed) | ||
new MomentLocalesPlugin({ | ||
// localesToKeep: ['fr'], | ||
}) | ||
}), | ||
// new BundleAnalyzerPlugin({ | ||
// generateStatsFile: true, | ||
// }), | ||
|
||
// https://github.com/patsimm/swagger-jsdoc-webpack-plugin | ||
// This writes a swagger.json file to ./dist/client/swagger.json. | ||
new SwaggerJSDocWebpackPlugin({ | ||
swaggerDefinition: { | ||
openapi: '3.0.2', | ||
info: { | ||
title: 'PHC Collaboration Portal API', | ||
version: '1.0.0', // TODO Get version from config | ||
description: `Personalized Health Care (PHC) Collaboration Portal | ||
developed by Sage Bionetworks and Roche/Genentech`, | ||
contact: { | ||
name: 'API Support', | ||
url: 'https://www.synapse.org', | ||
email: '[email protected]', | ||
}, | ||
license: { | ||
name: 'CC BY-NC 3.0', | ||
url: 'https://creativecommons.org/licenses/by-nc/3.0/', | ||
}, | ||
}, | ||
servers: [ | ||
{ | ||
url: 'plop/api', // `${config.domain}/api`, | ||
description: 'This app', | ||
}, | ||
], | ||
components: { | ||
securitySchemes: { | ||
BearerAuth: { | ||
type: 'http', | ||
scheme: 'bearer', | ||
bearerFormat: 'JWT', | ||
}, | ||
}, | ||
responses: { | ||
UnauthorizedError: { | ||
description: 'Access token is missing or invalid', | ||
}, | ||
}, | ||
}, | ||
}, | ||
apis: ['./**/api/**/index.js', './**/auth/**/*.js', './shared/interfaces/**/*.ts'], | ||
}) | ||
); | ||
} | ||
|
||
|