Skip to content

[BUG] openapi:reduce function messes up $ref import paths #1053

@mdonkers

Description

@mdonkers

We have a bigger OpenAPI spec for which we want to publish only specific parts to Readme.com and make public.

Therefore we're trying to use the rdme openapi:reduce function, but this breaks the resulting spec as the $ref import paths are completely messed up (and therefore the spec doesn't validate when trying to upload).

A small section from our spec:
api.yml:

openapi: 3.1.0
paths:
  /api/dashboards/{id}:
    get:
      tags: [public]
      summary: Receive a specific dashboard by its id.
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
          description: Dashboard Id.
      responses:
        '200':
          description: Receive a specific dashboard.
          content:
            application/json:
              schema:
                $ref: 'dashboarding.yml#/components/schemas/DashboardDefinition'
        default:
          description: In case any error happens.
          content:
            application/json:
              schema:
                $ref: 'common.yml#/components/schemas/ErrorResponse'

common.yml with the ErrorResponse definition:

openapi: 3.1.0
components:
  schemas:
    Error:
      properties:
        code:
          type: integer
        message:
          type: string
        traceId:
          type: string
      required:
        - code
        - message

    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/Error'
      required:
        - error

After running rdme openapi:reduce api.yml --tag public --out api.reduced.json, the $refs are messed up in different ways (full api.reduced.json):

{
  "openapi": "3.1.0",
  "paths": {
    "/api/dashboards/{id}": {
      "get": {
        "tags": [
          "public"
        ],
        "summary": "Receive a specific dashboard by its id.",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "Dashboard Id."
          }
        ],
        "responses": {
          "200": {
            "description": "Receive a specific dashboard.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/paths/~1api~1dashboards~1%7Bid%7D/put/requestBody/content/application~1json/schema"
                }
              }
            }
          },
          "default": {
            "description": "In case any error happens.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/paths/~1api~1map/post/responses/default/content/application~1json/schema"
                }
              }
            }
          }
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions