@thoughtspot/graph-to-openapi
TypeScript icon, indicating that this package has built-in type declarations

0.9.1 • Public • Published

graph-to-openapi

Coverage Status npm (scoped) example branch parameter

Convert a Graphql Schema to OpenAPI Spec w/ customization hooks

Usage

# schema.graphql

## This directive declaration needs to be added to your graphql definitions.
## Needs to be defined only once.
directive @rest(
  """
  REST path for the generated API route.
  """
  path: String = "/api/" # Can specify a default value.
  """
  API Method
  """
  method: String = "GET"
  """
  Tag to add to the generated API route.
  """
  tag: String = ""
  """
  Hide the operation from the generated spec.
  """
  hidden: Boolean = false
) on FIELD_DEFINITION

type Mutation {
  """
  This is a comment which will become the description of this REST
  endpoint.
  """
  updateUser(
    """
    This comment becomes the description of the query parameter.
    """
    name: String
    """
    The GUID of the user account to query
    """
    id: String!

    """
    The updated display name
    """
    displayName: String
  ): UserResponse @rest(path: "/user", method: "PUT", tag: "User") # Define the openAPI spec config here.
}

type Query {
  getUser(
    """
    The GUID of the user account to query
    """
    id: String!
  ): UserResponse @rest(path: "/user", method: "GET", tag: "User")
}

type UserResponse {
  ...
}
import { getOpenAPISpec } from '@thoughtspot/gql-to-openapi';

const { spec } = getOpenAPISpec({
    schema,
    info: {},
    basePath: '/api/v1',
});

fs.writeFile(fileName, openAPISpec);

/@thoughtspot/graph-to-openapi/

    Package Sidebar

    Install

    npm i @thoughtspot/graph-to-openapi

    Weekly Downloads

    1,517

    Version

    0.9.1

    License

    SEE LICENSE IN LICENSE.md

    Unpacked Size

    227 kB

    Total Files

    33

    Last publish

    Collaborators

    • rohit1508
    • tse-developers
    • divyam.lamiyan
    • girish-thoughtspot
    • mouryab
    • chetan1507
    • sastaachar
    • mdabdullasulaiman
    • nirmay_patel
    • ashubham
    • bhanu.jupally