Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwaggerParser#read's Behavior with URI #448

Closed
kevinmeredith opened this issue Aug 26, 2015 · 2 comments
Closed

SwaggerParser#read's Behavior with URI #448

kevinmeredith opened this issue Aug 26, 2015 · 2 comments

Comments

@kevinmeredith
Copy link

With "io.swagger" % "swagger-parser" % "1.0.10":

And the following code:

import io.swagger.parser.SwaggerParser
import io.swagger.models.Swagger
import java.net.URI

import scala.util.control.NonFatal

object SwaggerService {

  def getSwaggerObj(swaggerDoc: URI): Either[Throwable, Option[Swagger]] = {
    try {
      Right( Option( new SwaggerParser().read(swaggerDoc.toString) ) )
    }
    catch {
      case NonFatal(e) => Left(e)
    }
  }

I then ran it from Scala's REPL:

scala> new File("/Users/kevin/Workspace/Work/json_sandbox/petstore.json")
res7: java.io.File = /Users/kevin/Workspace/Work/json_sandbox/petstore.json

scala> res7.toURI
res8: java.net.URI = file:/Users/kevin/Workspace/Work/json_sandbox/petstore.json

scala> SwaggerService.getSwaggerObj(res8)
reading from file:/Users/kevin/Workspace/Work/json_sandbox/petstore.json
File 'file:/Users/kevin/Workspace/Work/json_sandbox/petstore.json' does not exist
reading from file:/Users/kevin/Workspace/Work/json_sandbox/petstore.json
File 'file:/Users/kevin/Workspace/Work/json_sandbox/petstore.json' does not exist
res9: Either[Throwable,Option[io.swagger.models.Swagger]] = Right(None)

However, if I cut out the file: from the URI's constructor's String argument, and then make a new URI, it works:

scala> new URI("/Users/kevin/Workspace/Work/json_sandbox/petstore.json")
res12: java.net.URI = /Users/kevin/Workspace/Work/json_sandbox/petstore.json

scala> SwaggerService.getSwaggerObj(res12)
reading from /Users/kevin/Workspace/Work/json_sandbox/petstore.json
res13: Either[Throwable,Option[io.swagger.models.Swagger]] = Right(Some(io.swagger.models.Swagger@657e4ba9))

Since a new URI can be created via java.io.File#toURI, I would've expected my File#toURI-created URI to have worked here, but it didn't.

@webron
Copy link
Member

webron commented Aug 27, 2015

This issue was moved to swagger-api/swagger-parser#81

@webron webron closed this as completed Aug 27, 2015
@kevinmeredith
Copy link
Author

Thank you, @webron!

My mistake for posting in the wrong repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants