Skip to content

Commit

Permalink
initial rewrite of RapiPdf as a cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Schubert authored and Stefan Schubert committed Sep 24, 2021
1 parent 978516c commit c0fe3a6
Show file tree
Hide file tree
Showing 176 changed files with 4,006 additions and 60,301 deletions.
11 changes: 0 additions & 11 deletions .babelrc

This file was deleted.

28 changes: 0 additions & 28 deletions .eslintrc

This file was deleted.

15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['prettier'],
extends: ['prettier', 'plugin:prettier/recommended'],
root: true,
env: {
node: true,
},
rules: {
'prettier/prettier': ['error', { singleQuote: true }],
},
};
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"printWidth": 120
}
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(The MIT License)

Copyright (c) 2019-2021
Mrinmoy Majumdar <[email protected]>
Stefan Schubert <[email protected]>

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.
20 changes: 0 additions & 20 deletions LICENSE.txt

This file was deleted.

36 changes: 9 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
<img alt="MrinDoc logo" src="https://github.com/mrin9/RapiPdf/blob/master/logo.png" width="60px" />
# OpenApi2Pdf


<p align="center">
<img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square"/>
<img src="https://img.shields.io/github/size/mrin9/rapipdf/dist/rapipdf-min.js.svg?colorB=blue&label=minified&style=flat-square">
<img src="https://img.shields.io/github/size/mrin9/rapipdf/dist/rapipdf-min.js.gz.svg?colorB=blue&label=zip&style=flat-square">
</p>

# RapiPDF
Custom element for Open-API to PDF generation
Converts a openapi spec file to pdf. Based on [RapiPDF](https://github.com/mrin9/RapiPdf)

## Features

- Supports Swagger 2.0 and OpenAPI 3.0
- Generate PDF using Web-Component
- Works with any framework or with no framework
- Plenty of customizing options, including selection of brand colors
- Supported on Chrome, FireFox and Safari. (Not yet tested on Edge)

## Documentation
[Check out the usage and examples](https://mrin9.github.io/RapiPdf/)
## Usage

## Build Process
We recommend `yarn` over `npm` as we use yarn [resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) to keep the bundle size smaller. As of this writing this feature is not supported in npm natively
```bash
# Clone / Download the project then
yarn install
npm install -g openapi2pdf

# build will generate rapidoc-min.js, this is the only file you will need.
# use it in the script tag of your html <script type="text/javascript" src="rapidoc-min.js"></script></body>
yarn build
openapi2pdf --spec ~/home/openapi-spec.json --out ~/home/pdf-spec.pdf
```

# for developement use yarn serve (this will start an webserver at port 8080, then navigate to localhost:8080)
yarn serve
## Licence

# alternative to yarn serve: (this will start an webserver at port 8080 listening to all adapters)
yarn serve-everyone
```
OpenApi2Pdf is [MIT licensed](LICENSE).
79 changes: 79 additions & 0 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env node
'use strict';

import createPdf from '../src/pdf-gen.mjs';
import { readFileSync, writeFileSync } from 'fs';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

const argv = yargs(hideBin(process.argv))
.option('spec', {
alias: 's',
type: 'string',
description: 'openapi spec file to convert',
requiresArg: true,
demandOption: true,
})
.option('out', { alias: 'o', type: 'string', description: 'output file', requiresArg: true, demandOption: true })
.option('primaryColor', { type: 'string', description: 'primary color to use in document', requiresArg: true })
.help().argv;

export async function generatePdf() {
try {
const data = await createPdf(JSON.parse(readFileSync(argv.spec, { encoding: 'utf-8' })), {
pdfSortTags: false,
pdfPrimaryColor: argv.primaryColor ? argv.primaryColor : '',
// pdfAlternateColor: '',
pdfTitle: 'API Reference',
pdfCoverText: '',
pdfSecurityText: '',
pdfApiText: '',
pdfSchemaStyle: 'object',
pdfFooterText: '',
includeInfo: true,
includeToc: true,
includeSecurity: true,
includeExample: false,
includeApiDetails: true,
includeApiList: false,
localize: {
index: 'INDEX',
api: 'API',
apiList: 'API List',
apiReference: 'API Reference',
apiVersion: 'API Version',
contact: 'CONTACT',
name: 'NAME',
email: 'EMAIL',
url: 'URL',
termsOfService: 'Terms of service',
securityAndAuthentication: 'Security and Authentication',
securitySchemes: 'SECURITY SCHEMES',
key: 'KEY',
type: 'TYPE',
example: 'EXAMPLE',
description: 'DESCRIPTION',
request: 'REQUEST',
requestBody: 'REQUEST BODY',
response: 'RESPONSE',
responseModel: 'RESPONSE MODEL',
statusCode: 'STATUS CODE',
deprecated: 'DEPRECATED',
allowed: 'ALLOWED',
default: 'DEFAULT',
readOnly: 'READ ONLY',
writeOnly: 'WRITE ONLY',
enumValues: 'ENUM',
pattern: 'PATTERN',
parameters: 'Parameters',
noRequestParameters: 'No request parameters',
method: 'METHOD',
},
});

writeFileSync(argv.out, data);
} catch (e) {
console.error('Something went wrong! Please check your input parameters!');
}
}
generatePdf();
7 changes: 0 additions & 7 deletions dist/index.html

This file was deleted.

Binary file removed dist/index.html.gz
Binary file not shown.
97 changes: 0 additions & 97 deletions dist/rapipdf-min.js

This file was deleted.

Binary file removed dist/rapipdf-min.js.gz
Binary file not shown.
1 change: 0 additions & 1 deletion dist/rapipdf-min.js.map

This file was deleted.

Binary file removed dist/rapipdf-min.js.map.gz
Binary file not shown.
Loading

0 comments on commit c0fe3a6

Please sign in to comment.