Skip to content

Changing request field type from string to oneOf: string, number shouldn't break #722

@nesk

Description

@nesk

Describe the bug
In the request body, if you change the following field:

requestBody:
  content:
    application/json:
      schema:
        type: object
        properties:
          name:
            type: integer
        required:
          - name
  required: true

to:

requestBody:
  content:
    application/json:
      schema:
        type: object
        properties:
          name:
            oneOf:
              - type: integer
              - type: string
        required:
          - name
  required: true

Then oasdiff reports this as a breaking change.

To Reproduce

base.yml
openapi: 3.0.1
info:
  title: User Service
  version: 1.0.0
paths:
  /users:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: integer
              required:
                - name
        required: true
      responses:
        201:
          description: Created
          content:
            application/json:
              schema:
                properties:
                  id:
                    type: integer
                required:
                  - id
                type: object
revision.yml
openapi: 3.0.1
info:
  title: User Service
  version: 1.0.0
paths:
  /users:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  oneOf:
                    - type: integer
                    - type: string
              required:
                - name
        required: true
      responses:
        201:
          description: Created
          content:
            application/json:
              schema:
                properties:
                  id:
                    type: integer
                required:
                  - id
                type: object
  1. Download the two files base.yml and revision.yml
  2. Run oasdiff breaking base.yml revision.yml
  3. Observe the following output:
1 changes: 1 error, 0 warning, 0 info
error	[request-property-type-changed] at revision.yml
	in API POST /users
		the 'name' request property type/format changed from 'integer'/'' to ''/''

Expected behavior
oasdiff shouldn't mark this as a breaking change. Actually, the request body should be considered as a contravariant contract: widening a field type isn't a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions