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

Panic encountered during jsonschema validation #83

Closed
TristanSpeakEasy opened this issue Jan 14, 2024 · 8 comments
Closed

Panic encountered during jsonschema validation #83

TristanSpeakEasy opened this issue Jan 14, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@TristanSpeakEasy
Copy link

This spec:

openapi: 3.1.0
info:
  title: Test
  version: 0.1.0
security:
  - apiKeyAuth: []
paths:
  /anything/queryParams/deepObject/obj:
    get:
      operationId: deepObjectQueryParamsObject
      parameters:
        - name: objParam
          in: query
          style: deepObject
          schema:
            $ref: "components.yaml#/components/schemas/simpleObject"
          required: true
        - name: objArrParam
          in: query
          style: deepObject
          schema:
            type: object
            properties:
              arr:
                type: array
                items:
                  type: string
                  examples:
                    - test
                    - test2
      responses:
        "200":
          description: OK
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Authenticate using an API Key generated via our platform.

when a request is sent causes the below panic:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x68 pc=0xade1e6]

goroutine 264 [running]:
github.com/santhosh-tekuri/jsonschema/v5.(*Schema).validateValue.func1()
        /home/runner/go/pkg/mod/github.com/santhosh-tekuri/jsonschema/v5@v5.3.1/schema.go:178 +0xa9
panic({0xce4100?, 0x1dbe3b0?})
        /opt/hostedtoolcache/go/1.21.5/x64/src/runtime/panic.go:914 +0x21f
github.com/santhosh-tekuri/jsonschema/v5.(*Schema).validate(0x0, {0x0, 0x0, 0x0}, 0x0, {0x0, 0x0}, {0xcd4cc0, 0xc00034d350?}, {0x0, ...})
        /home/runner/go/pkg/mod/github.com/santhosh-tekuri/jsonschema/v5@v5.3.1/schema.go:253 +0x526
github.com/santhosh-tekuri/jsonschema/v5.(*Schema).validateValue(0x0, {0xcd4cc0?, 0xc00034d350?}, {0x0, 0x0})
        /home/runner/go/pkg/mod/github.com/santhosh-tekuri/jsonschema/v5@v5.3.1/schema.go:182 +0xbf
github.com/santhosh-tekuri/jsonschema/v5.(*Schema).Validate(...)
        /home/runner/go/pkg/mod/github.com/santhosh-tekuri/jsonschema/v5@v5.3.1/schema.go:168
github.com/pb33f/libopenapi-validator/parameters.ValidateParameterSchema(0xc0002eaf00, {0xcd4cc0, 0xc00034d350?}, {0xc00095008c, 0x13}, {0xe6ec8a, 0xf}, {0xe718d6, 0x13}, {0xc0005fae78, ...}, ...)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.0.39/parameters/validate_parameter.go:84 +0x4c5
github.com/pb33f/libopenapi-validator/parameters.(*paramValidator).ValidateQueryParams(0xc0005e0a40, 0xc00094e000)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.0.39/parameters/query_parameters.go:188 +0x1659
github.com/pb33f/libopenapi-validator.(*validator).ValidateHttpRequest.func1.2(0x0?, 0x0?, 0x0?)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.0.39/validator.go:225 +0x27
created by github.com/pb33f/libopenapi-validator.(*validator).ValidateHttpRequest.func1 in goroutine 258
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.0.39/validator.go:233 +0x3b2
@daveshanley daveshanley added the bug Something isn't working label Jan 19, 2024
@daveshanley
Copy link
Member

will investigate

daveshanley added a commit to pb33f/libopenapi-validator that referenced this issue Jan 27, 2024
Signed-off-by: Dave Shanley <dave@quobix.com>
@daveshanley daveshanley mentioned this issue Jan 27, 2024
daveshanley added a commit to pb33f/libopenapi-validator that referenced this issue Jan 27, 2024
Signed-off-by: Dave Shanley <dave@quobix.com>
@daveshanley
Copy link
Member

This should be resolved in v0.1.1

@TristanSpeakEasy
Copy link
Author

I still encounter this exact panic on this spec

@TristanSpeakEasy
Copy link
Author

This spec also caused the panic:

openapi: 3.1.0
info:
  title: Test
  version: 0.1.0
security:
  - apiKeyAuth: []
paths:
  /anything/queryParams/form/obj:
    get:
      x-speakeasy-test: true
      operationId: formQueryParamsObject
      tags:
        - parameters
      parameters:
        - name: objParamExploded
          in: query
          explode: true
          schema:
            $ref: "#/components/schemas/simpleObject"
          required: true
        - name: objParam
          in: query
          explode: false
          schema:
            $ref: "#/components/schemas/simpleObject"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                title: res
                type: object
                properties:
                  url:
                    type: string
                    example: http://localhost:35123/anything/queryParams/form/obj?any=any&bigint=8821239038968084&bigintStr=9223372036854775808&bool=true&boolOpt=true&date=2020-01-01&dateTime=2020-01-01T00%3A00%3A00.000001Z&decimal=3.141592653589793&decimalStr=3.14159265358979344719667586&enum=one&float32=1.1&int=1&int32=1&int32Enum=55&intEnum=2&num=1.1&objParam=any%2Cany%2Cbigint%2C8821239038968084%2CbigintStr%2C9223372036854775808%2Cbool%2Ctrue%2CboolOpt%2Ctrue%2Cdate%2C2020-01-01%2CdateTime%2C2020-01-01T00%3A00%3A00.000001Z%2Cdecimal%2C3.141592653589793%2CdecimalStr%2C3.14159265358979344719667586%2Cenum%2Cone%2Cfloat32%2C1.1%2Cint%2C1%2Cint32%2C1%2Cint32Enum%2C55%2CintEnum%2C2%2Cnum%2C1.1%2Cstr%2Ctest%2CstrOpt%2CtestOptional&str=test&strOpt=testOptional
                    x-speakeasy-test-internal-directives:
                      - sortQueryParameters: {}
                      - sortSerializedMaps:
                          { "regex": "objParam=(.*?)&", "delim": "%2C" }
                  args:
                    type: object
                    properties:
                      str:
                        type: string
                        example: "test"
                      bool:
                        type: string
                        example: "true"
                      int:
                        type: string
                        example: "1"
                      int32:
                        type: string
                        example: "1"
                      num:
                        type: string
                        example: "1.1"
                      float32:
                        type: string
                        example: "1.1"
                      enum:
                        type: string
                        example: "one"
                      any:
                        type: string
                        example: "any"
                      date:
                        type: string
                        example: "2020-01-01"
                      dateTime:
                        type: string
                        example: "2020-01-01T00:00:00.000001Z"
                      boolOpt:
                        type: string
                        example: "true"
                      strOpt:
                        type: string
                        example: "testOptional"
                      intOptNull:
                        type: string
                      numOptNull:
                        type: string
                      objParam:
                        type: string
                        example: "any,any,bigint,8821239038968084,bigintStr,9223372036854775808,bool,true,boolOpt,true,date,2020-01-01,dateTime,2020-01-01T00:00:00.000001Z,decimal,3.141592653589793,decimalStr,3.14159265358979344719667586,enum,one,float32,1.1,int,1,int32,1,int32Enum,55,intEnum,2,num,1.1,str,test,strOpt,testOptional"
                        x-speakeasy-test-internal-directives:
                          - sortSerializedMaps:
                              { "regex": "(.*)", "delim": "," }
                      intEnum:
                        type: string
                        example: "2"
                      int32Enum:
                        type: string
                        example: "55"
                      bigint:
                        type: string
                        example: "8821239038968084"
                      bigintStr:
                        type: string
                        example: "9223372036854775808"
                      decimal:
                        type: string
                        example: "3.141592653589793"
                      decimalStr:
                        type: string
                        example: "3.14159265358979344719667586"
                    required:
                      - str
                      - bool
                      - int
                      - int32
                      - num
                      - float32
                      - enum
                      - any
                      - date
                      - dateTime
                      - objParam
                      - intEnum
                      - int32Enum
                required:
                  - url
                  - args
components:
  schemas:
    simpleObject:
      description: "A simple object that uses all our supported primitive types and enums and has optional properties."
      externalDocs:
        description: "A link to the external docs."
        url: "https://docs.speakeasyapi.dev"
      type: object
      properties:
        str:
          type: string
          description: "A string property."
          example: "test"
        bool:
          type: boolean
          description: "A boolean property."
          example: true
        int:
          type: integer
          description: "An integer property."
          example: 1
        int32:
          type: integer
          format: int32
          description: "An int32 property."
          example: 1
        num:
          type: number
          description: "A number property."
          example: 1.1
        float32:
          type: number
          format: float
          description: "A float32 property."
          example: 1.1
        enum:
          $ref: "#/components/schemas/enum"
        date:
          type: string
          format: date
          description: "A date property."
          example: "2020-01-01"
        dateTime:
          type: string
          format: date-time
          description: "A date-time property."
          example: "2020-01-01T00:00:00.000001Z"
        any:
          description: "An any property."
          example: "any"
        strOpt:
          type: string
          description: "An optional string property."
          example: "testOptional"
        boolOpt:
          type: boolean
          description: "An optional boolean property."
          example: true
        intOptNull:
          type: integer
          description: "An optional integer property will be null for tests."
        numOptNull:
          type: number
          description: "An optional number property will be null for tests."
        intEnum:
          type: integer
          description: "An integer enum property."
          enum:
            - 1
            - 2
            - 3
          example: 2
          x-speakeasy-enums:
            - First
            - Second
            - Third
        int32Enum:
          type: integer
          format: int32
          description: "An int32 enum property."
          enum:
            - 55
            - 69
            - 181
          example: 55
        bigint:
          type: integer
          format: bigint
          example: 8821239038968084
        bigintStr:
          type: string
          format: bigint
          example: "9223372036854775808"
        decimal:
          type: number
          format: decimal
          example: 3.141592653589793
        decimalStr:
          type: string
          format: decimal
          example: "3.14159265358979344719667586"
      required:
        - str
        - bool
        - int
        - int32
        - num
        - float32
        - enum
        - date
        - dateTime
        - any
        - intEnum
        - int32Enum
    enum:
      type: string
      description: "A string based enum"
      enum:
        - "one"
        - "two"
        - "three"
        - "four_and_more"
      example: "one"
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Authenticate using an API Key generated via our platform.

using URL: http://localhost:35123/anything/queryParams/form/obj?any=any&bigint=8821239038968084&bigintStr=9223372036854775808&bool=true&boolOpt=true&date=2020-01-01&dateTime=2020-01-01T00%3A00%3A00.000001Z&decimal=3.141592653589793&decimalStr=3.14159265358979344719667586&enum=one&float32=1.1&int=1&int32=1&int32Enum=55&intEnum=2&num=1.1&objParam=any%2Cany%2Cbigint%2C8821239038968084%2CbigintStr%2C9223372036854775808%2Cbool%2Ctrue%2CboolOpt%2Ctrue%2Cdate%2C2020-01-01%2CdateTime%2C2020-01-01T00%3A00%3A00.000001Z%2Cdecimal%2C3.141592653589793%2CdecimalStr%2C3.14159265358979344719667586%2Cenum%2Cone%2Cfloat32%2C1.1%2Cint%2C1%2Cint32%2C1%2Cint32Enum%2C55%2CintEnum%2C2%2Cnum%2C1.1%2Cstr%2Ctest%2CstrOpt%2CtestOptional&str=test&strOpt=testOptional

@TristanSpeakEasy
Copy link
Author

TristanSpeakEasy commented Jan 29, 2024

Another simpler spec that causes the issue:

openapi: 3.1.0
info:
  title: Test
  version: 0.1.0
security:
  - apiKeyAuth: []
