OpenAPITools / OpenAPITools/openapi-generator

[BUG] Since openapi generator 5.1.0 cannot parse the 3GPP R16-July-2020 yamls for 5G (related to $ref)

Open
#11,175 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 (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

Since openapi generator 5.1.0, I cannot parse the 3GPP R16-July-2020 yamls for 5G.

To highlight what cannot be parsed, the file example_part1.yaml represents an extract of TS29504_Nudr_DR.yaml which contains only the api /subscription-data/{ueId}/{servingPlmnId}/provisioned-data/am-data and renammed /my-api.
The api /my-api in example_part1.yaml refers to the file example_part2.yaml in the same way as the api /subscription-data/{ueId}/{servingPlmnId}/provisioned-data/am-data in TS29504_Nudr_DR.yaml refers to TS29505_Subscription_Data.yaml and these sub dependencies.
example_part1.yaml and example_part2.yaml have be simplified to maximum possible to reproduce the problem.

With openapi generator cli 5.0.0, example_part1.yaml is well parsed (openapi_generator_cli_5.0.0 generate -g java -i example_part1.yaml -o tmp).
But this fails with the generator 5.1.0 (openapi_generator_cli_5.1.0 generate -g java -i example_part1.yaml -o tmp).
Also if I parse example_part2.yaml with the generator 5.1.0, it works.

Thanks for the help.

openapi-generator version

regression since openapi generator 5.1.0

OpenAPI declaration file content or url

example_part1.yaml

openapi: 3.0.0
info:
  version: '-'
  title: 'part1'
paths:
  /my-api:
    $ref: 'example_part2.yaml#/paths/~1my-api'

example_part2.yaml

openapi: 3.0.0
info:
  version: '-'
  title: 'part2'

paths:

  /my-api:
    get:
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schema1'
        default:
          description: Unexpected error
          content:
            application/problem+json:
              schema:
                type: string

components:
  schemas:
  
    Bytes:
      format: byte
      type: string

    RgWirelineCharacteristics:
      $ref: '#/components/schemas/Bytes'

    Schema2:
      type: object
      properties:
        rgWirelineCharacteristics:
          $ref: '#/components/schemas/RgWirelineCharacteristics'

    Schema1:
      $ref: '#/components/schemas/Schema2'
Generation Details

java -Dlog.level=debug -jar openapi-generator-cli-5.1.0.jar generate -g java -i example_part1.yaml -o tmp

[main] DEBUG o.o.codegen.config.GeneratorSettings - GeneratorSettings#build: %s
[main] DEBUG o.o.codegen.config.WorkflowSettings - WorkflowSettings#build: %s
[main] WARN  io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving:
java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 18
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
        at java.base/java.lang.String.substring(String.java:1874)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:113)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchema(ExternalRefProcessor.java:921)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processSchema(ExternalRefProcessor.java:200)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processProperties(ExternalRefProcessor.java:223)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processProperties(ExternalRefProcessor.java:230)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:157)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:117)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchemaObject(ExternalRefProcessor.java:869)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalPathItem(ExternalRefProcessor.java:280)
        at io.swagger.v3.parser.processors.PathsProcessor.processReferencePath(PathsProcessor.java:299)
        at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:63)
        at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:49)
        at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:175)
        at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:154)
        at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:89)
        at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:523)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:573)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 3
Errors: 
        -begin 0, end -1, length 18
Warnings: 
        -begin 0, end -1, length 18

        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:546)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:573)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Steps to reproduce
Related issues/PRs
Suggest a fix

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 by running the Java CLI command against example_part1.yaml and example_part2.yaml, comparing 5.0.0 and 5.1.0 behavior. Read the ExternalRefProcessor.processRefToExternalSchema stack-trace path and the surrounding OpenAPI parser calls. Done means the external path reference and its nested schema references generate successfully without the StringIndexOutOfBoundsException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.