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

GetValidators failing on a valid JSON swagger file #10

Open
mfeledyn opened this issue Jul 9, 2024 · 7 comments
Open

GetValidators failing on a valid JSON swagger file #10

mfeledyn opened this issue Jul 9, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@mfeledyn
Copy link

mfeledyn commented Jul 9, 2024

Describe the bug
I try to use your oasvalidator (which looks and sounds great ^^) in a Lua/Resty context (Kong gateway), and try with this mock API: https://httpbin.dmuth.org/
The swagger for this API is https://httpbin.dmuth.org/openapi.json
I saved the swagger to a local file I set as param to the call to oasvalidator.GetValidators(), and I get an error:

Invalid type of parameter: #/paths/4.6567238936384e-310redirect4.6567238933799e-310{n}/get/parameters/code

To Reproduce
Steps to reproduce the behavior:
Get the file: https://httpbin.dmuth.org/openapi.json, then try to use it as swagger file for GetValidators(...)

Expected behavior
I expected no error loading the file.
A tested the file using https://validator.swagger.io/, and the web site tells the file is correct.
(BTW GetValidator(...) using your example file data/openAPI_example.json works, but validator.swagger.io tells that the file is not a valid ??...)

Screenshots
N/A

Desktop (please complete the following information):

  • OS: debian bookworm/sid (the one of dockerhub Kong image)
  • Lua: LuaJIT 2.1.0-20231117 (the one of dockerhub Kong image)
  • Compiler: gcc (Debian 12.2.0-14) 12.2.0
  • Cmake: cmake version 3.25.1

Additional context
GetValidator(...) works using your example file "data/openAPI_example.json".
It also works with a very simple swagger file like this:

{
  "openapi": "3.0.3",
  "info": {
    "title": "MFTest",
    "description": "TESTs for MF",
    "version": "1.0.0"
  },
  "paths": {
    "/get": {
      "get": {
        "tags": [
          "pet"
        ],
        "summary": "Finds Pets by status",
        "description": "Multiple status values can be provided with comma separated strings",
        "operationId": "findPetsByStatus",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "description": "Status values that need to be considered for filter",
            "required": false,
            "explode": true,
            "schema": {
              "type": "string",
              "default": "available",
              "enum": [
                "available",
                "pending",
                "sold"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation"
          },
          "400": {
            "description": "Invalid status value"
          }
        }
      }
    }
  },
  "components": null
}

Many thx for help on this.
Using this very simple swagger I've been able to see wrong path and invalid parameter value behavior, and it's good :-)
Example with wrong param value:
{"errorCode":"INVALID_QUERY_PARAM","details":{"specRef":"#/paths/%2Fget/get/parameters/status","code":"enum","description":"Property has a value that is not one of its allowed enumerated values.","instance":"#","schema":"#"}}

@mfeledyn mfeledyn added the bug Something isn't working label Jul 9, 2024
@nawaz1991
Copy link
Owner

nawaz1991 commented Jul 11, 2024

@mfeledyn , I am on it and will respond you soon with fix.

@nawaz1991
Copy link
Owner

Just inverstigates and found that the base project cpp-oasvalidator does not have support for null data type and need to fix,
https://github.com/nawaz1991/cpp-oasvalidator/blob/main/src/validators/param_validators.cpp#L170
Will be fixing under cpp-oasvalidator

@nawaz1991
Copy link
Owner

OAS Validator was initially implemeted considering OpenAPI 3.0.0 but OpenAPI 3.1.x is based on https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-4.2.1 and also the null JSON type was added in OpenAPI.
Hence, this support missed and needs to be added.

@mfeledyn
Copy link
Author

mfeledyn commented Jul 12, 2024 via email

@mfeledyn
Copy link
Author

mfeledyn commented Jul 18, 2024 via email

@nawaz1991
Copy link
Owner

Hi Mickael,

I'm currently working on implementing support for missing parameter deserialization features such as nested arrays, nested objects, arrays of objects, and arrays within objects. This enhancement is taking some time to complete, but I aim to release it soon.

If you're under time constraints, I can prioritize a quick fix for handling null values and adding support for OpenAPI 3.1, which are essential for your API requirements. Please let me know your preference.

@mfeledyn
Copy link
Author

mfeledyn commented Nov 5, 2024

Hello Muhammad,
Any news on this subject ? Thx!

Regards,
Mickael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

2 participants