Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ commands: # a reusable command with parameters
- run:
command: 'sudo docker info >/dev/null 2>&1 || sudo service docker start; '
- run:
command: |-
printf '127.0.0.1 petstore.swagger.io
' | sudo tee -a /etc/hosts
command: |
sudo tee -a /etc/hosts \<<< "127.0.0.1 path.v1.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.1 path.v2.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.111 path.v3.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.1 operation.v1.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.1 operation.v2.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.111 operation.v3.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.1 server.v1.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.1 server.v2.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.111 server.v3.test.openapi-generator.tech"
sudo tee -a /etc/hosts \<<< "127.0.0.1 petstore.swagger.io"
cat /etc/hosts
# - run: docker pull openapitools/openapi-petstore
# - run: docker run -d -e OPENAPI_BASE_PATH=/v3 -e DISABLE_API_KEY=1 -e DISABLE_OAUTH=1 -p 80:8080 openapitools/openapi-petstore
- run: docker pull swaggerapi/petstore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
# raise if data contains keys that are not known to the model
raise unless (data.keys - const.acceptable_attributes).empty?
model = const.build_from_hash(data)
return model if model && model.valid?
return model if model
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ paths:
- 80
- 8080
default: 80
- url: 'http://path.{version}.test.openapi-generator.tech/v2'
description: test server with variables
variables:
version:
description: target server
enum:
- 'v1'
- 'v2'
default: 'v2'
post:
tags:
- pet
Expand Down Expand Up @@ -178,6 +187,33 @@ paths:
- 'read:pets'
deprecated: true
'/pet/{petId}':
servers:
- url: 'http://petstore.swagger.io/v2'
- url: 'http://path-server-test.petstore.local/v2'
- url: 'http://{server}.swagger.io:{port}/v2'
description: test server with variables
variables:
server:
description: target server
enum:
- 'petstore'
- 'qa-petstore'
- 'dev-petstore'
default: 'petstore'
port:
enum:
- 80
- 8080
default: 80
- url: 'http://path.{version}.test.openapi-generator.tech/v2'
description: test server with variables
variables:
version:
description: target server
enum:
- 'v1'
- 'v2'
default: 'v2'
get:
tags:
- pet
Expand Down Expand Up @@ -1256,6 +1292,15 @@ servers:
default: 'v2'
- url: https://127.0.0.1/no_varaible
description: The local server without variables
- url: http://server.{version}.openapi-generator.tech
description: The openapi-generator test server
variables:
version:
description: target server
enum:
- 'v1'
- 'v2'
default: 'v2'
components:
requestBodies:
UserArray:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@
</property>
</activation>
<modules>
<module>samples/client/petstore/ruby-faraday</module>
<module>samples/client/petstore/ruby</module>
<module>samples/client/petstore/ruby-faraday</module>
<module>samples/client/petstore/ruby-autoload</module>
</modules>
</profile>
Expand Down
183 changes: 183 additions & 0 deletions samples/client/petstore/ruby/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ def server_settings
{
url: "https://127.0.0.1/no_varaible",
description: "The local server without variables",
},
{
url: "http://server.{version}.openapi-generator.tech",
description: "The openapi-generator test server",
variables: {
version: {
description: "target server",
default_value: "v2",
enum_values: [
"v1",
"v2"
]
}
}
}
]
end
Expand Down Expand Up @@ -353,6 +367,114 @@ def operation_server_settings
]
}
}
},
{
url: "http://path.{version}.test.openapi-generator.tech/v2",
description: "test server with variables",
variables: {
version: {
description: "target server",
default_value: "v2",
enum_values: [
"v1",
"v2"
]
}
}
}
],
"PetApi.delete_pet": [
{
url: "http://petstore.swagger.io/v2",
description: "No description provided",
},
{
url: "http://path-server-test.petstore.local/v2",
description: "No description provided",
},
{
url: "http://{server}.swagger.io:{port}/v2",
description: "test server with variables",
variables: {
server: {
description: "target server",
default_value: "petstore",
enum_values: [
"petstore",
"qa-petstore",
"dev-petstore"
]
},
port: {
description: "No description provided",
default_value: "80",
enum_values: [
"80",
"8080"
]
}
}
},
{
url: "http://path.{version}.test.openapi-generator.tech/v2",
description: "test server with variables",
variables: {
version: {
description: "target server",
default_value: "v2",
enum_values: [
"v1",
"v2"
]
}
}
}
],
"PetApi.get_pet_by_id": [
{
url: "http://petstore.swagger.io/v2",
description: "No description provided",
},
{
url: "http://path-server-test.petstore.local/v2",
description: "No description provided",
},
{
url: "http://{server}.swagger.io:{port}/v2",
description: "test server with variables",
variables: {
server: {
description: "target server",
default_value: "petstore",
enum_values: [
"petstore",
"qa-petstore",
"dev-petstore"
]
},
port: {
description: "No description provided",
default_value: "80",
enum_values: [
"80",
"8080"
]
}
}
},
{
url: "http://path.{version}.test.openapi-generator.tech/v2",
description: "test server with variables",
variables: {
version: {
description: "target server",
default_value: "v2",
enum_values: [
"v1",
"v2"
]
}
}
}
],
"PetApi.update_pet": [
Expand Down Expand Up @@ -386,6 +508,67 @@ def operation_server_settings
]
}
}
},
{
url: "http://path.{version}.test.openapi-generator.tech/v2",
description: "test server with variables",
variables: {
version: {
description: "target server",
default_value: "v2",
enum_values: [
"v1",
"v2"
]
}
}
}
],
"PetApi.update_pet_with_form": [
{
url: "http://petstore.swagger.io/v2",
description: "No description provided",
},
{
url: "http://path-server-test.petstore.local/v2",
description: "No description provided",
},
{
url: "http://{server}.swagger.io:{port}/v2",
description: "test server with variables",
variables: {
server: {
description: "target server",
default_value: "petstore",
enum_values: [
"petstore",
"qa-petstore",
"dev-petstore"
]
},
port: {
description: "No description provided",
default_value: "80",
enum_values: [
"80",
"8080"
]
}
}
},
{
url: "http://path.{version}.test.openapi-generator.tech/v2",
description: "test server with variables",
variables: {
version: {
description: "target server",
default_value: "v2",
enum_values: [
"v1",
"v2"
]
}
}
}
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def find_and_cast_into_type(klass, data)
# raise if data contains keys that are not known to the model
raise unless (data.keys - const.acceptable_attributes).empty?
model = const.build_from_hash(data)
return model if model && model.valid?
return model if model
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}
expect {
config.base_url(:'PetApi.add_pet')
}.to raise_error(ArgumentError, 'Invalid index 10 when selecting the server. Must not be nil and must be less than 3')
}.to raise_error(ArgumentError, 'Invalid index 10 when selecting the server. Must not be nil and must be less than 4')
end

it 'should remove trailing slashes' do
Expand Down
43 changes: 43 additions & 0 deletions samples/client/petstore/ruby/spec/custom/pet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,49 @@
expect(pet.category.name).to eq("category test")
end

it "should fetch a pet object using invalid operation path" do
# backup index
index_backup = @pet_api.api_client.config.server_operation_index
expect(index_backup).to eq({})
# test operation index 1 (invalid path)
@pet_api.api_client.config.server_operation_index = {
:'PetApi.get_pet_by_id' => 1
}

expect(@pet_api.api_client.config.base_url(:'PetApi.get_pet_by_id')).to eq('http://path-server-test.petstore.local/v2')

expect {
pet = @pet_api.get_pet_by_id(@pet_id)
}.to raise_error(Petstore::ApiError) # path-server-test.petstore.local is invalid (not defined in host table)

# restore index
@pet_api.api_client.config.server_operation_index = index_backup
expect(@pet_api.api_client.config.server_operation_index).to eq({})
end

it "should fetch a pet object using operation path" do
# backup index
index_backup = @pet_api.api_client.config.server_operation_index
expect(index_backup).to eq({})
# test operation index 3
@pet_api.api_client.config.server_operation_index = {
:'PetApi.get_pet_by_id' => 3
}

expect(@pet_api.api_client.config.base_url(:'PetApi.get_pet_by_id')).to eq('http://path.v2.test.openapi-generator.tech/v2')

pet = @pet_api.get_pet_by_id(@pet_id)
expect(pet).to be_a(Petstore::Pet)
expect(pet.id).to eq(@pet_id)
expect(pet.name).to eq("RUBY UNIT TESTING")
expect(pet.tags[0].name).to eq("tag test")
expect(pet.category.name).to eq("category test")
# restore index
@pet_api.api_client.config.server_operation_index = index_backup
expect(@pet_api.api_client.config.server_operation_index).to eq({})
expect(@pet_api.api_client.config.base_url(:'PetApi.get_pet_by_id')).to eq('http://petstore.swagger.io/v2')
end

it "should fetch a pet object with http info" do
pet, status_code, headers = @pet_api.get_pet_by_id_with_http_info(@pet_id)
expect(status_code).to eq(200)
Expand Down