swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

NullPointerException Thrown when Both `properties` and `allOf` are Defined in a `schema` Object #12402

Open ChihweiLHBird opened 6 months ago

ChihweiLHBird commented 6 months ago
Description

Not sure if it's my spec's issue but a null pointer exception was thrown.

Swagger-codegen version

Latest code in 3.0.0 branch

Swagger declaration file content or url
openapi: 3.0.1
info:
  version: 4.176.0
  title: Linode API
servers:
- url: https://api.linode.com/v4
paths:
  /networking/firewalls/{firewallId}/rules:
    parameters:
      - name: firewallId
        in: path
        required: true
        schema:
          type: integer
    put:
      tags:
      - Networking
      summary: Firewall Rules Update
      operationId: updateFirewallRules
      requestBody:
        content:
          application/json:
            schema:
              allOf:
              - $ref: '#/components/schemas/Firewall/properties/rules'
              type: object
              properties:
                inbound:
                  type: array
                  items:
                    $ref: '#/components/schemas/FirewallRuleConfig'
                outbound:
                  type: array
                  items:
                    $ref: '#/components/schemas/FirewallRuleConfig'
      responses:
        '200':
          description: Firewall Rules updated successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Firewall/properties/rules'
components:
  schemas:
    Firewall:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        rules:
          type: object
          properties:
            inbound:
              type: array
              items:
                $ref: '#/components/schemas/FirewallRuleConfig'
            outbound:
              type: array
              items:
                $ref: '#/components/schemas/FirewallRuleConfig'
    FirewallRuleConfig:
      type: object
      properties:
        protocol:
          type: string
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ./openapi.yaml -l go -o ./swagger-client-go
Exception in thread "Thread-0" java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: Networking
    description: null
    externalDocs: null
}
  Operation: updateFirewallRules
  Resource: put /networking/firewalls/{firewallId}/rules
  Exception: Cannot invoke "io.swagger.v3.oas.models.media.Schema.getProperties()" because "fileTypeSchema" is null
        at io.swagger.codegen.v3.DefaultGenerator.processOperation(DefaultGenerator.java:989)
        at io.swagger.codegen.v3.DefaultGenerator.processPaths(DefaultGenerator.java:891)
        at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:484)
        at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:796)
        at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.getProperties()" because "fileTypeSchema" is null
        at io.swagger.codegen.v3.generators.DefaultCodegenConfig.isFileTypeSchema(DefaultCodegenConfig.java:4443)
        at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromResponse(DefaultCodegenConfig.java:2349)
        at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromOperation(DefaultCodegenConfig.java:2042)
        at io.swagger.codegen.v3.generators.go.GoClientCodegen.fromOperation(GoClientCodegen.java:118)
        at io.swagger.codegen.v3.DefaultGenerator.processOperation(DefaultGenerator.java:965)
        ... 5 more
abhijeetshuklaoist commented 4 months ago

@ChihweiLHBird I believe this is because you missed defining the Tags. Try adding below at the root level

tags:
  - name: Networking
    description: Networking api