krakenjs / swaggerize-routes

Swagger document driven route builder.
Other
58 stars 57 forks source link

Resolve external $refs. #40

Open tlivings opened 9 years ago

paul42 commented 8 years ago

if I'm having this issue, is the currently (only?) workaround to just declare parameters in routes?

tlivings commented 8 years ago

You can use the extrefs module (https://www.npmjs.com/package/extrefs) to resolve everything beforehand and pass to the schemas option, but I will be integrating directly as well I think.

paul42 commented 8 years ago

sorry, I misunderstood the root cause I'm having, and my issue is unrelated to this - it may not be in this module either

tlivings commented 8 years ago

What are you seeing?

paul42 commented 8 years ago

I'm still trying to iron out where the issue is occurring, but basically I see validation stop if I change from an in-route definition to a reference. I'm using swaggerize-restify & swaggerize-routes, as well as some more custom code

1: the route before replacement https://gist.github.com/paul42/472fa78f2890e6766956

2: make a GET to localhost:5002/v1/check/wrong?startDate='2015-10-01'

3: result from that call: https://gist.github.com/paul42/ddcbe62b51976e6d2243

4: the route after replacement https://gist.github.com/paul42/681770ce6cb7c3c6bbb7

5: perform call from #2,

6: result showing validator properly responding with error: https://gist.github.com/paul42/c7a8ad73922e8f180892

again, I'm still trying to find out what portion of code is causing this strange behavior, I don't know if it's any of the krakenjs/* stuff or in house code, but if you have any hints on what to investigate, I'd be extremely appreciative - thanks for taking the time to respond already

jlee1201 commented 8 years ago

I have the same symptoms as @paul42 . using swaggerize-routes implicitly via swaggerize-hapi -- when using $ref, validation stops.

jlee1201 commented 8 years ago

I figured out what was wrong. In my case, I had type:"object" along with the $ref and that was causing the enjoi module to attempt resolving the schema as an object. I removed the "type" field, and it started validating again. Hope this helps someone else

wannabesrevenge commented 8 years ago

@tlivings I'm looking to make this happen myself and submit a pull request. I plan on using swagger-parser as the main library, but it uses async callbacks. This would require an api change since right now its all synchronous code.

Do you have any aversions to an API change? If you do, do you have any thoughts on adding this functionality?

tlivings commented 8 years ago

Yeah, I've considered adding this but the API change, at least for swaggerize-express gets pretty ugly. Due to the way express bootstraps, having an async swaggerize-routes would definitely change the dynamic and require something similar to what we do in kraken which keeps out requests until all bootstrapping is done.

I'm not totally opposed to it. It just presents some additional challenges for integration.

jsdevel commented 8 years ago

Not trying to troll, but with express-openapi we actually flipped it. So instead of the library fetching the external schemas, we require the application to fetch them before initializing the app. See https://github.com/kogosoftwarellc/express-openapi#argsexternalschemas.

tlivings commented 8 years ago

That's generally what I've recommended people to do before calling swaggerize.

wannabesrevenge commented 8 years ago

it seems like this is out of scope for the project given the design. I ended up doing the same as yall. this bug is kill