0

We use Camel for our application, so I initially thought it was an issue with the Camel plugins, but here's what I've tested with Java and OAS versions:

  • camel-restdsl-swagger-plugin (Java 8, Java 11, OAS v2.0)
  • camel-restdsl-openapi-plugin (Java 11, OAS v3.0)
  • swagger-codegen-maven-plugin (Java 11, OAS v3.0)
  • Swagger Editor Demo (OAS v2.0, OAS v3.0, generate Java client)
  • swagger-codegen-maven-plugin examples (Java 11, OAS v2.0)

We are building against Java 11 now, but in our previous version we used Java 8. We've tested with OAS v2.0, and I've now upgraded to OAS v3.0.

None of these attempts have worked, even though it appears they should have, based on this Github issue, implying that validation works for Java: https://github.com/swagger-api/swagger-codegen/issues/2663.

In the case of the 2 lattermost tests, I added a maximum and pattern to various attributes, built the project or generated the Java client, and saw this in one of the models (Order.java for the snip): https://pasteboard.co/JlVTLtL.png.

This same issue is mirror in our code, and our specification is valid based on the Swagger Editor. I just dropped our spec into the editor.

How do I get validation to show up? I can't paste in the entire spec, but here's an edited bit from one of our models. None of those validations are enforced in code. The max and min show up in comments, and the pattern is never mentioned.

AnExample:
      description: >
        The cow goes moo
      type: object
      properties:
        id:
          description: >
            Uniquely identify the cow
          type: string
          pattern: "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[0-9a-dA-D][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000"
        height:
          description: >
            How tall the cow is, counted in beagles
          type: number
          format: int64
          minimum: 1
          maximum: 60
Ungeheuer
  • 1,393
  • 3
  • 17
  • 32
  • Just remember Camel is a EIP toolkit if you want a full rest endpoint tool then maybe look at some other options. However here is what I have found. Top down engineering of Swagger in Camel does not do any validation. It simply produces an object model. You could use the validate EIP but you will need to manually code it. Thus in Camel it takes more work than say plain old springboot and frankly that is probably for the best as Camel is not a API tool but an integration tool. – Namphibian Aug 13 '20 at 01:22
  • See this for a bit more details: https://stackoverflow.com/questions/58254392/camel-json-validation-throws-nojsonbodyvalidationexception/58261512#comment102944764_58261512 – Namphibian Aug 13 '20 at 01:27
  • @Namphibian I was under the impression that the DTOs that swagger-codegen-maven-plugin generates are supposed to use annotations to mark maxes, mins, etc. The code that I get whether I use Camel's Maven plugins or Swagger's plugin doesn't have any of that annotations. Interesting to see the issues with the JSON schema validator component, I may just use the json-schema-validator on its own with a Processor. – Ungeheuer Aug 14 '20 at 02:29
  • Good luck with that let us know if you find some new ways if validation. Most of my REST interfaces are done by Springboot so I get full validation and then I use a producer template to send the message to a camel endpoint to consume – Namphibian Aug 14 '20 at 05:13

0 Answers0