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.

What is the best way to filter out and show only 1 endpoint?

See original GitHub issue

Q&A (please complete the following information)

  • Swagger-UI version: 3.10.0
  • Swagger/OpenAPI version: OpenAPI 3.0

Using swagger-ui-react. We want to render individual endpoints on a quickstart page. What is the best way to display only a single endpoint and method. Right now, I am looking fetching the spec in a higher order component and filtering down to only the path I want and passing that in to the spec param of SwaggerUI component. But that feels hacky. Is there a better way?

Here is what is currently there <SwaggerUI url={LINK_TO_SPEC} docExpansion="list"/>

What I’d like to be able to do <SwaggerUI url={SWAGGER_LINK} docExpansion="list" path={'/device/'} method='get'/>

And that will only show the GET method of the /device/ path. Ignoring all other paths in the spec.

I’ve been searching through the docs and issues but can’t figure a non hacky answer. Apologies if this is a basic question. Thank you for the help.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
thiagoalvescommented, Jan 19, 2021

After some struggling, I finally came out with a solution that works:

import React from 'react'
import { fromJS } from 'immutable'
import SwaggerUI from "swagger-ui-react"
import "swagger-ui-react/swagger-ui.css"
import './styles.css';

const apiUrl = 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml';

class MyTestLayout extends React.Component {
  render() {
    const {
      funcs,
      params
    } = this.props

    const specSelectors = {
      isOAS3() { return true },
      url() { return apiUrl },
      taggedOperations() {
        return fromJS({
          "default": {
            "operations": [
              {
                "path": params.path,
                "method": params.method
              }
            ]
          }
        })
      },
    }

    const Operations = funcs.getComponent("operations", true)

    return (
      <div>
        <Operations specSelectors={specSelectors} />
      </div>
    )
  }
}

// Create the plugin that provides our layout component
const TestPlugin = (props) => {
  return {
    components: {
      TestLayout: (funcs) => <MyTestLayout params={props} funcs={funcs} />
    }
  }
}

export default class ApiDoc extends React.Component {

  render() {
    return (
      <SwaggerUI
        url={apiUrl}
        docExpansion={"full"}
        plugins={[TestPlugin(this.props)]}
        layout={"TestLayout"}   
      />
    );
  }
}

Usage:

<ApiDoc method="get" path="/pets/{petId}" />
0reactions
tim-laicommented, Oct 1, 2020

@exit99 There currently does not exist a method to render a single endpoint via a query parameter or option field. It certainly is possible with a custom plugin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

REST API Design: Filtering, Sorting, and Pagination - Moesif
Advanced REST API design guidelines for API filtering, sorting, and pagination. ... URL parameters is the easiest way to add basic filtering to...
Read more >
REST Best practise for filtering and knowing the result is singular
1, 2, 3) to use plurals in your endpoints and the result is always a list of objects, unless it's filtered by a...
Read more >
GraphQL Search and Filter – How to search and filter results ...
Searching is filtering: Searching and filtering are two different ways to say the same thing. The goal is to find an item (or...
Read more >
Create filters in Microsoft Intune
Select Tenant administration > Filters. A list of all the filters is shown. You can also delete filters in Devices > Filters, or...
Read more >
Filter syntax - IBM
The filter parameter syntax is consistent for all endpoints that support it. Refer to the documentation for the endpoint to determine whether the...
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