swagger-api / swagger-api/swagger-codegen-generators
[Ruby] Components that use allOf are broken
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Using the allOf keyword in the OpenAPI YAML file causes the generator to create broken classes.
$ swagger-codegen version
> 3.0.26
Consider the components in the following YAML file:
openapi: 3.0.3
info:
title: Test
version: 0.0.1
components:
schemas:
SimpleThing:
type: object
properties:
prop1:
type: string
ComplexThing:
allOf:
- $ref: "#/components/schemas/SimpleThing"
- type: object
properties:
prop2:
type: string
paths:
/ping:
get:
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
Running swagger-codegen creates two model classes. SimpleThing, which doesn't inherit, looks fine:
simple_thing.rb
module SwaggerClient
class SimpleThing # <- Does not extend anything
def initialize(attributes = {})
# Nothing weird in here
end
end
end
ComplexThing looks like it wants to inherit SimpleThing, but does not:
complex_thing.rb
module SwaggerClient
class ComplexThing # <- Does not extend anything
def initialize(attributes = {})
# ...
# call parent's initialize
super(attributes) # <---- This line fails with "ArgumentError (wrong number of arguments (given 1, expected 0))"
# ...
end
end
end
The end result is that using the Ruby client to connect to any endpoint which returns a ComplexThing will fail with an ArgumentError.
I believe this is somewhat related to https://github.com/swagger-api/swagger-codegen-generators/pull/856, except the fix there was to remove the arguments in super, whereas the right fix here might be to have subclasses extend correctly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied OpenAPI YAML and Swagger Codegen 3.0.26, then compare the generated simple_thing.rb and complex_thing.rb files. Trace the Ruby model-generation path for allOf and verify that ComplexThing correctly inherits from SimpleThing and can initialize without the reported ArgumentError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100