eykrehbein / strest

⚡️ CI-ready tests for REST APIs configured in YAML
MIT License
1.74k stars 59 forks source link

Array objects matching template #109

Closed Paic closed 5 years ago

Paic commented 5 years ago

Is there any way to check if objects of an array match a "template" (see my comment in #12) ? The current implementation of JsonPath does not seems to be able to fulfill this use case.

eykrehbein commented 5 years ago

@jgroom33 is this possible with jsonpath? I'm not really into the jsonpath feature

jgroom33 commented 5 years ago

I don't think so. Would validating against a json schema work

Paic commented 5 years ago

What do you mean by json schema ? Without using JsonPath ?

jgroom33 commented 5 years ago

110

Paic commented 5 years ago

It seems it would work for validating array objects, but I think it's a common use case and using an external file to describe those tests would be inconvenient.

jgroom33 commented 5 years ago

In release 2.0, there are some proposed changes to validation. Adding a new validation type of jsonschema would work as follows (just convert the jsonschema to yaml and specify it in the strest.yml):

validate:
  jsonpath: path.to.array
  jsonschema:
    type: array
    items:
      type: object
      properties:
        loc:
          type: string
        toll:
          type:
          - string
          - 'null'
        message:
          type:
          - string
          - 'null'
      required:
      - loc
jgroom33 commented 5 years ago

it should even be possible to declare the schemas in the global var section:

variables:
  mySchema:
    type: array
    items:
      type: object
      properties:
        loc:
          type: string
        required:
        - loc
requests:
  foo:
    ...
    validate:
      jsonpath: path.to.array
      jsonschema: <$ variables.mySchema $>
Paic commented 5 years ago

Looks awesome! It would cover a lot of use case 😃