Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

The property '#/' did not contain a required property of 'swagger' #8

@paneq

Description

@paneq

Hey, I am trying to use Open API v3 that I made in SwaggerHub but it fails for me with given error. Any idea what could be the problem?

Spec

RSpec.describe BackendController, type: :request do
  let(:open_api_json) do
    File.read("openapi.json")
  end

  describe "GET article_v1" do
    specify do
      get "/Old-Road-Studio/blogging/1.0.0/v1/article/123"
      expect(response).to have_http_status(200)
      expect(response.body).to be_valid_openapi_schema
    end
  end

Error

  1) BackendController GET article_v1 should be valid openapi schema
     Failure/Error: expect(response.body).to be_valid_openapi_schema
     
     JSON::Schema::ValidationError:
       The property '#/' did not contain a required property of 'swagger'
     # ./spec/requests/backends_spec.rb:12:in `block (3 levels) in <top (required)>'

Schema

{
  "openapi" : "3.0.0",
  "info" : {
    "title" : "Simple Blogging API",
    "description" : "Blogging API",
    "contact" : {
      "email" : "robert@example.org"
    },
    "license" : {
      "name" : "Apache 2.0",
      "url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
    },
    "version" : "1.0.0-oas3"
  },
  "servers" : [ {
    "url" : "https://virtserver.swaggerhub.com/Old-Road-Studio/blogging/1.0.0"
  } ],
  "tags" : [ {
    "name" : "blogging",
    "description" : "Api for blogging and articles"
  } ],
  "paths" : {
    "/v1/article/{articleId}" : {
      "get" : {
        "tags" : [ "blogging" ],
        "summary" : "returns a single article",
        "description" : "Get an Article by ID\n",
        "operationId" : "getArticleV1",
        "parameters" : [ {
          "name" : "articleId",
          "in" : "path",
          "description" : "article Id",
          "required" : true,
          "style" : "simple",
          "explode" : false,
          "schema" : {
            "type" : "integer"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "search results matching criteria",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ArticleV1"
                }
              }
            }
          },
          "404" : {
            "description" : "incorrect Article Id"
          }
        }
      }
    },
    "/v2/article/{articleId}" : {
      "get" : {
        "tags" : [ "blogging" ],
        "summary" : "returns a single article",
        "description" : "Get an Article by ID\n",
        "operationId" : "getArticleV2",
        "parameters" : [ {
          "name" : "articleId",
          "in" : "path",
          "description" : "article Id",
          "required" : true,
          "style" : "simple",
          "explode" : false,
          "schema" : {
            "type" : "integer"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "search results matching criteria",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ArticleV2"
                }
              }
            }
          },
          "404" : {
            "description" : "incorrect Article Id"
          }
        }
      }
    },
    "/v2/article" : {
      "post" : {
        "tags" : [ "blogging" ],
        "summary" : "Creates a draft of an article",
        "description" : "New article draft is created",
        "operationId" : "createArticleV2",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/NewArticleDraftV2"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "created article",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ArticleV2"
                }
              }
            }
          }
        }
      }
    },
    "/v1/article" : {
      "post" : {
        "tags" : [ "blogging" ],
        "summary" : "Creates a draft of an article",
        "description" : "New article draft is created",
        "operationId" : "createArticleV1",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/NewArticleDraftV1"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "created article",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ArticleV1"
                }
              }
            }
          }
        }
      }
    },
    "/article/{articleId}/publish" : {
      "post" : {
        "tags" : [ "blogging" ],
        "summary" : "Publishes an article",
        "description" : "Article is published and visible to everyone",
        "operationId" : "publishArticle",
        "parameters" : [ {
          "name" : "articleId",
          "in" : "path",
          "description" : "article Id",
          "required" : true,
          "style" : "simple",
          "explode" : false,
          "schema" : {
            "type" : "integer"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "article published",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ArticleV2"
                }
              }
            }
          },
          "404" : {
            "description" : "article not found"
          }
        }
      }
    }
  },
  "components" : {
    "schemas" : {
      "NewArticleDraftV1" : {
        "required" : [ "content", "title" ],
        "type" : "object",
        "properties" : {
          "title" : {
            "type" : "string",
            "example" : "Ruby is cool"
          },
          "content" : {
            "type" : "string",
            "example" : "This is a very long article about Ruby"
          }
        }
      },
      "NewArticleDraftV2" : {
        "required" : [ "category", "content", "title" ],
        "type" : "object",
        "properties" : {
          "title" : {
            "type" : "string",
            "example" : "Ruby is cool"
          },
          "content" : {
            "type" : "string",
            "example" : "This is a very long article about Ruby"
          },
          "category" : {
            "type" : "string",
            "enum" : [ "lifestyle", "programming", "cooking" ]
          }
        }
      },
      "ArticleV1" : {
        "required" : [ "content", "id", "status", "title" ],
        "type" : "object",
        "properties" : {
          "id" : {
            "type" : "integer",
            "example" : 123
          },
          "title" : {
            "type" : "string",
            "example" : "Ruby is cool"
          },
          "content" : {
            "type" : "string",
            "example" : "This is a very long article about Ruby"
          },
          "status" : {
            "type" : "string",
            "example" : "published",
            "enum" : [ "draft", "published", "deleted" ]
          },
          "publishedAt" : {
            "type" : "string",
            "format" : "date-time"
          }
        }
      },
      "ArticleV2" : {
        "required" : [ "category", "content", "id", "status", "title" ],
        "type" : "object",
        "properties" : {
          "id" : {
            "type" : "integer",
            "example" : 123
          },
          "title" : {
            "type" : "string",
            "example" : "Ruby is cool"
          },
          "content" : {
            "type" : "string",
            "example" : "This is a very long article about Ruby"
          },
          "status" : {
            "type" : "string",
            "example" : "published",
            "enum" : [ "draft", "published", "deleted" ]
          },
          "publishedAt" : {
            "type" : "string",
            "format" : "date-time"
          },
          "category" : {
            "type" : "string",
            "enum" : [ "lifestyle", "programming", "cooking" ]
          }
        }
      },
      "ArticlePublishedEvent" : {
        "required" : [ "event_type", "id", "publishedAt", "status" ],
        "type" : "object",
        "properties" : {
          "event_type" : {
            "type" : "string",
            "example" : "ArticlePublishedEvent",
            "enum" : [ "ArticlePublishedEvent" ]
          },
          "id" : {
            "type" : "integer",
            "example" : 123
          },
          "status" : {
            "type" : "string",
            "example" : "published",
            "enum" : [ "published" ]
          },
          "publishedAt" : {
            "type" : "string",
            "format" : "date-time"
          }
        }
      }
    }
  }
}⏎   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions