What is the difference between the global definitions
section and the components
section in Swagger 2.0?
I came across a Swagger definition YAML file which is marked as swagger: '2.0'
.
It has one section called definitions
just below parameters
. This is similar to what is described in
https://swagger.io/docs/specification/2-0/basic-structure/
under the "Input and Output Models" section.
Also further down the file, it has the components
section with the schemas
section underneath it. That is similar to what is described in
https://swagger.io/docs/specification/components/
This looks like OAS3.
However, this specific YAML file has both sections. I am not exactly sure whether definitions
is for Swagger 2.0 and components
and schemas
is in OAS 3.0. Is that so?
Can both definitions
and components
be used in the same YAML file of type swagger: '2.0'
or should we stick to either definitions
or components
?
# definitions section looks like this
definitions:
User:
properties:
id:
type: integer
name:
type: string
# Both properties are required
required:
- id
- name
# components section looks like this
components:
schemas:
Address:
type: object
properties:
line1:
type: string
city:
type: string