Skip to content
ADP
API Design PrincipleBETA

[ADP-762] OpenAPI: HTTP Profile basis

Guidance

Combining Profiles with OpenAPI Schema

Profiles can be combined with OpenAPI Schema to provide enriched semantics and constraints. OpenAPI Schema is primarily used to describe the structure and validation rules of an API, while profiles can offer additional semantics and conventions.

  1. Define Profile

    • Define a profile that describes additional semantics and constraints for a specific resource.
    • Example:
      • Profile URI: http://example.com/profiles/user-profile
      • Description: This profile defines additional semantics for user resources, including validation rules and business constraints.
  2. Reference Profile in OpenAPI Schema

    • Use the Link header or _links field to link profiles in the resource representation.
    • Example OpenAPI Schema referencing a profile:
yaml
openapi: 3.1.0
info:
  title: User API
  version: 1.0.0
paths:
  /users:
    get:
      summary: Get a list of users
      responses:
        '200':
          description: A list of users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
              examples:
                example1:
                  value:
                    - name: John Doe
                      email: john.doe@example.com
                      _links:
                        profile:
                          href: "http://example.com/profiles/user-profile"
components:
  schemas:
    User:
      type: object
      properties:
        name:
          type: string
        email:
          type: string
          format: email
        _links:
          type: object
          properties:
            profile:
              type: object
              properties:
                href:
                  type: string
                  format: uri
                  example: "http://example.com/profiles/user-profile"

References