|
1 |
| -<h1 align="center"> |
2 |
| - <br> |
3 |
| -API Doc Parser |
4 |
| -</h1> |
5 |
| - |
6 |
| -<p align="center"> |
7 |
| - <b> |
8 |
| -Effortlessly turn Hydra, Swagger/OpenAPI, and GraphQL specs into actionable data for your tools and apps. |
9 |
| - </b> |
10 |
| -</p> |
11 |
| - |
12 |
| -<p align="center"> |
13 |
| - <a href="https://github.com/api-platform/api-doc-parser/actions/workflows/ci.yml"> |
14 |
| - <img src="https://github.com/api-platform/api-doc-parser/actions/workflows/ci.yml/badge.svg" alt="CI"> |
15 |
| - </a> |
16 |
| - <a href="https://github.com/api-platform/api-doc-parser/blob/main/LICENSE"> |
17 |
| - <img src="https://img.shields.io/github/license/api-platform/api-doc-parser" alt="GitHub License"> |
18 |
| - </a> |
19 |
| - <a href="https://bundlephobia.com/package/@api-platform/api-doc-parser"> |
20 |
| - <img src="https://img.shields.io/bundlephobia/minzip/@api-platform/api-doc-parser" alt="npm bundle size"> |
21 |
| - </a> |
22 |
| - <a href="https://badge.fury.io/js/%40api-platform%2Fapi-doc-parser"> |
23 |
| - <img src="https://badge.fury.io/js/%40api-platform%2Fapi-doc-parser.svg" alt="npm version"> |
24 |
| - </a> |
25 |
| - <a href="https://img.shields.io/npm/dw/%40api-platform%2Fapi-doc-parser"> |
26 |
| - <img src="https://img.shields.io/npm/dw/%40api-platform%2Fapi-doc-parser" alt="NPM Downloads"> |
27 |
| - </a> |
28 |
| -</p> |
29 |
| - |
30 |
| -<p align="center"> |
31 |
| - <a href="#installation">Installation</a> • |
32 |
| - <a href="#usage">Usage</a> • |
33 |
| - <a href="#type-definitions">Type definitions</a> • |
34 |
| - <a href="#contributing">Contributing</a> • |
35 |
| - <a href="#credits">Credits</a> • |
36 |
| - <a href="#license">License</a> |
37 |
| -</p> |
| 1 | +# API Doc Parser |
| 2 | + |
| 3 | +**Effortlessly turn Hydra, Swagger/OpenAPI, and GraphQL specs into actionable data for your tools and apps.** |
| 4 | + |
| 5 | +[](https://github.com/api-platform/api-doc-parser/actions/workflows/ci.yml) |
| 6 | +[](https://github.com/api-platform/api-doc-parser/blob/main/LICENSE) |
| 7 | +[](https://bundlephobia.com/package/@api-platform/api-doc-parser) |
| 8 | +[](https://badge.fury.io/js/%40api-platform%2Fapi-doc-parser) |
| 9 | +[](https://img.shields.io/npm/dw/%40api-platform%2Fapi-doc-parser) |
38 | 10 |
|
39 | 11 | ---
|
40 | 12 |
|
41 |
| - <br> |
42 |
| -<p align="center"> |
43 |
| - <code>api-doc-parser</code> is a standalone TypeScript library that parses |
44 |
| - <a href="https://www.hydra-cg.com/">Hydra</a>, |
45 |
| - <a href="https://swagger.io/specification/v2/">Swagger</a>, |
46 |
| - <a href="https://github.com/OAI/OpenAPI-Specification#the-openapi-specification">OpenAPI</a>, |
47 |
| - and <a href="https://graphql.org/">GraphQL</a> documentation into a unified, intermediate representation.<br> |
48 |
| - This normalized structure enables smart API clients, code generators, admin interfaces, and more.<br> |
49 |
| - It integrates seamlessly with the <a href="https://api-platform.com/">API Platform</a> framework. |
50 |
| -</p> |
| 13 | +**`api-doc-parser` is a standalone TypeScript library that parses [Hydra](https://www.hydra-cg.com/), [Swagger](https://swagger.io/specification/v2/), [OpenAPI](https://github.com/OAI/OpenAPI-Specification#the-openapi-specification), and [GraphQL](https://graphql.org/) documentation into a unified, intermediate representation.** |
| 14 | +This normalized structure enables smart API clients, code generators, admin interfaces, and more. |
| 15 | +It integrates seamlessly with the [API Platform](https://api-platform.com/) framework. |
51 | 16 |
|
52 | 17 | ## ✨ Key Features
|
53 | 18 |
|
@@ -117,7 +82,7 @@ parseGraphQl("https://demo.api-platform.com/graphql").then(({ api }) =>
|
117 | 82 | );
|
118 | 83 | ```
|
119 | 84 |
|
120 |
| -## <img src="https://www.typescriptlang.org/icons/icon-48x48.png" alt="TypeScript" width="24" height="24" style="vertical-align:top; padding-right:4px;" /> Type definitions |
| 85 | +##  Type definitions |
121 | 86 |
|
122 | 87 | Each parse function returns a Promise that resolves to an object containing the normalized API structure, the raw documentation, and the HTTP status code:
|
123 | 88 |
|
@@ -298,7 +263,7 @@ If a rule is not met, the resource concerned is silently skipped.
|
298 | 263 | | **Schema discovery** | **GET** → first searches `responses → 200 → content → application/json`; if missing, falls back to `components` (component name must be singular, e.g. `Book`).<br/>**PUT/PATCH** → only `requestBody → content → application/json` is considered.<br/>If both GET & PUT/PATCH schemas exist, their fields are **merged**. |
|
299 | 264 | | **Collection paths** | A create (`POST`) or list (`GET`) endpoint **must** be plural:<br/>`/books`. |
|
300 | 265 | | **Deletion path** | `DELETE` must live under the single-item GET path (`/books/{id}`). |
|
301 |
| -| **Relations & Embeddeds** | Links between resources are inferred from property names and their JSON schema:<br/>• **Plural object/array properties** (e.g. `reviews`, `authors`) become **embedded** resources when their item schema matches an existing resource (`Review`, `Author`).<br/>• **ID-like properties** (e.g. `review_id`, `reviewId`, `review_ids`, `reviewIds`, `authorId`) are treated as **references** to that resource.<br/>• Matching algorithm: `camelize` → strip trailing `Id`/`Ids` → `classify` (singular PascalCase) → exact compare with resource titles. This effectively handles both plural and ID variants, regardless of original casing.<br/>• As a result, fields such as **`reviews`** (object/array) and **`review_ids`** (scalar/array of IDs) each point to the **same** `Review` resource, one flagged _embedded_, the other _reference_. | |
| 266 | +| **Relations & Embeddeds** | Links between resources are inferred from property names and their JSON schema:<br/>• **Plural object/array properties** (e.g. `reviews`, `authors`) become **embedded** resources when their item schema matches an existing resource (`Review`, `Author`).<br/>• **ID-like properties** (e.g. `review_id`, `reviewId`, `review_ids`, `reviewIds`, `authorId`) are treated as **references** to that resource.<br/>• As a result, fields such as **`reviews`** (object/array) and **`review_ids`** (scalar/array of IDs) each point to the **same** `Review` resource, one flagged _embedded_, the other _reference_. | |
302 | 267 | | **Parameter extraction** | Parameters are read **only** from the list path (`/books`). |
|
303 | 268 |
|
304 | 269 | ## 🧩 Support for other formats (JSON:API, AsyncAPI...)
|
@@ -347,9 +312,7 @@ Contributions are welcome! To contribute:
|
347 | 312 |
|
348 | 313 | ## 👥 Contributors
|
349 | 314 |
|
350 |
| -<a href="https://github.com/api-platform/api-doc-parser/graphs/contributors"> |
351 |
| - <img src="https://contrib.rocks/image?repo=api-platform/api-doc-parser" /> |
352 |
| -</a> |
| 315 | +[](https://github.com/api-platform/api-doc-parser/graphs/contributors) |
353 | 316 |
|
354 | 317 | ## 🌟 Star History
|
355 | 318 |
|
|
0 commit comments