JSPM

openapi-generator-gas

0.0.3
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 10
    • Score
      100M100P100Q33367F
    • License MIT

    A OpenAPI code generator for Google Apps Script

    Package Exports

      This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (openapi-generator-gas) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

      Readme

      OpenAPI code generator for Google Apps Script

      A CLI tool that generate codes for Google Apps Script.

      An example project is here.

      Roadmap

      • .yml file support
      • typescript code generation
      • requestBody parsing(support type: array, type: object in object)
      • $ref and $component parsing
      • nested responses parsing(support type: array in object)
      • server and example field support
        • if google.script.run is not defined, api calls to localhost
      • .json file support
      • javascript(jsdoc) code generation
      • throw error for invalid input(a file specified by --spec option)
      • http status 400 support(rejectable)

      not supported

      • API spec bundle

      Usage

      npm install -D openapi-generator-gas
      npx openapi-generator-gas --spec openapi.yml --outfile ./frontend/src/openapi.ts --frontend # Generate codes for frontend
      npx openapi-generator-gas --spec openapi.yml --outfile ./backend/src/openapi.ts --backend # Generate codes for backend

      Example

      • openapi.yml
      openapi: 3.0.3
      info:
        title: My OpenAPI spec
        summary: example spec
        version: 0.0.1
      servers:
        - url: http://localhost:8080
          description: A local server
      
      paths:
        /todo:
          get:
            summary: get TODO item                 # anything ok(not used)
            description: get TODO item             # anything ok(not used)
            operationId: getTodoItem
            parameters:
              - name: itemId
                in: query                          # anything ok(not used)
                required: true
                schema:
                  type: integer
            responses:
              200:                                 # 200 only supported(will be function's return type)
                description: specific TODO item    # anything ok(not used)
                content:
                  application/json:                # `application/json` only supported
                    schema:
                      type: object
                      required:
                        - itemId
                        - title
                      properties:
                        itemId:
                          type: integer
                        title:
                          type: string
                        description:
                          type: string
      • generated codes for frontend
      export type GetTodoItemRequest = {
        itemId: number;
      }
      
      export type GetTodoItemResponse = {
        itemId: number;
        title: string;
        description?: string;
      }
      
      export function getTodoItem(request: GetTodoItemRequest): Promise<GetTodoItemResponse> {
        return new Promise((resolve, reject) => {
          google.script.run
            .withSuccessHandler(resolve)
            .withFailureHandler(reject)
            .getTodoItem(request);
        });
      }

      and codes that you implemented

      import { getTodoItem } from 'path/to/outfile.ts';
      
      const test = async () => {
        const req = { itemId: 1 };
        const res = await getTodoItem(req);
      };
      • generated codes for backend
      export type GetTodoItemRequest = {
        itemId: number;
      }
      
      export type GetTodoItemResponse = {
        itemId: number;
        title: string;
        description?: string;
      }
      
      export type IGetTodoItem = (request: GetTodoItemRequest) => GetTodoItemResponse;

      and codes that you implemented

      import type { IGetTodoItem } from 'path/to/outfile.ts';
      
      const getTodoItem: IGetTodoItem = (req) => {
        const itemId = req.itemId;
      
        return {
          itemId: 1,
          title: 'Some title',
          description: 'Some description',
        }
      }