Skip to main content

Add a Service Definition

Petstore Example​

Let's start by downloading an existing Service Definition. Swagger.io offers an example Swagger doc defining an example pet store service: Petstore. Download the source json file as petstore.json and put it in the root folder of your project:

curl https://petstore3.swagger.io/api/v3/openapi.json -o petstore.json

Update the source property​

Update the source property in your basketry.config.json file to point to the petstore.json file:

basketry.config.json
{
"source": "petstore.json",
"parser": "",
"rules": [],
"generators": [],
"output": "",
"options": {
"basketry": {}
}
}

Install a parser​

By default, Basketry doesn't know about OpenAPI v3—Basketry needs a parser to convert the source file into a format usable by the rest of the pipeline. Install the @basketry/openapi-3 package to parse OpenAPI 3.0 documents:

npm install @basketry/openapi-3

Update the parser property​

Update the parser property in your basketry.config.json file to point to the @basketry/openapi-3 package:

basketry.config.json
{
"source": "petstore.json",
"parser": "@basketry/openapi-3",
"rules": [],
"generators": [],
"output": "",
"options": {
"basketry": {}
}
}
info

Learn more about the parsers that Basketry provides by checking out the parser components.

Now, Basketry knows where to source your service definition and how to parse it. Next, we'll generate some code!