sngular / scs-multiapi-plugin

This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncApi and OpenAPI.
http://sngular.com
Mozilla Public License 2.0
48 stars 10 forks source link

[AsyncAPI] CompilationFailureException when using integer minimum and maximum #270

Closed gaby-roland closed 1 year ago

gaby-roland commented 1 year ago

It seems like using minimum and maximum on an integer causes a CompilationFailureException as soon as another integer is introduced.

I have a very simple sample API spec with a few integer types. The moment I add minimum or maximum to one of the integer types, it starts causing a CompilationFailureException.

I can use minimum and maximum as long as I only have one integer in my schema. But adding a second integer breaks it. I can also have as many integers as I want if I don't specify minimum or maximum.

For example, this API spec works for me, and produces the correct classes:

asyncapi: "2.0.0"
info:
  title: Demo API
  version: "1.0.0"

channels:
  user/signedup:
    subscribe:
      operationId: emitUserSignUpEvent
      message:
        $ref : '#/components/messages/UserSignedUp'

components:
  messages:
    UserSignedUp:
      name: userSignedUp
      title: User signed up event
      summary: Inform about a new user registration in the system
      contentType: application/json
      payload:
        $ref: '#/components/schemas/userSignedUpPayload'

  schemas:
    userSignedUpPayload:
      type: object
      properties:
        firstName:
          type: string
          description: "foo"
        lastName:
          type: string
          description: "bar"
        age:
          type: integer
          minimum: 0
          maximum: 200

But as soon as I add a second integer under age

...
        age:
          type: integer
          minimum: 0
          maximum: 200
        pin:
          type: integer

I get the following failure:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (d
efault-compile) on project asyncapi-demo-service-api: Compilation failure
...
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
github-actions[bot] commented 1 year ago

Thank you for collaborating with the project by giving us feedback! Cheers!

jemacineiras commented 1 year ago

Hi @gaby-roland, thanks for the feedback, I'll check it and will provide a fix asap. Cheers

jemacineiras commented 1 year ago

Hi @gaby-roland,

I modified an existing test to reproduce your issue and provide a small fix. Do you mind trying it? BTW, I found we have a problem in how we create the custom validators, that will try to address soon. I think for now, we can only support custom validators about max and min for a single data type. I am considering which will be the best approach .

Cheers

gaby-roland commented 1 year ago

Hi @jemacineiras

Thanks for the quick responses. With your changes I got a new Compilation failure. image

This is the generated class, it looks like it duplicates the class line right after defining the maximum member variable. Lines 8-10 are duplicated on lines 11-13. Hope this helps.

jemacineiras commented 1 year ago

HI @gaby-roland,

got it. Found that issue for the OpenApi part, but miss fixing it for the AsyncApi one. Now I think should work, but with the condition I said before.

Cheers

gaby-roland commented 1 year ago

@jemacineiras Your latest commit seems to work well! It generates the min/max validators properly. I understand that for now we can only use min/max validation for a single type, and that is fine for my use case. Thanks for the quick responses and for working a fix quickly!