Skip to content
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

Closed
abompard opened this issue Feb 20, 2020 · 6 comments
Assignees
Labels
spike Research needed

Comments

@abompard
Copy link
Member

abompard commented Feb 20, 2020

Things to think about when designing the API:

  • REST and HTTP links between results
  • API version
  • schema (food for thought: OpenAPI, CoreAPI, Swagger, etc)
  • handling of paginated results
  • writing a client should be easy

Acceptance criteria:

  • The schema format has been decided
  • We have a good vision of how fasjson's API should look like

DoD: all of the above

@odra
Copy link
Contributor

odra commented Feb 21, 2020

I would lean towards giving OpenAPI a try because:

@odra
Copy link
Contributor

odra commented Feb 21, 2020

I am writing a simple example using the openapi spec

@odra
Copy link
Contributor

odra commented Feb 21, 2020

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 HEAD request into each path could return its own schema and a HEAD request to / would return the whole spec (either in json or yaml)

@odra odra self-assigned this Feb 24, 2020
@odra odra mentioned this issue Feb 24, 2020
@StephenCoady
Copy link
Contributor

This looks good. I don't have much experience with formal api spec - so the following might be dumb questions/statements:

@odra
Copy link
Contributor

odra commented Feb 25, 2020

  • The license is GPLv3, the same as this repository.
  • yes we do, I didn't add it since I didn't find anything in the spec reference
  • If I got that right from the code, it queries groups using your token, so it will return whatever groups you have access/read permission
  • I only added methods that are already in the app code (whoami, groups and users)
  • I set error responses and the "default" ones for each method in the PR, we can add specific ones later if needed
  • The spec in hardcoded as a yaml file for now but it can be auto generated in the future

@StephenCoady
Copy link
Contributor

I didn't see the PR, I thought you just wanted feedback on the comment 🤦‍♂️

@odra odra closed this as completed Mar 16, 2020
@ryanlerch ryanlerch added this to AAA Jul 19, 2024
@ryanlerch ryanlerch moved this to Overall Done in AAA Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spike Research needed
Projects
No open projects
Status: Overall Done
Development

No branches or pull requests

3 participants