From 71f5a8b3939025b91f2effd9f1bf1c0b2c23c27e Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Wed, 7 Aug 2024 14:49:02 +0200 Subject: [PATCH] Add example for anonymous node and regression for array. --- test/files/openapi/minimal.yml | 28 ++++++++++++++++++++++++ test/reynard/schema/model_naming_test.rb | 27 ++++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 test/files/openapi/minimal.yml diff --git a/test/files/openapi/minimal.yml b/test/files/openapi/minimal.yml new file mode 100644 index 0000000..330127d --- /dev/null +++ b/test/files/openapi/minimal.yml @@ -0,0 +1,28 @@ +openapi: "3.0.0" +info: + title: Spaceships + version: 1.0.0 + contact: {} + description: Everything you want to know about your favorite mode of transportation. +servers: + - url: http://example.com +tags: + - name: spaceships + description: Ships of space +paths: + /spaceships: + get: + summary: List all spaceships + description: Produces a list of all spaceships known to us. + operationId: allSpaceShips + tags: + - spaceships + responses: + "200": + description: Array of spaceships. + content: + application/json: + schema: + type: array + items: + type: object diff --git a/test/reynard/schema/model_naming_test.rb b/test/reynard/schema/model_naming_test.rb index 407a544..2237ddd 100644 --- a/test/reynard/schema/model_naming_test.rb +++ b/test/reynard/schema/model_naming_test.rb @@ -50,17 +50,27 @@ class RegressionModelNamingTest < Reynard::Test EXPECTED = { 'bare' => [], 'external' => %w[Author Bio Error], + 'minimal' => %w[Spaceship SpaceshipCollection], 'naming' => %w[ Sector Subsector IndustryGroup Industry NationalIndustry Art NationalIndustry + SectorCollection SubsectorsCollection IndustryGroupsCollection IndustriesCollection + NationalIndustriesCollection NationalIndustryCollection NationalIndustryCollection + ], + 'nested' => %w[ + Library Book Author Error Library Book Author Book Author Error + BooksCollection BooksCollection ], - 'nested' => %w[Library Book Author Error Library Book Author Book Author Error], 'params' => %w[], 'simple' => %w[ Book Error Book BookFormData Book Error Book Error Book Error Book Error Book Error Book Error Book Bookformdata Book Error + BooksCollection BooksCollection BooksCollection ], - 'titled' => %w[ISBN], - 'weird' => %w[HowdyPardner AFRootWithInThe Fugol Bird Duckbill Duckbill HowdyPardner] + 'titled' => %w[ISBN IsbnCollection], + 'weird' => %w[ + HowdyPardner AFRootWithInThe Fugol Bird Duckbill Duckbill HowdyPardner + FugolCollection BirdsCollection DuckbillCollection + ] }.freeze test 'produces a model name for every schema node in every specification' do @@ -69,6 +79,7 @@ class RegressionModelNamingTest < Reynard::Test generated = [] specification = Specification.new(filename: filename) + specification.find_each(type: 'object') do |node| naming = ModelNaming.new(specification: specification, node: node) model_name = naming.model_name @@ -79,6 +90,16 @@ class RegressionModelNamingTest < Reynard::Test assert model_name.size > 2, model_name end + specification.find_each(type: 'array') do |node| + naming = ModelNaming.new(specification: specification, node: node) + model_name = naming.model_name + generated << model_name + + refute_nil model_name + assert_kind_of(String, model_name) + assert model_name.size > 2, model_name + end + assert_equal(EXPECTED.fetch(example_name), generated, "In filename: #{filename}") end end