swagger-api / swagger-api/swagger-codegen-generators

[Ruby] Nested resources are not using datatype defined in documentation.

Open
#1,140 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

I am working with an API and the datatype is created correctly for c#

I have tried for Ruby and Typescript-fetch and it is returning generic values.

I can't see what I am doing wrong for Ruby or Typescript.

# documentation.yml

openapi: 3.0.3
info:
  title: Testing
  version: 2.0.0.alpha1
servers:
  - url: https://www.lvh.me/api/v1

paths:
  /now:
    get:
      summary: me
      operationId: get_me
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"

components:
  schemas:
    Device:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 1
        name:
          type: string
          example: "Device 1"
    User:
      type: object
      properties:
        devices:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
                format: int64
                example: 1
              name:
                type: string
                example: "Device 1"
        number_of_devices_allowed:
          type: integer
          example: 20
          description: Maximum of devices allowed for the current client
docker pull swaggerapi/swagger-codegen-cli-v3:3.0.42

docker run -it --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate \
    -i /local/docs/api/tes.yml \
    -l ruby \
    -o /local/lib/test\

The data model generated for user looks like this:

require 'date'

module MobileDataAnywhere
  class User
    attr_accessor :devices

    # Maximum of devices allowed for the current client
    attr_accessor :number_of_devices_allowed

    # Attribute type mapping.
    def self.openapi_types
      {
        :'devices' => :'Object',
        :'number_of_devices_allowed' => :'Object'
      }
    end

As a matter of fact, when the object is replaced manually to "Array", works perfectly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided Docker command and documentation.yml, then inspect the generator templates responsible for the Ruby User model's nested devices property and number_of_devices_allowed type. Compare the generated Ruby and working C# models; done means nested properties use their documented types instead of generic Object values.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.