Giter VIP home page Giter VIP logo

apibake-js's Introduction

ApiBake

Convert OpenAPI spec to PDF. Supports OpenAPI 3.0.0+ json and yaml.

Quick Start

Node.js 16+ required.

npm install -g apibake

apibake <openapi.json|.yaml|folder-name> [<file-or-folder2> <file-or-folder3> ...] [<options>]

Options:

 --out <string>: Output PDF file name.
 --title <string>: Document title.
 --subtitle <string>: Document sub title.
 --separate-schemas: When multiple API files parsed, create separate schemas section for each.
 --footer <string>: Defines content of common page footer. Options: "page-number". To turn off: "".
 --config <string>: Path to apibake-config.json. See --export-config.
 --export-config: Save default config into json file for editing.
 -h: Show this help.

Examples

Specify title and subtitle for your PDF:

apibake openapi.json --title 'REST API Spec' --subtitle 'created with ApiBake'

Combine several OpenAPI specs into one PDF:

apibake api1.json api2.yaml --title 'REST API Spec'
apibake dir/with/openapi-specs --title 'REST API Spec'

Custom config: fonts, colors, page margins.

To modify default apibake config - first export it into a file:

apibake --export-config

Modify apibake-config.json and tell apibake to use it:

apibake openapi.json --config apibake-config.json

PDF default fonts can be specified by their names:

  • Courier
  • Courier-Bold
  • Courier-Oblique
  • Courier-BoldOblique
  • Helvetica
  • Helvetica-Bold
  • Helvetica-Oblique
  • Helvetica-BoldOblique
  • Symbol
  • Times-Roman
  • Times-Bold
  • Times-Italic
  • Times-BoldItalic
  • ZapfDingbats

Alternatively, external font files can be specified. Supported font formats: TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collection (.ttc), and Datafork TrueType (.dfont) fonts.

Example:

{
  "font": {
    "baseSize": 10,
    "main": {
      "norm": {
        "face": "fonts/Roboto-Regular.ttf"
      },
      "bold": {
        "face": "fonts/Roboto-Bold.ttf"
      },
      "italic": {
        "face": "fonts/Roboto-Italic.ttf"
      }
    },
    "mono": {
      "norm": {
        "face": "Courier"
      },
      "bold": {
        "face": "Courier-Bold"
      },
      "italic": {
        "face": "Courier-Oblique"
      }
    }
  },
  ...
}

Note: if font file is a collection (.ttc) - then font style must be also specified. Example:

 "font": {
    "main": {
      "norm": {
        "face": "fonts/Roboto.ttc",
        "style": "Roboto-Regular"
      },
      "bold": {
        "face": "fonts/Roboto.ttc",
        "style": "Roboto-Bold"
      },
    },
    ...
 }

MIT License

Copyright (c) 2023 CurvedNebula.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

apibake-js's People

Contributors

curvednebula avatar defkon1 avatar illyasikeryn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aagormley defkon1

apibake-js's Issues

[FEAT] Add support for information section

It would be great adding the parsing of the information from info section (when available) on the frontpage of the PDF:

