Skip to content

Optional parameter on endpoint level is categorised as breaking change #429

Open
@mencnert

Description

@mencnert

When parameter is added as required: false I would expect it to be non breaking change.

version: github.com/pb33f/libopenapi v0.22.3

code sample:

package main

import (
	"fmt"
	"testing"

	"github.com/pb33f/libopenapi"
)

func TestBreakingChanges(t *testing.T) {

	prev := []byte(`openapi: 3.0.3
paths:
  test:
    get: {}
    parameters:
      - in: query
        name: test
        required: true 
        schema:
          type: string
`)

	curr := []byte(`openapi: 3.0.3
paths:
  test:
    get: {}
    parameters:
      - in: query
        name: test
        required: true
        schema:
          type: string
      - in: query
        name: test2
        required: false
        schema:
          type: string
`)

	prevDoc, err := libopenapi.NewDocument(prev)

	if err != nil {
		panic(fmt.Sprintf("cannot create prev document: %e", err))
	}

	currDoc, err := libopenapi.NewDocument(curr)

	if err != nil {
		panic(fmt.Sprintf("cannot create curr document: %e", err))
	}

	documentChanges, errs := libopenapi.CompareDocuments(prevDoc, currDoc)

	if len(errs) > 0 {
		for i := range errs {
			fmt.Printf("error: %e\n", errs[i])
		}
		panic(fmt.Sprintf("cannot compare documents: %d errors reported", len(errs)))
	}

	if documentChanges.TotalBreakingChanges() > 0 {
		t.Errorf("expected no breaking changes, but found %d", documentChanges.TotalBreakingChanges())
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions