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

Required fields in nested definitions are being reported as breaking when they are not #54

Closed
sumanswaroop opened this issue Jun 3, 2021 · 3 comments
Labels

Comments

@sumanswaroop
Copy link

sumanswaroop commented Jun 3, 2021

Consider these two spec files:
Old

swagger: '2.0'
info:
  description: ABC
  version: 1.0.5
  title: Swagger Petstore
  termsOfService: 'http://swagger.io/terms/'
host: petstore.swagger.io
basePath: /v2
schemes:
  - https
  - http
paths:
  /pet/uploadImage:
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: ''
      operationId: updatePet
      parameters:
        - in: body
          name: body
          description: Pet object that needs to be added to the store
          required: true
          schema:
            $ref: '#/definitions/Pet'
      responses:
        '400':
          description: Invalid ID supplied
definitions:
  Pet:
    type: object
    required:
      - id
    properties:
      id:
        type: integer
        format: int64

Lets add a new field in the body parameter Pet which is optional but a field inside that is required.

swagger: '2.0'
info:
  description: ABC
  version: 1.0.5
  title: Swagger Petstore
  termsOfService: 'http://swagger.io/terms/'
host: petstore.swagger.io
basePath: /v2
schemes:
  - https
  - http
paths:
  /pet/uploadImage:
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: ''
      operationId: updatePet
      parameters:
        - in: body
          name: body
          description: Pet object that needs to be added to the store
          required: true
          schema:
            $ref: '#/definitions/Pet'
      responses:
        '400':
          description: Invalid ID supplied
definitions:
  Pet:
    type: object
    required:
      - id
    properties:
      id:
        type: integer
        format: int64
      breed:
        $ref: '#/definitions/Breed'
  Breed:
    type: object
    required:
      - name
    properties:
      name:
        type: string

This means that if Breed is passed in body then it must have name property. Or else we can send the request without the whole breed object.

This is being reported as breaking change.
java -jar /usr/local/lib/swagger-brake-cli-2.2.0.jar --old-api=old.yml --new-api=new.yaml Loading old API from old.yml Loading new API from new.yaml Successfully loaded APIs Starting the check for breaking API changes Check is finished There were breaking API changes R007 Request parameter breed.name is required in PUT /pet/uploadImage
Incase there already exist a optional parameter and we add new required fields inside that, then it qualifies as a breaking change.

@sumanswaroop
Copy link
Author

Verified that swagger-diff tool doesn't report it as a breaking change.

@galovics
Copy link
Member

galovics commented Dec 9, 2021

Hi @sumanswaroop,
I'm gonna check it, sorry for the long wait.

@galovics galovics added the 2.3.0 label Dec 9, 2021
galovics added a commit that referenced this issue Dec 9, 2021
@galovics
Copy link
Member

galovics commented Dec 9, 2021

@sumanswaroop fixed. With the new 2.3.0 version that will be released pretty soon (might be even today), you can give it a try.

@galovics galovics closed this as completed Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants