`oneOf` in path params is causing validation errors when using OAS 3.0

Open
#458 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
openapi, ruby
Domain
api

Research direction

The bug is in path parameter handling: lib/openapi_first/validators/request_parameters.rb around line 15 receives the path as a string when the schema uses oneOf, but as an integer when it uses type: integer. Start by reproducing with the spec in the issue and checking how the path value is coerced before validation. Done means GET /accounts/1 passes for a oneOf integer/enum path parameter, with a regression test added to the request validation specs.

Written by the indexing model from the issue text.

Description

I have the following spec:

openapi: 3.0.1
paths:
  /accounts/{id}:
    get:
      operationId: getAccountId
      summary: Get the details of an account
      parameters:
        - name: id
          in: path
          required: true
          schema:
            oneOf:
              - type: integer
              - type: string
                enum: [current]

When validating e.g. GET /accounts/1 request, I get an Path segment is invalid: value at '/id' is not an integer. value at '/id' is not one of: ["current"] error.
The following schema for the path parameter already reproduces the issue:

oneOf:
  - type: integer

The following schema does not give a validation error:

type: integer

The parsed_request in /lib/openapi_first/validators/request_parameters.rb:15 in the case of a schema using oneOf:
#<data OpenapiFirst::ParsedRequest path={"id"=>"1"}, ...>, without oneOf: #<data OpenapiFirst::ParsedRequest path={"id"=>1}, ...>, that could cause the path param to be invalid.

I believe the spec above using the schema with the oneOf is valid and should not give validation errors for requests like GET /accounts/1.

Dominant language
Ruby
Stars
222
Forks
27
Avg merge
17h 15m
Merged PRs (30d)
6

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ahx/openapi_first

All issues in ahx/openapi_first

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.