Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ballerina OpenAPI sanitize is not working for the type names used with the array #6919

Closed
TharmiganK opened this issue Aug 26, 2024 · 1 comment · Fixed by ballerina-platform/openapi-tools#1766
Assignees
Labels
Milestone

Comments

@TharmiganK
Copy link
Contributor

TharmiganK commented Aug 26, 2024

Description:

The --use-sanitized-oas option is not working with the type reference name used as a member of an array schema. Currently the generation failed with the NPE. But the root cause is the sanitisation.

Identified from: #6906

Steps to reproduce:

Please use the following OpenAPI specification to reproduce the issue:

openapi: 3.0.1
info:
  title: Api
  version: 0.1.0
servers:
- url: "{server}:{port}/api"
  variables:
    server:
      default: http://localhost
    port:
      default: "9999"
paths:
  /albums:
    get:
      operationId: getAlbums
      description: Get albums by genre
      parameters:
      - name: genre
        in: query
        required: true
        description: Album genre
        schema:
          type: string
      - name: API-VERSION
        in: header
        description: API Version
        schema:
          $ref: '#/components/schemas/VERSION'
          default: V1
      responses:
        "200":
          description: Albums found
          headers:
            req-id:
              required: true
              description: Request ID
              schema:
                type: integer
                format: int64
            api-version:
              required: true
              description: API Version
              schema:
                type: string
            session-id:
              required: true
              description: Session ID
              schema:
                type: string
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/album'
components:
  schemas:
    album:
      required:
      - artist
      - genre
      - id
      - name
      type: object
      properties:
        id:
          type: string
          description: Album ID
        name:
          type: string
          description: Album name
        artist:
          type: string
          description: Album artist
        genre:
          type: string
          description: Album genre
      additionalProperties: false
    VERSION:
      type: string
      description: API Version
      enum:
      - V1
      - V2
$ bal openapi -i openapi.yaml --mode client --use-sanitize-oas
ballerina: Oh no, something really went wrong. Bad. Sad.

We appreciate it if you can report the code that broke Ballerina in
https://github.com/ballerina-platform/ballerina-lang/issues with the
log you get below and your sample code.

We thank you for helping make us better.

[2024-08-26 13:28:42,213] SEVERE {b7a.log.crash} - Cannot invoke "io.swagger.v3.oas.models.media.Schema.get$ref()" because "schemaValue" is null 
java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.get$ref()" because "schemaValue" is null
        at io.ballerina.openapi.core.generators.type.TypeGeneratorUtils.getTypeGenerator(TypeGeneratorUtils.java:67)
        at io.ballerina.openapi.core.generators.type.generators.ArrayTypeGenerator.getTypeDescNodeForArraySchema(ArrayTypeGenerator.java:176)
        at io.ballerina.openapi.core.generators.type.BallerinaTypesGenerator.generateTypeDescriptorNodeForOASSchema(BallerinaTypesGenerator.java:151)
        at io.ballerina.openapi.core.generators.type.BallerinaTypesGenerator.generateTypeDescriptorNodeForOASSchema(BallerinaTypesGenerator.java:88)
        at io.ballerina.openapi.core.generators.common.TypeHandler.getTypeNodeFromOASSchema(TypeHandler.java:196)
        at io.ballerina.openapi.core.generators.common.TypeHandler.getTypeNodeFromOASSchema(TypeHandler.java:191)
        at io.ballerina.openapi.core.generators.client.FunctionReturnTypeGeneratorImp.getDataType(FunctionReturnTypeGeneratorImp.java:188)
        at io.ballerina.openapi.core.generators.client.FunctionReturnTypeGeneratorImp.populateReturnType(FunctionReturnTypeGeneratorImp.java:135)
        at io.ballerina.openapi.core.generators.client.FunctionReturnTypeGeneratorImp.getReturnTypeInfo(FunctionReturnTypeGeneratorImp.java:113)
        at io.ballerina.openapi.core.generators.client.FunctionReturnTypeGeneratorImp.getReturnType(FunctionReturnTypeGeneratorImp.java:81)
        at io.ballerina.openapi.core.generators.client.ResourceFunctionSignatureGenerator.generateFunctionSignature(ResourceFunctionSignatureGenerator.java:86)
        at io.ballerina.openapi.core.generators.client.ResourceFunctionGenerator.generateFunction(ResourceFunctionGenerator.java:88)
        at io.ballerina.openapi.core.generators.client.BallerinaClientGenerator.addResourceFunction(BallerinaClientGenerator.java:653)
        at io.ballerina.openapi.core.generators.client.BallerinaClientGenerator.createResourceFunctions(BallerinaClientGenerator.java:643)
        at io.ballerina.openapi.core.generators.client.BallerinaClientGenerator.getClassDefinitionNode(BallerinaClientGenerator.java:260)
        at io.ballerina.openapi.core.generators.client.BallerinaClientGenerator.getModuleMemberDeclarationNodes(BallerinaClientGenerator.java:216)
        at io.ballerina.openapi.core.generators.client.BallerinaClientGenerator.getSyntaxTree(BallerinaClientGenerator.java:194)
        at io.ballerina.openapi.core.generators.client.BallerinaClientGenerator.generateSyntaxTree(BallerinaClientGenerator.java:188)
        at io.ballerina.openapi.cmd.BallerinaCodeGenerator.generateClientFiles(BallerinaCodeGenerator.java:439)
        at io.ballerina.openapi.cmd.BallerinaCodeGenerator.generateClient(BallerinaCodeGenerator.java:258)
        at io.ballerina.openapi.cmd.OpenApiCmd.generatesClientFile(OpenApiCmd.java:445)
        at io.ballerina.openapi.cmd.OpenApiCmd.openApiToBallerina(OpenApiCmd.java:368)
        at io.ballerina.openapi.cmd.OpenApiCmd.execute(OpenApiCmd.java:267)
        at java.base/java.util.Optional.ifPresent(Optional.java:178)
        at io.ballerina.cli.launcher.Main.main(Main.java:59)

Affected Versions:

Ballerina SwanLake Update 10(2201.10.x)

Copy link

github-actions bot commented Sep 3, 2024

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@lnash94 lnash94 added this to the 2201.11.0 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants