-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
As a developer I want to design the best possible API so I can implement it in a stable future-proof manner #6
Comments
I would lean towards giving OpenAPI a try because:
|
I am writing a simple example using the openapi spec |
I'v' created a simple openapi sample: openapi: 3.0.0
info:
title: Fedora Account Service JSON API
version: 0.0.1
paths:
/1/:
get:
operationId: whoami
responses:
"401":
description: requester identity authentication error
content:
application/json:
schema:
$ref: "#/components/schemas/error"
"200":
description: requester identity success
content:
application/json:
schema:
$ref: "#/components/schemas/user"
links:
user:
$ref: "#/components/links/UserProfile"
/1/groups:
get:
operationId: queryGroups
parameters:
- name: query
in: query
schema:
type: string
- name: page
in: query
schema:
type: integer
- name: per_page
in: query
schema:
type: integer
responses:
"404":
description: no groups for this user
content:
application/json:
schema:
$ref: "#/components/schemas/error"
"200":
description: get user groups
content:
application/json:
schema:
$ref: "#/components/schemas/groups"
links:
pagination:
$ref: "#/components/links/GroupPaging"
components:
schemas:
user:
type: object
properties:
id:
type: integer
username:
type: string
group:
type: object
properties:
id:
type: integer
name:
type: string
total_users:
type: integer
groups:
type: array
items:
$ref: "#/components/schemas/group"
group_page:
type: object
properties:
data:
$ref: "#/components/schemas/groups"
pagination:
type: object
properties:
current:
type: integer
previous:
type: integer
next:
type: integer
error:
type: object
required:
- code
- message
properties:
code:
type: integer
message:
type: string
data:
type: object
links:
UserProfile:
operationId: whoami
parameters:
id: $response.body#/id
GroupPaging:
operationId: queryGroups
parameters:
previous:
operationId: queryGroups
page: $response.body#/pagination/previous
per_page: $request.query.per_page
query: $request.query.query
current:
operationId: queryGroups
page: $response.body#/pagination/current
per_page: $request.query.per_page
query: $request.query.query
next:
operationId: queryGroups
page: $response.body#/pagination/next
per_page: $request.query.per_page
query: $request.query.query The code can be used in swagger: https://editor.swagger.io/ I used the jsonprc spec for the error schema: https://www.jsonrpc.org/specification I did not add it into the spec but a |
This looks good. I don't have much experience with formal api spec - so the following might be dumb questions/statements:
|
|
I didn't see the PR, I thought you just wanted feedback on the comment 🤦♂️ |
Things to think about when designing the API:
Acceptance criteria:
DoD: all of the above
The text was updated successfully, but these errors were encountered: