question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to embed a link into each operation in Swagger UI

See original GitHub issue

Q&A (please complete the following information)

  • OS: Windows 10 / Mac OS Latest
  • Browser: Chrome Latest
  • Version: Latest
  • Method of installation: Dist Assets
  • Swagger-UI version: Latest
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

You can see it here: https://api.cloudmersive.com/swagger/index.html?urls.primaryName=Image Recognition and Processing API

Swagger/OpenAPI definition (JSON): https://api.cloudmersive.com/swagger/api/image

Swagger-UI configuration options:

SwaggerUI({
  // your config options here
})

var configObject = JSON.parse('{"urls":[{"url":"/swagger/api/convert","name":"Convert API"},{"url":"/swagger/api/nlp","name":"Natural Language Processing (NLP) API"},{"url":"/swagger/api/ocr","name":"Optical Character Recognition (OCR) API"},{"url":"/swagger/api/validate","name":"Validate API"},{"url":"/swagger/api/virus","name":"Virus Scan API"},{"url":"/swagger/api/image","name":"Image Recognition and Processing API"},{"url":"/swagger/api/barcode","name":"Barcode API"},{"url":"/swagger/api/speech","name":"Speech API"}],"validatorUrl":null}');
--
  | var oauthConfigObject = JSON.parse('{}');
  |  
  | // Apply mandatory parameters
  | configObject.dom_id = "#swagger-ui";
  | configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
  | configObject.layout = "StandaloneLayout";
  |  
  | // If oauth2RedirectUrl isn't specified, use the built-in default
  | if (!configObject.hasOwnProperty("oauth2RedirectUrl"))
  | configObject.oauth2RedirectUrl = window.location.href.replace("index.html", "oauth2-redirect.html");
  |  
  | configObject.onComplete = function () {
  | // Here, "basicAuth" and "apiKey" are the security scheme names/keys in the "securityDefinitions" collection
  | ui.preauthorizeApiKey("Apikey", "28e63794-ef8a-4616-80bb-26fdd3709a19");
  |  
  |  
  | };
  |  
  | // Build a system
  | const ui = SwaggerUIBundle(configObject);


Screenshots

You can see it running here: https://api.cloudmersive.com/swagger/index.html?urls.primaryName=Image Recognition and Processing API

How can we help?

We want to add a hyperlink to each Operation that links contextually to help documentation with more information, so ideally it is a parameterized link that includes the ID or name of the operation.

Hopefully this is simple to do - what is the best way to do it? We tried with the documented JS APIs but were not able to get this to work.

Any help with this is greatly appreciated!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shockeycommented, Sep 17, 2018

@Cloudmersive sure, this isn’t too hard!

Plugin code

const CloudmersiveCodeExamplesAfterResponsesPlugin = () => ({
  wrapComponents: {
    responses: (Responses, { React }) => (props) => {
      return React.createElement("div", null,
        React.createElement(Responses, props),
        React.createElement("iframe", { 
          src: "https://docs.cloudmersive.com", // `props.path` and `props.method` are available here so you can identify the operation
          width: "100%",
          height: "300px"
        })
      );
    }
  }
})

Result

image

The only gotcha here is that this won’t render if an operation has no responses defined (which would make it invalid).

0reactions
shockeycommented, Aug 20, 2018

Glad I could help, @Cloudmersive! Looks great 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Links
Links are one of the new features of OpenAPI 3.0. Using links, you can describe how various values returned by one operation can...
Read more >
How to add <a href> link to make an element clickable in ...
Assuming you mean clickable in Swagger UI – you can add links in the operation description ( notes attribute) using the Markdown syntax....
Read more >
Integrating Swagger UI with the rest of your docs
It's pretty easy to embed Swagger into an HTML page — just copy the code from the index.html file from the dist folder...
Read more >
Using OpenAPI and Swagger UI
This guide explains how your Quarkus application can expose its API description through an OpenAPI specification and how you can test it via...
Read more >
ASP.NET Core web API documentation with Swagger ...
Each public action method in your controllers can be tested from the UI. Select a method name to expand the section. Add any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found