Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for anonymous node and regression for array #59

Merged
merged 1 commit into from
Aug 7, 2024
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
28 changes: 28 additions & 0 deletions test/files/openapi/minimal.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 24 additions & 3 deletions test/reynard/schema/model_naming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading