openapi: 3.0.0
info:
  contact:
    email: dev@invopop.com
    name: Invopop Developers
  description: >-
    The Invopop Sequence Service API allows you to define a "series" whose
    entries are guaranteed to be sequential.
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  title: Sequence Service API
  version: 1.0.3
servers:
  - description: production
    url: https://api.invopop.com
security:
  - authToken: []
paths:
  /sequence/v1/series:
    get:
      description: Fetch all the series in the current company.
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SequenceSeriesCollection'
          description: OK
  /sequence/v1/series/{id}:
    get:
      description: Fetch an existing series given its UUID.
      parameters:
        - description: UUID of the series to fetch
          in: path
          name: id
          required: true
          schema:
            description: UUID of the series to fetch
            title: ID
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SequenceSeries'
          description: OK
    put:
      description: Create a new series idempotently with the given UUID (any version).
      parameters:
        - description: The UUID (any version) of the series to create.
          in: path
          name: id
          required: true
          schema:
            description: The UUID (any version) of the series to create.
            example: a8904315-3d16-4a95-91c1-30d6cdde553e
            title: ID
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SequenceCreateSeries'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SequenceSeries'
          description: OK
  /sequence/v1/series/{series_id}/entries:
    get:
      description: Fetch all the entries in a given series.
      parameters:
        - description: UUID of the series to fetch entries for
          in: path
          name: series_id
          required: true
          schema:
            description: UUID of the series to fetch entries for
            title: Series ID
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SequenceEntryCollection'
          description: OK
  /sequence/v1/series/{series_id}/entries/{id}:
    get:
      description: Fetch an existing entry in a series given its UUID.
      parameters:
        - description: UUID of the series to fetch entries for
          in: path
          name: series_id
          required: true
          schema:
            description: UUID of the series to fetch entries for
            title: Series ID
            type: string
        - description: UUID of the entry to fetch
          in: path
          name: id
          required: true
          schema:
            description: UUID of the entry to fetch
            title: ID
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SequenceEntry'
          description: OK
    put:
      description: >-
        Create a new entry in a given series idempotently with the given UUID
        (any version).
      parameters:
        - description: UUID of the series to fetch entries for
          in: path
          name: series_id
          required: true
          schema:
            description: UUID of the series to fetch entries for
            title: Series ID
            type: string
        - description: The UUID (any version) of the entry to create.
          in: path
          name: id
          required: true
          schema:
            description: The UUID (any version) of the entry to create.
            example: a8904315-3d16-4a95-91c1-30d6cdde553e
            title: ID
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SequenceCreateEntry'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SequenceEntry'
          description: OK
components:
  schemas:
    SequenceCreateEntry:
      properties:
        meta:
          additionalProperties:
            type: string
          description: >-
            A set of key/value pairs that can be used to store additional
            information about the entry.
          example:
            name: John Doe
          title: Meta
          type: object
        sig:
          description: JSON Web Signature of the key properties used to create the entry.
          title: Signature
          type: string
      type: object
    SequenceCreateSeries:
      properties:
        code:
          description: A code that can be used to identify the series.
          example: SALES-2020
          title: Code
          type: string
        description:
          description: A description of the series.
          example: This series is used for sales.
          title: Description
          type: string
        name:
          description: The name of the series.
          example: My Series
          title: Name
          type: string
        padding:
          description: The number of 0s to pad the generated codes with.
          example: 5
          title: Padding
          type: integer
        prefix:
          description: A prefix that will be prepended to all entries.
          example: INV-
          title: Prefix
          type: string
        sig:
          description: JSON Web Signature of the key properties used to create the series.
          title: Signature
          type: string
        start:
          description: The starting index for the series.
          example: 1
          title: Start
          type: integer
        suffix:
          description: A suffix that will be appended to all entries.
          example: '-F1'
          title: Suffix
          type: string
      type: object
    SequenceEntry:
      properties:
        code:
          description: The complete code for the entry, including prefix and suffix.
          example: INV-00001-F1
          title: Code
          type: string
        created_at:
          description: The date and time the entry was created.
          example: '2020-10-01T00:00:00Z'
          title: Created At
          type: string
        id:
          description: The UUID (any version) of the entry.
          example: a8904315-3d16-4a95-91c1-30d6cdde553e
          title: ID
          type: string
        meta:
          additionalProperties:
            type: string
          description: >-
            A set of key/value pairs that can be used to store additional
            information about the entry.
          example:
            name: John Doe
          title: Meta
          type: object
        previous_id:
          description: The UUID of the previous entry in the series.
          example: a8904315-3d16-4a95-91c1-30d6cdde553e
          title: Previous ID
          type: string
        series_id:
          description: The UUID of the series the entry belongs to.
          example: a8904315-3d16-4a95-91c1-30d6cdde553e
          title: Series ID
          type: string
        sigs:
          description: >-
            Set of JSON Web Signatures validating the information contained in
            the entry.
          items:
            type: string
          title: Signatures
          type: array
        updated_at:
          description: The date and time the entry was last updated.
          example: '2020-10-01T00:00:00Z'
          title: Updated At
          type: string
      type: object
    SequenceEntryCollection:
      properties:
        cursor:
          description: The cursor used to retrieve the next page of entries.
          example: >-
            eyJpZCI6ImE4OTA0MzE1LTNkMTYtNGE5NS05MWMxLTMwZDZjZGRlNTUzZSIsImxpbWl0IjoyMH0=
          title: Cursor
          type: string
        limit:
          description: The maximum number of entries returned in the list.
          example: 20
          title: Limit
          type: integer
        list:
          description: A list of entries.
          items:
            $ref: '#/components/schemas/SequenceEntry'
          nullable: true
          title: List
          type: array
      type: object
    SequenceSeries:
      properties:
        code:
          description: A code that can be used to identify the series.
          example: SALES-2020
          title: Code
          type: string
        created_at:
          description: The date and time the series was created.
          example: '2020-10-01T00:00:00Z'
          title: Created At
          type: string
        description:
          description: A description of the series.
          example: This series is used for sales.
          title: Description
          type: string
        id:
          description: The UUID (any version) of the series.
          example: a8904315-3d16-4a95-91c1-30d6cdde553e
          title: ID
          type: string
        last_entry_id:
          description: The ID of the last entry in the series.
          example: a8904315-3d16-4a95-91c1-30d6cdde553e
          title: Last Entry ID
          type: string
        last_index:
          description: The last index used in the series.
          example: 100
          title: Last Index
          type: integer
        name:
          description: The name of the series.
          example: My Series
          title: Name
          type: string
        padding:
          description: The number of 0s to pad the generated codes with.
          example: 5
          title: Padding
          type: integer
        prefix:
          description: A prefix that will be prepended to all entries.
          example: INV-
          title: Prefix
          type: string
        suffix:
          description: A suffix that will be appended to all entries.
          example: '-F1'
          title: Suffix
          type: string
        updated_at:
          description: The date and time the series was last updated.
          example: '2020-10-01T00:00:00Z'
          title: Updated At
          type: string
      type: object
    SequenceSeriesCollection:
      properties:
        list:
          description: A list of series.
          items:
            $ref: '#/components/schemas/SequenceSeries'
          nullable: true
          title: List
          type: array
      type: object
  securitySchemes:
    authToken:
      bearerFormat: JWT
      description: >-
        Use the `Bearer` scheme with a valid JWT token to authenticate requests.
        Example: `Authorization: Bearer <token>`
      scheme: bearer
      type: http
