Skip to content

[BUG][ruby] required properties referencing a oneOf schema break generation #9191

@jfeltesse-mdsol

Description

@jfeltesse-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?
Description

It looks like #8040 broke the ruby client generator when required properties point to a oneOf schema.

openapi-generator version

master @ acedd1c

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: oneOf repro
  version: v1
paths:
  '/hello':
    post:
      operationId: hello.post
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [greeting]
              properties:
                greeting:
                  $ref: '#/components/schemas/Greeting'
      responses:
        '204':
          description: returns a greeting

components:
  schemas:
    Greeting:
      oneOf:
        - type: string
        - type: object
Generation Details
openapi-generator generate -i oneof_broken.yaml -g ruby --library faraday -o out/ruby_oneof
Steps to reproduce
  1. run the command above by passing the openapi file yet above
  2. generation fails with
    Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'Default'
    	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:675)
    	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:878)
    	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:440)
    	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:736)
    	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:751)
    	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:726)
    	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:759)
    	at org.openapitools.codegen.languages.RubyClientCodegen.constructExampleCode(RubyClientCodegen.java:664)
    	at org.openapitools.codegen.languages.RubyClientCodegen.postProcessOperationsWithModels(RubyClientCodegen.java:588)
    	at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1194)
    	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:580)
    
  3. comment out the required: [greeting] line
  4. generation works
Related issues/PRs

#8040

Suggest a fix

unsure, sorry.

@zippolyte @jirikuncar @wing328

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions