Skip to content

Commit

Permalink
close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRuiz committed Aug 11, 2021
1 parent 0b0244e commit f96a1f3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/open_api_import.rb
Expand Up @@ -925,6 +925,8 @@ class << self
if dpv[:pattern].include?('\\\\/')
#for cases like this: ^[^\.\\/:*?"<>|][^\\/:*?"<>|]{0,13}[^\.\\/:*?"<>|]?$
data_pattern << "'#{dpk}': /#{dpv[:pattern].to_s.gsub('\/','/')}/"
elsif dpv[:pattern].include?('\\x')
data_pattern << "'#{dpk}': /#{dpv[:pattern].to_s.gsub('\\x','\\u')}/"
else
data_pattern << "'#{dpk}': /#{dpv[:pattern].to_s}/"
end
Expand Down
2 changes: 1 addition & 1 deletion open_api_import.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'open_api_import'
s.version = '0.10.8'
s.version = '0.10.9'
s.summary = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML"
s.description = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML"
s.authors = ["Mario Ruiz"]
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/v2.0/yaml/petstore.yaml
Expand Up @@ -83,6 +83,7 @@ definitions:
format: int64
name:
type: string
pattern: ^[a-z\x00DF-\x00FF][a-z0-9\-_\x{DF}-\x{FF}]*$
tag:
type: string
Pets:
Expand Down
14 changes: 14 additions & 0 deletions spec/open_api_import/open_api_import_spec.rb
Expand Up @@ -238,6 +238,20 @@
expect(content).to include('def self.get_products(latitude: LATITUDE, longitude: LONGITUDE)')
end

it 'converts patterns from \\x to \\u' do
file_name = './spec/fixtures/v2.0/yaml/petstore.yaml'
File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb")
OpenApiImport.from file_name, create_method_name: :operation_id
expect(File.exist?("#{file_name}.rb")).to eq true
content = File.read("#{file_name}.rb")
eval(content)
req = Swagger::SwaggerPetstore::V1_0_0::Root.list_pets
expect(req.key?(:data_pattern)).to eq true
expect(req[:data_pattern].key?(:name)).to eq true
expect(req[:data_pattern][:name].to_s).to eq '(?-mix:^[a-z\u00DF-\u00FF][a-z0-9\-_\u{DF}-\u{FF}]*$)'
end


end


Expand Down

0 comments on commit f96a1f3

Please sign in to comment.