-
Notifications
You must be signed in to change notification settings - Fork 427
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
#1808: add external Refs #1831
#1808: add external Refs #1831
Conversation
content: | ||
application/json: | ||
schema: | ||
$ref: https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml#/Problem |
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.
value of $ref
should be quoted like 'xxx'
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.
I agree. But this seems to be done somewhere in the YAML serializer. I have no idea how this works. Some help here would be appreciated. I'll have a look but I'm not confident that I can fix this.
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.
This depends on the String Style of the TapirOpenAPICirceYaml.toYaml
method. In the Printer
class in line 69 is this check:
private def stringScalarStyle(value: String): DumperOptions.ScalarStyle =
if (isBad(value)) DumperOptions.ScalarStyle.DOUBLE_QUOTED
else if (stringStyle == StringStyle.Plain && hasNewline(value)) DumperOptions.ScalarStyle.LITERAL
else StringStyle.toScalarStyle(stringStyle)
So I'm not sure how to fix this or if it's working as intended.
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.
Maybe the Printer.isBad
method needs to be adjusted? I'm not sure...
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.
It seems the Printer needs to be modified somewhat: https://yaml.org/spec/1.2.2/#733-plain-style
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.
I think it's handled in such way in the underlying snakeyaml
lib since it's used by circe Printer
. I see that Printer
is not changing the string style for url string. If you are convinced that this is incorrect handling as for yaml definition I think you can try to report issue in snakeyaml
, I am not a yaml expert :D
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.
I'm also not an expert there. Do you think this PR can be merged then?
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.
Yes, thanks!
val actualYaml = | ||
OpenAPIDocsInterpreter().toOpenAPI(List(external_reference), Info("Fruits", "1.0")).toYaml | ||
|
||
println(actualYaml) |
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.
We can remove that ;)
|
||
case class Problem() | ||
|
||
object Problem { |
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.
I think that this class won't be reused in other tests maybe we can put it into companion object in VerifyYamlTest
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.
moved the class
@@ -5,6 +5,6 @@ import sttp.tapir.{Schema => TSchema} | |||
|
|||
private[schema] class NameToSchemaReference(nameToKey: Map[TSchema.SName, ObjectKey]) { | |||
def map(name: TSchema.SName): Reference = { | |||
Reference.to("#/components/schemas/", nameToKey(name)) | |||
nameToKey.get(name).fold(Reference.to(name.fullName, ""))(key => Reference.to("#/components/schemas/", key)) |
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.
It will be nice to have a comment here describing what's the case when we don't have a entry in the map for the given name, something like:
def map(name: TSchema.SName): Reference =
nameToKey.get(name) match {
// we have a reference to internal model
case Some(key) => Reference.to("#/components/schemas/", key)
// we have a reference to external model
case None => Reference.to(name.fullName, "")
}
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.
I added a comment.
No description provided.