0.1.1 • Published 3 years ago
@sklandplus/openapi v0.1.1
@sklandplus/openapi
This package is used to generate the OpenAPI 3.1 schema for the API. Users who wish to use the API directly should refer
to the @sklandplus/client package instead.
Usage
import { schema } from '@sklandplus/openapi'
console.log(schema)Contributing
How to add a new API operation
- Put response body into a JSON -> JSON Schema converter, such as Quicktype.
- Copy the generated schema into
src/lib/renderer/schema/schemas/${operationName}Response.json. - Make sure the schema has a top-level definition. Quicktype, for example, have the issue where it only outputs
definitionswithout a top-leveltypeand (propertiesoritems) definition. Typically, you should just simply copy the firstdefinitionobject into the top-level of the schema. If the schema have a top-leveltypeand (propertiesoritems) definition, you are good to go. - Make sure the schema does NOT have a top-level
$refproperty. Quicktype, for example, also have this issue and this would cause the Swagger UI to stop rendering the schema. If the schema have a top-level$refproperty, you should remove it. - Add the schema to
src/lib/renderer/schema/index.ts. - Add the operation to
src/lib/renderer/index.ts. Make sure you are usingregistry.assertThenRefto reference the schema. - After you are done, run
yarn devto start a Swagger UI server locally and check if everything looks good.