The Swagger Builder differentiates five kinds of item from a specification:
During the merge process, the tool will list all items included in the four kinds and will add each item into the same list of items in the previous Swagger specification.
Merging applies to the list of Swagger specifications in input from the first one (left) to the last one (right). This means that the last Swagger specification of the list will be the one used in case of replacement.
There are three ways to provide a list of Swagger specifications:
CLI argument
specified directly in the Swagger Builder command.specs
field of the configuration file (provided via the --configuration
option)--apis
options)The priority will be managed from left to right, as follows:
spec
-> CLI argument
-> API.
Conflict management is processed differently depending on the type of items that are conflicting:
# input 1:
definitions:
example:
type: object
properties:
ex1:
type: string
ex2:
type: string
# input 2:
definitions:
example:
type: object
properties:
ex1:
type: number
# Will be merged to:
definitions:
example:
type: object
properties:
ex1:
type: number
In the case of paths, the merging process will stop with an error (status code 1). The error can be ignored thanks to the --ignore-conflict
option that resolves the paths conflicts in the same way as for the definitions and parameters.
The templates are merged field by field. In case of conflict, the latest one will be taken
As specified in the conflict management section, a definition can be easily overridden with a new definition with the same name.
Example:
Example :# input 1:
definitions:
Example:
type: object
...
# input 2:
definitions:
Example:
type: object
...
# Will be merged to result to the Example definition of the input 2
A definition can be extended by using a recomposition thanks to the allOf
instruction of Swagger 2.0:
# input 1 (@api/public-swagger-spec package):
definitions:
Example:
type: object
properties:
exampleField:
type: string
...
# input 2 (@custom/public-swagger-spec package):
definitions:
Example:
type: object
allOf:
- $ref: '@api/public-swagger-spec#/definitions/Example'
- type: object
properties:
otherExampleField:
type: string
...
Refer to the referencing documentation to get information regarding the package reference.
As specified in the conflict management section, a path resource override will produce an error unless the --ignore-conflict
flag has been specified. If specified, the resource can be overridden with the same path and method.
Example:
Example :# input 1:
paths:
/examples/{id}:
get:
...
# input 2:
paths:
/examples/{id}:
get:
...
# Will be merged to result to the /examples/{id} resource of the input 2
As specified in the conflict management section, a path can be easily updated with a new resource by specifying the same path but a different method.
[!TIP] The
--ignore-conflict
flag is not necessary if no couple path, method is conflicting.
Example:
Example :# input 1:
paths:
/examples/{id}:
get:
...
# input 2:
paths:
/examples/{id}:
POST:
...
# Will be merged to result to the /examples/{id} with both Get and Post methods coming from input 1 and input 2
A new path can be added to the paths collection by specifying a different path
Example:
Example :# input 1:
paths:
/examples/{id}: ...
/samples/{id}: ...
# input 2:
paths:
/actions/{id}: ...
# Will be merged to result to a definition containing the 3 different paths