Skip to content

Commit 789b086

Browse files
committed
Initial docs. issue #75
1 parent 123e77a commit 789b086

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ Install package via **npm**:
5151
npm i --save openapi3-ts
5252
```
5353

54-
## Versions and Changelog
54+
## Documentation, Versions, and Changelog
5555

56-
See [changelog](Changelog.md).
56+
* [Documentation](docs/index.md).
57+
* See [changelog](Changelog.md) for version and changes.
5758

5859
## References
5960

@@ -67,4 +68,4 @@ Licensed under the MIT License.
6768

6869
**Contact:** Pedro J. Molina | github: [pjmolina](https://github.com/pjmolina) | twitter: [pmolinam](https://twitter.com/pmolinam)
6970

70-
(c) 2017-2023. [Pedro J. Molina](http://pjmolina.com) at Metadev S.L. [https://metadev.pro](https://metadev.pro) & contributors.
71+
(c) 2017-2024. [Pedro J. Molina](http://pjmolina.com) at Metadev S.L. [https://metadev.pro](https://metadev.pro) & contributors.

docs/index.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# OpenAPI3-TS Documentation
2+
3+
OpenAPI3-TS is a library implemented in TypeScript to help creating documents following the [**OpenAPI Specifications**](https://spec.openapis.org/oas/latest.html) to describe REST APIs in a machine & humam processable format.
4+
5+
## Use Cases
6+
7+
1. Create a OAS document from scratch and export it to JSON or YAML.
8+
9+
The builder pattern, the TS compiler & the code-completion will guide you to add the correct data.
10+
11+
- I can be used in TypeScript or Javascript projects working with NodeJS or Deno (in the backend).
12+
- But also on the browser as the libraries has not dependencies on other libs.
13+
14+
## Basic Example
15+
16+
Minimal example to generate a 3.1 OAS compliant document:
17+
18+
```typescript
19+
import * from 'openapi3-ts/oas31';
20+
21+
function buildOas() {
22+
const builder = OpenApiBuilder
23+
.create()
24+
.addOpenApiVersion('3.1.0')
25+
.addInfo({
26+
title: 'app',
27+
version: 'version'
28+
})
29+
.addLicense({
30+
name: 'Apache 2.0',
31+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
32+
}),
33+
.addTitle('my title')
34+
.addPath('pet/{petId}', {
35+
get: {
36+
tags: ["pet"],
37+
summary: "Find pet by ID",
38+
description: "Returns a single pet",
39+
operationId: "getPetById",
40+
produces: ["application/json", "application/xml"]
41+
}
42+
})
43+
.addResponse('Created', {
44+
description: 'Object created'
45+
})
46+
.addSchema('Email', {
47+
type: 'string',
48+
format: 'email'
49+
})
50+
.addParameter('id', {
51+
name: 'id',
52+
in: 'header' as ParameterLocation,
53+
schema: {
54+
$ref: '#/components/schemas/id'
55+
});
56+
//...keep building
57+
58+
const doc = builder.getSpec();
59+
const docJson = builder.getSpecAsJson();
60+
const docYaml = builder.getSpecAsYaml();
61+
}
62+
63+
```
64+
65+
## Dependencies
66+
67+
The unique dependency in runtime is `yaml` to provide the YAML from/to conversions features.
68+
69+
## Code Organization
70+
71+
- `src` contains the production code.
72+
- `dsl` provides the API of the library following the [intenal DSL style](https://martinfowler.com/bliki/InternalDslStyle.html) (or _fluent interface_) with two flavours: 3.0.x & 3.1.x to allow conformance with both versions of the spec.
73+
- `model` provides a DOM (Document Object Model) describing the concepts defined in the OpenAPI spec. Again in two flavours: 3.0.x and 3.1.x.
74+
- Finally `oas30.ts` & `oas31.ts` expose the types as separate namespaces.
75+
- `test` constains the unit tests.
76+
77+
## License
78+
79+
Licensed under the MIT License.

0 commit comments

Comments
 (0)