Giter Club home page Giter Club logo

swagger-js's Introduction

Swagger Client

Build Status

Swagger Client is a JavaScript module that allows you to fetch, resolve, and interact with Swagger/OpenAPI documents.

New!

This is the new version of swagger-js, 3.x. The new version supports Swagger 2.0 as well as OpenAPI 3.

Want to learn more? Check out our FAQ.

For features known to be missing from 3.x please see the Graveyard.

For the older version of swagger-js, refer to the 2.x branch.

The npm package is called swagger-client and the GitHub repository is swagger-js. We'll be consolidating that soon. Just giving you the heads-up. You may see references to both names.

Compatibility

The OpenAPI Specification has undergone multiple revisions since initial creation in 2010. Compatibility between Swagger Client and the OpenAPI Specification is as follows:

Swagger Client Version Release Date OpenAPI Spec compatibility Notes
3.19.x 2023-01-23 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0 tag v3.19.0-alpha.3
3.10.x 2020-01-17 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 tag v3.10.0
2.1.32 2017-01-12 1.0, 1.1, 1.2 tag v2.1.32. This release is only available on GitHub.

Documentation

Usage

Development

Migrations

Runtime

Node.js

swagger-client requires Node.js >=12.20.0 and uses different fetch implementation depending on Node.js version.

NOTE: swagger-client minimum Node.js runtime version aligns with Node.js Releases which means that we can drop support for EOL (End Of Life) Node.js versions without doing major version bump.

Browsers

swagger-client works in the latest versions of Chrome, Safari, Firefox, and Edge and uses native fetch implementation provided by each supported browser.

Security contact

Please disclose any security-related issues or vulnerabilities by emailing [email protected], instead of using the public issue tracker.

swagger-js's People

Contributors

ayush avatar bodnia avatar brodyd avatar buunguyen avatar cameracker avatar char0n avatar dballance avatar dependabot-preview[bot] avatar dependabot[bot] avatar djmax avatar extempl avatar fehguy avatar glowcloud avatar jimmywarting avatar kojoru avatar martinwoitzik avatar mrhanlon avatar noirbizarre avatar owenconti avatar ponelat avatar pose avatar semantic-release-bot avatar shockey avatar swagger-bot avatar swaggerhub-bot avatar tim-lai avatar webron avatar whitlockjc avatar xoss avatar zeke avatar

Stargazers

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

Watchers

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

swagger-js's Issues

Preload client-side manifest?

When I call new SwaggerApi(), each set of resources is fetched with a separate ajax request. e.g.:

There are only 2 calls now, but I'm just getting started -- Is there a way to do a JSON dump into the HTML such that the client library won't need to make all of these calls? I'm worried about the time it'll take to complete all the necessary calls. (I'm using swagger-node-express, for what it's worth.)

Errors when running swagger in the browser

I grabbed the code of the site here:

<script src='lib/shred.bundle.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script type="text/javascript">
  // initialize swagger, point to a resource listing
  window.swagger = new SwaggerApi({discoveryUrl: "http://petstore.swagger.wordnik.com/api/api-docs.json"});
  swagger.build();

  // add a success handler to dump the raw json into a div element named `mydata`
  success = function(data) {
    document.getElementById("mydata").innerHTML = data.content.data;
  }

  // a function to fetch a pet
  function getPet() {
    swagger.apis.pet.getPetById({petId:1}, success);
  }
