OpenAPITools / OpenAPITools/openapi-generator

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

Open
#22,290 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java, around schema-name resolution, and reproduce the case with the shell command in the linked gist. Compare the generated Asciidoc output and log with the reported behavior; done when the external partial file's self-referencing $ref is resolved rather than rejected by the filter.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.