{
  "openapi": "3.0.1",
  "info": {
    "title": "My API title",
    "description": "My API description",
    "termsOfService": "https://www...",
    "contact": {
      "name": "Defkon1",
      "url": "https://www.github.com/defkon1",
      "email": "..."
    },
    "license": {
      "name": "CC-BY 4.0",
      "url": "https://creativecommons.org/licenses/by/4.0/legalcode"
    },
    "version": "1.0.0",
    "x-summary": "...",
    "x-api-id": "..."
  }

Something similar to RapiPDF, just to give an example:

image

Not able to finish installation via npm command

After running command "npm install -g apibake"
I got the message: "40 packages are looking for funding".
It seems some depandency issue exist. Can any one help me to fix it?

Environment:

  • OS: Ubuntu 20.04
  • npm version: 10.2.3
  • node.js version: v18.17.1

some character encoding error happens with the `ő` character

to reproduce download this openAPI spec: https://opendata.bkk.hu/docs/futar-openapi.yaml (it's in hungarian & the API spec for the local public transport company)

then try to run apibake. The resulting PDF has some wierd characters in it:

output.pdf

image

⛵ vnagy-eu in /tmp/apibake-character-encoding on ☁️  [email protected] 
❯ wget https://opendata.bkk.hu/docs/futar-openapi.yaml 
futar-openapi.yaml.1 100% [===========================================================================================================================================================================================>]   35.05K    --.-KB/s
                          [Files: 1  Bytes: 35.05K [93.73KB/s] Redirects: 0  Todo: 0  Errors: 0                                                                                                                        ]

⛵ vnagy-eu in /tmp/apibake-character-encoding on ☁️  [email protected] took 3s 
❯ apibake -h
ApiBake 0.1.25 - Convert OpenAPI spec to PDF.
Usage: apibake <openapi.json|.yaml|folder-name> [<file-or-folder2> <file-or-folder3> ...] [<options>]
Options:
 --out <string>: Output PDF file name.
 --title <string>: Document title.
 --subtitle <string>: Document sub title.
 --separate-schemas: When multiple API files parsed, create separate schemas section for each.
 --footer <string>: Defines content of common page footer. Options: "page-number". To turn off: "".
 --config <string>: Path to apibake-config.json. See --export-config.
 --export-config: Save default config into json file for editing.
 -h: Show this help.

⛵ vnagy-eu in /tmp/apibake-character-encoding on ☁️  [email protected] took 3s 
❯ apibake futar-openapi.yaml
Parsing: futar-openapi.yaml
File info:
 - title: realCity Query Server API
 - description: Specification for the realCity Query Server API.
 - version: 1.0.1
Endpoints:
 - GET /{dialect}/api/where/alert-search
 - GET /{dialect}/api/where/arrivals-and-departures-for-location
 - GET /{dialect}/api/where/arrivals-and-departures-for-stop
 - GET /{dialect}/api/where/bicycle-rental
 - GET /{dialect}/api/where/booking-redirect
 - GET /{dialect}/api/where/metadata
 - GET /{dialect}/api/where/multi-route-details
 - POST /{dialect}/api/where/onboard-depart-search
 - GET /{dialect}/api/where/plan-trip
 - GET /{dialect}/api/where/plan-access
 - GET /{dialect}/api/where/references
 - GET /{dialect}/api/where/route-details-for-stop
 - GET /{dialect}/api/where/route-details
 - GET /{dialect}/api/where/schedule-for-stop
 - GET /{dialect}/api/where/search
 - GET /{dialect}/api/where/statistics
 - GET /{dialect}/api/where/stops-for-location
 - GET /{dialect}/api/where/ticketing-locations
 - GET /{dialect}/api/where/trip-details
 - GET /{dialect}/api/where/vehicle-for-trip
 - GET /{dialect}/api/where/vehicles-for-location
 - GET /{dialect}/api/where/vehicles-for-route
 - GET /{dialect}/api/where/vehicles-for-stop
Schemas:
 - ApiVersion
 - Dialect
 - ReferencesSchema
 - AlertSearchMethodResponse
 - EffectType
 - MobileTransitReferences
 - OTPTransitReferences
 - Status
 - TransitAgency
 - TransitAlert
 - TransitAlertRoute
 - TransitEntryWithReferencesTransitSearch
 - TransitReferences
 - TransitRoute
 - TransitRouteStyle
 - TransitRouteStyleIcon
 - TransitSearch
 - TransitStop
 - TransitStopStyle
 - TransitTrip
 - TransitVehicleStyleIcon
 - TranslatedString
 - ArrivalsAndDeparturesForLocationOTPMethodResponse
 - TransitDepartureGroup
 - TransitListEntryWithReferencesTransitDepartureGroup
 - TransitScheduleStopTime
 - ArrivalsAndDeparturesForStopOTPMethodResponse
 - TransitArrivalsAndDepartures
 - TransitEntryWithReferencesTransitArrivalsAndDepartures
 - BicycleRentalMethodResponse
 - TransitBikeRentalStation
 - TransitListEntryWithReferencesTransitBikeRentalStation
 - MetadataResponse
 - TransitEntryWithReferencesTransitMetadata
 - TransitMetadata
 - MultiRouteDetailsMethodResponse
 - TransitListEntryWithReferencesTransitRouteDetails
 - TransitPolyline
 - TransitRouteDetails
 - TransitRouteVariant
 - OnboardDepartSearchMethodResponse
 - TransitCoordinatePoint
 - TransitListEntryWithReferencesTransitVehicle
 - TransitVehicle
 - TransitVehicleOccupancy
 - TransitVehicleStyle
 - OnboardDepartPosition
 - TraverseMode
 - WalkProfile
 - ApiTripSearchMetadata
 - BikeStreetCategory
 - DisplayedLeg
 - ElevationPoint
 - EncodedPolylineBean
 - Itinerary
 - Leg
 - PatternStatistics
 - Place
 - PlanTripResponse
 - PlannerError
 - Response
 - TicketingLocation
 - TicketingPeriod
 - TransitEntryWithReferencesResponse
 - TripPlan
 - WalkStep
 - ReferencesMethodErrors
 - ReferencesMethodResponse
 - ReferencesMethodResult
 - RouteDetailsForStopMethodResponse
 - TransitListEntryWithReferencesTransitRoute
 - RouteDetailsMethodResponse
 - TransitEntryWithReferencesTransitRouteDetails
 - ScheduleForStopOTPMethodResponse
 - TransitEntryWithReferencesTransitSchedule
 - TransitRouteSchedule
 - TransitRouteScheduleForDirection
 - TransitSchedule
 - TransitScheduleGroup
 - SearchMethodResponse
 - StatisticsResponse
 - StopsForLocationResponse
 - TransitListEntryWithReferencesTransitStop
 - TicketingMethodResponse
 - TicketingProduct
 - TransitEntryWithReferencesTransitTicketing
 - TransitTicketing
 - TransitEntryWithReferencesTransitTripDetailsOTP
 - TransitTripDetailsOTP
 - TransitTripStopTime
 - TripDetailsOTPMethodResponse
 - VehicleForTripMethodResponse
 - VehiclesForLocationMethodResponse
 - VehiclesForRouteMethodResponse
 - VehiclesForStopMethodResponse
Saving output to output.pdf

Add option to disable page numbers

Hey,

it would be great if there is an option to disable the page number generation. Looking at the code this should be quite simple.

What are your thoughts on this?

Mono fonts not showing, no errors on invalid fonts

When generating the document without any parameters, mono text is rendered with a proportional font:

image

I tried overriding the fonts in the config file:

{
  "font": {
    "baseSize": 10,
    "mono": {
      "norm": {
        "face": "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf"
      },
      "bold": {
        "face": "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf"
      },
      "italic": {
        "face": "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf"
      }
    }
}

However this did not make any visible difference. The config was definitely loading as it was respecting the baseSize setting.

When I set the face to an invalid font name/ path there were no errors in the console indicating it couldn't find the specified font.

I'm using Linux Mint with ApiBake 0.1.25.

Thanks for this tool! I hope more people use it as it's got a lot of promise to include in CI/CD workflows to automate documentation generation.

Please allow users to specify fonts

My swagger.json include some Chinese word. It generate pdf like here
image
If I change here
from

'Helvetica'

to

`${process.env.HOME}/Library/Fonts/NotoSansMonoCJKtc-Regular.otf`

it can show Chinese successfully.

Can you add a cli argument to set font?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.