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

[BUG][dart-dio] fails with Null context for variable '.' on line 29 #9319

Closed
vladaman opened this issue Apr 22, 2021 · 7 comments
Closed

[BUG][dart-dio] fails with Null context for variable '.' on line 29 #9319

vladaman opened this issue Apr 22, 2021 · 7 comments

Comments

@vladaman
Copy link

vladaman commented Apr 22, 2021

Description

When using dart-dio generator I get following exception. Regular dart generator works fine. Looks like it's related to allOf block but I can't pinpoint where exactly.

Exception in thread "main" java.lang.RuntimeException: Could not generate model 'CardWidget'
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:544)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:875)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:440)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException: Null context for variable '.' on line 29
	at com.samskivert.mustache.Template.getValueIn(Template.java:288)
	at com.samskivert.mustache.Template.getValue(Template.java:224)
	at com.samskivert.mustache.Template.getValueOrDefault(Template.java:279)
	at com.samskivert.mustache.Mustache$VariableSegment.execute(Mustache.java:802)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:866)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$InvertedSegment.execute(Mustache.java:906)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:881)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:866)
	at com.samskivert.mustache.Template.executeSegs(Template.java:157)
	at com.samskivert.mustache.Mustache$IncludedTemplateSegment.execute(Mustache.java:774)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$InvertedSegment.execute(Mustache.java:910)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:881)
	at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
	at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:866)
	at com.samskivert.mustache.Template.executeSegs(Template.java:157)
	at com.samskivert.mustache.Template.execute(Template.java:134)
	at com.samskivert.mustache.Template.execute(Template.java:125)
	at org.openapitools.codegen.templating.MustacheEngineAdapter.compileTemplate(MustacheEngineAdapter.java:65)
	at org.openapitools.codegen.TemplateManager.write(TemplateManager.java:163)
	at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1017)
	at org.openapitools.codegen.DefaultGenerator.generateModel(DefaultGenerator.java:382)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:535)
OpenAPI declaration file content or url
    AppResponse:
      type: object
      description: "View Objects"
      properties:
        popup:
          $ref: '#/components/schemas/CardWidget'
        widgets:
          type: array
          items:
            anyOf:
            - $ref: '#/components/schemas/CardWidget'
            - $ref: '#/components/schemas/TextWidget'
          discriminator:
            propertyName: objtype
    ClickableWidget:
      properties:
        style:
          type: object
          properties:
            bold:
              type: boolean
              default: false
    CardWidget:
      type: object
      description: "Card View Widget"
      allOf:
        - $ref: '#/components/schemas/ClickableWidget'
      properties:
        image_urL:
          type: string
       objtype:
          type: string
          enum: [SOMETYPE]
openapi-generator version
openapi-generator-cli 5.1.0
  commit : e023eaa
  built  : 2021-03-20T09:18:49Z
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/

Might be related to #8860 (comment)

@kuhnroyal
Copy link
Contributor

Hmm, not sure, you can try the dart-dio-next generator but I don't think it will change anything.
AllOF/AnyOF is not currently supported in a meaningful way.

@kuhnroyal
Copy link
Contributor

Can not reproduce the error on master with neither dart-dio or dart-dio-next.
The generated code is not working but it is being generated.
Do you have custom templates by any chance?

@kuhnroyal
Copy link
Contributor

@vladaman Any new insights on your side?

@jmartin127
Copy link

jmartin127 commented Jun 15, 2022

I am experiencing the same issue. So far, I have seen the issue within the allOf field:

      allOf:
      - $ref: '#/components/schemas/AccountBase'

As well as some of the non-standard fields. I'll see if I can get a smaller example together, but in the meantime:

Here is a Docker command the reproduces the issue against the Plaid Open API spec:

% docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v6.0.0 generate \
    -i https://raw.githubusercontent.com/plaid/plaid-openapi/master/2020-09-14.yml \
    -g dart-dio \
    -o /local/out/dart

The only thing I am seeing so far that all of these failures have in common is a $ref entry:

$ref: '#/components/schemas/...'

@jmartin127
Copy link

jmartin127 commented Jun 15, 2022

UPDATE: In my case, the cause of this was that the referenced components had an enumeration with a null value. For example:

      enum:
      - EMPLOYMENT_STATUS_ACTIVE
      - EMPLOYMENT_STATUS_INACTIVE
      - null

This issue may be caused by: #11625

@kuhnroyal
Copy link
Contributor

% docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v6.0.0 generate \
    -i https://raw.githubusercontent.com/plaid/plaid-openapi/master/2020-09-14.yml \
    -g dart-dio \
    -o /local/out/dart

I can generate that with the current master, the Dart code does not fully compile but the OpenAPI generator does not throw.
@wing328 It seems the issue can be closed.

@wing328 wing328 closed this as completed Jul 17, 2023
@kuhnroyal
Copy link
Contributor

This was likely fixed by the jmustache update to 1.15 - see samskivert/jmustache#96

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

4 participants