Parses OpenAPI 3.x / Swagger 2.x JSON specs into ApiEndpoint[] descriptors compatible with buildApiTestPrompt.
Supports JSON format only (covers the vast majority of specs). YAML support can be added later with a lightweight parser.
Exports
parseOpenApiSpec—(specText) → ApiEndpoint[]
- Source:
Methods
(static) parseOpenApiSpec(specText) → {Array.<ApiEndpoint>}
Parse an OpenAPI 3.x or Swagger 2.x JSON spec into ApiEndpoint[] descriptors.
Parameters:
| Name | Type | Description |
|---|---|---|
specText |
string | — raw JSON string of the OpenAPI spec |
- Source:
Returns:
— endpoint descriptors, or empty array if parsing fails
- Type
- Array.<ApiEndpoint>
(inner) exampleFromSchema(schema) → {*}
Attempt to generate an example value from a JSON Schema property.
Parameters:
| Name | Type | Description |
|---|---|---|
schema |
object |
- Source:
Returns:
- Type
- *
(inner) extractRequestBody(operation, root) → {string|null}
Extract request body example from an OpenAPI 3.x operation.
Parameters:
| Name | Type | Description |
|---|---|---|
operation |
object | — the operation object (get/post/put etc.) |
root |
object | — full spec for $ref resolution |
- Source:
Returns:
- Type
- string | null
(inner) extractResponseBody(operation, root) → {string|null}
Extract response body example from an OpenAPI 3.x operation. Tries the success response (200/201) first.
Parameters:
| Name | Type | Description |
|---|---|---|
operation |
object | |
root |
object |
- Source:
Returns:
- Type
- string | null
(inner) resolveRef(ref, root) → {object|null}
Resolve a $ref path like "#/components/schemas/User" against the root spec. Only supports local JSON pointer refs (the most common kind).
Parameters:
| Name | Type | Description |
|---|---|---|
ref |
string | |
root |
object | — the full spec object |
- Source:
Returns:
- Type
- object | null
(inner) resolveSchema(schema, root) → {object}
Recursively resolve $ref in a schema object (one level deep to avoid loops).
Parameters:
| Name | Type | Description |
|---|---|---|
schema |
object | |
root |
object |
- Source:
Returns:
- Type
- object