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

Allow enum parameter description. (#201) #429

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

masamichhhhi
Copy link

Currently, enum query parameter can't have description about each value as mentioned in #201 .
To handle this, I added method that generating json like OAI/OpenAPI-Specification#348 (comment).

the following code

parameter name: :foo, in: :query, enum: {'bar': 'lists bars', 'baz': 'lists people named baz'}, description: "this is foo"

generates following json and documents.

{
  "name": "foo",
  "in": "query",
  "enum": {
    "bar": "lists bars",
    "baz": "lists people named baz"
  },
  "description": "this is foo\n * `bar` lists bars\n * `baz` lists people named baz\n "
}

スクリーンショット 2021-05-30 21 54 28

@masamichhhhi masamichhhhi marked this pull request as ready for review May 30, 2021 12:58
@gabrielmansour
Copy link

I would like to see the Gem support enum values being automatically appended to the main description of a schema object too, but in my case, the enum is just a simple array. e.g.: enum: ['apples', 'oranges', 'bananas']

@kwent
Copy link

kwent commented Aug 16, 2022

Can we merge this ? 🙏🏻

@gabrielmansour
Copy link

Would be nice if the option to append the enums to the description were behind a configuration flag, so they can be turned on or off, depending on preference

@jtannas
Copy link
Collaborator

jtannas commented Nov 27, 2022

Hi @masamichhhhi
Apologies for the delay in looking into this. I like the idea and will be happy to merge once there's an accompanying Changelog entry and the latest master is merged so we can see the results of our CI suite.

Edit: It looks like the official OAS doesn't support per-enum-value descriptions https://swagger.io/docs/specification/data-models/enums/
Maybe we restrict the changes to just a description on the enum parameter?

@masamichhhhi
Copy link
Author

@jtannas
Thanks for your confirming! I added the CHANGELOG, please check it.

Edit: It looks like the official OAS doesn't support per-enum-value descriptions https://swagger.io/docs/specification/data-models/enums/
Maybe we restrict the changes to just a description on the enum parameter?

The document you are referring to appears to contain a statement about per-enum-description. Is there any problem with adding that?
Screen Shot 2022-12-10 at 23 33 41

@romanblanco romanblanco added this to the Gem 2.X.0 milestone Apr 1, 2023
@romanblanco romanblanco linked an issue Apr 2, 2023 that may be closed by this pull request
@mattpolito
Copy link
Collaborator

@romanblanco What's the status on this PR? It appears good to go with the exception of some documentation.

@romanblanco
Copy link
Member

@mattpolito, I believe the changes are ready to be merged once the PR is updated and rebased.

@masamichhhhi would you add the statement about per-enum-description to README.md together with some examples into README.md and test-app to demonstrate how to use the feature?

@masamichhhhi
Copy link
Author

@romanblanco
added the statement about per-enum-description and fixed rspec of test-app to use this functionality. Let me know If there are any other changes needed to release.

@romanblanco
Copy link
Member

@masamichhhhi Some of the test-app specs are still failing.

@masamichhhhi
Copy link
Author

masamichhhhi commented Mar 10, 2024

@romanblanco
I ran ci/test.sh in my environment and it appears that there are no tests that are failing (although there are tests in pending status.)
Is it possible for you to tell me which test is failing? 🙏

ci/test.sh
####################
Unit Tests
####################

##### rswag-api #####
..................

Finished in 0.01456 seconds (files took 0.43363 seconds to load)
18 examples, 0 failures

Coverage report generated for RSpec to /workspace/rswag/rswag-api/coverage. 73 / 73 LOC (100.0%) covered.
##### rswag-specs #####
........................................................................................................................................

Finished in 0.07683 seconds (files took 0.51735 seconds to load)
136 examples, 0 failures

Coverage report generated for RSpec to /workspace/rswag/rswag-specs/coverage. 549 / 568 LOC (96.65%) covered.
##### rswag-ui #####
......

Finished in 0.00903 seconds (files took 0.43286 seconds to load)
6 examples, 0 failures

Coverage report generated for RSpec to /workspace/rswag/rswag-ui/coverage. 37 / 42 LOC (88.1%) covered.
####################
Integration Tests
####################

##### test-app #####
DEPRECATION WARNING: Non-URL-safe CSRF tokens are deprecated. Use 6.1 defaults or above. (called from <top (required)> at /workspace/rswag/test-app/spec/rails_helper.rb:9)
DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.

The new connection handling does not support `connection_handlers`
getter and setter.

Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
 (called from load at /Path/to/ruby/bin/rspec:23)
*.......................*......*/Path/to/ruby/bin/ruby -I/Path/to/ruby/lib/ruby/gems/2.7.0/gems/rspec-core-3.13.0/lib:/Path/to/ruby/lib/ruby/gems/2.7.0/gems/rspec-support-3.13.1/lib /Path/to/ruby/lib/ruby/gems/2.7.0/gems/rspec-core-3.13.0/exe/rspec --pattern spec/requests/\*\*/\*_spec.rb,\ spec/api/\*\*/\*_spec.rb,\ spec/integration/\*\*/\*_spec.rb --format Rswag::Specs::SwaggerFormatter --order defined
DEPRECATION WARNING: Non-URL-safe CSRF tokens are deprecated. Use 6.1 defaults or above. (called from <top (required)> at /workspace/rswag/test-app/spec/rails_helper.rb:9)
Generating Swagger docs ...
DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.

The new connection handling does not support `connection_handlers`
getter and setter.

Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
 (called from block (2 levels) in <class:Railtie> at /Path/to/ruby/lib/ruby/gems/2.7.0/gems/activerecord-7.0.1/lib/active_record/railtie.rb:274)
Swagger doc generated at /workspace/rswag/test-app/swagger/v1/swagger.json
Swagger doc generated at /workspace/rswag/test-app/swagger/v3/openapi.json

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Generated OpenApi Media Types /stubs get OK declares output as application/json
     # Not yet implemented?
     Failure/Error: expect(tree).to have_key('application/json')
       expected nil to respond to `has_key?`
     # ./spec/integration/openapi3_spec.rb:106:in `block (6 levels) in <top (required)>'

  2) Generated OpenApi Request Body /stubs post OK declares requestBody is required
     # This output is massaged in SwaggerFormatter#stop, and isn't quite ready here to assert
     Failure/Error: expect(tree[:required]).to eq(true)

     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./spec/integration/openapi3_spec.rb:199:in `block (6 levels) in <top (required)>'

Finished in 0.35537 seconds (files took 1.15 seconds to load)
31 examples, 0 failures, 2 pending

Coverage report generated for RSpec to /workspace/rswag/test-app/coverage. 67 / 69 LOC (97.1%) covered.
.

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) swagger-ui browsing api-docs
     # Needs work to run on others' machines
     # ./spec/features/swagger_ui_spec.rb:5

  2) Generated OpenApi Media Types /stubs get OK declares output as application/json
     # Not yet implemented?
     Failure/Error: expect(tree).to have_key('application/json')
       expected nil to respond to `has_key?`
     # ./spec/integration/openapi3_spec.rb:106:in `block (6 levels) in <top (required)>'

  3) Generated OpenApi Request Body /stubs post OK declares requestBody is required
     # This output is massaged in SwaggerFormatter#stop, and isn't quite ready here to assert
     Failure/Error: expect(tree[:required]).to eq(true)

     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./spec/integration/openapi3_spec.rb:199:in `block (6 levels) in <top (required)>'

Finished in 2.18 seconds (files took 1.19 seconds to load)
33 examples, 0 failures, 3 pending

(The local path is masked.)

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

Successfully merging this pull request may close these issues.

feature request: enum description
6 participants