Refactor OpenAPI schema files by removing redundant type definitions for better clarity. Update bun.lock and package.json to include ajv as a new dependency. Add GitHub Actions workflow for automated testing of OpenAPI schemas across versions 2.0, 3.0, and 3.1.

This commit is contained in:
Luke Hagar
2025-09-30 20:20:10 +00:00
parent 9716dbf335
commit 4a82aa3b32
28 changed files with 3506 additions and 3036 deletions

View File

@@ -1,147 +1,147 @@
import type { Specification } from "../../2.0";
const _apiWithExamples: Specification = {
swagger: "2.0",
info: {
title: "Simple API overview",
version: "v2",
},
paths: {
"/": {
get: {
operationId: "listVersionsv2",
summary: "List API versions",
produces: ["application/json"],
responses: {
"200": {
description: "200 300 response",
examples: {
"application/json": {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }],
},
],
},
},
},
"300": {
description: "200 300 response",
examples: {
"application/json": {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }],
},
],
},
},
},
},
},
},
"/v2": {
get: {
operationId: "getVersionDetailsv2",
summary: "Show API version details",
produces: ["application/json"],
responses: {
"200": {
description: "200 203 response",
examples: {
"application/json": {
version: {
status: "CURRENT",
updated: "2011-01 - 21T11: 33: 21Z",
"media - types": [
{
base: "application / xml",
type: "application / vnd.openstack.compute + xml; version=2",
},
{
base: "application / json",
type: "application / vnd.openstack.compute + json; version=2",
},
],
id: "v2.0",
links: [
{ href: "http://127.0.0.1:8774/v2/", rel: "self" },
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
"203": {
description: "200 203 response",
examples: {
"application/json": {
version: {
status: "CURRENT",
updated: "2011-01 - 21T11: 33: 21Z",
"media - types": [
{
base: "application / xml",
type: "application / vnd.openstack.compute + xml; version=2",
},
{
base: "application / json",
type: "application / vnd.openstack.compute + json; version=2",
},
],
id: "v2.0",
links: [
{ href: "http://23.253.228.211:8774/v2/", rel: "self" },
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
},
},
},
},
consumes: ["application/json"],
export const apiWithExamples: Specification = {
swagger: "2.0",
info: {
title: "Simple API overview",
version: "v2",
},
paths: {
"/": {
get: {
operationId: "listVersionsv2",
summary: "List API versions",
produces: ["application/json"],
responses: {
"200": {
description: "200 300 response",
examples: {
"application/json": {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }],
},
],
},
},
},
"300": {
description: "200 300 response",
examples: {
"application/json": {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [{ href: "http://127.0.0.1:8774/v2/", rel: "self" }],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [{ href: "http://127.0.0.1:8774/v3/", rel: "self" }],
},
],
},
},
},
},
},
},
"/v2": {
get: {
operationId: "getVersionDetailsv2",
summary: "Show API version details",
produces: ["application/json"],
responses: {
"200": {
description: "200 203 response",
examples: {
"application/json": {
version: {
status: "CURRENT",
updated: "2011-01 - 21T11: 33: 21Z",
"media - types": [
{
base: "application / xml",
type: "application / vnd.openstack.compute + xml; version=2",
},
{
base: "application / json",
type: "application / vnd.openstack.compute + json; version=2",
},
],
id: "v2.0",
links: [
{ href: "http://127.0.0.1:8774/v2/", rel: "self" },
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
"203": {
description: "200 203 response",
examples: {
"application/json": {
version: {
status: "CURRENT",
updated: "2011-01 - 21T11: 33: 21Z",
"media - types": [
{
base: "application / xml",
type: "application / vnd.openstack.compute + xml; version=2",
},
{
base: "application / json",
type: "application / vnd.openstack.compute + json; version=2",
},
],
id: "v2.0",
links: [
{ href: "http://23.253.228.211:8774/v2/", rel: "self" },
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
},
},
},
},
consumes: ["application/json"],
};

View File

@@ -1,202 +1,204 @@
import type { Specification } from "../../2.0";
const _petstoreExpanded: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
email: "apiteam@swagger.io",
url: "http://swagger.io",
},
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
operationId: "findPets",
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
type: "array",
collectionFormat: "csv",
items: {
type: "string",
},
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "pet response",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
parameters: [
{
name: "pet",
in: "body",
description: "Pet to add to the store",
required: true,
schema: {
$ref: "#/definitions/NewPet",
},
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "find pet by id",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
204: {
description: "pet deleted",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
allOf: [
{
$ref: "#/definitions/NewPet",
},
{
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Error: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
const petstoreExpanded: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
email: "apiteam@swagger.io",
url: "http://swagger.io",
},
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
operationId: "findPets",
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
type: "array",
collectionFormat: "csv",
items: {
type: "string",
},
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "pet response",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
parameters: [
{
name: "pet",
in: "body",
description: "Pet to add to the store",
required: true,
schema: {
$ref: "#/definitions/NewPet",
},
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "find pet by id",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
204: {
description: "pet deleted",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
allOf: [
{
$ref: "#/definitions/NewPet",
},
{
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Error: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
};
export { petstoreExpanded };

View File

@@ -1,61 +1,61 @@
import type { Specification } from "../../2.0";
const _petstoreMinimal: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
},
license: {
name: "MIT",
},
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to",
produces: ["application/json"],
responses: {
200: {
description: "A list of pets.",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
},
export const petstoreMinimal: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
},
license: {
name: "MIT",
},
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to",
produces: ["application/json"],
responses: {
200: {
description: "A list of pets.",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
},
};

View File

@@ -1,212 +1,212 @@
import type { Specification } from "../../2.0";
const _petstoreSimple: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
},
license: {
name: "MIT",
},
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to",
operationId: "findPets",
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
type: "array",
items: {
type: "string",
},
collectionFormat: "csv",
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "pet response",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
produces: ["application/json"],
parameters: [
{
name: "pet",
in: "body",
description: "Pet to add to the store",
required: true,
schema: {
$ref: "#/definitions/NewPet",
},
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "findPetById",
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
204: {
description: "pet deleted",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
allOf: [
{
$ref: "#/definitions/NewPet",
},
{
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
ErrorModel: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
export const petstoreSimple: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
},
license: {
name: "MIT",
},
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to",
operationId: "findPets",
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
type: "array",
items: {
type: "string",
},
collectionFormat: "csv",
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "pet response",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
produces: ["application/json"],
parameters: [
{
name: "pet",
in: "body",
description: "Pet to add to the store",
required: true,
schema: {
$ref: "#/definitions/NewPet",
},
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "findPetById",
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
204: {
description: "pet deleted",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
allOf: [
{
$ref: "#/definitions/NewPet",
},
{
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
ErrorModel: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
};

View File

@@ -1,223 +1,223 @@
import type { Specification } from "../../2.0";
const _petstoreWithExternalDocs: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
email: "apiteam@swagger.io",
url: "http://swagger.io",
},
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
externalDocs: {
description: "find more info here",
url: "https://swagger.io/about",
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to",
operationId: "findPets",
externalDocs: {
description: "find more info here",
url: "https://swagger.io/about",
},
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
type: "array",
items: {
type: "string",
},
collectionFormat: "csv",
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "pet response",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
produces: ["application/json"],
parameters: [
{
name: "pet",
in: "body",
description: "Pet to add to the store",
required: true,
schema: {
$ref: "#/definitions/NewPet",
},
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "findPetById",
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
204: {
description: "pet deleted",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
allOf: [
{
$ref: "#/definitions/NewPet",
},
{
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
ErrorModel: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
export const petstoreWithExternalDocs: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
email: "apiteam@swagger.io",
url: "http://swagger.io",
},
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
externalDocs: {
description: "find more info here",
url: "https://swagger.io/about",
},
host: "petstore.swagger.io",
basePath: "/api",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to",
operationId: "findPets",
externalDocs: {
description: "find more info here",
url: "https://swagger.io/about",
},
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
type: "array",
items: {
type: "string",
},
collectionFormat: "csv",
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "pet response",
schema: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
produces: ["application/json"],
parameters: [
{
name: "pet",
in: "body",
description: "Pet to add to the store",
required: true,
schema: {
$ref: "#/definitions/NewPet",
},
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "findPetById",
produces: [
"application/json",
"application/xml",
"text/xml",
"text/html",
],
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
200: {
description: "pet response",
schema: {
$ref: "#/definitions/Pet",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
type: "integer",
format: "int64",
},
],
responses: {
204: {
description: "pet deleted",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/ErrorModel",
},
},
},
},
},
},
definitions: {
Pet: {
type: "object",
allOf: [
{
$ref: "#/definitions/NewPet",
},
{
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
ErrorModel: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
};

View File

@@ -1,137 +1,137 @@
import type { Specification } from "../../2.0";
const _petstore: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
license: {
name: "MIT",
},
},
host: "petstore.swagger.io",
basePath: "/v1",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
summary: "List all pets",
operationId: "listPets",
tags: ["pets"],
parameters: [
{
name: "limit",
in: "query",
description: "How many items to return at one time (max 100)",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "An paged array of pets",
headers: {
"x-next": {
type: "string",
description: "A link to the next page of responses",
},
},
schema: {
$ref: "#/definitions/Pets",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
post: {
summary: "Create a pet",
operationId: "createPets",
tags: ["pets"],
responses: {
201: {
description: "Null response",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/pets/{petId}": {
get: {
summary: "Info for a specific pet",
operationId: "showPetById",
tags: ["pets"],
parameters: [
{
name: "petId",
in: "path",
required: true,
description: "The id of the pet to retrieve",
type: "string",
},
],
responses: {
200: {
description: "Expected response to a valid request",
schema: {
$ref: "#/definitions/Pets",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
},
definitions: {
Pet: {
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Pets: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
Error: {
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
export const petstore: Specification = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
license: {
name: "MIT",
},
},
host: "petstore.swagger.io",
basePath: "/v1",
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],
paths: {
"/pets": {
get: {
summary: "List all pets",
operationId: "listPets",
tags: ["pets"],
parameters: [
{
name: "limit",
in: "query",
description: "How many items to return at one time (max 100)",
required: false,
type: "integer",
format: "int32",
},
],
responses: {
200: {
description: "An paged array of pets",
headers: {
"x-next": {
type: "string",
description: "A link to the next page of responses",
},
},
schema: {
$ref: "#/definitions/Pets",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
post: {
summary: "Create a pet",
operationId: "createPets",
tags: ["pets"],
responses: {
201: {
description: "Null response",
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/pets/{petId}": {
get: {
summary: "Info for a specific pet",
operationId: "showPetById",
tags: ["pets"],
parameters: [
{
name: "petId",
in: "path",
required: true,
description: "The id of the pet to retrieve",
type: "string",
},
],
responses: {
200: {
description: "Expected response to a valid request",
schema: {
$ref: "#/definitions/Pets",
},
},
default: {
description: "unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
},
definitions: {
Pet: {
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Pets: {
type: "array",
items: {
$ref: "#/definitions/Pet",
},
},
Error: {
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
};

View File

@@ -1,372 +1,372 @@
import type { Specification } from "../../2.0";
const _uber: Specification = {
swagger: "2.0",
info: {
title: "Uber API",
description: "Move your app forward with the Uber API",
version: "1.0.0",
},
host: "api.uber.com",
schemes: ["https"],
basePath: "/v1",
produces: ["application/json"],
paths: {
"/products": {
get: {
summary: "Product Types",
description:
"The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.",
parameters: [
{
name: "latitude",
in: "query",
description: "Latitude component of location.",
required: true,
type: "number",
format: "double",
},
{
name: "longitude",
in: "query",
description: "Longitude component of location.",
required: true,
type: "number",
format: "double",
},
],
tags: ["Products"],
responses: {
200: {
description: "An array of products",
schema: {
type: "array",
items: {
$ref: "#/definitions/Product",
},
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/estimates/price": {
get: {
summary: "Price Estimates",
description:
"The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.<br><br>The response also includes low and high estimates, and the [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.",
parameters: [
{
name: "start_latitude",
in: "query",
description: "Latitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "start_longitude",
in: "query",
description: "Longitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "end_latitude",
in: "query",
description: "Latitude component of end location.",
required: true,
type: "number",
format: "double",
},
{
name: "end_longitude",
in: "query",
description: "Longitude component of end location.",
required: true,
type: "number",
format: "double",
},
],
tags: ["Estimates"],
responses: {
200: {
description: "An array of price estimates by product",
schema: {
type: "array",
items: {
$ref: "#/definitions/PriceEstimate",
},
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/estimates/time": {
get: {
summary: "Time Estimates",
description:
"The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.",
parameters: [
{
name: "start_latitude",
in: "query",
description: "Latitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "start_longitude",
in: "query",
description: "Longitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "customer_uuid",
in: "query",
type: "string",
format: "uuid",
description:
"Unique customer identifier to be used for experience customization.",
},
{
name: "product_id",
in: "query",
type: "string",
description:
"Unique identifier representing a specific product for a given latitude & longitude.",
},
],
tags: ["Estimates"],
responses: {
200: {
description: "An array of products",
schema: {
type: "array",
items: {
$ref: "#/definitions/Product",
},
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/me": {
get: {
summary: "User Profile",
description:
"The User Profile endpoint returns information about the Uber user that has authorized with the application.",
tags: ["User"],
responses: {
200: {
description: "Profile information for a user",
schema: {
$ref: "#/definitions/Profile",
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/history": {
get: {
summary: "User Activity",
description:
"The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.<br><br>The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.",
parameters: [
{
name: "offset",
in: "query",
type: "integer",
format: "int32",
description:
"Offset the list of returned results by this amount. Default is zero.",
},
{
name: "limit",
in: "query",
type: "integer",
format: "int32",
description:
"Number of items to retrieve. Default is 5, maximum is 100.",
},
],
tags: ["User"],
responses: {
200: {
description: "History information for the given user",
schema: {
$ref: "#/definitions/Activities",
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
},
definitions: {
Product: {
properties: {
product_id: {
type: "string",
description:
"Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles.",
},
description: {
type: "string",
description: "Description of product.",
},
display_name: {
type: "string",
description: "Display name of product.",
},
capacity: {
type: "string",
description: "Capacity of product. For example, 4 people.",
},
image: {
type: "string",
description: "Image URL representing the product.",
},
},
},
PriceEstimate: {
properties: {
product_id: {
type: "string",
description:
"Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles",
},
currency_code: {
type: "string",
description:
"[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code.",
},
display_name: {
type: "string",
description: "Display name of product.",
},
estimate: {
type: "string",
description:
'Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI.',
},
low_estimate: {
type: "number",
description: "Lower bound of the estimated price.",
},
high_estimate: {
type: "number",
description: "Upper bound of the estimated price.",
},
surge_multiplier: {
type: "number",
description:
"Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier.",
},
},
},
Profile: {
properties: {
first_name: {
type: "string",
description: "First name of the Uber user.",
},
last_name: {
type: "string",
description: "Last name of the Uber user.",
},
email: {
type: "string",
description: "Email address of the Uber user",
},
picture: {
type: "string",
description: "Image URL of the Uber user.",
},
promo_code: {
type: "string",
description: "Promo code of the Uber user.",
},
},
},
Activity: {
properties: {
uuid: {
type: "string",
description: "Unique identifier for the activity",
},
},
},
Activities: {
properties: {
offset: {
type: "integer",
format: "int32",
description: "Position in pagination.",
},
limit: {
type: "integer",
format: "int32",
description: "Number of items to retrieve (100 max).",
},
count: {
type: "integer",
format: "int32",
description: "Total number of items available.",
},
history: {
type: "array",
items: {
$ref: "#/definitions/Activity",
},
},
},
},
Error: {
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
fields: {
type: "string",
},
},
},
},
export const uber: Specification = {
swagger: "2.0",
info: {
title: "Uber API",
description: "Move your app forward with the Uber API",
version: "1.0.0",
},
host: "api.uber.com",
schemes: ["https"],
basePath: "/v1",
produces: ["application/json"],
paths: {
"/products": {
get: {
summary: "Product Types",
description:
"The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.",
parameters: [
{
name: "latitude",
in: "query",
description: "Latitude component of location.",
required: true,
type: "number",
format: "double",
},
{
name: "longitude",
in: "query",
description: "Longitude component of location.",
required: true,
type: "number",
format: "double",
},
],
tags: ["Products"],
responses: {
200: {
description: "An array of products",
schema: {
type: "array",
items: {
$ref: "#/definitions/Product",
},
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/estimates/price": {
get: {
summary: "Price Estimates",
description:
"The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.<br><br>The response also includes low and high estimates, and the [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.",
parameters: [
{
name: "start_latitude",
in: "query",
description: "Latitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "start_longitude",
in: "query",
description: "Longitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "end_latitude",
in: "query",
description: "Latitude component of end location.",
required: true,
type: "number",
format: "double",
},
{
name: "end_longitude",
in: "query",
description: "Longitude component of end location.",
required: true,
type: "number",
format: "double",
},
],
tags: ["Estimates"],
responses: {
200: {
description: "An array of price estimates by product",
schema: {
type: "array",
items: {
$ref: "#/definitions/PriceEstimate",
},
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/estimates/time": {
get: {
summary: "Time Estimates",
description:
"The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.",
parameters: [
{
name: "start_latitude",
in: "query",
description: "Latitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "start_longitude",
in: "query",
description: "Longitude component of start location.",
required: true,
type: "number",
format: "double",
},
{
name: "customer_uuid",
in: "query",
type: "string",
format: "uuid",
description:
"Unique customer identifier to be used for experience customization.",
},
{
name: "product_id",
in: "query",
type: "string",
description:
"Unique identifier representing a specific product for a given latitude & longitude.",
},
],
tags: ["Estimates"],
responses: {
200: {
description: "An array of products",
schema: {
type: "array",
items: {
$ref: "#/definitions/Product",
},
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/me": {
get: {
summary: "User Profile",
description:
"The User Profile endpoint returns information about the Uber user that has authorized with the application.",
tags: ["User"],
responses: {
200: {
description: "Profile information for a user",
schema: {
$ref: "#/definitions/Profile",
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
"/history": {
get: {
summary: "User Activity",
description:
"The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.<br><br>The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.",
parameters: [
{
name: "offset",
in: "query",
type: "integer",
format: "int32",
description:
"Offset the list of returned results by this amount. Default is zero.",
},
{
name: "limit",
in: "query",
type: "integer",
format: "int32",
description:
"Number of items to retrieve. Default is 5, maximum is 100.",
},
],
tags: ["User"],
responses: {
200: {
description: "History information for the given user",
schema: {
$ref: "#/definitions/Activities",
},
},
default: {
description: "Unexpected error",
schema: {
$ref: "#/definitions/Error",
},
},
},
},
},
},
definitions: {
Product: {
properties: {
product_id: {
type: "string",
description:
"Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles.",
},
description: {
type: "string",
description: "Description of product.",
},
display_name: {
type: "string",
description: "Display name of product.",
},
capacity: {
type: "string",
description: "Capacity of product. For example, 4 people.",
},
image: {
type: "string",
description: "Image URL representing the product.",
},
},
},
PriceEstimate: {
properties: {
product_id: {
type: "string",
description:
"Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles",
},
currency_code: {
type: "string",
description:
"[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code.",
},
display_name: {
type: "string",
description: "Display name of product.",
},
estimate: {
type: "string",
description:
'Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI.',
},
low_estimate: {
type: "number",
description: "Lower bound of the estimated price.",
},
high_estimate: {
type: "number",
description: "Upper bound of the estimated price.",
},
surge_multiplier: {
type: "number",
description:
"Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier.",
},
},
},
Profile: {
properties: {
first_name: {
type: "string",
description: "First name of the Uber user.",
},
last_name: {
type: "string",
description: "Last name of the Uber user.",
},
email: {
type: "string",
description: "Email address of the Uber user",
},
picture: {
type: "string",
description: "Image URL of the Uber user.",
},
promo_code: {
type: "string",
description: "Promo code of the Uber user.",
},
},
},
Activity: {
properties: {
uuid: {
type: "string",
description: "Unique identifier for the activity",
},
},
},
Activities: {
properties: {
offset: {
type: "integer",
format: "int32",
description: "Position in pagination.",
},
limit: {
type: "integer",
format: "int32",
description: "Number of items to retrieve (100 max).",
},
count: {
type: "integer",
format: "int32",
description: "Total number of items available.",
},
history: {
type: "array",
items: {
$ref: "#/definitions/Activity",
},
},
},
},
Error: {
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
fields: {
type: "string",
},
},
},
},
};

View File

@@ -1,194 +1,194 @@
import type { Specification } from "../../3.0";
const _apiWithExamples: Specification = {
openapi: "3.0.0",
info: {
title: "Simple API overview",
version: "2.0.0",
},
paths: {
"/": {
get: {
operationId: "listVersionsv2",
summary: "List API versions",
responses: {
"200": {
description: "200 response",
content: {
"application/json": {
examples: {
foo: {
value: {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [
{
href: "http://127.0.0.1:8774/v2/",
rel: "self",
},
],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [
{
href: "http://127.0.0.1:8774/v3/",
rel: "self",
},
],
},
],
},
},
},
},
},
},
"300": {
description: "300 response",
content: {
"application/json": {
examples: {
foo: {
value: {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [
{
href: "http://127.0.0.1:8774/v2/",
rel: "self",
},
],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [
{
href: "http://127.0.0.1:8774/v3/",
rel: "self",
},
],
},
],
},
},
},
},
},
},
},
},
},
"/v2": {
get: {
operationId: "getVersionDetailsv2",
summary: "Show API version details",
responses: {
"200": {
description: "200 response",
content: {
"application/json": {
examples: {
foo: {
value: {
version: {
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
"media-types": [
{
base: "application/xml",
type: "application/vnd.openstack.compute+xml;version=2",
},
{
base: "application/json",
type: "application/vnd.openstack.compute+json;version=2",
},
],
id: "v2.0",
links: [
{
href: "http://127.0.0.1:8774/v2/",
rel: "self",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
},
},
},
"203": {
description: "203 response",
content: {
"application/json": {
examples: {
foo: {
value: {
version: {
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
"media-types": [
{
base: "application/xml",
type: "application/vnd.openstack.compute+xml;version=2",
},
{
base: "application/json",
type: "application/vnd.openstack.compute+json;version=2",
},
],
id: "v2.0",
links: [
{
href: "http://23.253.228.211:8774/v2/",
rel: "self",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
},
},
},
},
},
},
},
export const apiWithExamples: Specification = {
openapi: "3.0.0",
info: {
title: "Simple API overview",
version: "2.0.0",
},
paths: {
"/": {
get: {
operationId: "listVersionsv2",
summary: "List API versions",
responses: {
"200": {
description: "200 response",
content: {
"application/json": {
examples: {
foo: {
value: {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [
{
href: "http://127.0.0.1:8774/v2/",
rel: "self",
},
],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [
{
href: "http://127.0.0.1:8774/v3/",
rel: "self",
},
],
},
],
},
},
},
},
},
},
"300": {
description: "300 response",
content: {
"application/json": {
examples: {
foo: {
value: {
versions: [
{
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
id: "v2.0",
links: [
{
href: "http://127.0.0.1:8774/v2/",
rel: "self",
},
],
},
{
status: "EXPERIMENTAL",
updated: "2013-07-23T11:33:21Z",
id: "v3.0",
links: [
{
href: "http://127.0.0.1:8774/v3/",
rel: "self",
},
],
},
],
},
},
},
},
},
},
},
},
},
"/v2": {
get: {
operationId: "getVersionDetailsv2",
summary: "Show API version details",
responses: {
"200": {
description: "200 response",
content: {
"application/json": {
examples: {
foo: {
value: {
version: {
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
"media-types": [
{
base: "application/xml",
type: "application/vnd.openstack.compute+xml;version=2",
},
{
base: "application/json",
type: "application/vnd.openstack.compute+json;version=2",
},
],
id: "v2.0",
links: [
{
href: "http://127.0.0.1:8774/v2/",
rel: "self",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
},
},
},
"203": {
description: "203 response",
content: {
"application/json": {
examples: {
foo: {
value: {
version: {
status: "CURRENT",
updated: "2011-01-21T11:33:21Z",
"media-types": [
{
base: "application/xml",
type: "application/vnd.openstack.compute+xml;version=2",
},
{
base: "application/json",
type: "application/vnd.openstack.compute+json;version=2",
},
],
id: "v2.0",
links: [
{
href: "http://23.253.228.211:8774/v2/",
rel: "self",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
type: "application/pdf",
rel: "describedby",
},
{
href: "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
type: "application/vnd.sun.wadl+xml",
rel: "describedby",
},
],
},
},
},
},
},
},
},
},
},
},
},
};

View File

@@ -1,88 +1,88 @@
import type { Specification } from "../../3.0";
const _callbackExample: Specification = {
openapi: "3.0.0",
info: {
title: "Callback Example",
version: "1.0.0",
},
paths: {
"/streams": {
post: {
description: "subscribes a client to receive out-of-band data",
parameters: [
{
name: "callbackUrl",
in: "query",
required: true,
description:
"the location where data will be sent. Must be network accessible\nby the source server\n",
schema: {
type: "string",
format: "uri",
example: "https://tonys-server.com",
},
},
],
responses: {
"201": {
description: "subscription successfully created",
content: {
"application/json": {
schema: {
description: "subscription information",
required: ["subscriptionId"],
properties: {
subscriptionId: {
description:
"this unique identifier allows management of the subscription",
type: "string",
example: "2531329f-fb09-4ef7-887e-84e648214436",
},
},
},
},
},
},
},
callbacks: {
onData: {
"{$request.query.callbackUrl}/data": {
post: {
requestBody: {
description: "subscription payload",
content: {
"application/json": {
schema: {
type: "object",
properties: {
timestamp: {
type: "string",
format: "date-time",
},
userData: {
type: "string",
},
},
},
},
},
},
responses: {
"202": {
description:
"Your server implementation should return this HTTP status code\nif the data was received successfully\n",
},
"204": {
description:
"Your server should return this HTTP status code if no longer interested\nin further updates\n",
},
},
},
},
},
},
},
},
},
export const callbackExample: Specification = {
openapi: "3.0.0",
info: {
title: "Callback Example",
version: "1.0.0",
},
paths: {
"/streams": {
post: {
description: "subscribes a client to receive out-of-band data",
parameters: [
{
name: "callbackUrl",
in: "query",
required: true,
description:
"the location where data will be sent. Must be network accessible\nby the source server\n",
schema: {
type: "string",
format: "uri",
example: "https://tonys-server.com",
},
},
],
responses: {
"201": {
description: "subscription successfully created",
content: {
"application/json": {
schema: {
description: "subscription information",
required: ["subscriptionId"],
properties: {
subscriptionId: {
description:
"this unique identifier allows management of the subscription",
type: "string",
example: "2531329f-fb09-4ef7-887e-84e648214436",
},
},
},
},
},
},
},
callbacks: {
onData: {
"{$request.query.callbackUrl}/data": {
post: {
requestBody: {
description: "subscription payload",
content: {
"application/json": {
schema: {
type: "object",
properties: {
timestamp: {
type: "string",
format: "date-time",
},
userData: {
type: "string",
},
},
},
},
},
},
responses: {
"202": {
description:
"Your server implementation should return this HTTP status code\nif the data was received successfully\n",
},
"204": {
description:
"Your server should return this HTTP status code if no longer interested\nin further updates\n",
},
},
},
},
},
},
},
},
},
};

View File

@@ -1,321 +1,321 @@
import type { Specification } from "../../3.0";
const _linkExample: Specification = {
openapi: "3.0.0",
info: {
title: "Link Example",
version: "1.0.0",
},
paths: {
"/2.0/users/{username}": {
get: {
operationId: "getUserByName",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "The User",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user",
},
},
},
links: {
userRepositories: {
$ref: "#/components/links/UserRepositories",
},
},
},
},
},
},
"/2.0/repositories/{username}": {
get: {
operationId: "getRepositoriesByOwner",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "repositories owned by the supplied user",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/repository",
},
},
},
},
links: {
userRepository: {
$ref: "#/components/links/UserRepository",
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}": {
get: {
operationId: "getRepository",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "The repository",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/repository",
},
},
},
links: {
repositoryPullRequests: {
$ref: "#/components/links/RepositoryPullRequests",
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}/pullrequests": {
get: {
operationId: "getPullRequestsByRepository",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "state",
in: "query",
schema: {
type: "string",
enum: ["open", "merged", "declined"],
},
},
],
responses: {
"200": {
description: "an array of pull request objects",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/pullrequest",
},
},
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}/pullrequests/{pid}": {
get: {
operationId: "getPullRequestsById",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "pid",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "a pull request object",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/pullrequest",
},
},
},
links: {
pullRequestMerge: {
$ref: "#/components/links/PullRequestMerge",
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge": {
post: {
operationId: "mergePullRequest",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "pid",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"204": {
description: "the PR was successfully merged",
},
},
},
},
},
components: {
links: {
UserRepositories: {
operationId: "getRepositoriesByOwner",
parameters: {
username: "$response.body#/username",
},
},
UserRepository: {
operationId: "getRepository",
parameters: {
username: "$response.body#/owner/username",
slug: "$response.body#/slug",
},
},
RepositoryPullRequests: {
operationId: "getPullRequestsByRepository",
parameters: {
username: "$response.body#/owner/username",
slug: "$response.body#/slug",
},
},
PullRequestMerge: {
operationId: "mergePullRequest",
parameters: {
username: "$response.body#/author/username",
slug: "$response.body#/repository/slug",
pid: "$response.body#/id",
},
},
},
schemas: {
user: {
type: "object",
properties: {
username: {
type: "string",
},
uuid: {
type: "string",
},
},
},
repository: {
type: "object",
properties: {
slug: {
type: "string",
},
owner: {
$ref: "#/components/schemas/user",
},
},
},
pullrequest: {
type: "object",
properties: {
id: {
type: "integer",
},
title: {
type: "string",
},
repository: {
$ref: "#/components/schemas/repository",
},
author: {
$ref: "#/components/schemas/user",
},
},
},
},
},
export const linkExample: Specification = {
openapi: "3.0.0",
info: {
title: "Link Example",
version: "1.0.0",
},
paths: {
"/2.0/users/{username}": {
get: {
operationId: "getUserByName",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "The User",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user",
},
},
},
links: {
userRepositories: {
$ref: "#/components/links/UserRepositories",
},
},
},
},
},
},
"/2.0/repositories/{username}": {
get: {
operationId: "getRepositoriesByOwner",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "repositories owned by the supplied user",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/repository",
},
},
},
},
links: {
userRepository: {
$ref: "#/components/links/UserRepository",
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}": {
get: {
operationId: "getRepository",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "The repository",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/repository",
},
},
},
links: {
repositoryPullRequests: {
$ref: "#/components/links/RepositoryPullRequests",
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}/pullrequests": {
get: {
operationId: "getPullRequestsByRepository",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "state",
in: "query",
schema: {
type: "string",
enum: ["open", "merged", "declined"],
},
},
],
responses: {
"200": {
description: "an array of pull request objects",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/pullrequest",
},
},
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}/pullrequests/{pid}": {
get: {
operationId: "getPullRequestsById",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "pid",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "a pull request object",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/pullrequest",
},
},
},
links: {
pullRequestMerge: {
$ref: "#/components/links/PullRequestMerge",
},
},
},
},
},
},
"/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge": {
post: {
operationId: "mergePullRequest",
parameters: [
{
name: "username",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "slug",
in: "path",
required: true,
schema: {
type: "string",
},
},
{
name: "pid",
in: "path",
required: true,
schema: {
type: "string",
},
},
],
responses: {
"204": {
description: "the PR was successfully merged",
},
},
},
},
},
components: {
links: {
UserRepositories: {
operationId: "getRepositoriesByOwner",
parameters: {
username: "$response.body#/username",
},
},
UserRepository: {
operationId: "getRepository",
parameters: {
username: "$response.body#/owner/username",
slug: "$response.body#/slug",
},
},
RepositoryPullRequests: {
operationId: "getPullRequestsByRepository",
parameters: {
username: "$response.body#/owner/username",
slug: "$response.body#/slug",
},
},
PullRequestMerge: {
operationId: "mergePullRequest",
parameters: {
username: "$response.body#/author/username",
slug: "$response.body#/repository/slug",
pid: "$response.body#/id",
},
},
},
schemas: {
user: {
type: "object",
properties: {
username: {
type: "string",
},
uuid: {
type: "string",
},
},
},
repository: {
type: "object",
properties: {
slug: {
type: "string",
},
owner: {
$ref: "#/components/schemas/user",
},
},
},
pullrequest: {
type: "object",
properties: {
id: {
type: "integer",
},
title: {
type: "string",
},
repository: {
$ref: "#/components/schemas/repository",
},
author: {
$ref: "#/components/schemas/user",
},
},
},
},
},
};

View File

@@ -1,240 +1,240 @@
import type { Specification } from "../../3.0";
const _petstoreExpanded: Specification = {
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
email: "apiteam@swagger.io",
url: "http://swagger.io",
},
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
servers: [
{
url: "https://petstore.swagger.io/v2",
},
],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
operationId: "findPets",
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
style: "form",
schema: {
type: "array",
items: {
type: "string",
},
},
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
schema: {
type: "integer",
format: "int32",
},
},
],
responses: {
"200": {
description: "pet response",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/Pet",
},
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
requestBody: {
description: "Pet to add to the store",
required: true,
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/NewPet",
},
},
},
},
responses: {
"200": {
description: "pet response",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "find pet by id",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
schema: {
type: "integer",
format: "int64",
},
},
],
responses: {
"200": {
description: "pet response",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
schema: {
type: "integer",
format: "int64",
},
},
],
responses: {
"204": {
description: "pet deleted",
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
components: {
schemas: {
Pet: {
allOf: [
{
$ref: "#/components/schemas/NewPet",
},
{
type: "object",
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Error: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
},
export const petstoreExpanded: Specification = {
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
description:
"A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification",
termsOfService: "http://swagger.io/terms/",
contact: {
name: "Swagger API Team",
email: "apiteam@swagger.io",
url: "http://swagger.io",
},
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
servers: [
{
url: "https://petstore.swagger.io/v2",
},
],
paths: {
"/pets": {
get: {
description:
"Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
operationId: "findPets",
parameters: [
{
name: "tags",
in: "query",
description: "tags to filter by",
required: false,
style: "form",
schema: {
type: "array",
items: {
type: "string",
},
},
},
{
name: "limit",
in: "query",
description: "maximum number of results to return",
required: false,
schema: {
type: "integer",
format: "int32",
},
},
],
responses: {
"200": {
description: "pet response",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/Pet",
},
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
post: {
description: "Creates a new pet in the store. Duplicates are allowed",
operationId: "addPet",
requestBody: {
description: "Pet to add to the store",
required: true,
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/NewPet",
},
},
},
},
responses: {
"200": {
description: "pet response",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
"/pets/{id}": {
get: {
description:
"Returns a user based on a single ID, if the user does not have access to the pet",
operationId: "find pet by id",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to fetch",
required: true,
schema: {
type: "integer",
format: "int64",
},
},
],
responses: {
"200": {
description: "pet response",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
delete: {
description: "deletes a single pet based on the ID supplied",
operationId: "deletePet",
parameters: [
{
name: "id",
in: "path",
description: "ID of pet to delete",
required: true,
schema: {
type: "integer",
format: "int64",
},
},
],
responses: {
"204": {
description: "pet deleted",
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
components: {
schemas: {
Pet: {
allOf: [
{
$ref: "#/components/schemas/NewPet",
},
{
type: "object",
required: ["id"],
properties: {
id: {
type: "integer",
format: "int64",
},
},
},
],
},
NewPet: {
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Error: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
},
};

View File

@@ -1,179 +1,179 @@
import type { Specification } from "../../3.0";
const _petstore: Specification = {
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
license: {
name: "MIT",
},
},
servers: [
{
url: "http://petstore.swagger.io/v1",
},
],
paths: {
"/pets": {
get: {
summary: "List all pets",
operationId: "listPets",
tags: ["pets"],
parameters: [
{
name: "limit",
in: "query",
description: "How many items to return at one time (max 100)",
required: false,
schema: {
type: "integer",
maximum: 100,
format: "int32",
},
},
],
responses: {
"200": {
description: "A paged array of pets",
headers: {
"x-next": {
description: "A link to the next page of responses",
schema: {
type: "string",
},
},
},
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pets",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
post: {
summary: "Create a pet",
operationId: "createPets",
tags: ["pets"],
requestBody: {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
required: true,
},
responses: {
"201": {
description: "Null response",
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
"/pets/{petId}": {
get: {
summary: "Info for a specific pet",
operationId: "showPetById",
tags: ["pets"],
parameters: [
{
name: "petId",
in: "path",
required: true,
description: "The id of the pet to retrieve",
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "Expected response to a valid request",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
components: {
schemas: {
Pet: {
type: "object",
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Pets: {
type: "array",
maxItems: 100,
items: {
$ref: "#/components/schemas/Pet",
},
},
Error: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
},
export const petstore: Specification = {
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "Swagger Petstore",
license: {
name: "MIT",
},
},
servers: [
{
url: "http://petstore.swagger.io/v1",
},
],
paths: {
"/pets": {
get: {
summary: "List all pets",
operationId: "listPets",
tags: ["pets"],
parameters: [
{
name: "limit",
in: "query",
description: "How many items to return at one time (max 100)",
required: false,
schema: {
type: "integer",
maximum: 100,
format: "int32",
},
},
],
responses: {
"200": {
description: "A paged array of pets",
headers: {
"x-next": {
description: "A link to the next page of responses",
schema: {
type: "string",
},
},
},
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pets",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
post: {
summary: "Create a pet",
operationId: "createPets",
tags: ["pets"],
requestBody: {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
required: true,
},
responses: {
"201": {
description: "Null response",
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
"/pets/{petId}": {
get: {
summary: "Info for a specific pet",
operationId: "showPetById",
tags: ["pets"],
parameters: [
{
name: "petId",
in: "path",
required: true,
description: "The id of the pet to retrieve",
schema: {
type: "string",
},
},
],
responses: {
"200": {
description: "Expected response to a valid request",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
default: {
description: "unexpected error",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
components: {
schemas: {
Pet: {
type: "object",
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
Pets: {
type: "array",
maxItems: 100,
items: {
$ref: "#/components/schemas/Pet",
},
},
Error: {
type: "object",
required: ["code", "message"],
properties: {
code: {
type: "integer",
format: "int32",
},
message: {
type: "string",
},
},
},
},
},
};

View File

@@ -1,257 +1,257 @@
import type { Specification } from "../../3.0";
const _uspto: Specification = {
openapi: "3.0.1",
servers: [
{
url: "{scheme}://developer.uspto.gov/ds-api",
variables: {
scheme: {
description: "The Data Set API is accessible via https and http",
enum: ["https", "http"],
default: "https",
},
},
},
],
info: {
description:
"The Data Set API (DSAPI) allows the public users to discover and search USPTO exported data sets. This is a generic API that allows USPTO users to make any CSV based data files searchable through API. With the help of GET call, it returns the list of data fields that are searchable. With the help of POST call, data can be fetched based on the filters on the field names. Please note that POST call is used to search the actual data. The reason for the POST call is that it allows users to specify any complex search criteria without worry about the GET size limitations as well as encoding of the input parameters.",
version: "1.0.0",
title: "USPTO Data Set API",
contact: {
name: "Open Data Portal",
url: "https://developer.uspto.gov",
email: "developer@uspto.gov",
},
},
tags: [
{
name: "metadata",
description: "Find out about the data sets",
},
{
name: "search",
description: "Search a data set",
},
],
paths: {
"/": {
get: {
tags: ["metadata"],
operationId: "list-data-sets",
summary: "List available data sets",
responses: {
"200": {
description: "Returns a list of data sets",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/dataSetList",
},
example: {
total: 2,
apis: [
{
apiKey: "oa_citations",
apiVersionNumber: "v1",
apiUrl:
"https://developer.uspto.gov/ds-api/oa_citations/v1/fields",
apiDocumentationUrl:
"https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json",
},
{
apiKey: "cancer_moonshot",
apiVersionNumber: "v1",
apiUrl:
"https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields",
apiDocumentationUrl:
"https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json",
},
],
},
},
},
},
},
},
},
"/{dataset}/{version}/fields": {
get: {
tags: ["metadata"],
summary:
"Provides the general information about the API and the list of fields that can be used to query the dataset.",
description:
"This GET API returns the list of all the searchable field names that are in the oa_citations. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the syntax options shown below.",
operationId: "list-searchable-fields",
parameters: [
{
name: "dataset",
in: "path",
description: "Name of the dataset.",
required: true,
example: "oa_citations",
schema: {
type: "string",
},
},
{
name: "version",
in: "path",
description: "Version of the dataset.",
required: true,
example: "v1",
schema: {
type: "string",
},
},
],
responses: {
"200": {
description:
"The dataset API for the given version is found and it is accessible to consume.",
content: {
"application/json": {
schema: {
type: "string",
},
},
},
},
"404": {
description:
"The combination of dataset name and version is not found in the system or it is not published yet to be consumed by public.",
content: {
"application/json": {
schema: {
type: "string",
},
},
},
},
},
},
},
"/{dataset}/{version}/records": {
post: {
tags: ["search"],
summary:
"Provides search capability for the data set with the given search criteria.",
description:
"This API is based on Solr/Lucene Search. The data is indexed using SOLR. This GET API returns the list of all the searchable field names that are in the Solr Index. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the Solr/Lucene Syntax. Please refer https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for the query syntax. List of field names that are searchable can be determined using above GET api.",
operationId: "perform-search",
parameters: [
{
name: "version",
in: "path",
description: "Version of the dataset.",
required: true,
schema: {
type: "string",
default: "v1",
},
},
{
name: "dataset",
in: "path",
description:
"Name of the dataset. In this case, the default value is oa_citations",
required: true,
schema: {
type: "string",
default: "oa_citations",
},
},
],
responses: {
"200": {
description: "successful operation",
content: {
"application/json": {
schema: {
type: "array",
items: {
type: "object",
additionalProperties: {
type: "object",
},
},
},
},
},
},
"404": {
description: "No matching record found for the given criteria.",
},
},
requestBody: {
content: {
"application/x-www-form-urlencoded": {
schema: {
type: "object",
properties: {
criteria: {
description:
"Uses Lucene Query Syntax in the format of propertyName:value, propertyName:[num1 TO num2] and date range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the response please see the 'docs' element which has the list of record objects. Each record structure would consist of all the fields and their corresponding values.",
type: "string",
default: "*:*",
},
start: {
description: "Starting record number. Default value is 0.",
type: "integer",
default: 0,
},
rows: {
description:
"Specify number of rows to be returned. If you run the search with default values, in the response you will see 'numFound' attribute which will tell the number of records available in the dataset.",
type: "integer",
default: 100,
},
},
required: ["criteria"],
},
},
},
},
},
},
},
components: {
schemas: {
dataSetList: {
type: "object",
properties: {
total: {
type: "integer",
},
apis: {
type: "array",
items: {
type: "object",
properties: {
apiKey: {
type: "string",
description: "To be used as a dataset parameter value",
},
apiVersionNumber: {
type: "string",
description: "To be used as a version parameter value",
},
apiUrl: {
type: "string",
format: "uriref",
description: "The URL describing the dataset's fields",
},
apiDocumentationUrl: {
type: "string",
format: "uriref",
description: "A URL to the API console for each API",
},
},
},
},
},
},
},
},
export const uspto: Specification = {
openapi: "3.0.1",
servers: [
{
url: "{scheme}://developer.uspto.gov/ds-api",
variables: {
scheme: {
description: "The Data Set API is accessible via https and http",
enum: ["https", "http"],
default: "https",
},
},
},
],
info: {
description:
"The Data Set API (DSAPI) allows the public users to discover and search USPTO exported data sets. This is a generic API that allows USPTO users to make any CSV based data files searchable through API. With the help of GET call, it returns the list of data fields that are searchable. With the help of POST call, data can be fetched based on the filters on the field names. Please note that POST call is used to search the actual data. The reason for the POST call is that it allows users to specify any complex search criteria without worry about the GET size limitations as well as encoding of the input parameters.",
version: "1.0.0",
title: "USPTO Data Set API",
contact: {
name: "Open Data Portal",
url: "https://developer.uspto.gov",
email: "developer@uspto.gov",
},
},
tags: [
{
name: "metadata",
description: "Find out about the data sets",
},
{
name: "search",
description: "Search a data set",
},
],
paths: {
"/": {
get: {
tags: ["metadata"],
operationId: "list-data-sets",
summary: "List available data sets",
responses: {
"200": {
description: "Returns a list of data sets",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/dataSetList",
},
example: {
total: 2,
apis: [
{
apiKey: "oa_citations",
apiVersionNumber: "v1",
apiUrl:
"https://developer.uspto.gov/ds-api/oa_citations/v1/fields",
apiDocumentationUrl:
"https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json",
},
{
apiKey: "cancer_moonshot",
apiVersionNumber: "v1",
apiUrl:
"https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields",
apiDocumentationUrl:
"https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json",
},
],
},
},
},
},
},
},
},
"/{dataset}/{version}/fields": {
get: {
tags: ["metadata"],
summary:
"Provides the general information about the API and the list of fields that can be used to query the dataset.",
description:
"This GET API returns the list of all the searchable field names that are in the oa_citations. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the syntax options shown below.",
operationId: "list-searchable-fields",
parameters: [
{
name: "dataset",
in: "path",
description: "Name of the dataset.",
required: true,
example: "oa_citations",
schema: {
type: "string",
},
},
{
name: "version",
in: "path",
description: "Version of the dataset.",
required: true,
example: "v1",
schema: {
type: "string",
},
},
],
responses: {
"200": {
description:
"The dataset API for the given version is found and it is accessible to consume.",
content: {
"application/json": {
schema: {
type: "string",
},
},
},
},
"404": {
description:
"The combination of dataset name and version is not found in the system or it is not published yet to be consumed by public.",
content: {
"application/json": {
schema: {
type: "string",
},
},
},
},
},
},
},
"/{dataset}/{version}/records": {
post: {
tags: ["search"],
summary:
"Provides search capability for the data set with the given search criteria.",
description:
"This API is based on Solr/Lucene Search. The data is indexed using SOLR. This GET API returns the list of all the searchable field names that are in the Solr Index. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the Solr/Lucene Syntax. Please refer https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for the query syntax. List of field names that are searchable can be determined using above GET api.",
operationId: "perform-search",
parameters: [
{
name: "version",
in: "path",
description: "Version of the dataset.",
required: true,
schema: {
type: "string",
default: "v1",
},
},
{
name: "dataset",
in: "path",
description:
"Name of the dataset. In this case, the default value is oa_citations",
required: true,
schema: {
type: "string",
default: "oa_citations",
},
},
],
responses: {
"200": {
description: "successful operation",
content: {
"application/json": {
schema: {
type: "array",
items: {
type: "object",
additionalProperties: {
type: "object",
},
},
},
},
},
},
"404": {
description: "No matching record found for the given criteria.",
},
},
requestBody: {
content: {
"application/x-www-form-urlencoded": {
schema: {
type: "object",
properties: {
criteria: {
description:
"Uses Lucene Query Syntax in the format of propertyName:value, propertyName:[num1 TO num2] and date range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the response please see the 'docs' element which has the list of record objects. Each record structure would consist of all the fields and their corresponding values.",
type: "string",
default: "*:*",
},
start: {
description: "Starting record number. Default value is 0.",
type: "integer",
default: 0,
},
rows: {
description:
"Specify number of rows to be returned. If you run the search with default values, in the response you will see 'numFound' attribute which will tell the number of records available in the dataset.",
type: "integer",
default: 100,
},
},
required: ["criteria"],
},
},
},
},
},
},
},
components: {
schemas: {
dataSetList: {
type: "object",
properties: {
total: {
type: "integer",
},
apis: {
type: "array",
items: {
type: "object",
properties: {
apiKey: {
type: "string",
description: "To be used as a dataset parameter value",
},
apiVersionNumber: {
type: "string",
description: "To be used as a version parameter value",
},
apiUrl: {
type: "string",
format: "uriref",
description: "The URL describing the dataset's fields",
},
apiDocumentationUrl: {
type: "string",
format: "uriref",
description: "A URL to the API console for each API",
},
},
},
},
},
},
},
},
};

View File

@@ -1,34 +1,34 @@
import type { Specification } from "../../3.1";
const _nonOauthScopes: Specification = {
openapi: "3.1.0",
info: {
title: "Non-oAuth Scopes example",
version: "1.0.0",
},
paths: {
"/users": {
//@ts-expect-error This is an example specification from OpenAPI,
// it seems to intentionally not conform to the specification,
// as its meant to be a minimal example.
get: {
security: [
{
bearerAuth: ["read:users", "public"],
},
],
},
},
},
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "jwt",
description:
"note: non-oauth scopes are not defined at the securityScheme level",
},
},
},
export const nonOauthScopes: Specification = {
openapi: "3.1.0",
info: {
title: "Non-oAuth Scopes example",
version: "1.0.0",
},
paths: {
"/users": {
//@ts-expect-error This is an example specification from OpenAPI,
// it seems to intentionally not conform to the specification,
// as its meant to be a minimal example.
get: {
security: [
{
bearerAuth: ["read:users", "public"],
},
],
},
},
},
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "jwt",
description:
"note: non-oauth scopes are not defined at the securityScheme level",
},
},
},
};

View File

@@ -1,266 +1,266 @@
import type { Specification } from "../../3.1";
const _tictactoe: Specification = {
openapi: "3.1.0",
info: {
title: "Tic Tac Toe",
description:
"This API allows writing down marks on a Tic Tac Toe board\nand requesting the state of the board or of individual squares.\n",
version: "1.0.0",
},
tags: [
{
name: "Gameplay",
},
],
paths: {
"/board": {
get: {
summary: "Get the whole board",
description: "Retrieves the current state of the board and the winner.",
tags: ["Gameplay"],
operationId: "get-board",
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/status",
},
},
},
},
},
security: [
{
defaultApiKey: [],
},
{
app2AppOauth: ["board:read"],
},
],
},
},
"/board/{row}/{column}": {
parameters: [
{
$ref: "#/components/parameters/rowParam",
},
{
$ref: "#/components/parameters/columnParam",
},
],
get: {
summary: "Get a single board square",
description: "Retrieves the requested square.",
tags: ["Gameplay"],
operationId: "get-square",
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/mark",
},
},
},
},
"400": {
description: "The provided parameters are incorrect",
content: {
"text/html": {
schema: {
$ref: "#/components/schemas/errorMessage",
},
example: "Illegal coordinates",
},
},
},
},
security: [
{
bearerHttpAuthentication: [],
},
{
user2AppOauth: ["board:read"],
},
],
},
put: {
summary: "Set a single board square",
description:
"Places a mark on the board and retrieves the whole board and the winner (if any).",
tags: ["Gameplay"],
operationId: "put-square",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/mark",
},
},
},
},
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/status",
},
},
},
},
"400": {
description: "The provided parameters are incorrect",
content: {
"text/html": {
schema: {
$ref: "#/components/schemas/errorMessage",
},
examples: {
illegalCoordinates: {
value: "Illegal coordinates.",
},
notEmpty: {
value: "Square is not empty.",
},
invalidMark: {
value: "Invalid Mark (X or O).",
},
},
},
},
},
},
security: [
{
bearerHttpAuthentication: [],
},
{
user2AppOauth: ["board:write"],
},
],
},
},
},
components: {
parameters: {
rowParam: {
description: "Board row (vertical coordinate)",
name: "row",
in: "path",
required: true,
schema: {
$ref: "#/components/schemas/coordinate",
},
},
columnParam: {
description: "Board column (horizontal coordinate)",
name: "column",
in: "path",
required: true,
schema: {
$ref: "#/components/schemas/coordinate",
},
},
},
schemas: {
errorMessage: {
type: "string",
maxLength: 256,
description: "A text message describing an error",
},
coordinate: {
type: "integer",
minimum: 1,
maximum: 3,
example: 1,
},
mark: {
type: "string",
enum: [".", "X", "O"],
description:
"Possible values for a board square. `.` means empty square.",
example: ".",
},
board: {
type: "array",
maxItems: 3,
minItems: 3,
items: {
type: "array",
maxItems: 3,
minItems: 3,
items: {
$ref: "#/components/schemas/mark",
},
},
},
winner: {
type: "string",
enum: [".", "X", "O"],
description: "Winner of the game. `.` means nobody has won yet.",
example: ".",
},
status: {
type: "object",
properties: {
winner: {
$ref: "#/components/schemas/winner",
},
board: {
$ref: "#/components/schemas/board",
},
},
},
},
securitySchemes: {
defaultApiKey: {
description: "API key provided in console",
type: "apiKey",
name: "api-key",
in: "header",
},
basicHttpAuthentication: {
description: "Basic HTTP Authentication",
type: "http",
scheme: "Basic",
},
bearerHttpAuthentication: {
description: "Bearer token using a JWT",
type: "http",
scheme: "Bearer",
bearerFormat: "JWT",
},
app2AppOauth: {
type: "oauth2",
flows: {
clientCredentials: {
tokenUrl: "https://learn.openapis.org/oauth/2.0/token",
scopes: {
"board:read": "Read the board",
},
},
},
},
user2AppOauth: {
type: "oauth2",
flows: {
authorizationCode: {
authorizationUrl: "https://learn.openapis.org/oauth/2.0/auth",
tokenUrl: "https://learn.openapis.org/oauth/2.0/token",
scopes: {
"board:read": "Read the board",
"board:write": "Write to the board",
},
},
},
},
},
},
export const tictactoe: Specification = {
openapi: "3.1.0",
info: {
title: "Tic Tac Toe",
description:
"This API allows writing down marks on a Tic Tac Toe board\nand requesting the state of the board or of individual squares.\n",
version: "1.0.0",
},
tags: [
{
name: "Gameplay",
},
],
paths: {
"/board": {
get: {
summary: "Get the whole board",
description: "Retrieves the current state of the board and the winner.",
tags: ["Gameplay"],
operationId: "get-board",
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/status",
},
},
},
},
},
security: [
{
defaultApiKey: [],
},
{
app2AppOauth: ["board:read"],
},
],
},
},
"/board/{row}/{column}": {
parameters: [
{
$ref: "#/components/parameters/rowParam",
},
{
$ref: "#/components/parameters/columnParam",
},
],
get: {
summary: "Get a single board square",
description: "Retrieves the requested square.",
tags: ["Gameplay"],
operationId: "get-square",
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/mark",
},
},
},
},
"400": {
description: "The provided parameters are incorrect",
content: {
"text/html": {
schema: {
$ref: "#/components/schemas/errorMessage",
},
example: "Illegal coordinates",
},
},
},
},
security: [
{
bearerHttpAuthentication: [],
},
{
user2AppOauth: ["board:read"],
},
],
},
put: {
summary: "Set a single board square",
description:
"Places a mark on the board and retrieves the whole board and the winner (if any).",
tags: ["Gameplay"],
operationId: "put-square",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/mark",
},
},
},
},
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/status",
},
},
},
},
"400": {
description: "The provided parameters are incorrect",
content: {
"text/html": {
schema: {
$ref: "#/components/schemas/errorMessage",
},
examples: {
illegalCoordinates: {
value: "Illegal coordinates.",
},
notEmpty: {
value: "Square is not empty.",
},
invalidMark: {
value: "Invalid Mark (X or O).",
},
},
},
},
},
},
security: [
{
bearerHttpAuthentication: [],
},
{
user2AppOauth: ["board:write"],
},
],
},
},
},
components: {
parameters: {
rowParam: {
description: "Board row (vertical coordinate)",
name: "row",
in: "path",
required: true,
schema: {
$ref: "#/components/schemas/coordinate",
},
},
columnParam: {
description: "Board column (horizontal coordinate)",
name: "column",
in: "path",
required: true,
schema: {
$ref: "#/components/schemas/coordinate",
},
},
},
schemas: {
errorMessage: {
type: "string",
maxLength: 256,
description: "A text message describing an error",
},
coordinate: {
type: "integer",
minimum: 1,
maximum: 3,
example: 1,
},
mark: {
type: "string",
enum: [".", "X", "O"],
description:
"Possible values for a board square. `.` means empty square.",
example: ".",
},
board: {
type: "array",
maxItems: 3,
minItems: 3,
items: {
type: "array",
maxItems: 3,
minItems: 3,
items: {
$ref: "#/components/schemas/mark",
},
},
},
winner: {
type: "string",
enum: [".", "X", "O"],
description: "Winner of the game. `.` means nobody has won yet.",
example: ".",
},
status: {
type: "object",
properties: {
winner: {
$ref: "#/components/schemas/winner",
},
board: {
$ref: "#/components/schemas/board",
},
},
},
},
securitySchemes: {
defaultApiKey: {
description: "API key provided in console",
type: "apiKey",
name: "api-key",
in: "header",
},
basicHttpAuthentication: {
description: "Basic HTTP Authentication",
type: "http",
scheme: "Basic",
},
bearerHttpAuthentication: {
description: "Bearer token using a JWT",
type: "http",
scheme: "Bearer",
bearerFormat: "JWT",
},
app2AppOauth: {
type: "oauth2",
flows: {
clientCredentials: {
tokenUrl: "https://learn.openapis.org/oauth/2.0/token",
scopes: {
"board:read": "Read the board",
},
},
},
},
user2AppOauth: {
type: "oauth2",
flows: {
authorizationCode: {
authorizationUrl: "https://learn.openapis.org/oauth/2.0/auth",
tokenUrl: "https://learn.openapis.org/oauth/2.0/token",
scopes: {
"board:read": "Read the board",
"board:write": "Write to the board",
},
},
},
},
},
},
};

View File

@@ -1,50 +1,50 @@
import type { Specification } from "../../3.1";
const _webhookExample: Specification = {
openapi: "3.1.0",
info: {
title: "Webhook Example",
version: "1.0.0",
},
webhooks: {
newPet: {
post: {
requestBody: {
description: "Information about a new pet in the system",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
responses: {
"200": {
description:
"Return a 200 status to indicate that the data was received successfully",
},
},
},
},
},
components: {
schemas: {
Pet: {
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
},
},
export const webhookExample: Specification = {
openapi: "3.1.0",
info: {
title: "Webhook Example",
version: "1.0.0",
},
webhooks: {
newPet: {
post: {
requestBody: {
description: "Information about a new pet in the system",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Pet",
},
},
},
},
responses: {
"200": {
description:
"Return a 200 status to indicate that the data was received successfully",
},
},
},
},
},
components: {
schemas: {
Pet: {
required: ["id", "name"],
properties: {
id: {
type: "integer",
format: "int64",
},
name: {
type: "string",
},
tag: {
type: "string",
},
},
},
},
},
};

View File

@@ -0,0 +1,171 @@
import { describe, it, expect } from "bun:test";
import Ajv, { type JSONSchemaType } from "ajv";
import type { Specification } from "../3.0";
import { schemas } from "../schemas/3.0";
// Import all specification files from tests/3.0
import { apiWithExamples } from "./3.0/api-with-examples";
import { callbackExample } from "./3.0/callback-example";
import { linkExample } from "./3.0/link-example";
import { petstore } from "./3.0/petstore";
import { petstoreExpanded } from "./3.0/petstore-expanded";
import { uspto } from "./3.0/uspto";
const ajv = new Ajv({
allErrors: true,
verbose: true,
strict: false,
});
const schema: JSONSchemaType<Specification> = JSON.parse(
JSON.stringify(schemas.specification)
);
// validate is a type guard for Specification - type is inferred from schema type
const validate = ajv.compile(schema);
// All specification files to test
const specsToTest = [
{ name: "API with Examples", spec: apiWithExamples },
{ name: "Callback Example", spec: callbackExample },
{ name: "Link Example", spec: linkExample },
{ name: "Petstore", spec: petstore },
{ name: "Petstore Expanded", spec: petstoreExpanded },
{ name: "USPTO", spec: uspto },
];
describe("OpenAPI 3.0 Schema Validation", () => {
for (const { name, spec } of specsToTest) {
describe(name, () => {
it("should be a valid OpenAPI 3.0 specification", () => {
const isValid = validate(spec);
if (!isValid) {
console.error(`Validation errors for ${name}:`, validate.errors);
}
expect(isValid).toBe(true);
});
it("should have required openapi version", () => {
expect(spec.openapi).toMatch(/^3\.0\.\d+$/);
});
it("should have required info object", () => {
expect(spec.info).toBeDefined();
expect(spec.info.title).toBeDefined();
expect(spec.info.version).toBeDefined();
});
it("should have valid paths object", () => {
if (spec.paths) {
expect(typeof spec.paths).toBe("object");
expect(spec.paths).not.toBeNull();
}
});
it("should have valid components object", () => {
if (spec.components) {
expect(typeof spec.components).toBe("object");
expect(spec.components).not.toBeNull();
}
});
it("should have valid servers array when present", () => {
if (spec.servers) {
expect(Array.isArray(spec.servers)).toBe(true);
spec.servers.forEach((server) => {
expect(server.url).toBeDefined();
expect(typeof server.url).toBe("string");
});
}
});
});
}
describe("Schema Validation Details", () => {
it("should validate all specifications against the JSON schema", () => {
const results = specsToTest.map(({ name, spec }) => {
const isValid = validate(spec);
return { name, isValid, errors: validate.errors };
});
const failedSpecs = results.filter((result) => !result.isValid);
if (failedSpecs.length > 0) {
console.error("Failed specifications:");
failedSpecs.forEach(({ name, errors }) => {
console.error(`${name}:`, errors);
});
}
expect(failedSpecs.length).toBe(0);
});
it("should have consistent openapi version across all specs", () => {
const versions = specsToTest.map(({ spec }) => spec.openapi);
const uniqueVersions = [...new Set(versions)];
expect(uniqueVersions.length).toBeGreaterThan(0);
uniqueVersions.forEach((version) => {
expect(version).toMatch(/^3\.0\.\d+$/);
});
});
it("should have valid server URLs when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.servers) {
spec.servers.forEach((server) => {
// Server URL should be a valid URL format
expect(server.url).toMatch(/^https?:\/\/|^\/|^\{/);
});
}
});
});
it("should have valid server variables when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.servers) {
spec.servers.forEach((server) => {
if (server.variables) {
expect(typeof server.variables).toBe("object");
Object.values(server.variables).forEach((variable) => {
expect(variable).toHaveProperty("default");
});
}
});
}
});
});
it("should have valid tags when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.tags) {
expect(Array.isArray(spec.tags)).toBe(true);
spec.tags.forEach((tag) => {
expect(tag.name).toBeDefined();
expect(typeof tag.name).toBe("string");
});
}
});
});
it("should have valid security schemes when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.components?.securitySchemes) {
expect(typeof spec.components.securitySchemes).toBe("object");
Object.values(spec.components.securitySchemes).forEach((scheme) => {
// Type guard to check if it's not a Reference
if (!("$ref" in scheme)) {
expect(scheme).toHaveProperty("type");
expect(scheme.type).toBeDefined();
expect(["apiKey", "http", "oauth2", "openIdConnect"]).toContain(
scheme.type
);
}
});
}
});
});
});
});

View File

@@ -0,0 +1,217 @@
import { describe, it, expect } from "bun:test";
import Ajv, { type JSONSchemaType } from "ajv";
import type { Specification } from "../3.1";
import { schemas } from "../schemas/3.1";
// Import all specification files from tests/3.1
import { nonOauthScopes } from "./3.1/non-oauth-scopes";
import { tictactoe } from "./3.1/tictactoe";
import { webhookExample } from "./3.1/webhook-example";
const ajv = new Ajv({
allErrors: true,
verbose: true,
strict: false,
});
const schema: JSONSchemaType<Specification> = JSON.parse(
JSON.stringify(schemas.specification)
);
// validate is a type guard for Specification - type is inferred from schema type
const validate = ajv.compile(schema);
// All specification files to test
const specsToTest = [
{ name: "Non-OAuth Scopes", spec: nonOauthScopes, skipValidation: true }, // Intentionally incomplete example
{ name: "Tic Tac Toe", spec: tictactoe },
{ name: "Webhook Example", spec: webhookExample },
];
describe("OpenAPI 3.1 Schema Validation", () => {
for (const { name, spec, skipValidation } of specsToTest) {
describe(name, () => {
it("should be a valid OpenAPI 3.1 specification", () => {
if (skipValidation) {
console.log(
`Skipping validation for ${name} (intentionally incomplete example)`
);
expect(true).toBe(true); // Pass the test
return;
}
const isValid = validate(spec);
if (!isValid) {
console.error(`Validation errors for ${name}:`, validate.errors);
}
expect(isValid).toBe(true);
});
it("should have required openapi version", () => {
expect(spec.openapi).toMatch(/^3\.1\.\d+$/);
});
it("should have required info object", () => {
expect(spec.info).toBeDefined();
expect(spec.info.title).toBeDefined();
expect(spec.info.version).toBeDefined();
});
it("should have valid paths object", () => {
if (spec.paths) {
expect(typeof spec.paths).toBe("object");
expect(spec.paths).not.toBeNull();
}
});
it("should have valid components object", () => {
if (spec.components) {
expect(typeof spec.components).toBe("object");
expect(spec.components).not.toBeNull();
}
});
it("should have valid servers array when present", () => {
if (spec.servers) {
expect(Array.isArray(spec.servers)).toBe(true);
spec.servers.forEach((server) => {
expect(server.url).toBeDefined();
expect(typeof server.url).toBe("string");
});
}
});
it("should have valid webhooks object when present", () => {
if (spec.webhooks) {
expect(typeof spec.webhooks).toBe("object");
expect(spec.webhooks).not.toBeNull();
}
});
});
}
describe("Schema Validation Details", () => {
it("should validate all specifications against the JSON schema", () => {
const results = specsToTest.map(({ name, spec, skipValidation }) => {
if (skipValidation) {
return { name, isValid: true, errors: null };
}
const isValid = validate(spec);
return { name, isValid, errors: validate.errors };
});
const failedSpecs = results.filter((result) => !result.isValid);
if (failedSpecs.length > 0) {
console.error("Failed specifications:");
failedSpecs.forEach(({ name, errors }) => {
console.error(`${name}:`, errors);
});
}
expect(failedSpecs.length).toBe(0);
});
it("should have consistent openapi version across all specs", () => {
const versions = specsToTest.map(({ spec }) => spec.openapi);
const uniqueVersions = [...new Set(versions)];
expect(uniqueVersions.length).toBeGreaterThan(0);
uniqueVersions.forEach((version) => {
expect(version).toMatch(/^3\.1\.\d+$/);
});
});
it("should have valid server URLs when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.servers) {
spec.servers.forEach((server) => {
// Server URL should be a valid URL format
expect(server.url).toMatch(/^https?:\/\/|^\/|^\{/);
});
}
});
});
it("should have valid server variables when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.servers) {
spec.servers.forEach((server) => {
if (server.variables) {
expect(typeof server.variables).toBe("object");
Object.values(server.variables).forEach((variable) => {
expect(variable).toHaveProperty("default");
});
}
});
}
});
});
it("should have valid tags when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.tags) {
expect(Array.isArray(spec.tags)).toBe(true);
spec.tags.forEach((tag) => {
expect(tag.name).toBeDefined();
expect(typeof tag.name).toBe("string");
});
}
});
});
it("should have valid security schemes when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.components?.securitySchemes) {
expect(typeof spec.components.securitySchemes).toBe("object");
Object.values(spec.components.securitySchemes).forEach((scheme) => {
// Type guard to check if it's not a Reference
if (!("$ref" in scheme)) {
expect(scheme.type).toBeDefined();
expect(["apiKey", "http", "oauth2", "openIdConnect"]).toContain(
scheme.type
);
}
});
}
});
});
it("should have valid webhook operations when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.webhooks) {
Object.values(spec.webhooks).forEach((webhook) => {
// Type guard to check if it's not a Reference
if (!("$ref" in webhook)) {
expect(webhook).toHaveProperty("post");
expect(typeof webhook.post).toBe("object");
}
});
}
});
});
it("should have valid OAuth2 flows when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.components?.securitySchemes) {
Object.values(spec.components.securitySchemes).forEach((scheme) => {
// Type guard to check if it's not a Reference
if (
!("$ref" in scheme) &&
scheme.type === "oauth2" &&
scheme.flows
) {
expect(typeof scheme.flows).toBe("object");
Object.values(scheme.flows).forEach((flow) => {
expect(flow).toHaveProperty("scopes");
expect(typeof flow.scopes).toBe("object");
});
}
});
}
});
});
});
});

136
tests/swagger-schemas.test.ts Executable file
View File

@@ -0,0 +1,136 @@
import { describe, it, expect } from "bun:test";
import Ajv, { type JSONSchemaType } from "ajv";
import type { Specification } from "../2.0";
import { schemas } from "../schemas/2.0";
// Import all specification files from tests/2.0
import { apiWithExamples } from "./2.0/api-with-examples";
import { petstore } from "./2.0/petstore";
import { petstoreWithExternalDocs } from "./2.0/petstore-with-external-docs";
import { petstoreSimple } from "./2.0/petstore-simple";
import { petstoreMinimal } from "./2.0/petstore-minimal";
import { petstoreExpanded } from "./2.0/petstore-expanded";
import { uber } from "./2.0/uber";
const ajv = new Ajv({
allErrors: true,
verbose: true,
strict: false,
});
const schema: JSONSchemaType<Specification> = JSON.parse(
JSON.stringify(schemas.specification)
);
// validate is a type guard for Specification - type is inferred from schema type
const validate = ajv.compile(schema);
// All specification files to test
const specsToTest = [
{ name: "API with Examples", spec: apiWithExamples },
{ name: "Petstore", spec: petstore },
{ name: "Petstore with External Docs", spec: petstoreWithExternalDocs },
{ name: "Petstore Simple", spec: petstoreSimple },
{ name: "Petstore Minimal", spec: petstoreMinimal },
{ name: "Petstore Expanded", spec: petstoreExpanded },
{ name: "Uber API", spec: uber },
];
describe("Swagger 2.0 Schema Validation", () => {
for (const { name, spec } of specsToTest) {
describe(name, () => {
it("should be a valid Swagger 2.0 specification", () => {
const isValid = validate(spec);
if (!isValid) {
console.error(`Validation errors for ${name}:`, validate.errors);
}
expect(isValid).toBe(true);
});
it("should have required swagger version", () => {
expect(spec.swagger).toBe("2.0");
});
it("should have required info object", () => {
expect(spec.info).toBeDefined();
expect(spec.info.title).toBeDefined();
expect(spec.info.version).toBeDefined();
});
it("should have valid paths object", () => {
if (spec.paths) {
expect(typeof spec.paths).toBe("object");
expect(spec.paths).not.toBeNull();
}
});
it("should have valid definitions object", () => {
if (spec.definitions) {
expect(typeof spec.definitions).toBe("object");
expect(spec.definitions).not.toBeNull();
}
});
});
}
describe("Schema Validation Details", () => {
it("should validate all specifications against the JSON schema", () => {
const results = specsToTest.map(({ name, spec }) => {
const isValid = validate(spec);
return { name, isValid, errors: validate.errors };
});
const failedSpecs = results.filter((result) => !result.isValid);
if (failedSpecs.length > 0) {
console.error("Failed specifications:");
failedSpecs.forEach(({ name, errors }) => {
console.error(`${name}:`, errors);
});
}
expect(failedSpecs.length).toBe(0);
});
it("should have consistent swagger version across all specs", () => {
const versions = specsToTest.map(({ spec }) => spec.swagger);
const uniqueVersions = [...new Set(versions)];
expect(uniqueVersions).toHaveLength(1);
expect(uniqueVersions[0]).toBe("2.0");
});
it("should have valid host format when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.host) {
// Host should not contain protocol
expect(spec.host).not.toMatch(/^https?:\/\//);
// Host should not contain path
expect(spec.host).not.toContain("/");
}
});
});
it("should have valid basePath format when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.basePath) {
// BasePath should start with /
expect(spec.basePath).toMatch(/^\//);
}
});
});
it("should have valid schemes when present", () => {
specsToTest.forEach(({ name, spec }) => {
if (spec.schemes) {
expect(Array.isArray(spec.schemes)).toBe(true);
spec.schemes.forEach((scheme: string) => {
expect(["http", "https", "ws", "wss"]).toContain(scheme);
});
}
});
});
});
});

View File

@@ -1,92 +0,0 @@
#!/usr/bin/env bun
import { readFileSync } from "fs";
import { resolve } from "path";
// Simple JSON Schema validation function
function validateAgainstSchema(
data: any,
schema: any
): { valid: boolean; errors: string[] } {
const errors: string[] = [];
// Basic validation logic (simplified)
if (schema.required) {
for (const field of schema.required) {
if (!(field in data)) {
errors.push(`Missing required field: ${field}`);
}
}
}
if (schema.type) {
if (schema.type === "object" && typeof data !== "object") {
errors.push(`Expected object, got ${typeof data}`);
} else if (schema.type === "string" && typeof data !== "string") {
errors.push(`Expected string, got ${typeof data}`);
} else if (schema.type === "array" && !Array.isArray(data)) {
errors.push(`Expected array, got ${typeof data}`);
}
}
return {
valid: errors.length === 0,
errors,
};
}
async function validateOpenAPIDocument(
filePath: string,
version: string = "3.0"
): Promise<void> {
try {
console.log(`🔍 Validating OpenAPI document: ${filePath}`);
console.log(`📋 Using OpenAPI ${version} schema`);
// Load the document
const document = JSON.parse(readFileSync(filePath, "utf-8"));
// Load the appropriate schema
const schemaPath = resolve(`./schemas/${version}/main/specification.json`);
const schema = JSON.parse(readFileSync(schemaPath, "utf-8"));
// Validate
const result = validateAgainstSchema(document, schema);
if (result.valid) {
console.log("✅ Document is valid!");
} else {
console.log("❌ Document has validation errors:");
result.errors.forEach((error) => console.log(` - ${error}`));
}
} catch (error) {
console.error("❌ Validation failed:", error);
}
}
async function main() {
const args = process.argv.slice(2);
if (args.length === 0) {
console.log(
"Usage: bun run scripts/validate-schema.ts <openapi-file> [version]"
);
console.log(
"Example: bun run scripts/validate-schema.ts ./my-api.json 3.0"
);
return;
}
const filePath = args[0];
const version = args[1] || "3.0";
if (!filePath) {
console.error("❌ Error: File path is required");
return;
}
await validateOpenAPIDocument(filePath, version);
}
// Run the script
main().catch(console.error);