karenetheridge / OpenAPI-Modern

Validate HTTP requests and responses against an OpenAPI v3.1 document
https://metacpan.org/release/OpenAPI-Modern/
Other
5 stars 3 forks source link

convert request, response tests to a standard format for wider publication #60

Open karenetheridge opened 1 year ago

karenetheridge commented 1 year ago

This is modelled after the pattern used in JSON-Schema-Test-Suite.

each test group consists of:

And of course we should provide a JSON Schema describing this test structure.

Convert all existing request and response tests to this format. If all details from the test are preserved, we can delete the originals.

karenetheridge commented 1 year ago

in the harness that makes use of this test format, run the tests twice, as we do now - once parsing into HTTP::Request/Response objects, and the other parsing into Mojo::Message::Request/Response objects. Perform any doctoring of the HTTP::Request/Response objects as needed (set missing protocol?)

karenetheridge commented 1 year ago

consider outputting the tests in yaml rather than json, for readability - I think yaml supports a "heredoc" operator?

use this as a guide: https://yaml-multiline.info/ I think I want to use request: |-8 to include the serialized request with indentation (for readability) that will be removed.

$; perl -MYAML=Load -MData::Dumper -wle'print Dumper(Load("---\nhello: foo\nbloop: |-\n    mary had a little lamb\n    its fleece as white as snow\n\n"))'
$VAR1 = {
          'bloop' => 'mary had a little lamb
its fleece as white as snow',
          'hello' => 'foo'
        };

The $UseBlock option in YAML can do this:

perl -MYAML=Dump -MData::Dumper -wle'$YAML::UseBlock = 1; print Dump({hello=>"foo",bar=>{bloop=>"foo\nbar\n\nblah"}})'
---
bar:
  bloop: |-
    foo
    bar

    blah
hello: foo
karenetheridge commented 1 year ago

We can autogenerate this by creating a harness which does some method modifications and then calls do ./t/validate_request.t:

and then when execution is complete, dump the yaml version of the tests.

karenetheridge commented 1 year ago

and then we'll need to write a harness which knows how to read in the test cases and executes them, just as we do via Test::JSON::Schema::Acceptance. If this data format catches on we can publish the harness, and test cases, in Test::OpenAPI::Acceptance.

karenetheridge commented 2 months ago

kinda duped by #77