-
Notifications
You must be signed in to change notification settings - Fork 133
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
Update swagger-parser to fix definition parse bug #41
Update swagger-parser to fix definition parse bug #41
Conversation
Interesting new NPE introduced from this change. Investigating. |
Looks like we aren't handling # snip
property:
default: "what" According to the Swagger spec (2.0) definitions (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#definitionsObject) can have What is the most reasonable thing to do here? I can think of a few things:
|
For now, I'm failing property definitions that are untyped. |
@trane Thanks for the contribution and investigation! Everything looks good, save for the merge conflict -- would you please resolve this at your convenience? |
@trane One last time, my apologies |
@blast-hardcheese, I'm concerned about some of the behavior I'm seeing now with this code. Namely, I'm getting unhelpful errors now like:
Where before I would get
|
@trane So, addressing #41 (comment): As for HTTP, a " |
@blast-hardcheese I'm not sure I follow what you mean by "static parameters". Are you saying that we generate a class constructor which has the case class MyParam(foo: String, bar: None.type) |
I did a bit more digging into what swagger-codegen did with the addition of For all the Scala code generators, they either returned Perhaps the right answer here is to resolve as a |
Exposing it as the underlying json library type makes sense. This would also be a stopgap for #43, although not a great one. |
While parsing swagger with additionalProperties, not all definitions are resolved in swagger-parser < 1.0.34. (swagger-api/swagger-parser#602) This brings us to the most recent version of swagger-parser on the 1.x line. Fixes: guardrail-dev#40
According to the Swagger spec (2.0) definitions (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#definitionsObject) can have null type via the JSON schema spec: https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5 We don't currently have a mechanism to handle this case, so I am returning an error for now.
100655e
to
9dd3097
Compare
Alright, I have resolved the issue with the introduction of |
@@ -295,6 +295,8 @@ object SwaggerUtil { | |||
Target.pure(Resolved(t"Double", None, Default(d).extract[Double].map(Lit.Double(_)))) | |||
case d: DecimalProperty => | |||
Target.pure(Resolved(t"BigDecimal", None, None)) | |||
case u: UntypedProperty => | |||
Target.pure(Resolved(t"io.circe.Json", None, None)) // TODO: o.getProperties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does getProperties
exist on UntypedProperty
? UntypedProperty.java suggests it doesn't (which would also make sense, as there's no way for it to know)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, something to note here is that SwaggerUtil needs to eventually be collapsed down into the different ProtocolGenerators, otherwise io.circe.Json
won't be valid for other JSON libraries (json4s
, support for Java, etc). Not a concern right now, but this is something that'll need to happen for #36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I figured that the io.circe.Json
was good for now given that the protocol generator stuff isn't parameterized yet. I hope it's as simple as a find/replace of io.circe.Json
to ${correctProtocolGenerator}
when that happens.
swagger-codegen added UntypedProperty after version 1.0.32 which we didn't handle and this caused issues with code generation no longer properly reporting errors, just having a generic: Error: Unable to resolve type for null (null null null null) I took a look at the code that was added and what other implementations did: https://github.com/swagger-api/swagger-core#2507 For all the Scala code generators, they either returned Any (Akka, Scala, etc) or Object (finch). Though, how could we create an encoder/decoder for such an arbitrary type in any meaningful way? It appears in the case of additionalProperties and any other json schema proprty, all that is required is valid json. Since there is no actual type that we can infer from an untyped it makes sense to return the most specific type we can: Json. In this case, we are returning io.circe.Json
9dd3097
to
d5629ee
Compare
This looks good, thanks! |
While parsing swagger with additionalProperties, not all definitions are
resolved in swagger-parser < 1.0.34.
(swagger-api/swagger-parser#602)
This brings us to the most recent version of swagger-parser on the 1.x
line.
Fixes: #40