raml-java-parser icon indicating copy to clipboard operation
raml-java-parser copied to clipboard

Discriminator sub-datatype validates to anything

Open jam01 opened this issue 5 years ago • 3 comments

Consider the following RAML

types:
  event:
    type: object
    discriminator: eventType
    properties:
      eventType: string

  fooEvent:
    type: event
    discriminatorValue: foo
    properties:
      bar: string

/resource:
   post:
     body:
       application/json:
         type: fooEvent

Expected behavior resource/ should accept a value such as: {"eventType":"foo", "bar":"val"}

and reject a value such as: {"not":"acceptable"}

Current behavior Both are considered valid.

Seems to me the issue is that unless the discriminator field is present there's no validation at all and everything is valid.

There should be a validation that the discriminator field exists and then check for valid values of that field and validate accordingly, otherwise it should fail.

I added test cases in this PR https://github.com/raml-org/raml-java-parser/pull/602

Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-39

jam01 avatar Apr 14 '19 00:04 jam01

Hey @jpbelang , sorry to pull you in but it seems you're the most active maintainer. If you could point me in the right direction I could probably throw in a PR to fix this defect. I appreciate your input.

Also, is the library really deprecated as the repo description states?

jam01 avatar Jun 11 '19 20:06 jam01

Hi @jam01 , I've just bumped into this issue as well. I think @jpbelang has merged a PR not long ago: https://github.com/raml-org/raml-java-parser/pull/651/files, I think it will fix this issue, hope it gets released soon.

haolinj avatar Sep 16 '19 12:09 haolinj

@haolinj rebased my branch with the latest code that includes #650 and #651 but the tests still fail. I'm not sure they were related.

jam01 avatar Oct 02 '19 21:10 jam01