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

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

Open
mdonkers opened this issue Oct 11, 2024 · 0 comments
Open

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

mdonkers opened this issue Oct 11, 2024 · 0 comments

Comments

@mdonkers
Copy link

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"
                }
              }
            }
          }
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant