Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paneq opened this issue Jul 26, 2019 · 3 comments
Open

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

paneq opened this issue Jul 26, 2019 · 3 comments

Comments

@paneq
Copy link

paneq commented Jul 26, 2019

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" : "[email protected]"
    },
    "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"
          }
        }
      }
    }
  }
}⏎   
@ketiko
Copy link
Owner

ketiko commented Aug 1, 2019

First off, thanks for using this project! Sorry I haven't replied to this sooner. I've been meaning to debug it but have been busy with work.

I actually haven't tested this with version 3 of the spec. I should have put in the README that it's only v2 supported. My guess is that the json scheme I have for validating that your json is valid is failing because it's checking for v2 formatting. However, I haven't confirmed that.

This gem simply adds spec helpers around the validations in the https://github.com/ketiko/open_api-schema_validator gem. That gem recently had v3 support added to it.

We could now enhance this gem to support either format. I don't have the time right now, but I'd be happy to help if someone made an initial PR with a possible solution.

I would love to add v3 support, it just might take me a bit of time until I could do it on my own.

Thanks again for using this project! I hope it's been helpful to you in the past if you had other v2 projects.

@theaxel
Copy link

theaxel commented Aug 12, 2019

Will add v3 support soon. Already put the starting pieces into the schema-validator gem for that.
Problem is exactly the default being v2 spec. There is no option yet to define which spec version you wanna use.

@theaxel
Copy link

theaxel commented Aug 12, 2019

Fix won't happen immediately as I'm on vacation the next 2 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants