-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Strings "yes" and "no" serialized as boolean #3372
Comments
That's inaccurate. In YAML 1.1 has an extension that allows interpreting |
Well, you are right. But I would assume that swagger library would parse what it serializes into the same semantic. But that's apparently not possible. Try this snippet import io.swagger.v3.core.util.Yaml
import io.swagger.v3.oas.models.Components
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.media.StringSchema
import io.swagger.v3.parser.OpenAPIV3Parser
fun main(args: Array<String>) {
val yamlWriter = Yaml.pretty()
val schema = StringSchema().addEnumItem("yes").addEnumItem("no")
val openApi = OpenAPI().apply {
components = Components().addSchemas("testIt", schema)
}
val stringOpenApi = yamlWriter.writeValueAsString(openApi)
println(stringOpenApi)
val parseResult = OpenAPIV3Parser().readContents(stringOpenApi)
println(parseResult.openAPI.components.schemas.get("testIt")?.enum)
} Producing
This doesn't feel correct to me - I created string schema with enums values "yes" and "no" but after serialization roudntrip using the same library my "yes" and "no" turned to "true" and "false". So please either add clarifying quotes, or make the parser compatible with the serializer (this is IMHO impossible). The option would be to use YAML 1.2 - which would be nice, but it seems the underlying jackson doesn't support it yet. |
The current workaround is val yamlWriter = Yaml.pretty().apply {
(factory as YAMLFactory).configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, false)
} This uses all the configuration from swagger library but the shaved quoting. |
related swagger-api/swagger-parser#1205 |
The strings
"yes"
and"no"
are serialized wrongly to YAML, when for instance used in enums. Seems the underlying jackson library works well until configured to serve OpenAPI purposes.Produces following output:
The first one is unfortunately YAML's boolean...
The text was updated successfully, but these errors were encountered: