Skip to content

[BUG][ASCIIDOC] $ref resource in external file not found due to filter #22290

@fabianfrz

Description

@fabianfrz

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When an external file is used using a reference and that references itself, the object is not found because of a filter, that expects it under an expected path but I do not see where this is an requirement so this should work in my opinion. External files do not need to be valid OpenAPI files as the are partials.

openapi-generator version

podman run --rm -v ${PWD}:/local docker.io/openapitools/openapi-generator-cli:latest version

7.18.0-SNAPSHOT

OpenAPI declaration file content or url

https://gist.github.com/fabianfrz/11f339a03f180d421d5cc569ea939d8e

Generation Details

see gist

Steps to reproduce

see gist shell command

log output
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/local/example_api) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: asciidoc (documentation)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'asciidoc' is considered stable.
[main] WARN  o.o.c.l.AsciidocDocumentationCodegen - base part for include markup lambda not found: null as /null
[main] WARN  o.o.c.l.AsciidocDocumentationCodegen - base part for include markup lambda not found: null as /null
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Empty operationId found for path: post /example. Renamed to auto-generated operationId: examplePost
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref: #/Response. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] WARN  o.o.codegen.utils.ModelUtils - #/Response is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/Response
[main] INFO  o.o.codegen.TemplateManager - writing file /local/example_api/index.adoc
[main] INFO  o.o.codegen.TemplateManager - writing file /local/example_api/.openapi-generator-ignore
[main] INFO  o.o.codegen.TemplateManager - writing file /local/example_api/.openapi-generator/VERSION
[main] INFO  o.o.codegen.TemplateManager - writing file /local/example_api/.openapi-generator/FILES
Suggest a fix

Note that with this also the else if statements can be removed:

Index: modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java	(revision 7ce0096e73eccdf33af2e4cb8481efa4ceb0ab3f)
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java	(date 1762331609356)
@@ -392,9 +392,7 @@
         } else if (ref.startsWith("#/definitions/")) {
             ref = ref.substring(ref.lastIndexOf("/") + 1);
         } else {
-            once(LOGGER).warn("Failed to get the schema name: {}", ref);
-            //throw new RuntimeException("Failed to get the schema: " + ref);
-            return null;
+            ref = ref.substring(ref.lastIndexOf("/") + 1);
         }
 
         ref = URLDecoder.decode(ref, StandardCharsets.UTF_8);

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