Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Created November 18, 2024 22:34
Show Gist options
  • Save yokawasa/dda7b5f97ca313540b3e7fa787b90d59 to your computer and use it in GitHub Desktop.
Save yokawasa/dda7b5f97ca313540b3e7fa787b90d59 to your computer and use it in GitHub Desktop.
API Contract Samples

OpenAPI Spec

openapi: "3.0.0"
info:
  title: Sample API
  version: "1.0"
paths:
  /user/{id}:
    get:
      summary: Get user by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                  name:
                    type: string
                  email:
                    type: string

GraphQL schema

type User {
  id: ID!
  name: String!
  email: String!
}

type Query {
  getUser(id: ID!): User
}

JSON Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" },
    "email": { "type": "string" }
  },
  "required": ["id", "name", "email"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment