apicollective / apibuilder

Simple, Comprehensive Tooling for Modern APIs
https://www.apibuilder.io/
MIT License
563 stars 83 forks source link

Swagger parser is trying to match path to model #356

Open dspeele opened 9 years ago

dspeele commented 9 years ago

When attempting to parse swagger document, parser.scala is using the path to try to match against existing models. This is resulting in the following exception:

java.lang.RuntimeException: Could not find model at url[/inventory/product/{product_code}]
    at scala.sys.package$.error(package.scala:27)
    at me.apidoc.swagger.Parser$$anonfun$resources$1.apply(Parser.scala:129)
    at me.apidoc.swagger.Parser$$anonfun$resources$1.apply(Parser.scala:125)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.Iterator$class.foreach(Iterator.scala:750)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1202)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.AbstractTraversable.map(Traversable.scala:104)
    at me.apidoc.swagger.Parser.resources(Parser.scala:125)
    at me.apidoc.swagger.Parser.parse(Parser.scala:51)
    at me.apidoc.swagger.Parser.parseString(Parser.scala:19)
    at me.apidoc.swagger.SwaggerServiceValidator$$anonfun$1.apply(SwaggerServiceValidator.scala:13)
    at me.apidoc.swagger.SwaggerServiceValidator$$anonfun$1.apply(SwaggerServiceValidator.scala:13)

We can use the schema object to get the reference to the model instead.

dspeele commented 9 years ago

This becomes an issue when the path becomes more complex, for example: /store/pets/{product_code}

mbryzek commented 9 years ago

Thanks!

What's happening here is that apidoc assumes REST - and so need to find a way to turn a resource into a URL. I think it's possible by inspecting the response types to figure out what the resource is... and then can map to apidoc. This is a bit tricky but starting to think through best path

mbryzek commented 9 years ago

Ah - saw your other pull request - thanks!

chrishough commented 1 year ago

Do we know when the fix to support $refs is going in?