thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
77 stars 14 forks source link

Issue with InverseOperationId while parsing Free-Form object. #57

Closed SOPHIA2401 closed 1 year ago

SOPHIA2401 commented 2 years ago

Describe the bug The free-form object described in our yaml file gets lost when applying the InverseOperationId filter to various operations.

To Reproduce Steps to reproduce the behavior:

  1. Created an openapi.yaml file.
    
    openapi: 3.0.2
    info:
    title: OpenSearch
    version: '2021-11-23'
    paths:
    /_cat/indices:
    get:
      description: 'Returns information about indices: number of primaries and replicas, document counts, disk size, etc.'
      operationId: GetCatIndices
      parameters:
        - name: bytes
          in: query
          schema:
            type: number
            nullable: true
        - name: expand_wildcards
          in: query
          schema:
            $ref: '#/components/schemas/ExpandWildcards'
        - name: health
          in: query
          schema:
            $ref: '#/components/schemas/HealthStatus'
        - name: include_unloaded_segments
          in: query
          schema:
            type: boolean
            nullable: true
        - name: pri
          in: query
          schema:
            type: boolean
            nullable: true
        - name: master_timeout
          in: query
          schema:
            type: string
            pattern: '^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$'
        - name: timeout
          in: query
          schema:
            type: string
            pattern: '^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$'
      responses:
        '200':
          description: GetCatIndices 200 response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetCatIndicesOutputPayload'
    '/_cat/indices/{index}':
    get:
      description: 'Returns information about indices: number of primaries and replicas, document counts, disk size, etc.'
      operationId: GetCatIndicesWithIndex
      parameters:
        - name: index
          in: path
          schema:
            type: string
            pattern: '^[^+_\-\.][^\\, /*?"<>| ,#\nA-Z]+$'
          required: true
          example: books
        - name: bytes
          in: query
          schema:
            type: number
            nullable: true
        - name: expand_wildcards
          in: query
          schema:
            $ref: '#/components/schemas/ExpandWildcards'
        - name: health
          in: query
          schema:
            $ref: '#/components/schemas/HealthStatus'
        - name: include_unloaded_segments
          in: query
          schema:
            type: boolean
            nullable: true
        - name: pri
          in: query
          schema:
            type: boolean
            nullable: true
        - name: master_timeout
          in: query
          schema:
            type: string
            pattern: '^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$'
        - name: timeout
          in: query
          schema:
            type: string
            pattern: '^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$'
      responses:
        '200':
          description: GetCatIndicesWithIndex 200 response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetCatIndicesWithIndexOutputPayload'
    components:
    schemas:
    ExpandWildcards:
      type: string
      enum:
        - all
        - open
        - closed
        - hidden
        - none
    GetCatIndicesOutputPayload: {}
    GetCatIndicesWithIndexOutputPayload: {}
    HealthStatus:
      type: string
      enum:
        - green
        - yellow
        - red
2. Created a `InverseOperationId` filter in customFilter.json file.

{ "inverseOperationIds": ["GetCatIndicesWithIndex"] }

3. Command used: `openapi-format openapi.yaml -o catindices_filtered.yaml -f customFilter.json`
4. Content of resultant file (catindices_filtered.yaml ).

openapi: 3.0.2 info: title: OpenSearch version: '2021-11-23' paths: '/_cat/indices/{index}': get: operationId: GetCatIndicesWithIndex description: 'Returns information about indices: number of primaries and replicas, document counts, disk size, etc.' parameters:

**Issue:**  Free-form object `GetCatIndicesWithIndexOutputPayload: {}`  is getting skipped.

**Expected behavior**
After using `InverseOperationId` filter resultant file should be:

openapi: 3.0.2 info: title: OpenSearch version: '2021-11-23' paths: '/_cat/indices/{index}': get: description: 'Returns information about indices: number of primaries and replicas, document counts, disk size, etc.' operationId: GetCatIndicesWithIndex parameters:

thim81 commented 2 years ago

@SOPHIA2401 Thanks for providing such a clear and well described issue.

I'll try to find some time this or next week, to look into the logic to try to find the cause of the bug and keep you posted.

thim81 commented 1 year ago

@SOPHIA2401 We have found a fix for the unwanted removal of free-form objects in component schemas.

In the next release of openapi-format, this fix will be included.

thim81 commented 1 year ago

@SOPHIA2401 We just released openapi-format v1.10.2, which contains this fix.

It took a while, since I was hoping to include another potential issue, but that is no reproducable, so I went ahead and released a new version.

Thanks for reporting the issue and hope openapi-format helps with your OpenAPI organisation.

SOPHIA2401 commented 1 year ago

@thim81, thanks for resolving the issue.