Skip to content

Convert a Graphql Schema to OpenAPI Spec w/ customization hooks

License

Notifications You must be signed in to change notification settings

thoughtspot/graph-to-openapi

Repository files navigation

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);

About

Convert a Graphql Schema to OpenAPI Spec w/ customization hooks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published