TT#28828 openapi PUT, PATCH, DELETE

Change-Id: I57cd3d5a7f9a6ddb6ce479732b24a36cbb0a62c9
changes/05/18205/2
Gerhard Jungwirth 8 years ago
parent d8d1ea8221
commit b0c3b25897

@ -89,6 +89,25 @@ sub generate_swagger_datastructure {
"schema" => { type => "integer" },
},
);
my %requestBodies = (
PatchBody => {
description => "A JSON patch document specifying modifications",
required => JSON::true,
content => {
'application/json-patch+json' => {
schema => {
# '$ref' => 'http://json.schemastore.org/json-patch.json#/',
# "$ref": "https://raw.githubusercontent.com/fge/sample-json-schemas/master/json-patch/json-patch.json"
'$ref' => '/js/schemas/json-patch.json#/',
# type => 'array',
# items => {
# type => 'object',
# }
}
}
}
}
);
my @chapters = sort (keys %{ $collections });
@ -219,6 +238,78 @@ sub generate_swagger_datastructure {
};
}
if (grep {m/^PUT$/} @{ $col->{item_actions} }) {
$item_p->{put} = {
summary => "Replace/change a specific $entity",
tags => ['Item Put'],
requestBody => {
required => JSON::true,
content => {
"application/json" => {
schema => {
'$ref' => "#/components/schemas/$entity",
}
}
}
},
responses => {
"200" => {
description => "$title",
content => {
"application/json" => {
schema => {
'$ref' => "#/components/schemas/$entity",
}
},
},
},
"204" => {
description => "Put successful",
# empty content
},
}
};
}
if (grep {m/^PATCH$/} @{ $col->{item_actions} }) {
$item_p->{patch} = {
summary => "Change a specific $entity",
tags => ['Item Patch'],
requestBody => {
'$ref' => '#/components/requestBodies/PatchBody',
},
responses => {
"200" => {
description => "$title",
content => {
"application/json" => {
schema => {
'$ref' => "#/components/schemas/$entity",
}
},
},
},
"204" => {
description => "Patch successful",
# empty content
},
}
};
}
if (grep {m/^DELETE$/} @{ $col->{item_actions} }) {
$item_p->{delete} = {
summary => "Delete a specific $entity",
tags => ['Item Delete'],
responses => {
"204" => {
description => "Deletion successful",
# empty content
},
}
};
}
# common description for all methods
$p->{description} = $col->{description};
@ -303,6 +394,7 @@ sub generate_swagger_datastructure {
"schemas" => \%schemas,
"responses" => \%responses,
"parameters" => \%parameters,
"requestBodies" => \%requestBodies,
},
};

@ -0,0 +1,64 @@
{
"title": "JSON schema for JSONPatch files",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"$ref": "#/definitions/operation"
},
"definitions": {
"operation": {
"type": "object",
"required": [ "op", "path" ],
"allOf": [ { "$ref": "#/definitions/path" } ],
"oneOf": [
{
"required": [ "value" ],
"properties": {
"op": {
"description": "The operation to perform.",
"type": "string",
"enum": [ "add", "replace", "test" ]
},
"value": {
"description": "The value to add, replace or test."
}
}
},
{
"properties": {
"op": {
"description": "The operation to perform.",
"type": "string",
"enum": [ "remove" ]
}
}
},
{
"required": [ "from" ],
"properties": {
"op": {
"description": "The operation to perform.",
"type": "string",
"enum": [ "move", "copy" ]
},
"from": {
"description": "A JSON Pointer path pointing to the location to move/copy from.",
"type": "string"
}
}
}
]
},
"path": {
"properties": {
"path": {
"description": "A JSON Pointer path.",
"type": "string"
}
}
}
}
}
Loading…
Cancel
Save