Skip to content

base64 type properties fail validation for lack of example #132

Open

Description

@shoffmeister

Whenever an object has a property of base64 (i.e. type: string, format: byte) validation will fail the error message

*ERROR* in Model '...', property 'content', field 'example' -> This field should be present and not empty

although the field example is present. This is really tied to the property being of type base64; remove the "format: byte" and the specification document will pass validation.

To reproduce, download the attached Zip file y.zip which contains two files minimally reproducing:

  • pom.xml
  • broken-validation-base64-response.yaml

Run mvn verify

//exp: passes validation
//act: ERROR in Model

Activity

  1. JFCote commented on Nov 2, 2020

    @JFCote
    Member

    @shoffmeister Thanks for the bug report! I'm not sure when I'll be able to look at this, I'm very busy for the next 2 weeks but if you send me a PR, I will try to review it quickly and make sure we do a release. Otherwise, it might take a couple of weeks.

    Thanks!

  2. self-assigned this
    on Jan 22, 2021
  3. added this to the v1.6.0 milestone on Jan 22, 2021
  4. modified the milestones: v1.6.0, v1.7.0 on Mar 17, 2021
  5. removed this from the v1.7.0 milestone on Jun 29, 2021
  6. added a commit that references this issue on Nov 25, 2021
  7. JFCote commented on Nov 26, 2021

    @JFCote
    Member

    @gervaisb So either it's a bug with swagger-parser that we use under the hood or swagger-parser follow specification and a byte field should not have example. I can't find any specific information about the byte field examples here: https://swagger.io/docs/specification/adding-examples/

    If it's a bug: We need to create a bug in their project. https://github.com/swagger-api/swagger-parser

    If it's meant to be like that and follow spec, we need to create a special validation that when the field is "byte", we don't count it as an error when there are no examples.

    I don't have time right now to dig deeper but if you have some time, you could go and create an issue in their project since you already have examples.

  8. gervaisb commented on Nov 30, 2021

    @gervaisb
    Contributor

    It seems to be a bug on the parser that tries to cast the example to the wrong type: swagger-api/swagger-parser#1630 (comment)

  9. tymonx commented on Dec 27, 2021

    @tymonx

    I have the same issue here. As temporary workaround I use format: base64 with additional pattern: '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$'.

  10. JFCote commented on Jan 3, 2022

    @JFCote
    Member

    @gervaisb and @tymonx. As soon as swagger-parser release a new version with this fix, I will update our dependency and create a new release.

    Thanks for the workaround in the meantime! :)

  11. acabarbaye commented on Feb 28, 2022

    @acabarbaye

    same seems to be true with format: binary

  12. gervaisb commented on Mar 29, 2022

    @gervaisb
    Contributor

    Hello there,

    The parser has been patched, it will now automatically get the bytes of a string. However, there are some implications with this fix, see this comment in the issue: swagger-api/swagger-parser#1630 (comment)
    We should be able to fix that issue as soon as they release that fix.

    However, regarding the opinionated issues mentioned in the linked comment, should we not support the new swaggerParserBinaryAsString property too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions