api
This commit is contained in:
@ -0,0 +1,14 @@
|
||||
|
||||
### Demo of Swagger UI with Webpack.
|
||||
|
||||
This `webpack-getting-started` sample is for reference only.
|
||||
|
||||
It includes CSS and OAuth configuration.
|
||||
|
||||
`_sample_package.json` is a placeholder sample. You should rename this file, per `Usage` section below, and you should also verify and update this sample's `@latest` compared to the `swagger-ui@latest`
|
||||
|
||||
|
||||
#### Usage
|
||||
rename `_sample_package.json` to `package.json`
|
||||
npm install
|
||||
npm start
|
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "swagger-ui-webpack-getting-started",
|
||||
"version": "0.0.1",
|
||||
"description": "A simple setup of Swagger UI with Webpack",
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"start": "webpack-dev-server --open"
|
||||
},
|
||||
"author": "Shaun Luttin",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"webpack": "^5.74.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-dev-server": "^4.11.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"css-loader": "^6.7.1",
|
||||
"json-loader": "^0.5.7",
|
||||
"style-loader": "^3.3.1",
|
||||
"swagger-ui": "^4.14.0",
|
||||
"yaml-loader": "^0.8.0"
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Getting Started</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger"></div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,15 @@
|
||||
import SwaggerUI from 'swagger-ui'
|
||||
import 'swagger-ui/dist/swagger-ui.css';
|
||||
|
||||
const spec = require('./swagger-config.yaml');
|
||||
|
||||
const ui = SwaggerUI({
|
||||
spec,
|
||||
dom_id: '#swagger',
|
||||
});
|
||||
|
||||
ui.initOAuth({
|
||||
appName: "Swagger UI Webpack Demo",
|
||||
// See https://demo.identityserver.io/ for configuration details.
|
||||
clientId: 'implicit'
|
||||
});
|
@ -0,0 +1,30 @@
|
||||
openapi: "3.0.0"
|
||||
info:
|
||||
version: "0.0.1"
|
||||
title: "Swagger UI Webpack Setup"
|
||||
description: "Demonstrates Swagger UI with Webpack including CSS and OAuth"
|
||||
servers:
|
||||
- url: "https://demo.identityserver.io/api"
|
||||
description: "Identity Server test API"
|
||||
components:
|
||||
securitySchemes:
|
||||
# See https://demo.identityserver.io/ for configuration details.
|
||||
identity_server_auth:
|
||||
type: oauth2
|
||||
flows:
|
||||
implicit:
|
||||
authorizationUrl: "https://demo.identityserver.io/connect/authorize"
|
||||
scopes:
|
||||
api: "api"
|
||||
security:
|
||||
- identity_server_auth:
|
||||
- api
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
summary: "Runs a test request against the Identity Server demo API"
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
200:
|
||||
description: "OK"
|
@ -0,0 +1,52 @@
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
|
||||
const outputPath = path.resolve(__dirname, 'dist');
|
||||
|
||||
module.exports = {
|
||||
mode: 'development',
|
||||
entry: {
|
||||
app: require.resolve('./src/index'),
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.yaml$/,
|
||||
use: [
|
||||
{ loader: 'json-loader' },
|
||||
{ loader: 'yaml-loader', options:{ asJSON: true } }
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{ loader: 'style-loader' },
|
||||
{ loader: 'css-loader' },
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin(),
|
||||
new CopyWebpackPlugin({patterns:[
|
||||
{
|
||||
// Copy the Swagger OAuth2 redirect file to the project root;
|
||||
// that file handles the OAuth2 redirect after authenticating the end-user.
|
||||
from: require.resolve('swagger-ui/dist/oauth2-redirect.html'),
|
||||
to: './'
|
||||
}
|
||||
]}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'index.html'
|
||||
})
|
||||
],
|
||||
output: {
|
||||
filename: '[name].bundle.js',
|
||||
path: outputPath,
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user