Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #11158
Closed
Open
Issue created Dec 20, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Ruby] Request body with array raises java.lang.NullPointerException

Created by: ykitamura-mdsol

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Ruby client generation raises this exception:

Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'Pets'
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:678)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:903)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException
	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:674)
	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:683)
	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:615)
	at org.openapitools.codegen.languages.RubyClientCodegen.postProcessOperationsWithModels(RubyClientCodegen.java:589)
	at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1220)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:581)
	... 4 more
openapi-generator version

5.3.0

OpenAPI declaration file content or url
openapi: '3.0.3'
info:
  version: 1.0.0
  title: Petstore
paths:
  /pets:
    post:
      summary: Create pets
      operationId: createPets
      tags:
        - pets
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pets'
      responses:
        '201':
          description: Null response
components:
  schemas:
    Pets:
      type: array
      items:
        type: object
        properties:
          name:
            type: string
Generation Details

java -jar openapi-generator-cli-5.3.0.jar generate -i petstore.yaml -g ruby

Steps to reproduce

Use the generation details and the provided YAML file

Related issues/PRs

The generation doesn't fail with 5.2.1, it handles the array items as a number:

require 'time'
require 'openapi_client'

api_instance = OpenapiClient::PetsApi.new
request_body = [3.56] # Array<Object> | 

The changes in #10334 might cause this change.

The following languages also have the same issue:

  • crystal
  • go
  • powershell
Suggest a fix

Updating this part: https://github.com/OpenAPITools/openapi-generator/blob/1757c4d2ea8a2570bd616609ab7348e7183bd333/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java#L682-L683

to something like:

        } else if (codegenProperty.isMap) {
            if (codegenProperty.items != null) {
                return "{ key: " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
            } else {
                return "{ ... }";
            }

will be a quick fix, it will generate clients successfully with examples like this:

require 'time'
require 'openapi_client'

api_instance = OpenapiClient::PetsApi.new
request_body = [{ ... }] # Array<Object> | 

(a long-term fix could be having codegenProperty.items properly when codegenProperty.isMap = True)

Assignee
Assign to
Time tracking