metadevpro / openapi3-ts

TS Model & utils for creating and exposing OpenAPI 3.x contracts.
MIT License
485 stars 64 forks source link

Documentation #75

Closed alichampion closed 2 months ago

alichampion commented 2 years ago

Very Poor documentation!

No example of how to use it.

@pjmolina please at least attach an example.

After searching a lot I got this code sandbox example.

https://codesandbox.io/s/olpj88zyly?file=/src/index.ts

svrakata commented 2 years ago

You can build schema. Example:

import { OpenApiBuilder, PathsObject, PathItemObject, ResponseObject } from "openapi3-ts";
import apiConfig from "./config";

const getUserResponse: ResponseObject = {
    description: "Gets user info by user id.",
}

const user: PathItemObject = {
    get: {
        operationId: "user",
        responses: {
            "200": getUserResponse,
        }
    }
}

const paths: PathsObject = {
    "/user": user,
}

const builder = OpenApiBuilder.create({
    openapi: apiConfig.openAPIVersion,
    info: {
        title: apiConfig.title,
        version: apiConfig.version,
        description: apiConfig.description,
        contact: apiConfig.contact,
    },
    paths,
    servers: [
        {
            url: `${apiConfig.host}:${apiConfig.port}`,
        },
    ],
});

builder.addPath("/articles", {
    get: {
        operationId: "articles",
        responses: {
            "200": {
                description: "Gets all articles.",
            },
        },
        parameters: [
            {
                name: "page",
                in: "query",
            },
        ],
    },
});

export const definition = builder.getSpec(); // js object
export const definitionJson = builder.getSpecAsJson(); // json
export const definitionYaml = builder.getSpecAsYaml(); // yaml
strazto commented 2 years ago

Very Poor documentation!

No example of how to use it.

I mean yea.

Kinda surprising that no-one has even tried to contribute documentation given that this project seems to have like 550k weekly installs

pjmolina commented 2 years ago

Thanks for the time taken to prepare and example @svrakata (we can use it as the seed for minimal docs). As you all know, documentation like any other feature requires time. Unit tests provided are a good source for documentation. PR are open and therefore, contributions are welcome. Thank you in advance.

CaptainYarb commented 1 year ago

The lack of documentation has now even made these comments out of date.

rddyck commented 7 months ago

https://codesandbox.io/s/olpj88zyly?file=/src/index.ts

So. someone who is trying to learn what all it can do and how to use it is responsible for creating documentation?

pjmolina commented 4 months ago

Added some basic docs on PR #139 Feel free to ask for anything else, or better, add a PR to improve it.