Skip to content

[BUG] Generation failed on Windows for relative $ref #10053

@juanpablo-santos

Description

@juanpablo-santos

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

StringIndexOutOfBoundsException for relative $ref appears with a validated openapi.yaml contract, which is conformed following the description at the OpenAPI declaration file content or url section below. It seems that openapi-generator-maven-plugin 5.2.0 is hit by swagger-api/swagger-parser#1511. Adding swagger-parser v. 2.0.27 and jackson-core 2.12.4 seems enough to fix the problem, but then the generation fails with a much more weirder StackOverflowError:

Exception in thread "main" java.lang.StackOverflowError
	at java.base/java.lang.String.lastIndexOf(String.java:1852)
	at java.base/java.lang.String.lastIndexOf(String.java:1816)
	at java.base/java.lang.String.lastIndexOf(String.java:1795)
	at org.openapitools.codegen.utils.ModelUtils.getSimpleRef(ModelUtils.java:385)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1382)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1403)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1390)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1403)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1390)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1403)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1390)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1403)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1390)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1403)
	at org.openapitools.codegen.utils.ModelUtils.hasOrInheritsDiscriminator(ModelUtils.java:1390)
[...]

Turning on debug to see what spec has been understood by openapi, the aforementioned StackOverflowError seems to be caused because all models inheriting from any other model are parsed like this:

[...]
      "model\\beneficiarios\\BeneficiaryContactInformationContract" : {
        "allOf" : [ {
          "$ref" : "#/components/schemas/model\\beneficiarios\\BeneficiaryContactInformationContract"
        } ],
        "properties" : {
          "email" : {
            "$ref" : "#/components/schemas/model\\beneficiarios\\BeneficiaryContactInformationContract"
          },
[...]

Not sure where or why all allOf $refs are changed to self instead of its proper parent, hence causing this error.. Note that this only happens on Windows boxes, the same contract generates the associated files OK if it is launched on an Ubuntu box.

openapi-generator version

5.2.0 (but only on Windows environments), suspect it might happen with 5.0.0 onwards.

OpenAPI declaration file content or url

openapi.yaml

openapi: 3.0.1
[...]
components:
  schemas:
Beneficiario:
      $ref: './model/beneficiarios/BeneficiarioContract.yaml#/BeneficiarioContract'

and with ./model/beneficiarios/BeneficiarioContract.yaml been something like

type: object
allOf:
  - $ref: '../common/Base.yaml#/Base'
properties:
[...]

and ./common/Base.yaml being something like

Base:
  type: object
  discriminator:
    propertyName: baseId
  properties:
    baseId:
      type: string
Generation Details

Don't know how many languages are affected by this behaviour, I stumbled with this using JavaSpring, with no fancy configuration options..

Steps to reproduce

see Description section

Related issues/PRs

Not sure if #8495 is involved.

Suggest a fix

N/A

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