Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Last active March 4, 2025 17:19
Show Gist options
  • Save yokawasa/d4a722af671234177d58c6e240268225 to your computer and use it in GitHub Desktop.
Save yokawasa/d4a722af671234177d58c6e240268225 to your computer and use it in GitHub Desktop.
Simple samples of Postman Collection and OpenAPI (3.0 format). Both are minimal examples focused on the function of "getting user information".
openapi: 3.0.3
info:
title: Sample API
version: 1.0.0
servers:
- url: https://api.example.com
paths:
/users:
get:
summary: Get all users
operationId: getAllUsers
responses:
'200':
description: A list of users
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
/users/{id}:
get:
summary: Get a user by ID
operationId: getUserById
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
description: A single user object
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
required:
- id
- name
{
"info": {
"name": "Sample Collection with Tests",
"_postman_id": "1234-5678-9abc-def0",
"description": "A simple Postman Collection example with basic tests",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get All Users",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": "{{base_url}}/users",
"host": [
"{{base_url}}"
],
"path": [
"users"
]
}
},
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"// Test: Check the status code",
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"// Test: Check if response has at least one user",
"const jsonData = pm.response.json();",
"pm.test(\"Response array should not be empty\", function () {",
" pm.expect(jsonData.length).to.be.above(0);",
"});"
]
}
}
]
},
{
"name": "Get User by ID",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": "{{base_url}}/users/1",
"host": [
"{{base_url}}"
],
"path": [
"users",
"1"
]
}
},
"response": []
}
],
"variable": [
{
"key": "base_url",
"value": "https://api.example.com"
}
]
}
{
"info": {
"name": "Sample Collection",
"_postman_id": "1234-5678-9abc-def0",
"description": "A simple Postman Collection example for fetching user data.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get All Users",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": "{{base_url}}/users",
"host": [
"{{base_url}}"
],
"path": [
"users"
]
}
},
"response": []
},
{
"name": "Get User by ID",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": "{{base_url}}/users/1",
"host": [
"{{base_url}}"
],
"path": [
"users",
"1"
]
}
},
"response": []
}
],
"variable": [
{
"key": "base_url",
"value": "https://api.example.com"
}
]
}
@yokawasa
Copy link
Author

yokawasa commented Mar 4, 2025

Postman Collection と OpenAPI (3.0形式) のシンプルなサンプル。どちらも「ユーザー情報を取得する」という機能に絞った最小限の例。

  • sample-openapi.yaml
  • sample-postman-collection.json
  • sample-postman-collection-with-testscripts.json (上記のコレクションにテストスクリプトを追加)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment