Skip to content

query parameter using allOf with ref and default doesn't get default value at runtime #1065

@domantas-simplex

Description

@domantas-simplex

Describe the bug
Given such query parameter definition and not providing status query param at runtime we get status: undefined

      parameters:
        - name: status
          in: query
          schema:
            allOf:
              - $ref: '#/components/schemas/Status'
              - default: available

To Reproduce

  1. Start an express project and register one path with the below provided OpenAPI Spec.
app.use(
  OpenApiValidator.middleware({
    apiSpec: '<REPLACE_WITH_PATH_TO_SPEC>',
  }),
);

app.get('/pet', (req, res) => {
  res.send({
    query: req.query,
  });
});
Click for full OpenAPI spec
openapi: 3.0.4
info:
  title: Swagger Petstore - OpenAPI 3.0
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.

    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
  termsOfService: https://swagger.io/terms/
  contact:
    email: [email protected]
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.12
servers:
  - url: /
tags:
  - name: pet
externalDocs:
  description: Find out more about Swagger
  url: https://swagger.io
paths:
  /pet:
    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
          schema:
            allOf:
              - $ref: '#/components/schemas/Status'
              - default: available
        - name: status-additional
          in: query
          schema:
            type: string
            default: available
            enum:
              - available
              - pending
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
components:
  schemas:
    Status:
      type: string
      enum:
        - available
        - pending
  1. Call GET {baseUrl}/pet (e.g. http://localhost:3000/pet)

Actual behavior
You'll get this response:

{"query":{"status-additional":"available"}}

Expected behavior
Expected response is this:

{"query":{"status":"available","status-additional":"available"}}

Examples and context
Example where it's working correctly

        - name: status-additional
          in: query
          schema:
            type: string
            default: available
            enum:
              - available
              - pending

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