openapi: 3.0.3

info:
  title: Shop.MarcinZiemek.com APIs
  description: Specification for Shop.MarcinZiemek.com APIs
  termsOfService: https://api.shop.marcinziemek.com/api-terms.html
  contact:
    name: Marcin Ziemek
    url: https://marcinziemek.com
    email: marcin@marcinziemek.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: "1.0"

security:
- JwtAuthToken: []

paths:
  /v1/customers:
    get:
      tags:
      - Customers
      summary: List Customers
      description: Get a list of customers in the system
      operationId: listCustomersV1
      responses:
        200:
          description: List of customers
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerList'
        400:
          description: Bad Request
        401:
          description: Unauthorized access
        500:
          description: Internal Server Error
        503:
          description: Service Unavailable
    post:
      tags:
      - Customers
      summary: New Customer
      description: Create a new customer
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Customer'
        required: true
      responses:
        201:
          description: Customer Created
          headers:
            Location:
              description: Location of the created customer
              style: simple
              explode: false
              schema:
                type: string
                format: uri
                example: https://api.marcinziemek.com/v1/customers/{customerIdValue}
        400:
          description: Bad Request
        401:
          description: Unauthorized access
        500:
          description: Internal Server Error
        503:
          description: Service Unavailable
  
  /v1/customers/{customerId}:
    get:
      tags:
      - Customers
      summary: Get customer by id
      description: Get a customer details by id
      operationId: getCustomerDetailsV1
      parameters:
      - name: customerId
        in: path
        description: Customer Id
        required: true
        style: simple
        explode: false
        schema:
          type: string
          format: uuid
      responses:
        200:
          description:  Customer details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Customer'
        400:
          description: Bad Request
        401:
          description: Unauthorized access
        404:
          description: Not found
        500:
          description: Internal Server Error
        503:
          description: Service Unavailable
    put:
      tags:
      - Customers
      summary: Update Customer
      description: Update customer by id
      operationId: updateCustomerV1
      parameters:
      - name: customerId
        in: path
        description: Customer Id
        required: true
        style: simple
        explode: false
        schema:
          type: string
          format: uuid
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Customer'
        required: true
      responses:
        200:
          description: Customer Updated
        400:
          description: Bad Request
        401:
          description: Unauthorized access
        404:
          description: Not found
        500:
          description: Internal Server Error
        503:
          description: Service Unavailable
    delete:
      tags:
      - Customers
      summary: Delete Customer by id
      description: Delete a customer by id
      operationId: deleteCustomerV1
      parameters:
      - name: customerId
        in: path
        description: Customer Id
        required: true
        style: simple
        explode: false
        schema:
          type: string
          format: uuid
      responses:
        200:
          description: Customer Deleted
        400:
          description: Bad Request
        401:
          description: Unauthorized access
        404:
          description: Not found
        500:
          description: Internal Server Error
        503:
          description: Service Unavailable

components:
  schemas:
    Address:
      type: object
      description: Address object
      properties:
        street:
          type: string
          example: "Wesoła 2"
        flatNumber:
          type: string
          example: "13"
        city:
          type: string
          example: "Gdańsk"
        postalCode:
          type: string
          example: "80834"
        country:
          type: string
          example: "Polska"
      
    Customer:
      type: object
      description: Customer object
      required: [firstName, lastName, email]
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        firstName:
          maxLength: 100
          minLength: 1
          type: string
          example: Marcin
        lastName:
          maxLength: 100
          minLength: 1
          type: string
          example: Ziemek
        email:
          type: string
          example: marcin@marcinziemek.com
        address:
          $ref: '#/components/schemas/Address'
    
    CustomerList:
      type: array
      description: List of Customers
      items:
        $ref: '#/components/schemas/Customer'
    
  securitySchemes:
    JwtAuthToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
