mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-06-30 10:01:42 +02:00
Add native OpenAPI importer
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
# Real-World OpenAPI Fixtures
|
||||
|
||||
These fixtures were copied from the public APIs.guru OpenAPI directory:
|
||||
|
||||
- `apis-guru.yaml`: https://api.apis.guru/v2/specs/apis.guru/2.2.0/openapi.yaml
|
||||
- `httpbin.yaml`: https://api.apis.guru/v2/specs/httpbin.org/0.9.2/openapi.yaml
|
||||
- `nasa-apod.yaml`: https://api.apis.guru/v2/specs/nasa.gov/apod/1.0.0/openapi.yaml
|
||||
- `xkcd.yaml`: https://api.apis.guru/v2/specs/xkcd.com/1.0.0/openapi.yaml
|
||||
@@ -0,0 +1,399 @@
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: https://api.apis.guru/v2
|
||||
info:
|
||||
contact:
|
||||
email: mike.ralphson@gmail.com
|
||||
name: APIs.guru
|
||||
url: https://APIs.guru
|
||||
description: |
|
||||
Wikipedia for Web APIs. Repository of API definitions in OpenAPI format.
|
||||
**Warning**: If you want to be notified about changes in advance please join our [Slack channel](https://join.slack.com/t/mermade/shared_invite/zt-g78g7xir-MLE_CTCcXCdfJfG3CJe9qA).
|
||||
Client sample: [[Demo]](https://apis.guru/simple-ui) [[Repo]](https://github.com/APIs-guru/simple-ui)
|
||||
license:
|
||||
name: CC0 1.0
|
||||
url: https://github.com/APIs-guru/openapi-directory#licenses
|
||||
title: APIs.guru
|
||||
version: 2.2.0
|
||||
x-apisguru-categories:
|
||||
- open_data
|
||||
- developer_tools
|
||||
x-logo:
|
||||
url: https://api.apis.guru/v2/cache/logo/https_apis.guru_branding_logo_vertical.svg
|
||||
x-origin:
|
||||
- format: openapi
|
||||
url: https://api.apis.guru/v2/openapi.yaml
|
||||
version: "3.0"
|
||||
x-providerName: apis.guru
|
||||
x-tags:
|
||||
- API
|
||||
- Catalog
|
||||
- Directory
|
||||
- REST
|
||||
- Swagger
|
||||
- OpenAPI
|
||||
externalDocs:
|
||||
url: https://github.com/APIs-guru/openapi-directory/blob/master/API.md
|
||||
security: []
|
||||
tags:
|
||||
- description: Actions relating to APIs in the collection
|
||||
name: APIs
|
||||
paths:
|
||||
/list.json:
|
||||
get:
|
||||
description: |
|
||||
List all APIs in the directory.
|
||||
Returns links to the OpenAPI definitions for each API in the directory.
|
||||
If API exist in multiple versions `preferred` one is explicitly marked.
|
||||
Some basic info from the OpenAPI definition is cached inside each object.
|
||||
This allows you to generate some simple views without needing to fetch the OpenAPI definition for each API.
|
||||
operationId: listAPIs
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/APIs"
|
||||
description: OK
|
||||
summary: List all APIs
|
||||
tags:
|
||||
- APIs
|
||||
/metrics.json:
|
||||
get:
|
||||
description: |
|
||||
Some basic metrics for the entire directory.
|
||||
Just stunning numbers to put on a front page and are intended purely for WoW effect :)
|
||||
operationId: getMetrics
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Metrics"
|
||||
description: OK
|
||||
summary: Get basic metrics
|
||||
tags:
|
||||
- APIs
|
||||
/providers.json:
|
||||
get:
|
||||
description: |
|
||||
List all the providers in the directory
|
||||
operationId: getProviders
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
data:
|
||||
items:
|
||||
minLength: 1
|
||||
type: string
|
||||
minItems: 1
|
||||
type: array
|
||||
type: object
|
||||
description: OK
|
||||
summary: List all providers
|
||||
tags:
|
||||
- APIs
|
||||
"/specs/{provider}/{api}.json":
|
||||
get:
|
||||
description: Returns the API entry for one specific version of an API where there is no serviceName.
|
||||
operationId: getAPI
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/provider"
|
||||
- $ref: "#/components/parameters/api"
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/API"
|
||||
description: OK
|
||||
summary: Retrieve one version of a particular API
|
||||
tags:
|
||||
- APIs
|
||||
"/specs/{provider}/{service}/{api}.json":
|
||||
get:
|
||||
description: Returns the API entry for one specific version of an API where there is a serviceName.
|
||||
operationId: getServiceAPI
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/provider"
|
||||
- in: path
|
||||
name: service
|
||||
required: true
|
||||
schema:
|
||||
example: graph
|
||||
maxLength: 255
|
||||
minLength: 1
|
||||
type: string
|
||||
- $ref: "#/components/parameters/api"
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/API"
|
||||
description: OK
|
||||
summary: Retrieve one version of a particular API with a serviceName.
|
||||
tags:
|
||||
- APIs
|
||||
"/{provider}.json":
|
||||
get:
|
||||
description: |
|
||||
List all APIs in the directory for a particular providerName
|
||||
Returns links to the individual API entry for each API.
|
||||
operationId: getProvider
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/provider"
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/APIs"
|
||||
description: OK
|
||||
summary: List all APIs for a particular provider
|
||||
tags:
|
||||
- APIs
|
||||
"/{provider}/services.json":
|
||||
get:
|
||||
description: |
|
||||
List all serviceNames in the directory for a particular providerName
|
||||
operationId: getServices
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/provider"
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
data:
|
||||
items:
|
||||
minLength: 0
|
||||
type: string
|
||||
minItems: 1
|
||||
type: array
|
||||
type: object
|
||||
description: OK
|
||||
summary: List all serviceNames for a particular provider
|
||||
tags:
|
||||
- APIs
|
||||
components:
|
||||
parameters:
|
||||
api:
|
||||
in: path
|
||||
name: api
|
||||
required: true
|
||||
schema:
|
||||
example: 2.1.0
|
||||
maxLength: 255
|
||||
minLength: 1
|
||||
type: string
|
||||
provider:
|
||||
in: path
|
||||
name: provider
|
||||
required: true
|
||||
schema:
|
||||
example: apis.guru
|
||||
maxLength: 255
|
||||
minLength: 1
|
||||
type: string
|
||||
schemas:
|
||||
API:
|
||||
additionalProperties: false
|
||||
description: Meta information about API
|
||||
properties:
|
||||
added:
|
||||
description: Timestamp when the API was first added to the directory
|
||||
format: date-time
|
||||
type: string
|
||||
preferred:
|
||||
description: Recommended version
|
||||
type: string
|
||||
versions:
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/ApiVersion"
|
||||
description: List of supported versions of the API
|
||||
minProperties: 1
|
||||
type: object
|
||||
required:
|
||||
- added
|
||||
- preferred
|
||||
- versions
|
||||
type: object
|
||||
APIs:
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/API"
|
||||
description: |
|
||||
List of API details.
|
||||
It is a JSON object with API IDs(`<provider>[:<service>]`) as keys.
|
||||
example:
|
||||
googleapis.com:drive:
|
||||
added: 2015-02-22T20:00:45.000Z
|
||||
preferred: v3
|
||||
versions:
|
||||
v2:
|
||||
added: 2015-02-22T20:00:45.000Z
|
||||
info:
|
||||
title: Drive
|
||||
version: v2
|
||||
x-apiClientRegistration:
|
||||
url: https://console.developers.google.com
|
||||
x-logo:
|
||||
url: https://api.apis.guru/v2/cache/logo/https_www.gstatic.com_images_icons_material_product_2x_drive_32dp.png
|
||||
x-origin:
|
||||
format: google
|
||||
url: https://www.googleapis.com/discovery/v1/apis/drive/v2/rest
|
||||
version: v1
|
||||
x-preferred: false
|
||||
x-providerName: googleapis.com
|
||||
x-serviceName: drive
|
||||
swaggerUrl: https://api.apis.guru/v2/specs/googleapis.com/drive/v2/swagger.json
|
||||
swaggerYamlUrl: https://api.apis.guru/v2/specs/googleapis.com/drive/v2/swagger.yaml
|
||||
updated: 2016-06-17T00:21:44.000Z
|
||||
v3:
|
||||
added: 2015-12-12T00:25:13.000Z
|
||||
info:
|
||||
title: Drive
|
||||
version: v3
|
||||
x-apiClientRegistration:
|
||||
url: https://console.developers.google.com
|
||||
x-logo:
|
||||
url: https://api.apis.guru/v2/cache/logo/https_www.gstatic.com_images_icons_material_product_2x_drive_32dp.png
|
||||
x-origin:
|
||||
format: google
|
||||
url: https://www.googleapis.com/discovery/v1/apis/drive/v3/rest
|
||||
version: v1
|
||||
x-preferred: true
|
||||
x-providerName: googleapis.com
|
||||
x-serviceName: drive
|
||||
swaggerUrl: https://api.apis.guru/v2/specs/googleapis.com/drive/v3/swagger.json
|
||||
swaggerYamlUrl: https://api.apis.guru/v2/specs/googleapis.com/drive/v3/swagger.yaml
|
||||
updated: 2016-06-17T00:21:44.000Z
|
||||
minProperties: 1
|
||||
type: object
|
||||
ApiVersion:
|
||||
additionalProperties: false
|
||||
properties:
|
||||
added:
|
||||
description: Timestamp when the version was added
|
||||
format: date-time
|
||||
type: string
|
||||
externalDocs:
|
||||
description: Copy of `externalDocs` section from OpenAPI definition
|
||||
minProperties: 1
|
||||
type: object
|
||||
info:
|
||||
description: Copy of `info` section from OpenAPI definition
|
||||
minProperties: 1
|
||||
type: object
|
||||
link:
|
||||
description: Link to the individual API entry for this API
|
||||
format: url
|
||||
type: string
|
||||
openapiVer:
|
||||
description: The value of the `openapi` or `swagger` property of the source definition
|
||||
type: string
|
||||
swaggerUrl:
|
||||
description: URL to OpenAPI definition in JSON format
|
||||
format: url
|
||||
type: string
|
||||
swaggerYamlUrl:
|
||||
description: URL to OpenAPI definition in YAML format
|
||||
format: url
|
||||
type: string
|
||||
updated:
|
||||
description: Timestamp when the version was updated
|
||||
format: date-time
|
||||
type: string
|
||||
required:
|
||||
- added
|
||||
- updated
|
||||
- swaggerUrl
|
||||
- swaggerYamlUrl
|
||||
- info
|
||||
- openapiVer
|
||||
type: object
|
||||
Metrics:
|
||||
additionalProperties: false
|
||||
description: List of basic metrics
|
||||
example:
|
||||
datasets: []
|
||||
fixedPct: 22
|
||||
fixes: 81119
|
||||
invalid: 598
|
||||
issues: 28
|
||||
numAPIs: 2501
|
||||
numDrivers: 10
|
||||
numEndpoints: 106448
|
||||
numProviders: 659
|
||||
numSpecs: 3329
|
||||
stars: 2429
|
||||
thisWeek:
|
||||
added: 45
|
||||
updated: 171
|
||||
unofficial: 25
|
||||
unreachable: 123
|
||||
properties:
|
||||
datasets:
|
||||
description: Data used for charting etc
|
||||
items: {}
|
||||
type: array
|
||||
fixedPct:
|
||||
description: Percentage of all APIs where auto fixes have been applied
|
||||
type: integer
|
||||
fixes:
|
||||
description: Total number of fixes applied across all APIs
|
||||
type: integer
|
||||
invalid:
|
||||
description: Number of newly invalid APIs
|
||||
type: integer
|
||||
issues:
|
||||
description: Open GitHub issues on our main repo
|
||||
type: integer
|
||||
numAPIs:
|
||||
description: Number of unique APIs
|
||||
minimum: 1
|
||||
type: integer
|
||||
numDrivers:
|
||||
description: Number of methods of API retrieval
|
||||
type: integer
|
||||
numEndpoints:
|
||||
description: Total number of endpoints inside all definitions
|
||||
minimum: 1
|
||||
type: integer
|
||||
numProviders:
|
||||
description: Number of API providers in directory
|
||||
type: integer
|
||||
numSpecs:
|
||||
description: Number of API definitions including different versions of the same API
|
||||
minimum: 1
|
||||
type: integer
|
||||
stars:
|
||||
description: GitHub stars for our main repo
|
||||
type: integer
|
||||
thisWeek:
|
||||
description: Summary totals for the last 7 days
|
||||
properties:
|
||||
added:
|
||||
description: APIs added in the last week
|
||||
type: integer
|
||||
updated:
|
||||
description: APIs updated in the last week
|
||||
type: integer
|
||||
type: object
|
||||
unofficial:
|
||||
description: Number of unofficial APIs
|
||||
type: integer
|
||||
unreachable:
|
||||
description: Number of unreachable (4XX,5XX status) APIs
|
||||
type: integer
|
||||
required:
|
||||
- numSpecs
|
||||
- numAPIs
|
||||
- numEndpoints
|
||||
type: object
|
||||
x-optic-standard: "@febf8ac6-ee67-4565-b45a-5c85a469dca7/Fz6KU3_wMIO5iJ6_VUZ30"
|
||||
x-optic-url: https://app.useoptic.com/organizations/febf8ac6-ee67-4565-b45a-5c85a469dca7/apis/_0fKWqUvhs9ssYNkq1k-c
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: https://api.nasa.gov/planetary
|
||||
- url: http://api.nasa.gov/planetary
|
||||
info:
|
||||
contact:
|
||||
email: evan.t.yates@nasa.gov
|
||||
description: This endpoint structures the APOD imagery and associated metadata so that it can be repurposed for other applications. In addition, if the concept_tags parameter is set to True, then keywords derived from the image explanation are returned. These keywords could be used as auto-generated hashtags for twitter or instagram feeds; but generally help with discoverability of relevant imagery
|
||||
license:
|
||||
name: Apache 2.0
|
||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
title: APOD
|
||||
version: 1.0.0
|
||||
x-apisguru-categories:
|
||||
- media
|
||||
- open_data
|
||||
x-origin:
|
||||
- format: swagger
|
||||
url: https://raw.githubusercontent.com/nasa/api-docs/gh-pages/assets/json/APOD
|
||||
version: "2.0"
|
||||
x-providerName: nasa.gov
|
||||
x-serviceName: apod
|
||||
x-logo:
|
||||
url: https://api.apis.guru/v2/cache/logo/https_apis.guru_assets_images_no-logo.svg
|
||||
tags:
|
||||
- description: An example tag
|
||||
externalDocs:
|
||||
description: Here's a link
|
||||
url: https://example.com
|
||||
name: request tag
|
||||
paths:
|
||||
/apod:
|
||||
get:
|
||||
description: Returns the picture of the day
|
||||
parameters:
|
||||
- description: The date of the APOD image to retrieve
|
||||
in: query
|
||||
name: date
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
- description: Retrieve the URL for the high resolution image
|
||||
in: query
|
||||
name: hd
|
||||
required: false
|
||||
schema:
|
||||
type: boolean
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
items:
|
||||
x-thing: ok
|
||||
type: array
|
||||
description: successful operation
|
||||
"400":
|
||||
description: Date must be between Jun 16, 1995 and Mar 28, 2019.
|
||||
security:
|
||||
- api_key: []
|
||||
summary: Returns images
|
||||
tags:
|
||||
- request tag
|
||||
components:
|
||||
securitySchemes:
|
||||
api_key:
|
||||
in: query
|
||||
name: api_key
|
||||
type: apiKey
|
||||
@@ -0,0 +1,78 @@
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: http://xkcd.com/
|
||||
info:
|
||||
description: Webcomic of romance, sarcasm, math, and language.
|
||||
title: XKCD
|
||||
version: 1.0.0
|
||||
x-apisguru-categories:
|
||||
- media
|
||||
x-logo:
|
||||
url: https://api.apis.guru/v2/cache/logo/http_imgs.xkcd.com_static_terrible_small_logo.png
|
||||
x-origin:
|
||||
- format: openapi
|
||||
url: https://raw.githubusercontent.com/APIs-guru/unofficial_openapi_specs/master/xkcd.com/1.0.0/openapi.yaml
|
||||
version: "3.0"
|
||||
x-providerName: xkcd.com
|
||||
x-tags:
|
||||
- humor
|
||||
- comics
|
||||
x-unofficialSpec: true
|
||||
externalDocs:
|
||||
url: https://xkcd.com/json.html
|
||||
paths:
|
||||
/info.0.json:
|
||||
get:
|
||||
description: |
|
||||
Fetch current comic and metadata.
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
$ref: "#/components/schemas/comic"
|
||||
description: OK
|
||||
"/{comicId}/info.0.json":
|
||||
get:
|
||||
description: |
|
||||
Fetch comics and metadata by comic id.
|
||||
parameters:
|
||||
- in: path
|
||||
name: comicId
|
||||
required: true
|
||||
schema:
|
||||
type: number
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
$ref: "#/components/schemas/comic"
|
||||
description: OK
|
||||
components:
|
||||
schemas:
|
||||
comic:
|
||||
properties:
|
||||
alt:
|
||||
type: string
|
||||
day:
|
||||
type: string
|
||||
img:
|
||||
type: string
|
||||
link:
|
||||
type: string
|
||||
month:
|
||||
type: string
|
||||
news:
|
||||
type: string
|
||||
num:
|
||||
type: number
|
||||
safe_title:
|
||||
type: string
|
||||
title:
|
||||
type: string
|
||||
transcript:
|
||||
type: string
|
||||
year:
|
||||
type: string
|
||||
type: object
|
||||
@@ -5,7 +5,13 @@ import { convertOpenApi } from "../src";
|
||||
|
||||
describe("importer-openapi", () => {
|
||||
const p = path.join(__dirname, "fixtures");
|
||||
const fixtures = fs.readdirSync(p);
|
||||
const fixtures = fs.readdirSync(p).filter((fixture) => {
|
||||
return fs.statSync(path.join(p, fixture)).isFile();
|
||||
});
|
||||
const realWorldFixturesPath = path.join(p, "real-world");
|
||||
const realWorldFixtures = fs
|
||||
.readdirSync(realWorldFixturesPath)
|
||||
.filter((fixture) => fixture.endsWith(".yaml"));
|
||||
|
||||
test("Maps operation description to request description", async () => {
|
||||
const imported = await convertOpenApi(
|
||||
@@ -25,11 +31,188 @@ describe("importer-openapi", () => {
|
||||
|
||||
expect(imported?.resources.httpRequests).toEqual([
|
||||
expect.objectContaining({
|
||||
description: "Lijst van klanten",
|
||||
description: expect.stringContaining("Lijst van klanten"),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("Imports requests directly from OpenAPI details", async () => {
|
||||
const imported = await convertOpenApi(
|
||||
JSON.stringify({
|
||||
openapi: "3.0.0",
|
||||
info: { title: "Native Import Test", version: "1.0.0" },
|
||||
servers: [
|
||||
{ url: "https://api.example.com/{version}", variables: { version: { default: "v1" } } },
|
||||
],
|
||||
tags: [{ name: "accounts", description: "Account operations" }],
|
||||
paths: {
|
||||
"/accounts/{accountId}/members": {
|
||||
parameters: [
|
||||
{
|
||||
name: "accountId",
|
||||
in: "path",
|
||||
required: true,
|
||||
description: "Account identifier",
|
||||
schema: { type: "string", example: "acct_123" },
|
||||
},
|
||||
],
|
||||
post: {
|
||||
tags: ["accounts"],
|
||||
summary: "Create member",
|
||||
operationId: "createMember",
|
||||
parameters: [
|
||||
{
|
||||
name: "include",
|
||||
in: "query",
|
||||
description: "Related resources to include",
|
||||
schema: { type: "string", enum: ["roles"] },
|
||||
},
|
||||
{
|
||||
name: "X-Trace-Id",
|
||||
in: "header",
|
||||
schema: { type: "string", example: "trace-123" },
|
||||
},
|
||||
],
|
||||
security: [{ tokenAuth: [] }],
|
||||
requestBody: {
|
||||
description: "Member payload",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: { $ref: "#/components/schemas/MemberInput" },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
"201": { description: "Created" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
components: {
|
||||
securitySchemes: {
|
||||
tokenAuth: { type: "http", scheme: "bearer" },
|
||||
},
|
||||
schemas: {
|
||||
MemberInput: {
|
||||
type: "object",
|
||||
required: ["email"],
|
||||
properties: {
|
||||
email: { type: "string", example: "me@example.com" },
|
||||
admin: { type: "boolean", default: false },
|
||||
primaryContact: { $ref: "#/components/schemas/Contact" },
|
||||
secondaryContact: { $ref: "#/components/schemas/Contact" },
|
||||
},
|
||||
},
|
||||
Contact: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: { type: "string", example: "Taylor" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(imported?.resources.folders).toEqual([
|
||||
expect.objectContaining({ name: "accounts", description: "Account operations" }),
|
||||
]);
|
||||
expect(imported?.resources.httpRequests).toEqual([
|
||||
expect.objectContaining({
|
||||
name: "Create member",
|
||||
method: "POST",
|
||||
url: "https://api.example.com/v1/accounts/:accountId/members",
|
||||
authenticationType: "bearer",
|
||||
authentication: { token: "", prefix: "Bearer" },
|
||||
bodyType: "application/json",
|
||||
body: {
|
||||
text: JSON.stringify(
|
||||
{
|
||||
email: "me@example.com",
|
||||
admin: false,
|
||||
primaryContact: { name: "Taylor" },
|
||||
secondaryContact: { name: "Taylor" },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
},
|
||||
headers: expect.arrayContaining([
|
||||
{ enabled: false, name: "X-Trace-Id", value: "trace-123" },
|
||||
{ enabled: true, name: "Content-Type", value: "application/json" },
|
||||
]),
|
||||
urlParameters: [
|
||||
{ enabled: true, name: ":accountId", value: "acct_123" },
|
||||
{ enabled: false, name: "include", value: "roles" },
|
||||
],
|
||||
description: expect.stringContaining("Operation ID: createMember"),
|
||||
}),
|
||||
]);
|
||||
expect(imported?.resources.httpRequests[0]?.description).toContain("Member payload");
|
||||
expect(imported?.resources.httpRequests[0]?.description).toContain("201: Created");
|
||||
});
|
||||
|
||||
test("Handles large schemas without the Postman converter path", async () => {
|
||||
const paths: Record<string, unknown> = {};
|
||||
for (let i = 0; i < 500; i++) {
|
||||
paths[`/zones/{zoneId}/resources/${i}`] = {
|
||||
get: {
|
||||
tags: ["zones"],
|
||||
summary: `Read resource ${i}`,
|
||||
parameters: [
|
||||
{ name: "zoneId", in: "path", required: true, schema: { type: "string" } },
|
||||
{ name: "page", in: "query", schema: { type: "integer", default: 1 } },
|
||||
],
|
||||
responses: {
|
||||
"200": {
|
||||
description: "OK",
|
||||
content: {
|
||||
"application/json": { schema: { $ref: "#/components/schemas/Resource" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const imported = await convertOpenApi(
|
||||
JSON.stringify({
|
||||
openapi: "3.1.0",
|
||||
info: { title: "Large API", version: "1.0.0" },
|
||||
servers: [{ url: "https://api.example.com/client/v4" }],
|
||||
tags: [{ name: "zones" }],
|
||||
paths,
|
||||
components: {
|
||||
schemas: {
|
||||
Resource: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: { type: "string" },
|
||||
name: { type: "string" },
|
||||
metadata: { $ref: "#/components/schemas/Metadata" },
|
||||
},
|
||||
},
|
||||
Metadata: {
|
||||
type: "object",
|
||||
properties: {
|
||||
createdOn: { type: "string", format: "date-time" },
|
||||
tags: { type: "array", items: { type: "string" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(imported?.resources.httpRequests.length).toBe(500);
|
||||
expect(imported?.resources.httpRequests[499]).toEqual(
|
||||
expect.objectContaining({
|
||||
name: "Read resource 499",
|
||||
url: "https://api.example.com/client/v4/zones/:zoneId/resources/499",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test("Skips invalid file", async () => {
|
||||
const imported = await convertOpenApi("{}");
|
||||
expect(imported).toBeUndefined();
|
||||
@@ -46,7 +229,15 @@ describe("importer-openapi", () => {
|
||||
}),
|
||||
]);
|
||||
expect(imported?.resources.httpRequests.length).toBe(19);
|
||||
expect(imported?.resources.folders.length).toBe(7);
|
||||
expect(imported?.resources.folders.map((f) => f.name)).toEqual(["pet", "store", "user"]);
|
||||
});
|
||||
}
|
||||
|
||||
for (const fixture of realWorldFixtures) {
|
||||
test(`Snapshots real-world fixture ${fixture}`, async () => {
|
||||
const contents = fs.readFileSync(path.join(realWorldFixturesPath, fixture), "utf-8");
|
||||
const imported = await convertOpenApi(contents);
|
||||
expect(imported).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { convertOpenApiWithPostman } from "../src/legacy";
|
||||
|
||||
describe("importer-openapi legacy converter", () => {
|
||||
const realWorldFixturesPath = path.join(__dirname, "fixtures", "real-world");
|
||||
const realWorldFixtures = fs
|
||||
.readdirSync(realWorldFixturesPath)
|
||||
.filter((fixture) => fixture.endsWith(".yaml"));
|
||||
|
||||
for (const fixture of realWorldFixtures) {
|
||||
test(`Snapshots legacy Postman-converter output for ${fixture}`, async () => {
|
||||
const contents = fs.readFileSync(path.join(realWorldFixturesPath, fixture), "utf-8");
|
||||
const imported = await convertOpenApiWithPostman(contents);
|
||||
expect(imported).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user