PHPackages                             codeasashu/openapi-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. codeasashu/openapi-validator

ActiveLibrary[API Development](/categories/api)

codeasashu/openapi-validator
============================

Validates data against provide openapi spec

1.0.0(6y ago)020proprietaryPHPPHP &gt;=7.0CI failing

Since Dec 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/codeasashu/openapi-validator)[ Packagist](https://packagist.org/packages/codeasashu/openapi-validator)[ RSS](/packages/codeasashu-openapi-validator/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (4)Versions (26)Used By (0)

What is this?
-------------

[](#what-is-this)

Validate data against [openapi v3 spec](https://github.com/OAI/OpenAPI-Specification)

Features
--------

[](#features)

1. Checks for required fields
2. Checks types
3. Supports nested structures
4. Supports discriminator
5. Supports allOf, anyOf
6. Supports nullable
7. Resolves local references (components)
8. Supports additionalProperties

Unlike Dredd it does not require examples and does not check that data matches examples

Installation
------------

[](#installation)

```
composer req --dev mmal/openapi-validator
```

Requirements
------------

[](#requirements)

Your openapi spec has to be valid, You can use [Speccy](https://github.com/wework/speccy) to check Your schema first

This library assumes that each operation has operationId

Examples
--------

[](#examples)

Given we have api described by following OpenAPI specification

```
openapi: 3.0.2
info:
  title: Cards
  description: Cards and decks api
  contact:
    name: Mieszko Malawski
  license:
    name: GNU AGPLv3
    url: https://www.gnu.org/licenses/agpl.txt
  version: 1.0.0
tags:
  -
    name: Cards
paths:
  /cards:
    summary: Path used to manage the list of cards.
    description: The REST endpoint/path used to list and create zero or more card entities.  This path contains a GET and POST operation to perform the list and create tasks, respectively.
    get:
      tags:
        - Cards
      summary: List All cards
      description: Gets a list of all card entities.
      operationId: getcards
      responses:
        200:
          description: Successful response - returns an array of card entities.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/card'
components:
  schemas:
    card:
      title: Root Type for card
      description: The root of the card type's schema.
      required:
      - id
      - name
      - power
      type: object
      properties:
        id:
          description: "unique id"
          type: string
          format: int64
          readOnly: true
        name:
          type: string
        power:
          description: "how powerfull card is on the board"
          format: int32
          type: integer
      example:
        id: "23423423"
        name: "Geralt"
        power: 10

```

We have server implementation (this is of course example - normally You would fetch data from some storage)

```
