Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Start testing server responses against OpenAPI doc via Chai plugin #203

Merged
merged 1 commit into from
Aug 16, 2019

Conversation

rwalle61
Copy link
Contributor

@rwalle61 rwalle61 commented Aug 16, 2019

Signed-off-by: Richard Waller [email protected]

This uses the Chai OpenAPI response validator plugin (that @JonnySpruce and I made) to automatically test that PFE responds as our OpenAPI doc claims it does. This makes it easier to keep the two in sync, helping PFE's developers and users.

Notes:

  • The new package has been legally cleared by Nik.
  • When I connected our OpenAPI doc to this plugin, it immediately revealed 2 minor mistakes in our doc
  • This plugin can catch a lot of mistakes but not all of them:
    • If we specify that a response body can have certain properties, but forget to specify which are required, then this plugin assumes that we are following OpenAPI conventions to specify that the properties are optional
    • If we forget to specify what type (e.g. string, integer) a property should have, then this plugin assumes that we are following OpenAPI conventions to specify a multi-typed property (see Is type a required field for Schema Objects? OAI/OpenAPI-Specification#1657).
  • we cannot use this to verify responses with no content (e.g. 204 No Content responses).
    • This is because in these cases chai-http automatically inserts a body of {}. So if our doc specifies that the response should contain No Content, this plugin will (accurately) flag the fact that {} is not null.
    • Luckily, we don't need to use this plugin in those scenarios anyway, since a simple res.should.have.status(X) will suffice.

Copy link

@tetchel tetchel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it

@tetchel tetchel merged commit 530eac9 into eclipse-archived:master Aug 16, 2019
@rwalle61 rwalle61 deleted the add-openapi-testing branch August 16, 2019 16:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants