diff --git a/modules/openapi-generator/src/main/resources/crystal/api.mustache b/modules/openapi-generator/src/main/resources/crystal/api.mustache index c39d99bf0fe..18c3d4d41e1 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api.mustache @@ -87,7 +87,7 @@ module {{moduleName}} {{/maxLength}} {{#minLength}} if @api_client.config.client_side_validation && {{^required}}!{{{paramName}}}.nil? && {{/required}}{{{paramName}}}.to_s.size < {{{minLength}}} - raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, the character length must be great than or equal to {{{minLength}}}.") + raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, the character length must be greater than or equal to {{{minLength}}}.") end {{/minLength}} diff --git a/modules/openapi-generator/src/main/resources/crystal/api_test.mustache b/modules/openapi-generator/src/main/resources/crystal/api_test.mustache index 71d88915868..059f66f11f5 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api_test.mustache @@ -1,17 +1,16 @@ # {{#lambdaPrefixWithHash}}{{> api_info}}{{/lambdaPrefixWithHash}} require "../spec_helper" -require "json" -require "time" # Unit tests for {{moduleName}}::{{classname}} # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -{{#operations}}describe "{{classname}}" do +{{#operations}} +Spectator.describe "{{classname}}" do describe "test an instance of {{classname}}" do it "should create an instance of {{classname}}" do api_instance = {{moduleName}}::{{classname}}.new - # TODO expect(api_instance).to be_instance_of({{moduleName}}::{{classname}}) + expect(api_instance).to be_instance_of({{moduleName}}::{{classname}}) end end @@ -28,7 +27,7 @@ require "time" {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} {{/required}}{{/allParams}} # @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}] describe "{{operationId}} test" do - it "should work" do + skip "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end diff --git a/modules/openapi-generator/src/main/resources/crystal/configuration.mustache b/modules/openapi-generator/src/main/resources/crystal/configuration.mustache index a63e86ee876..21d61690bdd 100644 --- a/modules/openapi-generator/src/main/resources/crystal/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/configuration.mustache @@ -214,7 +214,7 @@ module {{moduleName}} {{#isApiKey}} "{{name}}" => { type: "api_key", - in: {{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}, + in: {{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}{{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}, key: "{{keyParamName}}", value: api_key_with_prefix(:{{keyParamName}}) }, diff --git a/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache b/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache index 22a113e8e32..9dde309808b 100644 --- a/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache @@ -4,7 +4,7 @@ require 'spec_helper' -describe {{moduleName}}::Configuration do +Spectator.describe {{moduleName}}::Configuration do let(:config) { {{moduleName}}::Configuration.default } before(:each) do diff --git a/modules/openapi-generator/src/main/resources/crystal/model_test.mustache b/modules/openapi-generator/src/main/resources/crystal/model_test.mustache index 3cc572b5878..04743fcb678 100644 --- a/modules/openapi-generator/src/main/resources/crystal/model_test.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/model_test.mustache @@ -1,26 +1,24 @@ # {{#lambdaPrefixWithHash}}{{> api_info}}{{/lambdaPrefixWithHash}} require "../spec_helper" -require "json" -require "time" # Unit tests for {{moduleName}}::{{classname}} # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate {{#models}} {{#model}} -describe {{moduleName}}::{{classname}} do +Spectator.describe {{moduleName}}::{{classname}} do {{^oneOf}} describe "test an instance of {{classname}}" do - it "should create an instance of {{classname}}" do + skip "should create an instance of {{classname}}" do #instance = {{moduleName}}::{{classname}}.new #expect(instance).to be_instance_of({{moduleName}}::{{classname}}) end end {{#vars}} describe "test attribute '{{{name}}}'" do - it "should work" do + skip "should work" do {{#isEnum}} # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html # validator = Petstore::EnumTest::EnumAttributeValidator.new("{{{dataType}}}", [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]) @@ -65,7 +63,7 @@ describe {{moduleName}}::{{classname}} do {{/mappedModels}} {{/discriminator}} describe ".build" do - it "returns the correct model" do + skip "returns the correct model" do end end {{/-first}} diff --git a/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache b/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache index 8e09ec2aba3..ba58fb06828 100644 --- a/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache @@ -105,7 +105,7 @@ {{/maxLength}} {{#minLength}} if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.size < {{{minLength}}} - invalid_properties.push("invalid value for \"{{{name}}}\", the character length must be great than or equal to {{{minLength}}}.") + invalid_properties.push("invalid value for \"{{{name}}}\", the character length must be greater than or equal to {{{minLength}}}.") end {{/minLength}} @@ -226,7 +226,7 @@ {{/maxLength}} {{#minLength}} if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.to_s.size < {{{minLength}}} - raise ArgumentError.new("invalid value for \"{{{name}}}\", the character length must be great than or equal to {{{minLength}}}.") + raise ArgumentError.new("invalid value for \"{{{name}}}\", the character length must be greater than or equal to {{{minLength}}}.") end {{/minLength}} diff --git a/modules/openapi-generator/src/main/resources/crystal/partial_oneof_module.mustache b/modules/openapi-generator/src/main/resources/crystal/partial_oneof_module.mustache index 64c4e0e9c93..ffd0c190d31 100644 --- a/modules/openapi-generator/src/main/resources/crystal/partial_oneof_module.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/partial_oneof_module.mustache @@ -2,106 +2,104 @@ # {{{.}}} {{/description}} module {{classname}} - class << self - {{#oneOf}} - {{#-first}} - # List of class defined in oneOf (OpenAPI v3) - def openapi_one_of - [ - {{/-first}} - :'{{{.}}}'{{^-last}},{{/-last}} - {{#-last}} - ] - end + {{#oneOf}} + {{#-first}} + # List of class defined in oneOf (OpenAPI v3) + def self.openapi_one_of + [ + {{/-first}} + :"{{{.}}}"{{^-last}},{{/-last}} + {{#-last}} + ] + end - {{/-last}} - {{/oneOf}} - {{#discriminator}} - {{#propertyName}} - # Discriminator's property name (OpenAPI v3) - def openapi_discriminator_name - :'{{{.}}}' - end + {{/-last}} + {{/oneOf}} + {{#discriminator}} + {{#propertyName}} + # Discriminator's property name (OpenAPI v3) + def self.openapi_discriminator_name + :"{{{.}}}" + end - {{/propertyName}} - {{#mappedModels}} - {{#-first}} - # Discriminator's mapping (OpenAPI v3) - def openapi_discriminator_mapping - { - {{/-first}} - :'{{{mappingName}}}' => :'{{{modelName}}}'{{^-last}},{{/-last}} - {{#-last}} - } - end + {{/propertyName}} + {{#mappedModels}} + {{#-first}} + # Discriminator's mapping (OpenAPI v3) + def self.openapi_discriminator_mapping + { + {{/-first}} + :"{{{mappingName}}}" => :"{{{modelName}}}"{{^-last}},{{/-last}} + {{#-last}} + } + end - {{/-last}} - {{/mappedModels}} - {{/discriminator}} - # Builds the object - # @param [Mixed] Data to be matched against the list of oneOf items - # @return [Object] Returns the model or the data itself - def build(data) - {{#discriminator}} - discriminator_value = data[openapi_discriminator_name] - return nil unless discriminator_value - {{#mappedModels}} - {{#-first}} + {{/-last}} + {{/mappedModels}} + {{/discriminator}} + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def self.build(data) + {{#discriminator}} + discriminator_value = data[openapi_discriminator_name] + return nil unless discriminator_value + {{#mappedModels}} + {{#-first}} - klass = openapi_discriminator_mapping[discriminator_value.to_sym] - return nil unless klass + klass = openapi_discriminator_mapping[discriminator_value.to_sym] + return nil unless klass - {{moduleName}}.const_get(klass).build_from_hash(data) - {{/-first}} - {{/mappedModels}} - {{^mappedModels}} - {{moduleName}}.const_get(discriminator_value).build_from_hash(data) - {{/mappedModels}} - {{/discriminator}} - {{^discriminator}} - # Go through the list of oneOf items and attempt to identify the appropriate one. - # Note: - # - We do not attempt to check whether exactly one item matches. - # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) - # due to the way the deserialization is made in the base_object template (it just casts without verifying). - # - TODO: scalar values are de facto behaving as if they were nullable. - # - TODO: logging when debugging is set. - openapi_one_of.each do |klass| - begin - next if klass == :AnyType # "nullable: true" - typed_data = find_and_cast_into_type(klass, data) - return typed_data if typed_data - rescue # rescue all errors so we keep iterating even if the current item lookup raises - end + {{moduleName}}.const_get(klass).build_from_hash(data) + {{/-first}} + {{/mappedModels}} + {{^mappedModels}} + {{moduleName}}.const_get(discriminator_value).build_from_hash(data) + {{/mappedModels}} + {{/discriminator}} + {{^discriminator}} + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + next if klass == :AnyType # "nullable: true" + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + rescue # rescue all errors so we keep iterating even if the current item lookup raises end - - openapi_one_of.includes?(:AnyType) ? data : nil - {{/discriminator}} end - {{^discriminator}} - private + openapi_one_of.includes?(:AnyType) ? data : nil + {{/discriminator}} + end + {{^discriminator}} - SchemaMismatchError = Class.new(StandardError) + SchemaMismatchError = Class.new(StandardError) - # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. - def find_and_cast_into_type(klass, data) - return if data.nil? + # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. + private def self.find_and_cast_into_type(klass, data) + return if data.nil? + begin case klass.to_s - when 'Boolean' + when "Boolean" return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) - when 'Float' + when "Float" return data if data.instance_of?(Float) - when 'Integer' + when "Integer" return data if data.instance_of?(Integer) - when 'Time' + when "Time" return Time.parse(data) - when 'Date' + when "Date" return Date.parse(data) - when 'String' + when "String" return data if data.instance_of?(String) - when 'Object' # "type: object" + when "Object" # "type: object" return data if data.instance_of?(Hash) when /\AArray<(?.+)>\z/ # "type: array" if data.instance_of?(Array) @@ -111,7 +109,7 @@ when /\AHash.+)>\z/ # "type: object" with "additionalProperties: { ... }" if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } sub_type = Regexp.last_match[:sub_type] - return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + return data.each_with_object({} of String | Symbol => Bool | Float | Integer | Time | Date | String | Array | Hash) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } end else # model const = {{moduleName}}.const_get(klass) @@ -132,6 +130,6 @@ rescue raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" end - {{/discriminator}} end + {{/discriminator}} end diff --git a/modules/openapi-generator/src/main/resources/crystal/shard.mustache b/modules/openapi-generator/src/main/resources/crystal/shard.mustache index f194083ac7b..424f5397e16 100644 --- a/modules/openapi-generator/src/main/resources/crystal/shard.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/shard.mustache @@ -16,5 +16,8 @@ development_dependencies: version: ~>1.5.0 ameba: github: crystal-ameba/ameba + spectator: + gitlab: arctic-fox/spectator + version: ~> 0.12.0 license: {{{shardLicense}}} diff --git a/modules/openapi-generator/src/main/resources/crystal/spec_helper.mustache b/modules/openapi-generator/src/main/resources/crystal/spec_helper.mustache index 56675bb6876..98890dcc246 100644 --- a/modules/openapi-generator/src/main/resources/crystal/spec_helper.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/spec_helper.mustache @@ -1,8 +1,9 @@ # {{#lambdaPrefixWithHash}}{{> api_info}}{{/lambdaPrefixWithHash}} # load modules -require "spec" +require "spectator" require "json" +require "time" require "../src/{{{shardName}}}" def assert_compilation_error(path : String, message : String) : Nil diff --git a/samples/client/petstore/crystal/pom.xml b/samples/client/petstore/crystal/pom.xml index 2cdbf1e1739..29b7e4bc351 100644 --- a/samples/client/petstore/crystal/pom.xml +++ b/samples/client/petstore/crystal/pom.xml @@ -37,7 +37,6 @@ install --ignore-crystal-version - --without-development diff --git a/samples/client/petstore/crystal/shard.lock b/samples/client/petstore/crystal/shard.lock index b2ac3af1d03..4bf5c767a16 100644 --- a/samples/client/petstore/crystal/shard.lock +++ b/samples/client/petstore/crystal/shard.lock @@ -1,9 +1,21 @@ version: 2.0 shards: + ameba: + git: https://github.com/crystal-ameba/ameba.git + version: 1.6.4 + + backtracer: + git: https://github.com/sija/backtracer.cr.git + version: 1.2.4 + crest: git: https://github.com/mamantoha/crest.git version: 1.3.13 + exception_page: + git: https://github.com/crystal-loot/exception_page.git + version: 0.4.1 + http-client-digest_auth: git: https://github.com/mamantoha/http-client-digest_auth.git version: 0.6.0 @@ -12,3 +24,15 @@ shards: git: https://github.com/mamantoha/http_proxy.git version: 0.10.3 + kemal: + git: https://github.com/kemalcr/kemal.git + version: 1.5.0 + + radix: + git: https://github.com/luislavena/radix.git + version: 0.4.1 + + spectator: + git: https://gitlab.com/arctic-fox/spectator.git + version: 0.12.1 + diff --git a/samples/client/petstore/crystal/shard.yml b/samples/client/petstore/crystal/shard.yml index acb14217d1b..61c0b4f651d 100644 --- a/samples/client/petstore/crystal/shard.yml +++ b/samples/client/petstore/crystal/shard.yml @@ -16,5 +16,8 @@ development_dependencies: version: ~>1.5.0 ameba: github: crystal-ameba/ameba + spectator: + gitlab: arctic-fox/spectator + version: ~> 0.12.0 license: diff --git a/samples/client/petstore/crystal/spec/api/fake_api_spec.cr b/samples/client/petstore/crystal/spec/api/fake_api_spec.cr index 829198b6aba..4ed70284e18 100644 --- a/samples/client/petstore/crystal/spec/api/fake_api_spec.cr +++ b/samples/client/petstore/crystal/spec/api/fake_api_spec.cr @@ -1,21 +1,19 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::FakeApi # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe "FakeApi" do +Spectator.describe "FakeApi" do describe "test an instance of FakeApi" do it "should create an instance of FakeApi" do api_instance = Petstore::FakeApi.new @@ -37,5 +35,4 @@ describe "FakeApi" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/api/pet_api_spec.cr b/samples/client/petstore/crystal/spec/api/pet_api_spec.cr index 5eb508ebd72..0538667c22c 100644 --- a/samples/client/petstore/crystal/spec/api/pet_api_spec.cr +++ b/samples/client/petstore/crystal/spec/api/pet_api_spec.cr @@ -1,21 +1,19 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#OpenAPI Generator version: 5.0.1-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::PetApi # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe "PetApi" do +Spectator.describe "PetApi" do describe "test an instance of PetApi" do it "should create an instance of PetApi" do api_instance = Petstore::PetApi.new @@ -45,12 +43,12 @@ describe "PetApi" do new_pet = Petstore::Pet.new(id: nil, category: nil, name: pet_name, photo_urls: Array(String).new, tags: nil, status: nil) pet = api_instance.add_pet(new_pet) - pet.id.should_not be_nil - pet.category.should be_nil - pet.name.should eq pet_name - pet.photo_urls.should eq Array(String).new - pet.status.should be_nil - pet.tags.should eq Array(Petstore::Tag).new + expect(pet.id).to_not be_nil + expect(pet.category).to be_nil + expect(pet.name).to eq pet_name + expect(pet.photo_urls).to eq Array(String).new + expect(pet.status).to be_nil + expect(pet.tags).to eq Array(Petstore::Tag).new end end @@ -58,7 +56,7 @@ describe "PetApi" do # Deletes a pet # @param pet_id Pet id to delete # @param [Hash] opts the optional parameters - # @option opts [String] :api_key + # @option opts [String] :api_key # @return [nil] describe "delete_pet test" do it "should work" do @@ -114,12 +112,12 @@ describe "PetApi" do pet = api_instance.add_pet(new_pet) pet_id = pet.id.not_nil! result = api_instance.get_pet_by_id(pet_id: pet_id) - result.id.should eq pet_id - result.category.should be_nil - result.name.should eq "crystal" - result.photo_urls.should eq Array(String).new - result.status.should be_nil - result.tags.should eq Array(Petstore::Tag).new + expect(result.id).to eq pet_id + expect(result.category).to be_nil + expect(result.name).to eq "crystal" + expect(result.photo_urls).to eq Array(String).new + expect(result.status).to be_nil + expect(result.tags).to eq Array(Petstore::Tag).new end end @@ -159,5 +157,4 @@ describe "PetApi" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/api/store_api_spec.cr b/samples/client/petstore/crystal/spec/api/store_api_spec.cr index f669cbeba87..c5e4fc67dff 100644 --- a/samples/client/petstore/crystal/spec/api/store_api_spec.cr +++ b/samples/client/petstore/crystal/spec/api/store_api_spec.cr @@ -1,21 +1,19 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::StoreApi # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe "StoreApi" do +Spectator.describe "StoreApi" do describe "test an instance of StoreApi" do it "should create an instance of StoreApi" do api_instance = Petstore::StoreApi.new @@ -60,7 +58,7 @@ describe "StoreApi" do # unit tests for place_order # Place an order for a pet - # + # # @param order order placed for purchasing the pet # @param [Hash] opts the optional parameters # @return [Order] @@ -69,5 +67,4 @@ describe "StoreApi" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/api/user_api_spec.cr b/samples/client/petstore/crystal/spec/api/user_api_spec.cr index 1abb6fe6b8f..a126ae543a3 100644 --- a/samples/client/petstore/crystal/spec/api/user_api_spec.cr +++ b/samples/client/petstore/crystal/spec/api/user_api_spec.cr @@ -1,21 +1,19 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::UserApi # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe "UserApi" do +Spectator.describe "UserApi" do describe "test an instance of UserApi" do it "should create an instance of UserApi" do api_instance = Petstore::UserApi.new @@ -37,7 +35,7 @@ describe "UserApi" do # unit tests for create_users_with_array_input # Creates list of users with given input array - # + # # @param user List of user object # @param [Hash] opts the optional parameters # @return [nil] @@ -49,7 +47,7 @@ describe "UserApi" do # unit tests for create_users_with_list_input # Creates list of users with given input array - # + # # @param user List of user object # @param [Hash] opts the optional parameters # @return [nil] @@ -73,7 +71,7 @@ describe "UserApi" do # unit tests for get_user_by_name # Get user by user name - # + # # @param username The name that needs to be fetched. Use user1 for testing. # @param [Hash] opts the optional parameters # @return [User] @@ -85,7 +83,7 @@ describe "UserApi" do # unit tests for login_user # Logs user into the system - # + # # @param username The user name for login # @param password The password for login in clear text # @param [Hash] opts the optional parameters @@ -98,7 +96,7 @@ describe "UserApi" do # unit tests for logout_user # Logs out current logged in user session - # + # # @param [Hash] opts the optional parameters # @return [nil] describe "logout_user test" do @@ -119,5 +117,4 @@ describe "UserApi" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/api_client_spec.cr b/samples/client/petstore/crystal/spec/api_client_spec.cr index 18209417eab..eb6ee572367 100644 --- a/samples/client/petstore/crystal/spec/api_client_spec.cr +++ b/samples/client/petstore/crystal/spec/api_client_spec.cr @@ -1,6 +1,6 @@ require "./spec_helper" -describe Petstore::ApiClient do +Spectator.describe Petstore::ApiClient do describe "#update_params_for_auth!" do describe "oauth2" do it "should add 'Authorization' to header" do @@ -13,8 +13,8 @@ describe Petstore::ApiClient do api_client = Petstore::ApiClient.new(config) api_client.update_params_for_auth!(header_params, query_params, ["petstore_auth"]) - header_params["Authorization"].should eq "Bearer xxx" - query_params.size.should eq 0 + expect(header_params["Authorization"]).to eq "Bearer xxx" + expect(query_params.size).to eq 0 end end @@ -30,8 +30,8 @@ describe Petstore::ApiClient do api_client = Petstore::ApiClient.new(config) api_client.update_params_for_auth!(header_params, query_params, ["api_key"]) - header_params["api_key"].should eq "xxx" - query_params.empty?.should be_true + expect(header_params["api_key"]).to eq "xxx" + expect(query_params.empty?).to be_true end end @@ -47,8 +47,8 @@ describe Petstore::ApiClient do api_client = Petstore::ApiClient.new(config) api_client.update_params_for_auth!(header_params, query_params, ["api_key"]) - header_params["api_key"].should eq "Token xxx" - query_params.empty?.should be_true + expect(header_params["api_key"]).to eq "Token xxx" + expect(query_params.empty?).to be_true end end end diff --git a/samples/client/petstore/crystal/spec/configuration_spec.cr b/samples/client/petstore/crystal/spec/configuration_spec.cr index a99e77166dd..a462dbf71a8 100644 --- a/samples/client/petstore/crystal/spec/configuration_spec.cr +++ b/samples/client/petstore/crystal/spec/configuration_spec.cr @@ -1,6 +1,6 @@ require "./spec_helper" -describe Petstore::Configuration do +Spectator.describe Petstore::Configuration do describe "#initialize" do context "with block" do it "works" do @@ -8,7 +8,7 @@ describe Petstore::Configuration do config.username = "xxx" end - config.username.should eq "xxx" + expect(config.username).to eq "xxx" end end end @@ -20,7 +20,7 @@ describe Petstore::Configuration do config.username = "xxx" end - config.username.should eq "xxx" + expect(config.username).to eq "xxx" end end end diff --git a/samples/client/petstore/crystal/spec/models/another_property_name_mapping_spec.cr b/samples/client/petstore/crystal/spec/models/another_property_name_mapping_spec.cr index 95840acd37b..23de0b60455 100644 --- a/samples/client/petstore/crystal/spec/models/another_property_name_mapping_spec.cr +++ b/samples/client/petstore/crystal/spec/models/another_property_name_mapping_spec.cr @@ -1,28 +1,26 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::AnotherPropertyNameMapping # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::AnotherPropertyNameMapping do - +Spectator.describe Petstore::AnotherPropertyNameMapping do describe "test an instance of AnotherPropertyNameMapping" do it "should create an instance of AnotherPropertyNameMapping" do - #instance = Petstore::AnotherPropertyNameMapping.new - #expect(instance).to be_instance_of(Petstore::AnotherPropertyNameMapping) + # instance = Petstore::AnotherPropertyNameMapping.new + # expect(instance).to be_instance_of(Petstore::AnotherPropertyNameMapping) end end + describe "test attribute 'http_debug_operation'" do it "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html @@ -46,5 +44,4 @@ describe Petstore::AnotherPropertyNameMapping do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/models/api_response_spec.cr b/samples/client/petstore/crystal/spec/models/api_response_spec.cr index e1b8029487e..14ad6b1b6aa 100644 --- a/samples/client/petstore/crystal/spec/models/api_response_spec.cr +++ b/samples/client/petstore/crystal/spec/models/api_response_spec.cr @@ -1,28 +1,26 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::ApiResponse # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::ApiResponse do - +Spectator.describe Petstore::ApiResponse do describe "test an instance of ApiResponse" do it "should create an instance of ApiResponse" do - #instance = Petstore::ApiResponse.new - #expect(instance).to be_instance_of(Petstore::ApiResponse) + # instance = Petstore::ApiResponse.new + # expect(instance).to be_instance_of(Petstore::ApiResponse) end end + describe "test attribute 'code'" do it "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html @@ -40,5 +38,4 @@ describe Petstore::ApiResponse do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/models/category_spec.cr b/samples/client/petstore/crystal/spec/models/category_spec.cr index 350aae9ed00..82d2527aaa5 100644 --- a/samples/client/petstore/crystal/spec/models/category_spec.cr +++ b/samples/client/petstore/crystal/spec/models/category_spec.cr @@ -1,28 +1,26 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::Category # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::Category do - +Spectator.describe Petstore::Category do describe "test an instance of Category" do it "should create an instance of Category" do - #instance = Petstore::Category.new - #expect(instance).to be_instance_of(Petstore::Category) + # instance = Petstore::Category.new + # expect(instance).to be_instance_of(Petstore::Category) end end + describe "test attribute 'id'" do it "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html @@ -34,5 +32,4 @@ describe Petstore::Category do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/models/format_test_spec.cr b/samples/client/petstore/crystal/spec/models/format_test_spec.cr index 58448e40162..6cc22cc964c 100644 --- a/samples/client/petstore/crystal/spec/models/format_test_spec.cr +++ b/samples/client/petstore/crystal/spec/models/format_test_spec.cr @@ -1,28 +1,26 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::FormatTest # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::FormatTest do - +Spectator.describe Petstore::FormatTest do describe "test an instance of FormatTest" do it "should create an instance of FormatTest" do - #instance = Petstore::FormatTest.new - #expect(instance).to be_instance_of(Petstore::FormatTest) + # instance = Petstore::FormatTest.new + # expect(instance).to be_instance_of(Petstore::FormatTest) end end + describe "test attribute 'integer'" do it "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html @@ -118,5 +116,4 @@ describe Petstore::FormatTest do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/models/order_spec.cr b/samples/client/petstore/crystal/spec/models/order_spec.cr index 19a2d003d0f..31bc80a8f66 100644 --- a/samples/client/petstore/crystal/spec/models/order_spec.cr +++ b/samples/client/petstore/crystal/spec/models/order_spec.cr @@ -1,28 +1,26 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::Order # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::Order do - +Spectator.describe Petstore::Order do describe "test an instance of Order" do it "should create an instance of Order" do - #instance = Petstore::Order.new - #expect(instance).to be_instance_of(Petstore::Order) + # instance = Petstore::Order.new + # expect(instance).to be_instance_of(Petstore::Order) end end + describe "test attribute 'id'" do it "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html @@ -62,5 +60,4 @@ describe Petstore::Order do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/models/pet_spec.cr b/samples/client/petstore/crystal/spec/models/pet_spec.cr index dac484057c9..66650f6ad85 100644 --- a/samples/client/petstore/crystal/spec/models/pet_spec.cr +++ b/samples/client/petstore/crystal/spec/models/pet_spec.cr @@ -1,61 +1,58 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#OpenAPI Generator version: 5.0.1-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::Pet # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::Pet do - +Spectator.describe Petstore::Pet do describe "test an instance of Pet" do - it "should fail to compile if any required properties is missing" do - assert_compilation_error(path: "./pet_compilation_error_spec.cr", message: "Error: expected argument 'name' to 'Petstore::Pet.new' to be String, not Nil") - end + # it "should fail to compile if any required properties is missing" do + # assert_compilation_error(path: "./pet_compilation_error_spec.cr", message: "Error: expected argument 'name' to 'Petstore::Pet.new' to be String, not Nil") + # end it "should create an instance of Pet with only required properties" do pet = Petstore::Pet.new(id: nil, category: nil, name: "new pet", photo_urls: Array(String).new, tags: nil, status: nil) - pet.should be_a(Petstore::Pet) + expect(pet).to be_a(Petstore::Pet) end it "should create an instance of Pet with all properties" do pet_id = 12345_i64 pet = Petstore::Pet.new(id: pet_id, category: Petstore::Category.new(id: pet_id + 10, name: "crystal category"), name: "crystal", photo_urls: ["https://crystal-lang.org"], tags: [Petstore::Tag.new(id: pet_id + 100, name: "crystal tag")], status: "available") - pet.should be_a(Petstore::Pet) + expect(pet).to be_a(Petstore::Pet) end end describe "#from_json" do it "should instantiate a new instance from json string with required properties" do pet = Petstore::Pet.from_json("{\"name\": \"json pet\", \"photoUrls\": []}") - pet.should be_a(Petstore::Pet) - pet.name.should eq "json pet" - pet.photo_urls.should eq Array(String).new + expect(pet).to be_a(Petstore::Pet) + expect(pet.name).to eq "json pet" + expect(pet.photo_urls).to eq Array(String).new end it "should raise error when instantiating a new instance from json string with missing required properties" do - expect_raises(JSON::SerializableError, "Missing JSON attribute: name") do + expect_raises(JSON::SerializableError, /Missing JSON attribute: name/) do Petstore::Pet.from_json("{\"photoUrls\": []}") end - expect_raises(JSON::SerializableError, "Missing JSON attribute: photoUrls") do + expect_raises(JSON::SerializableError, /Missing JSON attribute: photoUrls/) do Petstore::Pet.from_json("{\"name\": \"json pet\"}") end end it "should raise error when instantiating a new instance from json string with required properties set to null value" do - expect_raises(JSON::SerializableError, "Expected String but was Null") do + expect_raises(JSON::SerializableError, /Expected String but was Null/) do Petstore::Pet.from_json("{\"name\": null, \"photoUrls\": []}") end - expect_raises(JSON::SerializableError, "Expected BeginArray but was Null") do + expect_raises(JSON::SerializableError, /Expected BeginArray but was Null/) do Petstore::Pet.from_json("{\"name\": \"json pet\", \"photoUrls\": null}") end end @@ -100,5 +97,4 @@ describe Petstore::Pet do # end end end - end diff --git a/samples/client/petstore/crystal/spec/models/tag_spec.cr b/samples/client/petstore/crystal/spec/models/tag_spec.cr index 64a05f292ce..d500aa8309d 100644 --- a/samples/client/petstore/crystal/spec/models/tag_spec.cr +++ b/samples/client/petstore/crystal/spec/models/tag_spec.cr @@ -1,26 +1,23 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#OpenAPI Generator version: 5.0.1-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::Tag # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::Tag do - +Spectator.describe Petstore::Tag do describe "test an instance of Tag" do it "should create an instance of Tag" do - #instance = Petstore::Tag.new - #expect(instance).to be_instance_of(Petstore::Tag) + # instance = Petstore::Tag.new + # expect(instance).to be_instance_of(Petstore::Tag) end end @@ -28,13 +25,13 @@ describe Petstore::Tag do it "should equal to itself" do tag1 = Petstore::Tag.new(id: 0, name: "same") tag2 = tag1 - (tag1 == tag2).should be_true + expect(tag1 == tag2).to be_true end it "should equal to another instance with same attributes" do tag1 = Petstore::Tag.new(id: 0, name: "tag") tag2 = Petstore::Tag.new(id: 0, name: "tag") - (tag1 == tag2).should be_true + expect(tag1 == tag2).to be_true end end @@ -49,5 +46,4 @@ describe Petstore::Tag do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/models/user_spec.cr b/samples/client/petstore/crystal/spec/models/user_spec.cr index 194268274ec..981cd52d271 100644 --- a/samples/client/petstore/crystal/spec/models/user_spec.cr +++ b/samples/client/petstore/crystal/spec/models/user_spec.cr @@ -1,28 +1,26 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.11.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.11.0-SNAPSHOT # require "../spec_helper" -require "json" -require "time" # Unit tests for Petstore::User # Automatically generated by openapi-generator (https://openapi-generator.tech) # Please update as you see appropriate -describe Petstore::User do - +Spectator.describe Petstore::User do describe "test an instance of User" do it "should create an instance of User" do - #instance = Petstore::User.new - #expect(instance).to be_instance_of(Petstore::User) + # instance = Petstore::User.new + # expect(instance).to be_instance_of(Petstore::User) end end + describe "test attribute 'id'" do it "should work" do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html @@ -70,5 +68,4 @@ describe Petstore::User do # assertion here. ref: https://crystal-lang.org/reference/guides/testing.html end end - end diff --git a/samples/client/petstore/crystal/spec/petstore_spec.cr b/samples/client/petstore/crystal/spec/petstore_spec.cr index cca7698a536..59d84e90319 100644 --- a/samples/client/petstore/crystal/spec/petstore_spec.cr +++ b/samples/client/petstore/crystal/spec/petstore_spec.cr @@ -1,6 +1,6 @@ require "./spec_helper" -describe Petstore do +Spectator.describe Petstore do describe "#configure" do it "works" do Petstore.configure do |config| @@ -9,8 +9,8 @@ describe Petstore do config = Petstore.configure - config.should eq Petstore::Configuration.default - config.username.should eq "xxx" + expect(config).to eq Petstore::Configuration.default + expect(config.username).to eq "xxx" # Clean up Petstore::Configuration.default.username = nil diff --git a/samples/client/petstore/crystal/spec/spec_helper.cr b/samples/client/petstore/crystal/spec/spec_helper.cr index e15b6ea9e6d..66c09281983 100644 --- a/samples/client/petstore/crystal/spec/spec_helper.cr +++ b/samples/client/petstore/crystal/spec/spec_helper.cr @@ -1,22 +1,23 @@ -# #OpenAPI Petstore +# OpenAPI Petstore # -##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. +# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. # -#The version of the OpenAPI document: 1.0.0 +# The version of the OpenAPI document: 1.0.0 # -#Generated by: https://openapi-generator.tech -#Generator version: 7.13.0-SNAPSHOT +# Generated by: https://openapi-generator.tech +# Generator version: 7.13.0-SNAPSHOT # # load modules -require "spec" +require "spectator" require "json" +require "time" require "../src/petstore" def assert_compilation_error(path : String, message : String) : Nil buffer = IO::Memory.new result = Process.run("crystal", ["run", "--no-color", "--no-codegen", path], error: buffer) - result.success?.should be_false - buffer.to_s.should contain message + expect(result.success?).to be_false + expect(buffer.to_s).to contain message buffer.close end diff --git a/samples/client/petstore/crystal/src/petstore/models/format_test.cr b/samples/client/petstore/crystal/src/petstore/models/format_test.cr index b625575f982..570a1b6df51 100644 --- a/samples/client/petstore/crystal/src/petstore/models/format_test.cr +++ b/samples/client/petstore/crystal/src/petstore/models/format_test.cr @@ -127,7 +127,7 @@ module Petstore end if @password.to_s.size < 10 - invalid_properties.push("invalid value for \"password\", the character length must be great than or equal to 10.") + invalid_properties.push("invalid value for \"password\", the character length must be greater than or equal to 10.") end pattern = Regexp.new(/^\d{10}$/) @@ -253,7 +253,7 @@ module Petstore end if password.to_s.size < 10 - raise ArgumentError.new("invalid value for \"password\", the character length must be great than or equal to 10.") + raise ArgumentError.new("invalid value for \"password\", the character length must be greater than or equal to 10.") end @password = password