Get the curl command for each api endpoint defined in swagger.yaml file - node.js

I have a swagger.yaml file where I document all the node.js api endpoints. It uses openapi version 3.0.0. We also use express-openapi-validator package to validate the request and response of every api endpoint defined in the yaml file.
I want to get just the curl command for all the endpoints defined the yaml file. Is there any npm package or anything that can help me generate curl command from the swagger.yaml file so that I can display that curl command inside a custom component in react on a custom built page.

Related

Node - get file from local file system using http

I was wondering if its possible to get a file from the local file system (where node is running) using HTTP GET?
Meaning using a package such as axios, or request to get the file
The path to the file is full path.
Yes, check out the fs module..

How do you deploy Nodejs using Zeit now?

I'm trying to deploy my back-end nodejs server ising now by Zeit
I installed it using the npm i -g now command
and I used the now command to deploy, but I'm getting this error:
Now CLI 17.1.1
Error! The content of "~\AppData\Roaming\now\Data\auth.json" is invalid. No `token` property found inside. Run `now login` to authorize.
I'm confused on what I did wrong, any suggestions?
I had to run the command:
now login
then it asks for my Zeit account info. Afterwards, I navigated to the directory where my server files are and used the command:
now
to innitiate and deploy the backend.
Once it was done, it gave me a URL which I can use to access the backend within my front-end code

Is there an API in SwaggerHub to update the file definition?

Is there an API to update the file definition?
I am looking for a way to keep my project in Git and SwaggerHub in sync automatically, so I would like to update the file definition at every merge.
Is it possible? How do you manage keeping your project and SwaggerHub definition in sync automatically?
Yes, SwaggerHub has an API:
https://api.swaggerhub.com
Integrating with the SwaggerHub API
and a number of official API clients.
API
cURL command to create or update an API (note the use of --data-binary instead of -d/--data):
curl -X POST "https://api.swaggerhub.com/apis/OWNER/API_NAME" \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/yaml" \
--data-binary #myapi.yaml
Raw HTTP request for the reference:
POST https://api.swaggerhub.com/apis/OWNER/API_NAME
Authorization: YOUR_API_KEY
Content-Type: application/yaml
# Request body is your complete YAML/JSON file
swagger: '2.0'
info:
title: My API
version: 1.0.0
paths:
...
Use the correct Content-Type header value: application/yaml for YAML or application/json for JSON.
SwaggerHub CLI
A command-line wrapper around the SwaggerHub API, available as a npm module.
npm install -g swaggerhub-cli
Specify your API key (get it from https://app.swaggerhub.com/settings/apiKey):
swaggerhub configure
? SwaggerHub URL: https://api.swaggerhub.com
? API Key: <paste your key>
Create a new API:
swaggerhub api:create OWNER/API_NAME --file myapi.yaml
Update an existing API:
swaggerhub api:update OWNER/API_NAME/VERSION --file myapi.yaml --visibility private
Maven plugin
https://github.com/swagger-api/swaggerhub-maven-plugin/
Gradle plugin
https://github.com/swagger-api/swaggerhub-gradle-plugin/

GitLab API - Unable to access file which is within a directory

I have a GitLab project which is set up as follows:
myserver.com/SuperGroup/SubGroup/SubGroupProject
The tree of the following project is a top-level txt file and a txt file within a directory. I get the tree from the GitLab API with:
myserver.com/api/v4/projects/1/repository/tree?recursive=true
[{"id":"aba61143388f605d3fe9de9033ecb4575e4d9b69","name":"myDirectory","type":"tree","path":"myDirectory","mode":"040000"},{"id":"0e3a2b246ab92abac101d0eb2e96b57e2d24915d","name":"1stLevelFile.txt","type":"blob","path":"myDirectory/1stLevelFile.txt","mode":"100644"},{"id":"3501682ba833c3e50addab55e42488e98200b323","name":"top_level.txt","type":"blob","path":"top_level.txt","mode":"100644"}]
If I request the contents for top_level.txt they are returned without any issue via:
myserver.com/api/v4/projects/1/repository/files/top_level.txt?ref=master
However I am unable to access myDirectory/1stLevelFile.txt with any API call I try. E.g.:
myserver.com/api/v4/projects/1/repository/files/"myDirectory%2F1stLevelFile.txt"?ref=master
and,
myserver.com/api/v4/projects/1/repository/files/"myDirectory%2F1stLevelFile%2Etxt"?ref=master
Results in:
Not Found The requested URL /api/v4/projects/1/repository/files/myDirectory/1stLevelFile.txt was not found on this server.
Apache/2.4.25 (Debian) Server at myserver.com Port 443
myserver.com/api/v4/projects/1/repository/files/"myDirectory/1stLevelFile.txt"?ref=master and,
myserver.com/api/v4/projects/1/repository/files?ref=master&path=myDirectory%2F1stLevelFile.txt
Results in:
error "404 Not Found"
The versions of the components are:
GitLab 10.6.3-ee
GitLab Shell 6.0.4
GitLab Workhorse v4.0.0
GitLab API v4
Ruby 2.3.6p384
Rails 4.2.10
postgresql 9.6.8
According to my research there was a similar bug which was fixed with the 10.0.0 update.
I also added my ssh-key although I doubt it has any effect, following this advice with the same issue in php.
Solution:
I eventually solved it by adjusting the apache installed on the server.
Just follow these instructions: https://gitlab.com/gitlab-org/gitlab-ce/issues/35079#note_76374269
According to your code, I will go thinking you use curl.
If it is the case, why are you adding double quotes to your file path ?
The doc do not contains it.
Can you test it like that please ?
curl --request GET --header 'PRIVATE-TOKEN: XXXXXXXXX' myserver.com/api/v4/projects/1/repository/files/myDirectory%2F1stLevelFile%2Etxt?ref=master

requesting security token from STS with gSoap

I'm using gSoap 2.8.17 with C++ and need to request a security token from the STS.
I added wsee to my client code by following this:
Run wsdl2h -t typemap.dat on a WSDL of a service that requires WS-Security headers. The typemap.dat file is used to recognize and translate Security header blocks for XML signature and encryption.
Run soapcpp2 on the header file produced by wsdl2h.
(Re-)compile stdsoap2.c/pp, dom.c/pp, smdevp.c, mecevp.c, wsseapi.c and the generated source files with the -DWITH_DOM and -DWITH_OPENSSL compile flags set. The smdevp.c, mecevp.c, and wsseapi.c files are located in the 'plugin' directory.
I'm not clear how to add WS-Trust to my client code though.
I generated WS-Trust.h like this
wsdl2h -g -t ....\WS\WS-typemap.dat -x wsdl1.wsdl wsdl2.wsdl
WS-Trust.h contains Request token functions but I don't see an implementation for these.
/// Top-level root element "http://schemas.xmlsoap.org/ws/2005/02/trust":RequestSecurityToken of type "http://schemas.xmlsoap.org/ws/2005/02/trust":RequestSecurityTokenType.
/// Note: use wsdl2h option -g to auto-generate a top-level root element declaration and processing code.
Do I add WS-Trust.h (11 MB file) to my client proxy?
What are the steps to enable a client to use WS-Trust?
To generate the WS-Trust functions in the same header file as the other wsdls the -o argument is needed.
Example:
wsdl2h -t typemap.dat -o myService.h -x myService1.wsdl myService2.wsdl ../../WS/WS-Trust.wsdl
After running soapcpp2 I now see the request token functions declaration and implementation.

Resources