mrin9 / rapipdf Goto Github PK
View Code? Open in Web Editor NEWPDF generation from OpenAPI / Swagger Spec
Home Page: https://mrin9.github.io/RapiPdf
License: MIT License
PDF generation from OpenAPI / Swagger Spec
Home Page: https://mrin9.github.io/RapiPdf
License: MIT License
Dictionary<string, string> generates following schema in .net core:
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
And Swagger shows Example Value as
{
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
Can the pdf report show the same example instead of an empty response?
After troubleshooting some installation concerns, I'm now able to get the build process completed successfully:
cd ~/RapiPdf
yarn install
yarn build
I get this crazy looking browser window:
I'm not sure what to make of this. In any case if I continue on with the commands in the readme:
yarn serve
I get this:
$ yarn serve
yarn run v1.22.4
$ webpack-dev-server --mode=development
events.js:288
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use 127.0.0.1:8080
at Server.setupListenHandle [as _listen2] (net.js:1309:16)
at listenInCluster (net.js:1357:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1496:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:69:10)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1336:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '127.0.0.1',
port: 8080
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
In the event I accidentally started some other process on port 8080 and forgot about it, I rebooted and tried the yarn serve
command again and received same error.
How can I proceed to use this repository to view a local OpenAPI .json file?
When I click the Generate PDF button:
nothing happens. My issue is not the same as described in #5, in that issue the user describes a tab opening for a second and then closing, in my case nothing happens. Also the demo website https://mrin9.github.io/RapiPdf/ works great with the Swagger pet store example link https://mrin9.github.io/RapiPdf/specs/petstore.json.
Here is what I have done so far:
Clone RapiPdf to my home directory:
cd ~
git clone https://github.com/mrin9/RapiPdf.git
Based on the bottom of the readme I'm doing to build steps:
cd ~/RapiPdf
yarn install
yarn build
yarn serve
In the root directory of RapiPdf there is already a file named index.html, so I made a file index2.html:
cd ~/RapiPdf
touch index2.html
Then I copy/pasted in this text from the RapiPdf website:
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/rapipdf/dist/rapipdf-min.js"></script>
</head>
<body>
<rapi-pdf
style = "width:700px; height:40px; font-size:18px;"
spec-url = "https://mrin9.github.io/RapiPdf/examples/specs/petstore.json"
button-bg = "#b44646"
> </rapi-pdf>
</body>
</html>
Then I copied a file named MyApi.json
into the ~/RapiPdf
directory. This file contains the Swagger 2.0 pet store example so I'm 100% sure it's valid.
Next I edited the
spec-url = "https://mrin9.github.io/RapiPdf/examples/specs/petstore.json"
line in index2.html
to be:
spec-url = "../MyApi.json"
Please note that MyApi.json
and index2.html
are both located in the ~/RapiPdf/
directory. Next I double-clicked index2.html
to open it in Chrome, see the screenshot at the beginning of this post. If I press the Generate PDF button nothing happens. No error message, no pop-up blocker warning, no momentary tab opening and then closing.
I've tried it with and without the yarn serve
command above running. In the text box I've tried:
../MyApi.json
/home/cdahms/RapiPdf/MyApi.json
file://home/cdahms/RapiPdf/MyApi.json
file:///home/cdahms/RapiPdf/MyApi.json
In Chrome I went to:
Chrome -> dot dot dot button -> Settings -> Privacy and security -> Pop-ups and redirects
and added file:///home/cdahms/RapiPdf/index2.html
I also tried opening index2.html
in FireFox, same result.
Suggestions ??
Is there a way to include Components?
转换之后,中文乱码,如何解决?
When clicking the generate pdf button in chrome it opens a blank page and it closes it immediately.
I don't see the pdf. If I disable the chrome pdf display from the settings, then I get to download the pdf correctly. Any idea how to fix this? The demo from website doesn't work either, same issue.
So in browser pdf preview is not working.
This is the setting I have to change in chrome:
https://i.imgur.com/cLaDzFy.png
Hello,
Is there an example on how we could use this in node js? It would be a great functionality for microservice and serverless applications.
When tagging method with multiple tag, RapiPdf generator takes in account only the first.
I'll propose you a pull request.
When rendering out the PDF I seem to only get the model data from my OpenAPI v3 document. I'm not seeing the examples. Any reason why no examples shown?
In OpenAPI you can add images in the description of most items like this:
![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)
Unfortunately that breaks the PDF generation.
It would be really nice, if the images were included in the PDF as well.
I'm trying to generate a PDF from a Swagger document containing a deprecated endpoint and the operation fails. I see this in the console output:
rapipdf-min.js:45609 Uncaught (in promise) TypeError: Cannot read property 'depricated' of undefined
at rapipdf-min.js:45609
at Array.map (<anonymous>)
at M (rapipdf-min.js:45609)
at B (rapipdf-min.js:45609)
at rapipdf-min.js:45609
at Array.map (<anonymous>)
at D (rapipdf-min.js:45609)
at A (rapipdf-min.js:45609)
at A.next (<anonymous>)
at y (rapipdf-min.js:45609)
I assume that the error is caused by this line in the RapiPdf source code:
Line 137 in 4bf0538
Should it be paramSchema.deprecated
instead?
This is a custom property from NSwag. So e.g. a C# enum looks like the following in the OpenAPI spec:
public enum DataType {
String,
Integer
}
{
...
"DataType": {
"type": "integer",
"description": "",
"x-enumNames": [
"String",
"Integer"
],
"enum": [
1,
2
]
}
...
}
The RapiPDF doc currently tells users they can use 1
or 2
which is technically correct, but not so helpful. We can add a description manually, but it would be great to take this information from the spec automatically when it's available.
Wehn an ApiParam is annotated with e.g. @SiZe(min = 1, max = 255),
in the resulting PDF the open parenthesis is missing.
Hi,
I am trying to put a link into the footer:
rapiPdf.setAttribute("pdf-footer-text", "More info here: <a href='https://www.google.com\'>Google");
But that just prints all this as text.
How can I insert a hyperlink?
Thanks,
Guy
The quickstart demo assigns https://mrin9.github.io/RapiPdf/examples/specs/petstore.json
to the spec-url
property, but this produces a 404. The correct path should be https://mrin9.github.io/RapiPdf/specs/petstore.json
.
Hi! I am trying to use rapipdf in my react app, but I have a problem with it. So, I installed this package using: npm i rapipdf
and then I import it in my app like it is presented in RapiDoc examples :
import 'rapipdf';
...
class MyComponent extends React.Component<MyProps, MyState> {
...
render() {
return (<rapi-pdf
spec-url={'/apis/api.yml'}
button-bg="#b44646"
>
</rapi-pdf>);
}
Unfortunately, within the compilation, I have an error:
ERROR in ./node_modules/rapipdf/src/rapipdf.js
Module not found: Error: Can't resolve '@/pdf-gen' in '/home/me/project/node_modules/rapipdf/src'
@ ./node_modules/rapipdf/src/rapipdf.js 35:0-34 240:6-15
@ ./src/MyComponent.tsx
Could you help me fix it? And how can I use rapipdf in js applications without downloading and including rapipdf-min.js in html?
Would be nice to have an option to paginate each API call, so each call starts on a new page.
When include-security=false there is the blank page in pdf file
It would be really great to have an option to generate PDF using copy-paste of text, not by link. For example, I just had to generate API from swagger made by apicur.io and uploaded to my PC. File was protected by NDA so I couldn't upload it to open internet, so I had to install local web-server to open it by your app. So it would be great to have an option to paste json/yaml to textarea in app instead of url requesting
When you set hide-input
to true
, the right corners of the button are still rounded. Is it possible to have all 4 corners the same?
Just tried your home page demo with a file:/// uri and with a https:// url that only I can see from my location.
neither works.
Does that mean that hidden behind the scenes your javascript is calling a server that want's to connect to those resources?
Not finding anything here to help me use this locally (or within a build chain, my main priority).
Any suggestions gratefully received.
Thanks
Hi,
It seems that the last page of every generated PDF is empty.
Thanks,
Guy
I'm interested in using this lib, but the examples on the linked website open a new tab with nothing happening or downloading.
(using mac os catalina and latest chrome stable)
how to code multi-language?
I was trying to render a documentation from a still-very-early JSON from one of our service, but the PDF is not coming out with an error in Console.
This is the error in SAFARI:
[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'i.schema.properties')
generatorResume (rapipdf-min.js:47:1121664)
p (rapipdf-min.js:47:1125428)
i (rapipdf-min.js:47:1131402)
promiseReactionJob
This is the error in CHROME:
Spec Conversion - Success !!!
lodash.js:9 Uncaught (in promise) TypeError: Cannot read property 'properties' of undefined
at h (lodash.js:9)
at lodash.js:9
at Array.map ()
at lodash.js:9
at A (lodash.js:9)
at A.next ()
at p (lodash.js:9)
at i (lodash.js:9)
This is the error in FIREFOX:
Spec Conversion - Success !!! lodash.js:9
TypeError: i.schema is undefined
The reference is at: https://storage.gcloud.schema31.it/reference/api_1.0.0/openapi.json
Feel free to try it at: https://storage.gcloud.schema31.it/docs/public/api_1.0.0/pdf.php
Thanks, the project looks very cool!
Hi,
RapiPdf is very good, and would really fit my simple need, but I have one showstopper.
Just imagine a sligthly modified petstore example with just an added operation,
POST /store/backOrder, the same as POST /store/order, with the same input, but a supposedly different business logic.
(#/definitions/Order)
petstore_plus_backorder.txt
...
"/store/order": {
"post": {
"tags": [
"store"
],
"summary": "Place an order for a pet",
"description": "",
"operationId": "placeOrder",
"produces": [
"application/xml",
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "order placed for purchasing the pet",
"required": true,
"schema": {
"$ref": "#/definitions/Order"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Order"
}
},
"400": {
"description": "Invalid Order"
}
}
}
},
"/store/backorder": {
"post": {
"tags": [
"store"
],
"summary": "Place an back order for a pet",
"description": "",
"operationId": "placeBackOrder",
"produces": [
"application/xml",
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "order placed for purchasing the pet",
"required": true,
"schema": {
"$ref": "#/definitions/Order"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Order"
}
},
"400": {
"description": "Invalid Order"
}
}
}
},
...
if you do that, and this would happen a lot in real life, reusing the same schema for input on different operations,
then in the PDF, the two request sections content just disappear, only leaving the REQUEST title right before RESPONSE
To retrieve the desired output, the only solution I found is to duplicate the Order definition with another name.
which beats the purpose of openApi definitions reusability.
In our case, we may have for instance a definition called UserTokenInput, used in 15 different operations, this would mean we'd have to duplicate it from UserTokenInput1 to UserTokenInput15 ... and amend each operation accordingly.
RapiDoc does not have the same issue. It displays the 2 requests content correctly.
Can this be solved easily ?
Best regards,
David
Tried converting an OpenAPI Spec with a description that includes both a GitHub Format Markup table and an HTML table and both were excluded from the PDF that was produced. Both tables are displayed correctly via Swagger Editor/UI.
Example spec exhibiting the behavior described above:
openapi.txt
I have specified @SiZe annotations, which are not rendered in the model:
There's a misspelling of "element" — as "Eelement" — on the main README.md.
Nested lists don't seem to be supported when writing MD in the spec description.
Repro
info.description:
- item 1
- item 2
- item 2.1
- item 2.2
- item 2
Result:
* item 1
* item 2
* item 2.1
* item 2.2
This becomes a flat list, and after the first nested list ends the rest of the list is ignored.
Code
Line 84 in 6a8055c
Does it support Webhooks (Callbacks) defined in OpenAPI 3.0 Json file?
I mark any service-generated parameters as readOnly, such as UUIDs and timestamps for when resources are created and updated. The parameters should only be shown in responses, never in requests. RapiPdf includes those parameters in requests, which is confusing. It does show "read-only" in the type column, but that's not as clear as not showing those parameters at all for requests.
That is, it's better to say that a request body includes A, B, and C instead of A, B, C, and D, but D is read-only.
It could be great to have a format to upload custom PDF template or something. The case is: names localisation. My API is described in Russian so I would like to have translated headers (like "index", "Request", "request body" etc in generated PDF.
Unicode characters (such as Chinese or Japanese) are blank in the generated pdf.
I'm adding security manually to an OpenAPI 3 spec, so I may have got something wrong here.
I have include-security
turned on and I've tried adding both
security
at the top level and securitySchemes
in components
per the specsecuritySchemes
at the top level as per the codeNeither shows a security section in the PDF. In the debugger, it looks like if I do (2) then the swagger parser clears the object since it's not valid.
Am I doing this wrong or is this a bug?
I copied the example HTML file and pasted my JSON into it to try RapiPdf on my machine. I got this error in the console:
Uncaught (in promise) TypeError: A.split is not a function
That pointed to this code in the (formatted) rapipdf-min.js, starting at line 64329:
a.servers && a.servers.map(t=>{
if (t.url && "/" === t.url.substr(0, 1)) {
var e = A.split("/");
t.url = "".concat(e[0], "//").concat(e[2]).concat(t.url)
}
}
),
I changed the third line to this:
var e = u.split("/");
The error went away and the PDF file was generated. I'm a technical writer, and not good enough with JavaScript to be confident that I would be fixing the right thing in the source files, so I'm opening this issue instead of fixing it and creating a pull request. I don't even know if my change was the right thing to do, but it didn't work before and now it does.
Thanks for the great tool!
Hi,
After I set CSP sandbox flags, it breaks PDF rendering, nothing is displayed. New windows opened from the sandbox inherit the sandbox flags in CSP. Sandbox is applied to Chrome's PDF render component, rather than the PDF itself. Is there anything I can do to avoid this problem?
CSP rule:
sandbox allow-modals allow-forms allow-scripts allow-same-origin allow-popups
Thanks!
Latest version on unpkg https://unpkg.com/[email protected]/dist/ and even demo on https://mrin9.github.io/RapiPdf/ does not work (v1.0.0 works):
On firefox v67:
Spec Conversion - Success !!! rapipdf-min.js:50:1006691
Source map error: request failed with status 404
Resource URL: https://mrin9.github.io/RapiPdf/rapipdf-min.js
Source Map URL: rapipdf-min.js.map
RangeError: Trying to access beyond buffer length rapipdf-min.js:16:11116
Spec Conversion - Success !!! rapipdf-min.js:50:1006691
TypeError: e(...) is not a constructor rapipdf-min.js:23:64402
Spec Conversion - Success !!! rapipdf-min.js:50:1006691
TypeError: e(...) is not a constructor rapipdf-min.js:23:64402
On chrome v74:
14:52:20.014 rapipdf-min.js:50 Spec Conversion - Success !!!
14:52:20.505 rapipdf-min.js:16 Uncaught (in promise) RangeError: Trying to access beyond buffer length
at F (rapipdf-min.js:16)
14:52:23.923 rapipdf-min.js:50 Spec Conversion - Success !!!
14:52:24.081 rapipdf-min.js:23 Uncaught (in promise) TypeError: e(...) is not a constructor
at B._createDoc (rapipdf-min.js:23)
I'm using Ubuntu 18.04. Initially I did:
cd ~
sudo apt-get install yarn
git clone https://github.com/mrin9/RapiPdf.git
cd RapiPdf
Received this error:
00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'install'
Based on this post:
https://stackoverflow.com/questions/46013544/yarn-install-command-error-no-such-file-or-directory-install
I next did:
sudo apt remove cmdtest
sudo apt remove yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn
cd RapiPdf/
yarn install
Now I get this error:
yarn install v1.22.4
[1/4] Resolving packages...
warning babel-loader > [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
warning webpack > [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version ">= 8.16.2". Got "8.10.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
This post seems to mention this error:
https://github.com/babel/babel-loader/issues/833
However I have no idea what mkdirp
is or how to update it on Ubuntu 18.04 if that is even possible.
Suggestions ??
Note: this questions is similar to one I posted for RapiDoc @ rapi-doc/RapiDoc#167
--- edit ---
If I do:
cd ~
cd RapiPdf
npm install
I get:
$ npm install
loadDep:swagger2openapi → ▌ ╢████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm ERR! Linux 5.0.0-37-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code EMISSINGARG
npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror <http://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /home/cdahms/RapiPdf/npm-debug.log
Full log attached per error message instructions.
Suggestions??
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.