Jane-Terziev / dry-swagger

Generate swagger documentation out of Dry::Struct and Dry::Validation::Contract schemas.
https://jane-terziev.github.io/dry-swagger/
MIT License
30 stars 3 forks source link

Namespace config raises error #3

Closed RazvanFarte closed 4 months ago

RazvanFarte commented 4 months ago

Hi guys,

Not sure if this is something on your side, or on another Dry gem, but hope you could guide me to the proper repo to describe them the issue.

I have the following Contract:

class ApplicationContract < Dry::Validation::Contract
  config.messages.backend = :i18n
end

  class ResourceContract < ApplicationContract
config.messages.namespace = 'parcels.create'

...some json schema specs...
end

When running Dry::Swagger::DocumentationGenerator.new.from_validation(ResourceContract)

I get the error:

/home_path/.rvm/gems/ruby-3.2.2/gems/dry_validation_parser-0.1.11/lib/dry_validation_parser/validation_schema_parser.rb:58:in `public_send': undefined method `visit_namespace' for #<DryValidationParser::ValidationSchemaParser:0x00007e4380b005d0 @keys={}> (NoMethodError)                                                                                     

      public_send(:"visit_#{meth}", rest, opts)                                                                                                     
      ^^^^^^^^^^^                                                                                                                                   
Did you mean?  visit_each     

Commenting out the namespace configuration makes the Sweagger DocumentationGenerater run without issues and I get the schema as a Hash.

Jane-Terziev commented 4 months ago

Hi! Thanks for the report.

I'll take a look. The issue is most likely in the dry_validation_parser, where parsing through the contract definition AST causes an issue with additional configurations.

I'll notify you once i fix the issue.

Jane-Terziev commented 4 months ago

@RazvanFarte I pushed a new version, 2.0.5, try updating the version in the project and see if it works now.

You can close the issue when you confirm it is fine.

RazvanFarte commented 4 months ago

@Jane-Terziev Thanks for the fast intervention. It works :) I tested by patching the code of dry_validation_parser on my project with your change.

Yup, I'll close it from my end. Thanks again! :)