paths:
  /anything/headers/obj:
    get:
      x-speakeasy-test: true
      operationId: headerParamsObject
      tags:
        - parameters
      parameters:
        - name: X-Header-Obj
          in: header
          schema:
            $ref: "#/components/schemas/simpleObject"
          required: true
        - name: X-Header-Obj-Explode
          in: header
          explode: true
          schema:
            $ref: "#/components/schemas/simpleObject"
          required: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                title: res
                type: object
                properties:
                  headers:
                    type: object
                    properties:
                      X-Header-Obj:
                        type: string
                        example: any,any,bigint,8821239038968084,bigintStr,9223372036854775808,bool,true,boolOpt,true,date,2020-01-01,dateTime,2020-01-01T00:00:00.000001Z,decimal,3.141592653589793,decimalStr,3.14159265358979344719667586,enum,one,float32,1.1,int,1,int32,1,int32Enum,55,intEnum,2,num,1.1,str,test,strOpt,testOptional
                        x-speakeasy-test-internal-directives:
                          - sortSerializedMaps:
                              { "regex": "(.*)", "delim": "," }
                      X-Header-Obj-Explode:
                        type: string
                        example: any=any,bigint=8821239038968084,bigintStr=9223372036854775808,bool=true,boolOpt=true,date=2020-01-01,dateTime=2020-01-01T00:00:00.000001Z,decimal=3.141592653589793,decimalStr=3.14159265358979344719667586,enum=one,float32=1.1,int=1,int32=1,int32Enum=55,intEnum=2,num=1.1,str=test,strOpt=testOptional
                        x-speakeasy-test-internal-directives:
                          - sortSerializedMaps:
                              { "regex": "(.*)", "delim": "," }
                    required:
                      - X-Header-Obj
                      - X-Header-Obj-Explode
                required:
                  - headers
components:
  schemas:
    simpleObject:
      description: "A simple object that uses all our supported primitive types and enums and has optional properties."
      externalDocs:
        description: "A link to the external docs."
        url: "https://docs.speakeasyapi.dev"
      type: object
      properties:
        str:
          type: string
          description: "A string property."
          example: "test"
        bool:
          type: boolean
          description: "A boolean property."
          example: true
        int:
          type: integer
          description: "An integer property."
          example: 1
        int32:
          type: integer
          format: int32
          description: "An int32 property."
          example: 1
        num:
          type: number
          description: "A number property."
          example: 1.1
        float32:
          type: number
          format: float
          description: "A float32 property."
          example: 1.1
        enum:
          $ref: "#/components/schemas/enum"
        date:
          type: string
          format: date
          description: "A date property."
          example: "2020-01-01"
        dateTime:
          type: string
          format: date-time
          description: "A date-time property."
          example: "2020-01-01T00:00:00.000001Z"
        any:
          description: "An any property."
          example: "any"
        strOpt:
          type: string
          description: "An optional string property."
          example: "testOptional"
        boolOpt:
          type: boolean
          description: "An optional boolean property."
          example: true
        intOptNull:
          type: integer
          description: "An optional integer property will be null for tests."
        numOptNull:
          type: number
          description: "An optional number property will be null for tests."
        intEnum:
          type: integer
          description: "An integer enum property."
          enum:
            - 1
            - 2
            - 3
          example: 2
          x-speakeasy-enums:
            - First
            - Second
            - Third
        int32Enum:
          type: integer
          format: int32
          description: "An int32 enum property."
          enum:
            - 55
            - 69
            - 181
          example: 55
        bigint:
          type: integer
          format: bigint
          example: 8821239038968084
        bigintStr:
          type: string
          format: bigint
          example: "9223372036854775808"
        decimal:
          type: number
          format: decimal
          example: 3.141592653589793
        decimalStr:
          type: string
          format: decimal
          example: "3.14159265358979344719667586"
      required:
        - str
        - bool
        - int
        - int32
        - num
        - float32
        - enum
        - date
        - dateTime
        - any
        - intEnum
        - int32Enum
    enum:
      type: string
      description: "A string based enum"
      enum:
        - "one"
        - "two"
        - "three"
        - "four_and_more"
      example: "one"
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Authenticate using an API Key generated via our platform.

@TristanSpeakEasy
Copy link
Author

The theme seems to be it struggles with object schemas

@daveshanley daveshanley reopened this Jan 29, 2024
@daveshanley
Copy link
Member

Will re-investigate.

daveshanley added a commit that referenced this issue May 2, 2024
mocking upgraded upstream in libopenapi
@daveshanley daveshanley mentioned this issue May 2, 2024
daveshanley added a commit that referenced this issue May 2, 2024
mocking upgraded upstream in libopenapi
@daveshanley
Copy link
Member

This is resolved in v0.1.10 no more panics.

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
None yet
Development

No branches or pull requests

2 participants