metadevpro / openapi3-ts

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

Usage question #64

Closed patb23 closed 4 years ago

patb23 commented 4 years ago

Note: Have read 2 questions on usage and still not clear, hence this question. Request some help on usecases.

our application is based on Typescript, the API is hand-written in swagger hub. Looking for tools/api that would ensure the contract and implementation are aligned. Wanted to know, how this project can help in that regard. I tried a sample

import {SchemaObject} from "openapi3-ts";

export class TestSchema implements SchemaObject {

    title = "test ";
    type = "object";
    properties = {
        "test": {
            type: "string"
        }
    };

}

Questions:

  1. Am I doing it right here? I can build up on defining entire spec.
  2. I understand that I can use this to validate, can I use this to generate the document that can be rendered using other openapi tools?
pjmolina commented 4 years ago
  1. Yes. You can build a complete spec using this library with support for Typescript. And the expose or serialize the final doc to JSON or YAML (in v.2). Best guidance here is to take a look to how specs are build on the tests.
  2. Exactly. Once you render the contract, you can use it for all purposes.