hotmeteor / spectator

OpenAPI testing for PHP
MIT License
285 stars 52 forks source link

Adds support for required, readOnly and writeOnly properties #147

Closed devan1011 closed 1 year ago

devan1011 commented 1 year ago

Removes readOnly properties from request schemas and visa versa removes writeOnly properties from response schemas.

Resolves #112

Tests pass + 2 new ones to test this use case

   PASS  Spectator\Tests\AssertionsTest
  ✓ asserts invalid path
  ✓ exception points to mixin method
  ✓ request assertion does not format laravel validation response errors when errors are not suppressed

   PASS  Spectator\Tests\MiddlewareTest
  ✓ only processes request once

   PASS  Spectator\Tests\RequestFactoryTest
  ✓ sets and gets spec name
  ✓ resets spec name
  ✓ resolves yaml spec
  ✓ resolves yml spec
  ✓ resolves json spec
  ✓ throws exception on invalid source
  ✓ throws exception on missing spec name
  ✓ throws exception on invalid spec name
  ✓ throws exception on invalid spec extension

   PASS  Spectator\Tests\RequestValidatorTest
  ✓ cannot resolve prefixed path
  ✓ resolves prefixed path from config
  ✓ uses global path via inline setting
  ✓ uses global path through config
  ✓ uses global path with route prefix
  ✓ resolve route model binding
  ✓ resolve route model explicit binding
  ✓ cannot resolve route model explicit binding with invalid format
  ✓ resolve route model binding with multiple parameters
  ✓ handle nullables with data set "3.0, missing"
  ✓ handle nullables with data set "3.0, empty"
  ✓ handle nullables with data set "3.0, null"
  ✓ handle nullables with data set "3.0, valid"
  ✓ handle nullables with data set "3.1, missing"
  ✓ handle nullables with data set "3.1, empty"
  ✓ handle nullables with data set "3.1, null"
  ✓ handle nullables with data set "3.1, valid"
  ✓ handles one of with data set "valid request, first type"
  ✓ handles one of with data set "valid request, second type"
  ✓ handles one of with data set "invalid request"
  ✓ handles one of with data set "invalid request, mixed"
  ✓ handles any of with data set "valid, one required"
  ✓ handles any of with data set "valid, other required"
  ✓ handles any of with data set "valid, both required"
  ✓ handles any of with data set "invalid request, missing required"
  ✓ handles all of with data set "valid, Cat"
  ✓ handles all of with data set "valid, Dog"
  ✓ handles all of with data set "valid, Dog 2"
  ✓ handles all of with data set "invalid request, missing required"
  ✓ handles all of with data set "invalid request, invalid attribute"
  ✓ handles query parameters
  ✓ handles query parameters int
  ✓ handles form data
  ✓ handles form data with multiple files
  ✓ nullable object
  ✓ nullable object with data set #1
  ✓ nullable object with data set #2
  ✓ numeric values
  ✓ ignores request validation if not asserted
  ✓ required readonly with data set "valid, Readonly not passed"
  ✓ required readonly with data set "Invalid, Books not passed"
  ✓ required readonly with data set "invalid, Readonly passed"
  ✓ required readonly with data set "invalid, Required not passed"

   PASS  Spectator\Tests\ResponseValidatorTest
  ✓ validates valid json response
  ✓ validates invalid json response
  ✓ validates valid problem json response
  ✓ validates invalid problem json response
  ✓ validates problem json response using components
  ✓ fallback to request uri if operation id not given
  ✓ cannot locate path without path prefix
  ✓ uncaught exceptions are thrown when exception handling is disabled
  ✓ handle nullables with data set "3.0, missing"
  ✓ handle nullables with data set "3.0, empty"
  ✓ handle nullables with data set "3.0, null"
  ✓ handle nullables with data set "3.0, valid"
  ✓ handle nullables with data set "3.0, invalid"
  ✓ handle nullables with data set "3.1, missing"
  ✓ handle nullables with data set "3.1, empty"
  ✓ handle nullables with data set "3.1, null"
  ✓ handle nullables with data set "3.1, valid"
  ✓ handle nullables with data set "3.1, invalid"
  ✓ handles one of with data set "valid response, first type"
  ✓ handles one of with data set "valid response, second type"
  ✓ handles one of with data set "invalid response"
  ✓ handles one of with data set "invalid response, mixed"
  ✓ handles any of with data set "valid, one required"
  ✓ handles any of with data set "valid, other required"
  ✓ handles any of with data set "valid, both required"
  ✓ handles any of with data set "invalid request, missing required"
  ✓ handles all of with data set "valid, Cat"
  ✓ handles all of with data set "valid, Dog"
  ✓ handles all of with data set "valid, Dog 2"
  ✓ handles all of with data set "invalid request, missing required"
  ✓ handles all of with data set "invalid request, invalid attribute"
  ✓ handles invalid spec
  ✓ handles inheritance
  ✓ response example
  ✓ errors contain
  ✓ response succeeds with empty array
  ✓ response fails with invalid array
  ✓ array any of
  ✓ required writeonly with data set "valid, Writeonly not passed"
  ✓ required writeonly with data set "Invalid, Books not passed"
  ✓ required writeonly with data set "invalid, Writeonly passed"
  ✓ required writeonly with data set "invalid, required not passed"

   PASS  Spectator\Tests\ServiceProviderTest
  ✓ middleware is registered