Saturday, October 3, 2020

OAS 3.0 Features

 In this blog, we will compare the differences between OAS 2.0 and OAS 3.0

  • Host, base path and schemes are replaced with Servers. 
    • OAS 2.0
host: dev.example.com
basePath: /v1
schemes:
- https
- http
            • OAS 3.0
          servers:
          - url: https://dev.example.com/v1
          - url: http://dev.example.com/v1
              • Instead of consumes and produces, keyword content will be used
              • Content allows wildcard media types. For example, image/* represents all image types
              • 4 type of parameters are available now - query, path, header and cookie(new)
              • Instead of securityDefinitions, new keyword is securitySchemes under components
              • For Basic Authentication, type: basic was replaced with type: http and scheme: basic
              • CommonMark will be used for descriptions instead of MarkDown
              • type should be put under schema
                • OAS 2.0
               parameters:
                      - in: path
                        name: meme-id
                        required: true
                        type: integer
                        • OAS 3.0
                       parameters:
                            - name: q
                              in: query
                              schema:
                                type: string
                                format: byte
                                • It uses semantic versioning (MAJOR.MINOR.PATCH)
                                  • OAS 2.0
                                swagger: "2.0"
                                  • OAS 3.0
                                openapi: 3.0.1
                                • Body and form parameters are replaced with requestBody
                                  • OAS 2.0
                                paths:
                                  /dummy:
                                    post:
                                      description: sample
                                      consumes:
                                      - image/jpeg
                                      - image/gif
                                      produces:
                                      - application/xml
                                      parameters:
                                      - in: formData
                                        name: inputFile
                                        required: true
                                        type: file
                                      - in: query
                                        name: caption
                                        type: string
                                      responses:
                                        200:
                                          description: successful
                                          schema:
                                            type: file
                                                                                • OAS3.0
                                                                              /dummy:
                                                                                  post:
                                                                                    description: sample
                                                                                    parameters:
                                                                                    - name: caption
                                                                                      in: query
                                                                                      schema:
                                                                                        type: string
                                                                                    requestBody:
                                                                                      content:
                                                                                        image/jpeg:
                                                                                          schema:
                                                                                            required:
                                                                                            - inputFile
                                                                                            properties:
                                                                                              inputFile:
                                                                                                type: string
                                                                                                format: binary
                                                                                        image/gif:
                                                                                          schema:
                                                                                            required:
                                                                                            - inputFile
                                                                                            properties:
                                                                                              inputFile:
                                                                                                type: string
                                                                                                format: binary
                                                                                      required: true
                                                                                    responses:
                                                                                      200:
                                                                                        description: successful
                                                                                        content:
                                                                                          application/xml:
                                                                                            schema:
                                                                                              type: string
                                                                                              format: binary
                                                                              • The global components/schemas will be used for common data structures
                                                                                • OAS 2.0
                                                                              $ref: "#/definitions/Meme"
                                                                                • OAS 3.0
                                                                               $ref: '#/components/schemas/Meme'

                                                                               

                                                                               

                                                                                                                                                  No comments:

                                                                                                                                                  Post a Comment