Skip to content

[Ruby] Incorrect MinLength and MaxLength on partial_model_generic.mustache template #3400

@littlechu

Description

@littlechu
Description

Notice that when I generate from yml/json that contain properties maxLength but without maxLength, the ruby code generated is incorrect

If you look at the mustache file, you will see there are multi places that's look like this:

     {{#minLength}}
      if @{{{name}}}.to_s.length > {{{maxLength}}}
        invalid_properties.push("invalid value for '{{{name}}}', the character length must be smaller than or equal to {{{maxLength}}}.")
      end

      {{/minLength}}

This is most likely copy/paste error

Swagger-codegen version

Swagger 2.2.0

Swagger declaration file content or url

By adding maxLength to Pet Name properties in petstore-minimal.yaml

---
  swagger: "2.0"
  info:
    version: "1.0.0"
    title: "Swagger Petstore"
    description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification"
    termsOfService: "http://swagger.io/terms/"
    contact:
      name: "Swagger API Team"
    license:
      name: "MIT"
  host: "petstore.swagger.io"
  basePath: "/api"
  schemes:
    - "http"
  consumes:
    - "application/json"
  produces:
    - "application/json"
  paths:
    /pets:
      get:
        description: "Returns all pets from the system that the user has access to"
        produces:
          - "application/json"
        responses:
          "200":
            description: "A list of pets."
            schema:
              type: "array"
              items:
                $ref: "#/definitions/Pet"
  definitions:
    Pet:
      type: "object"
      required:
        - "id"
        - "name"
      properties:
        id:
          type: "integer"
          format: "int64"
        name:
          type: "string"
          maxLength: 999
        tag:
          type: "string"
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i petstore-minimal.yaml -o ruby -l ruby

Steps to reproduce

Run IRB like the following and require the swagger_client library

irb -I ruby/lib
require 'swagger_client'
you will run into library error at this point

Related issues
Suggest a Fix

fix all the incorrect minLength and MaxLength in the mustache template

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions