PHRAS-3153_Doc-to-Swagger

- add extended mode to /record and /story
- fix compilation in 1 file
- better examples
- todo : extended mode for /search
- todo : check "include[]" available keys (compare with extended mode)
- todo : remove 'id' type ?
This commit is contained in:
jygaulier
2021-02-11 19:41:40 +01:00
parent d832d505a2
commit 5cb70407a6
8 changed files with 2464 additions and 275 deletions

View File

@@ -13,7 +13,7 @@ to update in swaggerhub (single file) :
- compile sources in a single file for swaggerhub (run from <phraseanet-dir>) - compile sources in a single file for swaggerhub (run from <phraseanet-dir>)
`swagger-cli bundle API_documentation/v3/api.yaml -o API_documentation/v3/_compiled.yaml -t yaml` `swagger-cli bundle API_documentation/v3/api.yaml -r -o API_documentation/v3/_compiled.yaml -t yaml`
- copy/paste the generated content from `_compiled.yaml` to - copy/paste the generated content from `_compiled.yaml` to

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
openapi: 3.0.0 openapi: 3.0.3
info: info:
description: > description: >
This is the documentation of Phraseanet API (v3) This is the documentation of Phraseanet API (v3)
@@ -82,7 +82,7 @@ components:
per_page: per_page:
name: per_page name: per_page
in: query in: query
description: number of results per page. Use along with "page" description: number of items per page. Use along with "page"
required: false required: false
schema: schema:
type: integer type: integer
@@ -93,7 +93,7 @@ components:
offset: offset:
name: offset name: offset
in: query in: query
description: offset in records count, from 0. Use along with "limit" description: offset in items unit count, from 0. Use along with "limit"
required: false required: false
schema: schema:
type: integer type: integer
@@ -103,7 +103,7 @@ components:
limit: limit:
name: limit name: limit
in: query in: query
description: number of results. Use along with "offset" description: number of items. Use along with "offset"
required: false required: false
schema: schema:
type: integer type: integer
@@ -213,7 +213,7 @@ paths:
schema: schema:
$ref: 'search.yaml#/ApiResponse_search' $ref: 'search.yaml#/ApiResponse_search'
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'
# ---------------- searchraw ---------------- # ---------------- searchraw ----------------
'/searchraw': '/searchraw':
@@ -241,7 +241,7 @@ paths:
schema: schema:
$ref: 'searchraw.yaml#/ApiResponse_searchraw' $ref: 'searchraw.yaml#/ApiResponse_searchraw'
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'
# ------------ record ----------- # ------------ record -----------
'/records/{sbas_id}/{record_id}': '/records/{sbas_id}/{record_id}':
@@ -251,6 +251,15 @@ paths:
summary: Find record by sbas_id and record_id summary: Find record by sbas_id and record_id
description: | description: |
Returns a single record, which can be a real record or a story (check `is_story`) Returns a single record, which can be a real record or a story (check `is_story`)
## About extended mode
passing header `Accept: application/vnd.phraseanet.record-extended+json`
will add/populate objects :
- subdefs
- status
- metadata
- dces
operationId: getRecordById operationId: getRecordById
parameters: parameters:
- $ref: '#/components/parameters/sbas_id' - $ref: '#/components/parameters/sbas_id'
@@ -261,11 +270,14 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: schemas.yaml#/ApiResponse_record $ref: record.yaml#/ApiResponse_record
'application/vnd.phraseanet.record-extended+json':
schema:
$ref: record.yaml#/ApiResponse_record_extended
404: 404:
description: Record not found description: Record not found
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'
'/records/{base_id}': '/records/{base_id}':
post: post:
@@ -314,9 +326,9 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: schemas.yaml#/ApiResponse_record $ref: record.yaml#/ApiResponse_record
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'
# security: # security:
# - api_key: [] # - api_key: []
@@ -684,9 +696,9 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: schemas.yaml#/ApiResponse_record $ref: record.yaml#/ApiResponse_record
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'
'/stories/{sbas_id}/{record_id}': '/stories/{sbas_id}/{record_id}':
get: get:
@@ -696,7 +708,8 @@ paths:
description: | description: |
Returns a single story Returns a single story
This is the __same__ parameters / result as _/records/..._, except that here the record __must__ be a story else 404 is returned This is the __same__ parameters / result as _/records/..._, (including "extended mode"),
except that here the record __must__ be a story else 404 is returned
operationId: getStoryById operationId: getStoryById
parameters: parameters:
@@ -708,11 +721,14 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: schemas.yaml#/ApiResponse_story $ref: record.yaml#/ApiResponse_story
'application/vnd.phraseanet.record-extended+json':
schema:
$ref: record.yaml#/ApiResponse_story_extended
404: 404:
description: Story not found ( description: Story not found (
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'
'/stories/{sbas_id}/{record_id}/children': '/stories/{sbas_id}/{record_id}/children':
@@ -725,26 +741,18 @@ paths:
parameters: parameters:
- $ref: '#/components/parameters/sbas_id' - $ref: '#/components/parameters/sbas_id'
- $ref: '#/components/parameters/record_id' - $ref: '#/components/parameters/record_id'
- name: page - $ref: '#/components/parameters/page'
in: query - $ref: '#/components/parameters/per_page'
description: page number (default 1) - $ref: '#/components/parameters/offset'
required: false - $ref: '#/components/parameters/limit'
schema:
type: integer
- name: per_page
in: query
description: number of children (records uri) per page (default 10)
required: false
schema:
type: integer
responses: responses:
200: 200:
description: ok description: ok
content: content:
application/json: application/json:
schema: schema:
$ref: schemas.yaml#/ApiResponse_RecordsUriArray $ref: record.yaml#/ApiResponse_RecordsUriArray
404: 404:
description: Story (record) not found description: Story (record) not found
default: default:
$ref: 'responses.yaml#/error_response' $ref: 'common.yaml#/error_response'

View File

@@ -1,20 +1,43 @@
error_response:
description: Any other error
ApiResponse_meta: ApiResponse_meta:
type: object type: object
properties: properties:
api_version: api_version:
type: string type: string
example:
'3.0.0'
request: request:
type: string type: string
example:
'GET|POST|... /api/v3/....'
response_time: response_time:
type: string type: string
format: date-time format: date-time
example:
'2021-02-11T14:18:02+00:00'
http_code: http_code:
type: integer type: integer
format: int32 format: int32
example:
200
error_type: error_type:
type: string type: string
example:
null
error_message: error_message:
type: string type: string
example:
null
error_details:
type: string
example:
null
charset:
type: string
example:
'UTF-8'
Facet: Facet:
type: object type: object
@@ -77,3 +100,14 @@
ID: ID:
type: integer type: integer
Metadata_value:
type: object
properties:
meta_id:
type: integer
example: 1771
value:
type: string
example: value_of_the_field

View File

@@ -2,13 +2,13 @@
type: object type: object
properties: properties:
databox_id: databox_id:
$ref: 'common.yaml#/ID' type: integer
example:
2
record_id: record_id:
$ref: 'common.yaml#/ID' type: integer
title: example:
type: string 34
original_name:
type: string
updated_on: updated_on:
type: string type: string
format: date-time format: date-time
@@ -16,13 +16,67 @@
type: string type: string
format: date-time format: date-time
collection_id: collection_id:
$ref: 'common.yaml#/ID' type: integer
example:
5
base_id: base_id:
$ref: 'common.yaml#/ID' type: integer
example:
14
thumbnail: thumbnail:
$ref: '#/Subdef' $ref: '#/Thumbnail'
uuid: uuid:
type: string type: string
example:
'5b079f33-0851-4aec-a978-b7f8d7204e5a'
_record_extension_:
type: object
properties:
subdefs:
type: array
items:
$ref: '#/Subdef'
status:
type: array
items:
type: object
properties:
bit:
type: integer
example: 4
state:
type: boolean
example: false
metadata:
type: array
items:
type: object
properties:
meta_structure_id:
type: integer
name:
type: string
labels:
type: object
additionalProperties:
type: string
example:
fr: label_du_champ_en_français
en: field_label_in_english
value:
oneOf:
- $ref: 'common.yaml#/Metadata_value'
- type: array
items:
$ref: 'common.yaml#/Metadata_value'
dces:
type: array
items:
type: string
example:
'_not_documented_TODO_'
Record: Record:
allOf: # Combines the basic _Record_ and the records-only properties allOf: # Combines the basic _Record_ and the records-only properties
@@ -31,23 +85,58 @@
properties: properties:
mime_type: mime_type:
type: string type: string
example:
'image/jpeg'
title:
type: string
example:
'Sleepy cat'
original_name:
type: string
example:
'DSC_12345.jpg'
technical_informations: technical_informations:
type: array type: array
items: items:
$ref: '#/TechnicalInformation' $ref: '#/TechnicalInformation'
sha256: sha256:
type: string type: string
example:
'6f330ac0ae2...'
phrasea_type: phrasea_type:
type: string type: string
enum: enum:
- image - image
- video - video
example:
'image'
is_story:
type: boolean
default: false
Record_extended:
allOf:
- $ref: '#/Record'
- $ref: '#/_record_extension_'
Story: Story:
allOf: # Combines the basic _Record_ and the stories-only properties allOf: # Combines the basic _Record_ and the stories-only properties
- $ref: '#/_Record_' - $ref: '#/_Record_'
- type: object - type: object
properties: properties:
mime_type:
type: string
default: null
title:
type: string
example:
'sans-titre'
original_name:
type: string
default: null
is_story:
type: boolean
default: true
children_offset: children_offset:
type: integer type: integer
description: 'Children pagination offset ; Always 0' description: 'Children pagination offset ; Always 0'
@@ -71,13 +160,23 @@
items: items:
$ref: '#/Record' $ref: '#/Record'
Story_extended:
allOf:
- $ref: '#/Story'
- $ref: '#/_record_extension_'
TechnicalInformation: TechnicalInformation:
type: object type: object
properties: additionalProperties:
name:
type: string
value:
type: string type: string
example:
Aperture: 6.3
CameraModel: 'Canon EOS 5D Mark II'
Channels: 3
ColorSpace: RGB
FileSize: 5618218
Subdef: Subdef:
type: object type: object
@@ -107,6 +206,7 @@
type: string type: string
substituted: substituted:
type: boolean type: boolean
example: false
created_on: created_on:
type: string type: string
format: date-time format: date-time
@@ -117,3 +217,77 @@
type: string type: string
url_ttl: url_ttl:
type: integer type: integer
example: 7200
Thumbnail:
allOf:
- type: object
properties:
name:
example: 'thumbnail'
mime_type:
example: 'image/jpeg'
height:
example: 160
width:
example: 240
filesize:
example: 2375
url:
example: 'http://phraseanet.demo.fr/medias/eyJ0eXAiOiJKV1Q...'
- $ref: '#/Subdef'
ApiResponse_record:
type: object
properties:
meta:
$ref: 'common.yaml#/ApiResponse_meta'
response:
$ref: '#/Record'
ApiResponse_record_extended:
type: object
properties:
meta:
$ref: 'common.yaml#/ApiResponse_meta'
response:
$ref: '#/Record_extended'
ApiResponse_story:
type: object
properties:
meta:
$ref: 'common.yaml#/ApiResponse_meta'
response:
$ref: '#/Story'
ApiResponse_story_extended:
type: object
properties:
meta:
$ref: 'common.yaml#/ApiResponse_meta'
response:
$ref: '#/Story_extended'
# for "/stories/{sbas_id}/{record_id}/children"
RecordUri:
type: string
example: '/api/v3/records/1/48'
RecordsUriArray:
type: array
items:
$ref: '#/RecordUri'
example:
- '/api/v3/records/1/48'
- '/api/v3/records/1/49'
- '/api/v3/records/1/50'
ApiResponse_RecordsUriArray:
type: object
properties:
meta:
$ref: 'common.yaml#/ApiResponse_meta'
response:
$ref: '#/RecordsUriArray'

View File

@@ -1,15 +0,0 @@
record_response:
type: object
properties:
200:
description: successful operation
content:
application/json:
schema:
$ref: schemas.yaml#/ApiResponse_record
400:
description: Any other error
404:
description: Record not found
error_response:
description: Any other error

View File

@@ -41,94 +41,9 @@ RecordPatch:
type: array type: array
items: items:
$ref: '#/RecordPatch_status' $ref: '#/RecordPatch_status'
ApiResponse_meta:
type: object
properties:
api_version:
type: string
request:
type: string
response_time:
type: string
format: date-time
http_code:
type: integer
format: int32
error_type:
type: string
error_message:
type: string
ApiResponse_record:
type: object
properties:
meta:
$ref: '#/ApiResponse_meta'
response:
$ref: 'record.yaml#/Record'
ApiResponse_story:
type: object
properties:
meta:
$ref: '#/ApiResponse_meta'
response:
$ref: 'record.yaml#/Story'
# -------------------- searchraw --------------- # -------------------- searchraw ---------------
# -------------------- search --------------- # -------------------- search ---------------
ApiResponse_search:
type: object
properties:
meta:
$ref: '#/ApiResponse_meta'
response:
$ref: '#/ApiResponse_search_response'
ApiResponse_search_response:
type: object
properties:
offset:
type: integer
description: 'Pagination offset as passed (or computed from "page/per_page") in request'
limit:
type: integer
description: 'Pagination limit as passed in request'
count:
type: integer
description: 'Number of results in this page [0...limit]'
total:
type: integer
description: 'Total number of results'
minimum: 1
results:
type: object
properties:
stories:
type: array
items:
$ref: 'record.yaml#/Story'
records:
type: array
items:
$ref: 'record.yaml#/Record'
facets:
$ref: 'common.yaml#/FacetsArray'
RecordUri:
type: string
example:
'/api/v3/records/1/48'
RecordsUriArray:
type: array
items:
$ref: '#/RecordUri'
ApiResponse_RecordsUriArray:
type: object
properties:
meta:
$ref: '#/ApiResponse_meta'
response:
$ref: '#/RecordsUriArray'