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.

Revisions

  1. yokawasa created this gist Nov 18, 2024.
    61 changes: 61 additions & 0 deletions api-contract-samples.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    # OpenAPI Spec

    ```yaml
    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

    ```json
    {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" },
    "email": { "type": "string" }
    },
    "required": ["id", "name", "email"]
    }
    ```