Skip to content

OpenAPI to Pact #403

Description

@krozhdestvenski

Source format: OpentAPI(https://swagger.io/specification/)
Destination format: Pact(https://github.com/pact-foundation/pact-specification/tree/version-3)

Example
Source OpenAPI file:

openapi: 3.0.0
info:
  title: Product Service API
  version: 1.0.0
paths:
  /products:
    get:
      summary: Get all products
      responses:
        '200':
          description: A list of products
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Product'
  /products/{id}:
    get:
      summary: Get product by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: A product object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
components:
  schemas:
    Product:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
      required:
        - id
        - name 

Destination Pact-file:

{
  "consumer": {
    "name": "ApiClient"
  },
  "interactions": [
    {
      "description": "Get product by ID",
      "request": {
        "method": "GET",
        "path": "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/products/10"
      },
      "response": {
        "body": {
          "id": "10",
          "name": "Test"
        },
        "matchingRules": {
          "$.body": {
            "match": "type"
          }
        },
        "status": 200
      }
    },
    {
      "description": "Get all products",
      "request": {
        "method": "GET",
        "path": "/products"
      },
      "response": {
        "body": [
          {
            "id": "09",
            "name": "Test"
          }
        ],
        "matchingRules": {
          "$.body": {
            "match": "type",
            "min": 1
          }
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-js": {
      "version": "12.1.0"
    },
    "pactRust": {
      "ffi": "0.4.19",
      "models": "1.1.19"
    },
    "pactSpecification": {
      "version": "2.0.0"
    }
  },
  "provider": {
    "name": "Product Service API"
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions