Skip to content

Commit

Permalink
seperate wrappers for resource/collection look better
Browse files Browse the repository at this point in the history
  • Loading branch information
philsturgeon committed Feb 2, 2024
1 parent b4da318 commit c790745
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
preview/
package-lock.json
4 changes: 0 additions & 4 deletions components/schemas/Links.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions components/schemas/Wrapper-Collection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$id: WrapperCollection
description: This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS).
type: object
properties:
data:
description: The wrapper for a collection is an array of objects.
type: array
items:
type: object
links:
description: A set of hypermedia links which serve as controls for the client.
type: object
readOnly: true
11 changes: 11 additions & 0 deletions components/schemas/Wrapper-Resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$id: WrapperResource
description: This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS).
type: object
properties:
data:
description: The wrapper for a resource is a single object.
type: object
links:
description: A set of hypermedia links which serve as controls for the client.
type: object
readOnly: true
25 changes: 0 additions & 25 deletions components/schemas/Wrapper.yaml

This file was deleted.

44 changes: 22 additions & 22 deletions paths/bookings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ get:
application/json:
schema:
allOf:
- $ref: ../components/schemas/Wrapper.yaml
- data:
type: array
items:
$ref: ../components/schemas/Booking.yaml
- links:
allOf:
- $ref: ../components/schemas/Links.yaml
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Links-Pagination.yaml
- $ref: ../components/schemas/Wrapper-Collection.yaml
- properties:
data:
type: array
items:
$ref: ../components/schemas/Booking.yaml
- properties:
links:
allOf:
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Links-Pagination.yaml
example:
data:
- booking_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
Expand Down Expand Up @@ -57,11 +58,10 @@ post:
application/json:
schema:
allOf:
- $ref: ../components/schemas/Wrapper.yaml
- data:
type: array
items:
$ref: ../components/schemas/Trip.yaml
- $ref: ../components/schemas/Wrapper-Resource.yaml
- properties:
data:
$ref: ../components/schemas/Booking.yaml
example:
data:
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
Expand All @@ -75,13 +75,13 @@ post:
application/json:
schema:
allOf:
- $ref: ../components/schemas/Wrapper.yaml
- data:
$ref: ../components/schemas/Booking.yaml
- links:
allOf:
- $ref: ../components/schemas/Links.yaml
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Wrapper-Resource.yaml
- properties:
data:
$ref: ../components/schemas/Booking.yaml
- properties:
links:
$ref: ../components/schemas/Links-Self.yaml
'400':
$ref: ../components/responses/BadRequest.yaml
'401':
Expand Down
21 changes: 11 additions & 10 deletions paths/stations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ get:
application/json:
schema:
allOf:
- $ref: ../components/schemas/Wrapper.yaml
- data:
type: array
items:
$ref: ../components/schemas/Station.yaml
- links:
allOf:
- $ref: ../components/schemas/Links.yaml
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Links-Pagination.yaml
- $ref: ../components/schemas/Wrapper-Collection.yaml
- properties:
data:
type: array
items:
$ref: ../components/schemas/Station.yaml
- properties:
links:
allOf:
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Links-Pagination.yaml
example:
data:
- id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
Expand Down
21 changes: 11 additions & 10 deletions paths/trips.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ get:
application/json:
schema:
allOf:
- $ref: ../components/schemas/Wrapper.yaml
- data:
type: array
items:
$ref: ../components/schemas/Trip.yaml
- links:
allOf:
- $ref: ../components/schemas/Links.yaml
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Links-Pagination.yaml
- $ref: ../components/schemas/Wrapper-Collection.yaml
- properties:
data:
type: array
items:
$ref: ../components/schemas/Trip.yaml
- properties:
links:
allOf:
- $ref: ../components/schemas/Links-Self.yaml
- $ref: ../components/schemas/Links-Pagination.yaml
example:
data:
- id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
Expand Down

0 comments on commit c790745

Please sign in to comment.