</script>```

I get this:

no zlib library
shred.bundle.js (line 1761)
NS_ERROR_MALFORMED_URI: The URI is malformed
[Break On This Error]   

true

Supporting HMAC calculation via callback(s)

How would Swagger be best enhanced to support the calculation of certain headers or request parameters upon each call, on behalf of HMAC-based authentication and authorization?

I've noticed the pull request swagger-api/swagger-ui#77 (which didn't ultimately get submitted to swagger-js) which would allow you to calculate a single header via a callback. But I'm wondering if the solution should be more flexible. addressing:

  • That in HMAC auth solutions, there are often multiple headers, calculated in concert (the HMAC signature with associated nonce, timestamp, or other values, etc.)
  • That some APIs put these values in the headers, whereas others put them in the request parameters (e.g. Amazon)
  • That the callback will likely need the entire SwaggerOperation object, so that it can factor-in things like the httpMethod into the signature

I am thinking of enhancing SwaggerOperation.getMatchingParams to support this kind of dynamic header calculation on each call, but wondering what the official team thinks of the best direction:

  • it could support single-header callbacks, as in the pull request above
  • or it could be a single callback to calculate arbitrary additional params (either header or query)
  • or it could be a single callback which fires sometime later (just before the call is made) to decorate the call in arbitrary ways

I'm leaning towards the middle option but wanted to get feedback before I submit a Pull Request. Thanks in advance.

Can't run tests

I can't get the tests running using cake dev. I suppose you need to have a server serving the api-docs (swagger-core? which version?) running somewhere but I can't figure it out.

Thanks for your help!

sanitize nicknames

currently nicknames can contain illegal characters which cause chaos in just about every programming language. Support just a-z, A-Z, 0-9, _

Unable to run example.html

I am trying to run this example from my local Apache server: https://github.com/wordnik/swagger.js/blob/master/example.html.

It appears to reference URL for spec file that is no longer valid (should probably be changed?).

After changing it to the following it appears to run but still returns an error:

XMLHttpRequest cannot load http://developer.wordnik.com/v4/api-docs.json?api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5. Origin http://local is not allowed by Access-Control-Allow-Origin.

Uncaught Can't read from server. It may not have the appropriate access-control-origin settings.

<title>swagger.js example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/wordnik/swagger.js/master/lib/swagger.js"></script>
<script type="text/javascript">
    $(function() {
        wordnik = new SwaggerApi({
            api_key: 'a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5', // sample wordnik API key
            discoveryUrl: "http://developer.wordnik.com/v4/api-docs.json",
            verbose: true,
            success: function() {
                args = {word: 'sanctimonious'}
                wordnik.word.getDefinitions(args, function(definitions){
                    console.log(definitions[0].word);
                    for (var i = 0; i < definitions.length; i++) {
                        var definition = definitions[i];
                        console.log(definition.partOfSpeech + ": " + definition.text);
                    }
                });
            }
        });
    });
</script>

Recursive model schemas cause the library to have a stack overflow error

A recursive model like the example below

{
   "Pet":{
      "properties":{
         "age":{
            "type":"int"
         },
         "name":{
            "type":"string"
         },
         "children":{
            "items":{
               "$ref":"Pet"
            },
            "type":"List"
         },
         "parent":{
            "type":"Pet"
         }
      },
      "type":"Pet"
   }
}

Causes the json model generation based on model schema to error with a Stack overflow error

NB: I have a fix for this and can send in a PR

Empty form params are sent as undefined

When you submit a form with form parameters, all empty inputs are sent as "undefined".
(referenced at swagger-api/swagger-ui#399)

Here's a fix in swagger.js 966 (not sure about the coffee):

for(var i = 0; i < formParams.length; i++){
  var param = formParams[i];
  var value = this.params[param.name];
  if (value !== undefined) {
    values[param.name] = value;
  }
}

var encoded = "";
for(key in values) {
  value = values[key];
  if(encoded !== "")
    encoded += "&";
  encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}

File Upload Bug in UI

The following code in the swagger-u.js code appears to make it impossible for the file(s) to be attached to the API request. Is this code old or in need of an upgrade?

The 'bodyParam = null'; seems to kill things.

    isFileUpload = $('input[type~="file"]').size !== 0;
    if (isFileUpload) {
      bodyParam = new FormData();
      _ref1 = this.model.parameters;
      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
        param = _ref1[_j];
        if (param.paramType === 'body') {
          bodyParam.append(param.name, map[param.name]);
        }
      }
      $.each($('input[type~="file"]'), function(i, el) {
        return bodyParam.append($(el).attr('name'), el.files[0]);
      });
    } else {

    }
    bodyParam = null;
    _ref2 = this.model.parameters;
    for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
      param = _ref2[_k];
      if (param.paramType === 'body') {
        bodyParam = map[param.name];
      }
    }
    log("bodyParam = " + bodyParam);

Uncaught Type Error: cannot read property $ref of undefined

I am not sure why I am getting the following error. It occurred after generating my Swagger resources via swagger-php:

Uncaught TypeError: Cannot read property '$ref' of undefined swagger.js:698
SwaggerOperation swagger.js:698
SwaggerResource.addOperations swagger.js:471
SwaggerResource.addApiDeclaration swagger.js:402
obj.on.response swagger.js:357
res.response swagger.js:1307
EventEmitter.emit shred.bundle.js:1391
emit shred.bundle.js:1191
(anonymous function) shred.bundle.js:1211
setBodyAndFinish shred.bundle.js:1815
(anonymous function) shred.bundle.js:1832
EventEmitter.emit shred.bundle.js:1388
Response.handle shred.bundle.js:2715
xhr.onreadystatechange

My Swagger resources did not throw any upon doc generation. Here is what my resource looks like:

{
    "basePath":"https://myapp.com/v1",
    "swaggerVersion":"1.2.0",
    "apiVersion":"1.0.0",
    "resourcePath":"v1",
    "apis":[
        {
            "path":"/copyResources/",
            "description":"copyResources(): Handler to copy resources. Gets the user's home directory and prepends the home directory to each passed in path. Calls copyResources on the file controller with the full paths. This is available to users with the \"upload\"  permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Copies the specified file paths to the specified destination path",
                    "nickname":"copyResources",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"filePaths",
                            "type":"array",
                            "required":true,
                            "description":"Remote paths of the files or folders to copy"
                        },
                        {
                            "paramType":"query",
                            "name":"destinationPath",
                            "type":"string",
                            "required":true,
                            "description":"Remote destination path to copy files/folders to"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/createFolder/",
            "description":"createFolder(): Handler to create a new folder. Gets the user's home directory and calls create folder on the file controller with the full path. This is available to users  with the \"upload\" permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Get the user's home directory and calls getFolders on the file controller with the full path",
                    "nickname":"createFolder",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"folderName",
                            "type":"string",
                            "required":true,
                            "description":"Name of the folder to create"
                        },
                        {
                            "paramType":"query",
                            "name":"path",
                            "type":"string",
                            "required":true,
                            "description":"Where to create the folder"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/getFolders/",
            "description":"getFolders(): Handler to get folder list Gets the user's home directory and calls getFolders on the file  controller with the full path",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Get the user's home directory and calls getFolders on the file controller with the full path",
                    "nickname":"getFolders",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"path",
                            "type":"string",
                            "required":true,
                            "description":"The remote file path"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/getResourceList/",
            "description":"getResourceList(): Handler for folder / file path listing Gets the user's home directory and calls getResourceList on the file controller  with the full path. This is available to users with the \"list files\" permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Get a listing of files/folders for the specified path. Available for users with list files permission",
                    "nickname":"getResourceList",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"path",
                            "type":"string",
                            "required":true,
                            "description":"The remote file path"
                        },
                        {
                            "paramType":"query",
                            "name":"sortBy",
                            "type":"string",
                            "required":true,
                            "description":"Sort according to attribute"
                        },
                        {
                            "paramType":"query",
                            "name":"sortOrder",
                            "type":"string",
                            "required":true,
                            "description":"Sort in either ascending or descending order"
                        },
                        {
                            "paramType":"query",
                            "name":"offset",
                            "type":"integer",
                            "required":true,
                            "description":"Determines which item to start on for pagination"
                        },
                        {
                            "paramType":"query",
                            "name":"limit",
                            "type":"integer",
                            "required":true,
                            "description":"The number of files to limit the result"
                        },
                        {
                            "paramType":"query",
                            "name":"detailed",
                            "type":"boolean",
                            "description":"If true, returns sharedFolder, notifications or other objects associated with specified path"
                        },
                        {
                            "paramType":"query",
                            "name":"pattern",
                            "type":"string",
                            "description":"Regex string. If not null, perform a search with specified pattern"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/moveResources/",
            "description":"moveResources(): Handler to move resources. Gets the user's home directory and prepends it to each passed in path. Calls moveResources on the file controller with the full paths. This is  available to users with the \"upload\" permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Moves the specified file paths to the specified destination path",
                    "nickname":"moveResources",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"filePaths",
                            "type":"array",
                            "required":true,
                            "description":"Remote paths of the files or folders to move"
                        },
                        {
                            "paramType":"query",
                            "name":"destinationPath",
                            "type":"string",
                            "required":true,
                            "description":"Remote destination path to move files/folders to"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        }
    ],
    "produces":[
        "application/json",
        "application/xml",
        "text/plain",
        "text/html"
    ]
}

Does anyone have any idea why this might be?

RangeError: Maximum call stack size exceeded

swagger-ui is able to fetch my individual API endpoint JSON documents, but when it starts parsing the models, it never displays anything and Chrome shows:

Uncaught RangeError: Maximum call stack size exceeded
SwaggerModelProperty.getSampleValue
SwaggerModel.createJSONSample
SwaggerModelProperty.getSampleValue
SwaggerModel.createJSONSample
SwaggerModelProperty.getSampleValue
SwaggerModel.createJSONSample
SwaggerModelProperty.getSampleValue
SwaggerModel.createJSONSample
SwaggerModelProperty.getSampleValue
SwaggerModel.createJSONSample
SwaggerModelProperty.getSampleValue
...

in the console. I'm using https://github.com/ryankennedy/swagger-jaxrs-doclet to generate my documentation off of a Dropwizard Java service. The JSON files it outputs are correct, so I'm not sure why the UI is looping. This is using the latest checkout of swagger-ui from master.

Using PasswordAuthorization fails because btoa is undefined on nodejs

When run on nodejs 0.10.20, new swagger.PasswordAuthorization( ... ) ends with this error:

/.../node_modules/swagger-client/lib/swagger.js:1216
      return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":
                                                       ^
ReferenceError: btoa is not defined
    at PasswordAuthorization.apply (/.../node_modules/swagger-client/lib/swagger.js:1216:56)

Workaround: btoa can be added by npm install btoa and then by requiring it before the swagger-client:

var btoa = require( "btoa" );
var swagger = require( "swagger-client" );

The final solution should include btoa in dependent nodejs modules and require it in PasswordAuthorization when not running in the web browser.

Absolute path calculated not correctly in swagger.js

Moved this issue into right place.

Abs path in getAbsoluteBasePath from swagger.js calculated not correctly in case when relativeBasePath is /. Currently it returns whole url except slash itself. When the basePath is / then we should treat url as <proto>://<domain> (root of the domain path). Check the patch to see what i mean.

--- dist/lib/swagger.js (revision c92e9a14b98a99064a6256a71706b6b586271a98)
+++ dist/lib/swagger.js (revision )
@@ -381,7 +381,9 @@
       return url + "/" + relativeBasePath;
     }
   } else if (relativeBasePath === "/") {
-    return url.substring(0, pos);
+    parts = url.split("/");
+    url = parts[0] + "//" + parts[2];
+    return url;
   } else {
     return url.substring(0, pos) + relativeBasePath;
   }

Save build to a javascript file

I would like to generate an API client and save the build to a javascript file. Is this possible?

This file can be cached and versioned, loaded into a page and used to communicate with my swagger enabled API.

Dynamically creating the javascript client requires first fetching the spec from the server and then building it. Both actions cause a slight performance hit.

Also having a static build could enable IDE auto completion.

Unable to use from node

I am getting this error:

.../node_modules/swagger-client/lib/swagger.js:760
window.SwaggerApi = SwaggerApi;
^
(It seems that this library was designed to only work in the browser...)

Different approach

I took a slightly different approach:

  • I created a base Node.js module which has an "ApiInterface".
  • I build the raw json from all the docs of an endpoint, writing it to another Node.js module.
  • The "ApiInterface" requires the raw swagger json.
  • I use browserify to bundle and then minify for client (production ready - one request), so the library can be used in Node.js or on the client-side.

Since I use AngularJS, I created a service with a class which implements the HTTP methods from the code link below.

Code is here:

https://github.com/m2mIO/node-2lemetry/blob/master/lib/swagger.litcoffee
https://github.com/m2mIO/node-2lemetry/blob/master/api/v2-0.0.1.litcoffee

Some of this is "specific" to the API I built it for, but it throws validation errors, authenticates on instantiation, etc.

The repo README.md has usage instructions.

Just thought I'd show another way of doing it :)

support file upload

Need to port the code from swagger-ui for uploading files. This will likely only be supported in browser mode.

Should recognize "required" array parameter of JSON model

...in develop-2.0 branch...

See section "5.4.3. required" in the JSON schema docs:
http://json-schema.org/latest/json-schema-validation.html#anchor61

Currently to set a model's property as required, you must set a boolean "required" attribute on the property itself.

ex:

"models": {
   "ModelA": {
      "id": "ModelA",
      "type": "object",
      "properties": {
         "propA": { "type": "string", "required": true },
         "propB": { "type": "string", "required": true },
         "propC": { "type": "int" }
      }
   }
}

Per the JSON schema documentation, there should be an array[string] "required" property on the model itself rather than a boolean on the individual properties.

ex:

   "required": [ "propA", "propB" ]

...as in...

"models": {
   "ModelA": {
      "id": "ModelA",
      "type": "object",
      "required": [ "propA", "propB" ],
      "properties": {
         "propA": { "type": "string" },
         "propB": { "type": "string" },
         "propC": { "type": "int" }
      }
   }
}

Content Negotiation

Hello,

I'm not sure if this is an issue with Swagger-JS or Shred, but my API returns JSON with a content-type of application/json, but Swagger-JS doesn't parse it into a JSON object. It's returning as a string.

You can see below the content type header and that response.content.[data/body] are both strings.

Am I missing something here? Is it related to #57 ?

screen shot 2014-01-17 at 11 22 28 pm

Representing Maps and Generic Types in general

Working on supporting Maps in the swagger-springmvc project

So in that vein, I've generated api-docs as follows

"models": {
//...
      "Entry[String,Pet]": {
            "properties": {
                "value": {
                    "properties": {
                        "id": {
                            "type": "string"
                        },
                        "age": {
                            "type": "int"
                        },
                        "name": {
                            "type": "string"
                        }
                    },
                    "type": "Pet"
                },
                "key": {
                    "type": "string"
                }
            },
            "type": "Entry[String,Pet]"
        },
//...
   },
//...
"apis": [
{
            "path": "/pets/nameMap",
            "description": "Operations about pets",
            "operations": [
                {
                    "httpMethod": "POST",
                    "summary": "name Map",
                    "notes": "",
                    "deprecated": false,
                    "responseClass": "List[Entry[String,Pet]]",
                    "nickname": "nameMap",
                    "parameters": [
                        {
                            "name": "someInput",
                            "description": "some Input",
                            "notes": "",
                            "paramType": "body",
                            "defaultValue": "",
                            "required": false,
                            "allowMultiple": false,
                            "dataType": "List[Entry[String,Pet]]"
                        }
                    ]
                }
            ]
        },
//...
}

Currently any model with a "[" is considered a list (isListType method) which seems like it is a bug. Also the logic doesnt seem to support nested generic types, for e.g.
List[Entry[String, Pet]]
HttpEntity[List[Pet]]
which may not be relevant for languages that dont support generics but are essential for genererating models in languages like Java or C#

May be i'll bring it up in the forum to solicit ideas in a more general setting.

query string is invalid when optional parameters are not supplied

In v2.0.19, when some but not all query string parameters are provided the resulting query string is invalid.

For example:
Consider option query parameters limit and offset. Neither is required to be supplied on the query string. If the first is provided and the second is not, the resulting query string is "?limit=10&". This issue becomes worse with additional parameters, if there were 3 more optional query parameters that were not provided, the resulting query string would be "?limit=10&&&&".

This seems to be caused by the urlify function in swagger.js, lines 832-835:

      if(queryParams !== '')
        queryParams += "&";
      if(args[param.name] !== undefined)
        queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);

To fix this, I propose the following change:

        if (args[param.name] !== undefined) {
            if (queryParams !== '')
                queryParams += "&";
            queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
        }

errorResponses->responseMessages translated only partially

When moved from 1.1 swagger spec to 1.2 the errorResponses in operation metadata were renamed to responseMessages. This change is supported for backward compatibility here.
But also 'reason' was 'renamed' to 'message'. But this is not supported. Fix is pretty trivial:

          if (o.errorResponses) {
            responseMessages = o.errorResponses;
            var _ri, _rlen, _r;
            for (_ri = 0, _rlen = responseMessages.length; _ri < _rlen; _ri++) {
                _r = responseMessages[_ri];
                if (_r.reason) {
                    _r.message = _r.reason;
                    delete _r.reason;
                }
            }
          }

Proxy enhancement for client side in node app

Hi,
I am new in this area, so apologizes for potential mistakes ...
first of all, it's not an issue but I don't know where to post my queries !
I am playing with Swagger js lib client inside a Node.js App and I can't figure how to set a proxy to reach a Swagger API service outside my company network.
Thanks for your help.
Regards,
Vernon

Path autorization

I have path authorization in project, sample:
/api/{api_key}/v1/resource
How i can do that, cose default authorizations support only 'query' and 'header' types ?

Using Swagger.js in the browser, preventing JSONP wrapper

Currently when i make a cross domain call, it does so and returns the data in a callback. The server I'm hitting uses CORS, so the wrapper isn't needed.
What can I do to let my server decide how to handle cross domain, not swagger-js, or am I missing something?

less confusing names for input data type

the supportedDataTypes is confusing since it's not clear whether it's the data type being consumed or produced. consumes is better, since it is clear that this is the data format being consumed. produces will be added as well.

To avoid breaking clients which are expecting supportedDataTypes, swagger.js will check for supportedDataTypes and set the consumes field from that value.

build works in REPL but not when run as node app.js

build doesn't seem to work or object props are being exposed when build is run outside of REPL. I must be doing something wrong here.

gsp-api.js

var swagger=require("swagger-client");

swagger.authorizations.add("auth",new swagger.PasswordAuthorization("auth","login","pw"));
var client = new swagger.SwaggerApi({url: "http://science.gild.com/docs/api-docs/"});

client.build()

module.exports.client=client

REPL

var swagger=require("swagger-client");
undefined

undefined
swagger.authorizations.add("auth",new swagger.PasswordAuthorization("auth",login","pw"));
{ name: 'auth',
username: 'gildscience',
password: 'l33tgsp' }
var client = new swagger.SwaggerApi({url: "http://science.gild.com/docs/api-docs/",debug: true});
undefined
client.build();
{ url: 'http://science.gild.com/docs/api-docs/',
failure: [Function],
progress: [Function] }
client.ready
true

node app.js

(app.js)
var gsp_api=require("./lib/gsp-api")
console.log(gsp_api.client);
console.log("Client Ready? "+gsp_api.ready);

node app.js
{ url: 'http://science.gild.com/docs/api-docs/',
failure: [Function],
progress: [Function] }
Client Ready? undefined

Consecutive model types not expanded in createJSONSample

...In develop-2.0 branch...

If you have a model:

{
  "DistanceSpan": {
    "id": "DistanceSpan",
    "type": "object",
    "required": [ "start", "end" ],
    "properties": {
      "start": { "type": "Point" },
      "end": { "type": "Point" }
    }
  },
  "Point": {
    "id": "Point",
    "type": "object",
    "required": [ "latitude", "longitude" ],
    "properties": {
      "latitude": { "type": "double" },
      "longitude": { "type": "double" }
    }
  }
}

Then when you expand it, it will look like:

{
  "start": {
    "latitude": "double",
    "longitude": "double"
  },
  "end": "Point"
}

...rather than:

{
  "start": {
    "latitude": "double",
    "longitude": "double"
  },
  "end": {
    "latitude": "double",
    "longitude": "double"
  }
}

Full Resource Name

I'm setting up swagger right now and hit a snag. The following line removes the path of the resource:

https://github.com/wordnik/swagger.js/blob/master/src/swagger.coffee#L124

We make full use of the url in our restful api so this will not work for us. For example we end up with this:

/mailings
/mailings

When we need to display this:

/content/mailings
/delivery/campaign/mailings

I wanted to see if you are interested in a pull request enabling this and if so how would you prefer doing it? For now we've manually edited that line to be this.name = this.path.replace('.{format}', ''); but it would be nice if we could use swagger straight up without the tweak.

Thanks,

m

Example server code does not work

I have a test server setup on localhost:8000 and I have tried to use the example code in the readme but i get the following error,

Can't read swagger JSON from http://localhost:8000/api-docs/

I have tried using curl and I do get back valid JSON from that endpoint....

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.