Skip to content

[BUG] [Rust] SIMPLIFY_ONEOF_ANYOF=false causes NullPointerException: ... "name" is null in AbstractRustCodegen.sanitizeIdentifier #21192

@JMLX42

Description

@JMLX42

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
Exception in thread "main" java.lang.RuntimeException: Could not process model 'list_accessor_sparse_indices_4XX_response_allOf_errors_inner_source'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:518)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:443)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1293)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:535)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException: Cannot invoke "String.replaceAll(String, String)" because "name" is null
        at org.openapitools.codegen.languages.AbstractRustCodegen.sanitizeIdentifier(AbstractRustCodegen.java:187)
        at org.openapitools.codegen.languages.AbstractRustCodegen.toModelName(AbstractRustCodegen.java:349)
        at org.openapitools.codegen.languages.RustClientCodegen.fromModel(RustClientCodegen.java:295)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1755)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:513)
        ... 5 more
openapi-generator version

7.13.0

OpenAPI declaration file content or url
{
  "openapi": "3.1.0",
  "paths": {
    "/api/accessor-sparse-indices/": {
      "get": {
        "tags": [
          "Accessor Sparse Indices"
        ],
        "operationId": "list_accessor_sparse_indices",
        "parameters": [
          {
            "name": "fields[accessor-sparse-indices]",
            "in": "query",
            "description": "Specifies which fields should be returned. The value **MUST** be a comma-separated\n(U+002C COMMA, “,”) list that refers to the name(s) of the fields to be returned.\n\nAn empty value indicates that no fields should be returned.\n\nOmitting this parameter indicates that all fields should be returned.",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "bufferView",
                  "byteOffset",
                  "componentType"
                ]
              }
            },
            "explode": false
          },
          {
            "name": "include",
            "in": "query",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "bufferView"
                ]
              }
            },
            "explode": false
          },
          {
            "name": "page[number]",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int64",
              "default": 1
            },
            "allowReserved": true,
            "example": 1
          },
          {
            "name": "page[size]",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int64",
              "default": 100
            },
            "allowReserved": true,
            "example": 100
          }
        ],
        "responses": {
          "4XX": {
            "description": "Client error response.",
            "content": {
              "application/vnd.api+json": {
                "schema": {
                  "allOf": [
                    {
                      "type": "object",
                      "required": [
                        "errors"
                      ],
                      "properties": {
                        "errors": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "status",
                              "title",
                              "detail"
                            ],
                            "properties": {
                              "status": {
                                "type": "string",
                                "example": "404"
                              },
                              "title": {
                                "type": "string",
                                "example": "Not found"
                              },
                              "detail": {
                                "type": "string",
                                "example": "The requested resource cannot be found."
                              },
                              "source": {
                                "oneOf": [
                                  {
                                    "type": "null"
                                  },
                                  {
                                    "$ref": "#/components/schemas/Source"
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "example": "\n{\n  \"errors\": [\n    {\n      \"status\": \"404\",\n      \"title\": \"Resource not found\",\n      \"detail\": \"The requested resource could not be found.\"\n    }\n  ]\n}\n"
              }
            }
          },
Generation Details
$ java -DloggerPath=conf/log4j.properties -jar openapi-generator-cli.jar generate -i ${INPUT_FILE} \
        -g rust \
        -o ${TMP_PATH} \
        --openapi-normalizer=SIMPLIFY_ONEOF_ANYOF=false \
        --additional-properties=avoidBoxedModels=true
Steps to reproduce
$ java -DloggerPath=conf/log4j.properties -jar openapi-generator-cli.jar generate -i ${INPUT_FILE} \
        -g rust \
        -o ${TMP_PATH} \
        --openapi-normalizer=SIMPLIFY_ONEOF_ANYOF=false \
        --additional-properties=avoidBoxedModels=true
Related issues/PRs

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