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

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

Merged
merged 4 commits into from
Dec 14, 2023

Conversation

exoego
Copy link
Owner

@exoego exoego commented Dec 14, 2023

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
lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide fixed
lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide fixed
lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide fixed
lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide fixed
lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide fixed
Copy link

codecov bot commented Dec 14, 2023

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.

lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide fixed
lib/rspec/openapi/schema_sorter.rb Fixed Show fixed Hide 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
14 checks passed
@exoego exoego deleted the sort-everything branch December 14, 2023 03:28
@ipepe
Copy link
Contributor

ipepe commented Jan 4, 2024

@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.
2 participants