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

Getting NPE when generating a client from an OpenAPI spec with the JSON path reference #7314

Open
TharmiganK opened this issue Oct 30, 2024 · 1 comment

Comments

@TharmiganK
Copy link
Contributor

Description

$Subject

Steps to Reproduce

Try to generate the client for the following spec:

openapi: 3.0.0
info:
  title: Albums API
  version: 1.0.0
  description: A simple API to get a list of albums
paths:
  /albums:
    get:
      summary: Get a list of albums
      responses:
        '200':
          description: A list of albums
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AlbumArray'
  /albums/{id}:
    get:
      summary: Get an album by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: An album
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AlbumArray/items'
components:
  schemas:
    AlbumArray:
      type: array
      items:
        type: object
        properties:
          id:
            type: integer
            example: 1
          title:
            type: string
            example: Album Title
          artist:
            type: string
            example: Artist Name
          release_date:
            type: string
            format: date
            example: '2023-01-01'
$ bal openapi -i openapi.yaml --mode client --single-file
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-10-30 11:37:34,774] 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.BallerinaTypesGenerator.generateTypeDescriptorNodeForOASSchema(BallerinaTypesGenerator.java:122)
        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:428)
        at io.ballerina.openapi.cmd.BallerinaCodeGenerator.generateClient(BallerinaCodeGenerator.java:257)
        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)

Version

Ballerina SwanLake Update 10(2201.10.x)

Environment Details (with versions)

No response

@TharmiganK
Copy link
Contributor Author

This is discovered from the smart sheet connector development. The original spec can be found in here: https://gist.github.com/TharmiganK/cab050e07357bf79bf745f3cdacdba11

The issue is with all the json path in the reference such as properties, allOf etc. Currently we only support basic references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant