Skip to content

Instantly share code, notes, and snippets.

@jkeam
Last active February 14, 2024 23:08
Show Gist options
  • Save jkeam/b5851a983efdd61e529e2ba918d833e8 to your computer and use it in GitHub Desktop.
Save jkeam/b5851a983efdd61e529e2ba918d833e8 to your computer and use it in GitHub Desktop.
OCP API Demo Script

Service Registry Script

API Designer

Link

Designer

Based off of this

Basics

  1. Title - Product Catalog API
  2. Description - API for the Product Catalog Service
  3. License - MIT
  4. Tags - retail and catalog
  5. Security Schemes - name - product-catalog-api type - API Key key location - HTTP header name - api_key
  6. Security - select product-catalog-api just created

New Data Type

  1. Create product

New Response

  1. Name it product
  2. application/json
  3. Type of product just created
  4. Add examples
    "product-with-inventory": {
        "value": {
            "itemId": "329299",
            "name": "Quarkus T-shirt",
            "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
            "price": 10,
            "quantity": 736
        }
    },
    "product-without-inventory": {
        "value": {
            "itemId": "329299",
            "name": "Quarkus T-shirt",
            "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
            "price": 10
        }
    } 

Paths

  1. /services/product/{id}

  2. Summary - Get product by Id

  3. Description - Get product by Id

  4. Path Parameter

  5. "parameters": [
     {
         "examples": {
             "product-with-inventory": {
                 "value": "329299"
             },
             "product-without-inventory": {
                 "value": "329299"
             },
             "product-non-existing": {
                 "value": "999999"
             }
         },
         "name": "id",
         "schema": {
             "type": "string"
         },
         "in": "path",
         "required": true
     }
  6. Create GET operation

  7. Query param in the GET operation

    {
    "name": "inventory",
    "description": "whether to include inventory information in the response",
    "schema": {
        "type": "boolean"
    },
    "in": "query"
    }

    with example:

    "product-without-inventory": {
        "value": "false"
    }
  8. Response - plus sign, add 200, select product

  9. Response - plus sign, add 404, not found

  10. Security Requirements - choose api key

Drop in Real Value

  1. Just get this json, click the API name, source and paste it in.
  2. Click Save As JSON

Apicurio Registry

Link

  1. Click Upload Artifact
  2. Name it globex / ProductCatalogAPI
  3. Validity rule -> Full

Demonstrate messing up the json.

Microcks

Link

  1. Importers
    • Select Product Catalog
    • Enter in URL
  2. Open URL and see the example being served

3scale

Based off of this.

Docs

@jkeam
Copy link
Author

jkeam commented Feb 14, 2024

Example spec:

{
    "openapi": "3.0.2",
    "info": {
        "title": "Product Catalog API",
        "version": "1.0.0",
        "description": "API for the Product Catalog Service",
        "license": {
            "name": "MIT License",
            "url": "https://opensource.org/licenses/MIT"
        }
    },
    "paths": {
        "/services/product/{id}": {
            "summary": "Get product by Id",
            "description": "Get product by Id",
            "get": {
                "parameters": [
                    {
                        "examples": {
                            "product-without-inventory": {
                                "value": "false"
                            }
                        },
                        "name": "inventory",
                        "description": "whether to include inventory information in the response",
                        "schema": {
                            "type": "boolean"
                        },
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/product"
                    },
                    "404": {
                        "description": "Product not found"
                    }
                },
                "security": [
                    {
                        "product-catalog-api": [
                        ]
                    }
                ],
                "summary": "Get product by Id",
                "description": "Get product by Id"
            },
            "parameters": [
                {
                    "examples": {
                        "product-with-inventory": {
                            "value": "329299"
                        },
                        "product-without-inventory": {
                            "value": "329299"
                        },
                        "product-non-existing": {
                            "value": "999999"
                        }
                    },
                    "name": "id",
                    "schema": {
                        "type": "string"
                    },
                    "in": "path",
                    "required": true
                }
            ]
        },
        "/services/products": {
            "summary": "Get paginated list of Products",
            "get": {
                "parameters": [
                    {
                        "examples": {
                            "paginated-product-list-with-inventory": {
                                "value": "5"
                            },
                            "paginated-product-list-without-inventory": {
                                "value": "5"
                            }
                        },
                        "name": "limit",
                        "description": "Max number of records returned.",
                        "schema": {
                            "type": "integer"
                        },
                        "in": "query"
                    },
                    {
                        "examples": {
                            "paginated-product-list-with-inventory": {
                                "value": "1"
                            },
                            "paginated-product-list-without-inventory": {
                                "value": "1"
                            }
                        },
                        "name": "page",
                        "description": "The page number. First page is 1.",
                        "schema": {
                            "type": "integer"
                        },
                        "in": "query"
                    },
                    {
                        "examples": {
                            "paginated-product-list-without-inventory": {
                                "value": "false"
                            }
                        },
                        "name": "inventory",
                        "description": "Whether to define inventory information in the response",
                        "schema": {
                            "type": "boolean"
                        },
                        "in": "query",
                        "required": false
                    }
                ],
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/paginated-product-list"
                    }
                },
                "security": [
                    {
                        "product-catalog-api": [
                        ]
                    }
                ],
                "summary": "Get paginated list of products"
            }
        },
        "/services/product/list/{ids}": {
            "description": "Get products list by Ids",
            "get": {
                "parameters": [
                    {
                        "examples": {
                            "product-list-without-inventory": {
                                "value": "false"
                            }
                        },
                        "name": "inventory",
                        "description": "Whether to include inventory information in the response",
                        "schema": {
                            "type": "boolean"
                        },
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/product-list"
                    }
                },
                "security": [
                    {
                        "product-catalog-api": [
                        ]
                    }
                ],
                "summary": "Get list of product by Id"
            },
            "parameters": [
                {
                    "examples": {
                        "product-list-with-inventory": {
                            "value": "329199,329299"
                        },
                        "product-list-without-inventory": {
                            "value": "329199,329299"
                        }
                    },
                    "name": "ids",
                    "schema": {
                        "type": "string"
                    },
                    "in": "path",
                    "required": true
                }
            ]
        }
    },
    "components": {
        "schemas": {
            "paginated-product-list": {
                "description": "",
                "type": "object"
            },
            "product": {
                "description": "",
                "type": "object"
            }
        },
        "responses": {
            "product": {
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/product"
                        },
                        "examples": {
                            "product-with-inventory": {
                                "value": {
                                    "itemId": "329299",
                                    "name": "Quarkus T-shirt",
                                    "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                    "price": 10,
                                    "quantity": 736
                                }
                            },
                            "product-without-inventory": {
                                "value": {
                                    "itemId": "329299",
                                    "name": "Quarkus T-shirt",
                                    "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                    "price": 10
                                }
                            }
                        }
                    }
                },
                "description": "Product Details by Id"
            },
            "product-list": {
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/components/schemas/product"
                            }
                        },
                        "examples": {
                            "product-list-with-inventory": {
                                "value": [
                                    {
                                        "itemId": "329299",
                                        "name": "Quarkus T-shirt",
                                        "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                        "price": 10,
                                        "quantity": 736
                                    },
                                    {
                                        "itemId": "329199",
                                        "name": "Pronounced Kubernetes",
                                        "desc": "Our Men's Value T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                        "price": 9,
                                        "quantity": 512
                                    }
                                ]
                            },
                            "product-list-without-inventory": {
                                "value": [
                                    {
                                        "itemId": "329299",
                                        "name": "Quarkus T-shirt",
                                        "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                        "price": 10
                                    },
                                    {
                                        "itemId": "329199",
                                        "name": "Pronounced Kubernetes",
                                        "desc": "Our Men's Value T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                        "price": 9
                                    }
                                ]
                            }
                        }
                    }
                },
                "description": "List of products"
            },
            "paginated-product-list": {
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/paginated-product-list"
                        },
                        "examples": {
                            "paginated-product-list-with-inventory": {
                                "value": {
                                    "content": [
                                        {
                                            "itemId": "329299",
                                            "name": "Quarkus T-shirt",
                                            "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                            "price": 10,
                                            "quantity": 736
                                        },
                                        {
                                            "itemId": "329199",
                                            "name": "Pronounced Kubernetes",
                                            "desc": "Our Men's Value T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                            "price": 9,
                                            "quantity": 512
                                        },
                                        {
                                            "itemId": "165613",
                                            "name": "Knit socks",
                                            "desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut urna leo, cursus a fringilla et, aliquam at tellus. Praesent est nulla, mattis in auctor vitae, commodo sed eros. Etiam volutpat a felis vel elementum. Duis ut vestibulum orci, ut hendrerit felis. Nulla nunc lectus, luctus ut tortor a, sollicitudin gravida dolor. Integer euismod, velit non tempor mattis, odio neque ornare neque, nec sollicitudin elit massa nec ante.",
                                            "price": 4.15,
                                            "quantity": 256
                                        },
                                        {
                                            "itemId": "165614",
                                            "name": "Quarkus H2Go water bottle",
                                            "desc": "Copper vacuum insulated sport bottle with 650 ml capacity. Durable, double wall stainless steel vacuum construction with copper insulation, which allows your beverage to stay cold for 48 hours and at least 12 hours for hot beverages. The construction also prevents condensation on the outside of the bottle. Material: Stainless Steel. Colour: Black Height:27,20 cm Diameter:7,20 cm Weight:380 gram",
                                            "price": 14.45,
                                            "quantity": 54
                                        },
                                        {
                                            "itemId": "165954",
                                            "name": "Patagonia Refugio pack 28L",
                                            "desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut urna leo, cursus a fringilla et, aliquam at tellus. Praesent est nulla, mattis in auctor vitae, commodo sed eros. Etiam volutpat a felis vel elementum. Duis ut vestibulum orci, ut hendrerit felis. Nulla nunc lectus, luctus ut tortor a, sollicitudin gravida dolor. Integer euismod, velit non tempor mattis, odio neque ornare neque, nec sollicitudin elit massa nec ante.",
                                            "price": 6,
                                            "quantity": 87
                                        }
                                    ],
                                    "pageable": {
                                        "sort": {
                                            "sorted": false,
                                            "unsorted": true,
                                            "empty": true
                                        },
                                        "offset": 0,
                                        "pageNumber": 0,
                                        "pageSize": 5,
                                        "paged": true,
                                        "unpaged": false
                                    },
                                    "totalPages": 9,
                                    "totalElements": 41,
                                    "last": false,
                                    "size": 5,
                                    "number": 0,
                                    "sort": {
                                        "sorted": false,
                                        "unsorted": true,
                                        "empty": true
                                    },
                                    "numberOfElements": 5,
                                    "first": true,
                                    "empty": false
                                }
                            },
                            "paginated-product-list-without-inventory": {
                                "value": {
                                    "content": [
                                        {
                                            "itemId": "329299",
                                            "name": "Quarkus T-shirt",
                                            "desc": "Our T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                            "price": 10
                                        },
                                        {
                                            "itemId": "329199",
                                            "name": "Pronounced Kubernetes",
                                            "desc": "Our Men's Value T-Shirt is an everyday essential! This short-sleeve heavyweight T-shirt is comfortable, economical and made to last. Designed with a traditional fit that runs true to size, he’ll show off his personality, humor and interests with an easy, relaxed style.",
                                            "price": 9
                                        },
                                        {
                                            "itemId": "165613",
                                            "name": "Knit socks",
                                            "desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut urna leo, cursus a fringilla et, aliquam at tellus. Praesent est nulla, mattis in auctor vitae, commodo sed eros. Etiam volutpat a felis vel elementum. Duis ut vestibulum orci, ut hendrerit felis. Nulla nunc lectus, luctus ut tortor a, sollicitudin gravida dolor. Integer euismod, velit non tempor mattis, odio neque ornare neque, nec sollicitudin elit massa nec ante.",
                                            "price": 4.15
                                        },
                                        {
                                            "itemId": "165614",
                                            "name": "Quarkus H2Go water bottle",
                                            "desc": "Copper vacuum insulated sport bottle with 650 ml capacity. Durable, double wall stainless steel vacuum construction with copper insulation, which allows your beverage to stay cold for 48 hours and at least 12 hours for hot beverages. The construction also prevents condensation on the outside of the bottle. Material: Stainless Steel. Colour: Black Height:27,20 cm Diameter:7,20 cm Weight:380 gram",
                                            "price": 14.45
                                        },
                                        {
                                            "itemId": "165954",
                                            "name": "Patagonia Refugio pack 28L",
                                            "desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut urna leo, cursus a fringilla et, aliquam at tellus. Praesent est nulla, mattis in auctor vitae, commodo sed eros. Etiam volutpat a felis vel elementum. Duis ut vestibulum orci, ut hendrerit felis. Nulla nunc lectus, luctus ut tortor a, sollicitudin gravida dolor. Integer euismod, velit non tempor mattis, odio neque ornare neque, nec sollicitudin elit massa nec ante.",
                                            "price": 6
                                        }
                                    ],
                                    "pageable": {
                                        "sort": {
                                            "sorted": false,
                                            "unsorted": true,
                                            "empty": true
                                        },
                                        "offset": 0,
                                        "pageNumber": 0,
                                        "pageSize": 5,
                                        "paged": true,
                                        "unpaged": false
                                    },
                                    "totalPages": 9,
                                    "totalElements": 41,
                                    "last": false,
                                    "size": 5,
                                    "number": 0,
                                    "sort": {
                                        "sorted": false,
                                        "unsorted": true,
                                        "empty": true
                                    },
                                    "numberOfElements": 5,
                                    "first": true,
                                    "empty": false
                                }
                            }
                        }
                    }
                },
                "description": "API to get product details.\n- get Paginated list of Products\n- get Product details based on comma separated ids\n- get Product detail of a specific product id"
            }
        },
        "securitySchemes": {
            "product-catalog-api": {
                "type": "apiKey",
                "name": "api_key",
                "in": "header"
            }
        }
    },
    "security": [
        {
            "product-catalog-api": [
            ]
        }
    ],
    "tags": [
        {
            "name": "retail",
            "description": ""
        },
        {
            "name": "catalog",
            "description": ""
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment