question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter ignores some $refs

See original GitHub issue

Hello! I wanted to use the openapi-filter to remove some internal headers from our public openapi specifications. Unfortunately, it doesn’t seem to fully work.

An example:

openapi: 3.0.2
info:
  title: Swagger Petstore - OpenAPI 3.0
  description: omit
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
  version: 1.0.5
servers:
  - url: /api/v3
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      parameters:
        - $ref: '#/components/parameters/InternalHeader'
        - $ref: '#/components/parameters/OtherInternalHeader'
        - in: header
          name: X-ThirdInternalHeader
          schema:
            type: string
          required: true
          x-internal: true
      requestBody:
        description: Create a new pet in the store
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '405':
          description: Invalid input

components:
  parameters:
    InternalHeader:
      in: header
      name: X-InternalHeader
      schema:
        type: string
      required: true
      x-internal: true
    OtherInternalHeader:
      in: header
      name: X-OtherInternalHeader
      schema:
        type: string
      required: true
      x-internal: true
  schemas:
    Pet:
      required:
        - name
        - photoUrls
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
      xml:
        name: pet

You can see there are three headers (InternalHeader, OtherInternalHeader & ThirdInternalHeader). After running the openapi-filter the result looks like this:

... omitted because irrelevant
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      parameters:
        - $ref: "#/components/parameters/OtherInternalHeader"

...
components:
  parameters: {}
... omitted because irrelevant

In the end all the parameter definitions are removed but the reference to ONE of the two headers is still there.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
MikeRalphsoncommented, Apr 7, 2021

Will try and publish today.

1reaction
eliasdraexlercommented, Apr 7, 2021

@MikeRalphson Thanks for the merge! When will this be released to npm? I would need the changes for a project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding why git-filter-branch is not cleaning my history
The refs that git filter-branch reports as unchanged did not have a file named terra/fixtures.go anywhere in their histories.
Read more >
preserve git notes · Issue #22 · newren/git-filter-repo - GitHub
I am new to Git scripting - how do i ignore commits with no notes ? ... tail -n +2 .git/filter-repo/commit-map | git...
Read more >
git-filter-branch Documentation - Git
If you have any grafts or replacement refs defined, running this command will make them permanent. WARNING! The rewritten history will have different...
Read more >
Ubuntu Manpage: git-filter-branch - Rewrite branches
If you have any grafts or replacement refs defined, running this command will make them permanent. WARNING! The rewritten history will have different...
Read more >
git-filter-repo — Debian testing
git-filter-repo - Rewrite repository history ... •Rewriting history may delete some refs (e.g. branches that only had files that you wanted ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found