Skip to content

Sort HTTP methods, response status codes, and contents lexicographically - #163

Merged
exoego merged 4 commits into
masterfrom
sort-everything
Dec 14, 2023
Merged

Sort HTTP methods, response status codes, and contents lexicographically#163
exoego merged 4 commits into
masterfrom
sort-everything

Conversation

@exoego

@exoego exoego commented Dec 14, 2023

Copy link
Copy Markdown
Owner

Closes #159

Changes

This is a generalization of #155

The below keys are sorted lexicographically.

Keys in other places remain as-is.

Alternative considered

I initially implemented sorting every keys in Hash recursively, but it feels not good.
Keys of some places should remain as-is.

E.g.) Some top-level keys. It makes a bit surprising ifopenapi: keys are in the very bottom of the file.

openapi: 3.0.3
info:
  title: OpenAPI Documentation
  version: 1.0.0
servers: []
paths:

E.g.) The properties of schema. I assume users defined properties as they feel it natural.

  schemas:
    Table:
      type: object
      properties:
        id:
          type: integer
        # This field should exists in expected
        # name:
        #  type: string
        this_field_should_not_exist_in_expected:
          type: string
        description:
          type: string
        database:
          "$ref": "#/components/schemas/Database"
        columns:
          type: array
          items:
            "$ref": "#/components/schemas/Column"
        null_sample:
          nullable: true
        storage_size:
          type: number
          format: float
        created_at:
          type: string
        updated_at:
          type: string

@exoego exoego added the enhancement New feature or request label Dec 14, 2023
Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
@codecov

codecov Bot commented Dec 14, 2023

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1d3dccc) 96.79% compared to head (583a508) 96.88%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #163      +/-   ##
==========================================
+ Coverage   96.79%   96.88%   +0.08%     
==========================================
  Files          14       15       +1     
  Lines         437      449      +12     
  Branches       97       96       -1     
==========================================
+ Hits          423      435      +12     
  Misses         14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
Comment thread lib/rspec/openapi/schema_sorter.rb Fixed
@exoego exoego changed the title Sort some paths, path methods, responses, and contents lexicographically Sort path methods, responses, and contents lexicographically Dec 14, 2023
@exoego exoego changed the title Sort path methods, responses, and contents lexicographically Sort HTTP methods, response status codes, and contents lexicographically Dec 14, 2023
@exoego
exoego merged commit 4d021af into master Dec 14, 2023
@exoego
exoego deleted the sort-everything branch December 14, 2023 03:28
@ipepe

ipepe commented Jan 4, 2024

Copy link
Copy Markdown
Contributor

@exoego I'm using this version and I noticed that it doesn't sort properly. Seems like files that were already generated with the wrong sorting are not being sorted after the update to this version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regenerating (remove file and run rspec) the schema without changing the code, generates different file.

3 participants