RepreZen / KaiZen-OpenApi-Parser

High-performance Parser, Validator, and Java Object Model for OpenAPI 3.x
130 stars 31 forks source link

Support parsing spec from String only without needing URL #172

Closed jason-cohen closed 6 years ago

jason-cohen commented 6 years ago

I am trying to load a spec from the classpath. I have the resource loaded into a String already, but the parser requires a URL be passed as parameter. I don't have a need for a URL, but am forced to put a "dummy" object because null results in a NullPointerException. The parser should be made to function without the need of an URL.

andylowry commented 6 years ago

@jason-cohen Thanks. The problem, of course, is that without a "resolution base" URL handed to the parser, there's no way to resolve any relative URLs encountered in reference nodes during the parse. That said, there's no reason the parser could treat such references as it does other unresolvable references (e.g. malformed URLs, failed retrieval, etc.). And if no such references were present, all would be fine. So I'll put that on the agenda.

Meanwhile, if you're loading your model from a resource, that you read into a string, I assume you're using the getResourceAsStream() method of Class or ClassPath. If so, you might instead use getResource(), which returns a URL. You could pass that URL to the parser, and it would then read the model from the resource and there'd be no "dummy" URL involved. And if you ever wanted to split your models across model files, relative references would work just fine within the jar file.

jason-cohen commented 6 years ago

@andylowry Good point. Yes, we were using getResourceAsStream() of the class loader. Instead, we'll use getResource(). I just checked and it works just fine, even when within the jar file.

I didn't fully understand the purpose of the "resolution base", thanks for clearing that up.

Closing as a non-issue.

Thanks!