Skip to content

Update swagger ui and add support for deprecated property of endpoint #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions res/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Swagger UI Dist
[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/swagger-ui-dist)

# API

This module, `swagger-ui-dist`, exposes Swagger-UI's entire dist folder as a dependency-free npm module.
Use `swagger-ui` instead, if you'd like to have npm install dependencies for you.

`SwaggerUIBundle` and `SwaggerUIStandalonePreset` can be imported:
```javascript
import { SwaggerUIBundle, SwaggerUIStandalonePreset } from "swagger-ui-dist"
```

To get an absolute path to this directory for static file serving, use the exported `getAbsoluteFSPath` method:

```javascript
const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath()

// then instantiate server that serves files from the swaggerUiAssetPath
```

For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository.
14 changes: 14 additions & 0 deletions res/absolute-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* getAbsoluteFSPath
* @return {string} When run in NodeJS env, returns the absolute path to the current directory
* When run outside of NodeJS, will return an error message
*/
const getAbsoluteFSPath = function () {
// detect whether we are running in a browser or nodejs
if (typeof module !== "undefined" && module.exports) {
return require("path").resolve(__dirname)
}
throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment');
}

module.exports = getAbsoluteFSPath
9 changes: 5 additions & 4 deletions res/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
Expand Down Expand Up @@ -41,6 +41,7 @@
const ui = SwaggerUIBundle({
url: "/%%API.JSON%%",
dom_id: '#swagger-ui',
validatorUrl: 'none',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
Expand All @@ -50,11 +51,11 @@
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
});
// End Swagger UI call region

window.ui = ui
}
window.ui = ui;
};
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions res/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
try {
module.exports.SwaggerUIBundle = require("./swagger-ui-bundle.js")
module.exports.SwaggerUIStandalonePreset = require("./swagger-ui-standalone-preset.js")
} catch(e) {
// swallow the error if there's a problem loading the assets.
// allows this module to support providing the assets for browserish contexts,
// without exploding in a Node context.
//
// see https://github.com/swagger-api/swagger-ui/issues/3291#issuecomment-311195388
// for more information.
}

// `absolutePath` and `getAbsoluteFSPath` are both here because at one point,
// we documented having one and actually implemented the other.
// They were both retained so we don't break anyone's code.
module.exports.absolutePath = require("./absolute-path.js")
module.exports.getAbsoluteFSPath = require("./absolute-path.js")
21 changes: 11 additions & 10 deletions res/oauth2-redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
</body>
</html>
<script>
'use strict';
function run () {
Expand All @@ -20,19 +18,20 @@
qp = location.search.substring(1);
}

arr = qp.split("&")
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value)
return key === "" ? value : decodeURIComponent(value);
}
) : {}
) : {};

isValid = qp.state === sentState
isValid = qp.state === sentState;

if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
Expand All @@ -48,7 +47,7 @@
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
Expand All @@ -72,3 +71,5 @@
run();
});
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions res/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "swagger-ui-dist",
"version": "3.52.5",
"main": "index.js",
"repository": "[email protected]:swagger-api/swagger-ui.git",
"contributors": [
"(in alphabetical order)",
"Anna Bodnia <[email protected]>",
"Buu Nguyen <[email protected]>",
"Josh Ponelat <[email protected]>",
"Kyle Shockey <[email protected]>",
"Robert Barnwell <[email protected]>",
"Sahar Jafari <[email protected]>"
],
"license": "Apache-2.0",
"dependencies": {},
"devDependencies": {}
}
2 changes: 1 addition & 1 deletion res/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-es-bundle-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-es-bundle-core.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-es-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-es-bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui-standalone-preset.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions res/swagger-ui.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/swagger-ui.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/oatpp-swagger/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ void Generator::generatePathItemData(const std::shared_ptr<Endpoint>& endpoint,
operation->operationId = info->name;
operation->summary = info->summary;
operation->description = info->description;
operation->deprecated = info->deprecated;

if(info->tags.size() > 0) {
operation->tags = oatpp::List<String>({});
Expand Down
5 changes: 5 additions & 0 deletions src/oatpp-swagger/oas3/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ class PathItemOperation : public oatpp::DTO {
*/
DTO_FIELD(String, operationId);

/**
* Is operation deprecated.
*/
DTO_FIELD(Boolean, deprecated);

/**
* Request Body.
*/
Expand Down