Giter Site home page Giter Site logo

Comments (11)

fehguy avatar fehguy commented on April 30, 2024

I believe you can add routes directly to the express object:

https://github.com/wordnik/swagger-node-express/blob/master/Apps/petstore/main.js#L25

Wouldn't that do it? Swagger won't even know about the routes.

from swagger-node.

joseairosa avatar joseairosa commented on April 30, 2024

Possibly. I need to read more about express, still fairly new.

Any chance you could point me into the right direction?

Lets use this example. I've got the following API endpoint, https://api.com/resource/blergh and I want to document it so that when the user clicks on "Try me" it goes directly to the API and not swagger.

Thanks!

from swagger-node.

fehguy avatar fehguy commented on April 30, 2024

OK, I misread your request then--what you really want is to generate documentation manually, and still have the node server process it?

If that's the case, you can easily just write the JSON by hand, and have express display the json as static docs. Look here for an example:

https://github.com/wordnik/swagger-core/tree/master/samples/no-server

from swagger-node.

joseairosa avatar joseairosa commented on April 30, 2024

Yes that's correct.

I'd have something like https://docs.api.com/ which is where swagger would be and, instead of querying localhost, it would query directly the api that is on https://api.com/

From what I understand I'd have to change api-docs.json to something like:

{
  "apiVersion":"0.2",
  "swaggerVersion":"1.1",
  "basePath":"https://api.com",
  "apis":[
    {
      "path":"/resource/blergh",
      "description":"Operations about store"
    }
  ]
}

from swagger-node.

joseairosa avatar joseairosa commented on April 30, 2024

Actually, no, I think I understand now. I'd have to keep this file as:

{
  "apiVersion":"0.2",
  "swaggerVersion":"1.1",
  "basePath":"https://docs.api.com",
  "apis":[
    {
      "path":"/api-docs/resource",
      "description":"Operations about resource"
    }
  ]
}

And then create a file in /api-docs named resource.

Inside this file I'd have:

{
  "apiVersion":"0.2",
  "swaggerVersion":"1.1",
  "basePath":"https://api.com",
  "resourcePath":"/resource",
  "apis":[
    {
      "path":"/blergh",
      "description":"Operations about pets"
    }
  ]
}

Correct?

from swagger-node.

joseairosa avatar joseairosa commented on April 30, 2024

So I've got it more or less working.

I did the changes above and still using node.js to have as my standalone server.

The problem is that all my requests to the real API are coming out as OPTIONS instead of GET.

I've clearly set them as GET in my json description file. Any clues?

from swagger-node.

fehguy avatar fehguy commented on April 30, 2024

You do need to support OPTIONS requests to the resource files, which are the resource listing (i.e. http://petstore.swagger.wordnik.com/api/api-docs.json) and the api declarations (such as http://petstore.swagger.wordnik.com/api/api-docs.json/pet)

If you're manually generating the files, take a look at those files as examples (in fact, just clone them for your test) and the wiki which defines their structure:

https://github.com/wordnik/swagger-core/wiki/Resource-Listing

from swagger-node.

joseairosa avatar joseairosa commented on April 30, 2024

Hi @fehguy,

Lets assume that the UI is running on http://localhost and the real api is running on https://api.com

Both requests for the resource listing work with no problems. The one that doesn't work the actual request to the API.

So, in short, it shows my documents GET endpoint on the UI (http://localhost). I click on it to show the description and the "Try me" button. When I press it all data is sent to https://api.com but instead of being sent as GET it's being sent as OPTIONS.

Check the image attached.

Thanks

screen shot 2013-05-13 at 11 00 26

from swagger-node.

joseairosa avatar joseairosa commented on April 30, 2024

Any update on this?

from swagger-node.

fehguy avatar fehguy commented on April 30, 2024

Hi, sorry for the delay, with the 1.2 spec getting released I probably won't be able to get to this for a bit.

from swagger-node.

fehguy avatar fehguy commented on April 30, 2024

the 1.2 spec version is pushed, and you should give that a shot.

from swagger-node.

Related Issues (20)

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.