Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI to Pact #403

Open
krozhdestvenski opened this issue Jun 8, 2024 · 0 comments
Open

OpenAPI to Pact #403

krozhdestvenski opened this issue Jun 8, 2024 · 0 comments

Comments

@krozhdestvenski
Copy link

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": "/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"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant