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] Referencing schemas or messages from a local file leads to an error #344

Closed arthureberledev closed 3 weeks ago

arthureberledev commented 5 months ago

We have multiple asyncapi files in our project that share the same components. If i try to seperate them into multiple yaml files to reuse them, I either get an error that findValue(String) is null or that "properties" is null.

This is an example asyncapi spec file:

# asyncapi.yaml
asyncapi: 2.6.0
info:
  title: Account Service
  version: "1.0.0"
channels:
  user/signedup:
    subscribe:
      operationId: userSignedUp
      message:
        $ref: "#/components/messages/UserSignedUp"
components:
  messages:
    UserSignedUp:
      payload:
        # this works:
        $ref: "#/components/schemas/user"
        # this leads to the error
        # `Cannot invoke "com.fasterxml.jackson.databind.JsonNode.get(String)" because the return value of "com.fasterxml.jackson.databind.JsonNode.findValue(String)" is null`:
        $ref: "./user-message.yaml"
  schemas:
    user:
      # this works:
      type: object
      properties:
        firstName:
          type: string
          description: "foo"
        lastName:
          type: string
          description: "bar"
      # this leads to the error
      # `Cannot invoke "com.fasterxml.jackson.databind.JsonNode.has(String)" because "properties" is null`:
      $ref: "./user.yaml"

# user-message.yaml
payload:
  type: object
  properties:
    firstName:
      type: string
      description: "foo"
    lastName:
      type: string
      description: "bar"

# user.yaml
type: object
properties:
  firstName:
    type: string
    description: "foo"
  lastName:
    type: string
    description: "bar"

It works with referencing parameters from a local file though, e. g.:

...
components:
  parameters:
    stage:
     $ref: "./stage.yaml"

Is this just not supported currently or is this perhaps a bug?

jemacineiras commented 1 month ago

Hi @arthureberledev,

I'm sorry for not getting back to you sooner. I will take a look at it. I guess part of this problem is solved with the refactoring I recently made. But I think we force to keep the component structure inside the files, at least for now.

I will back to you as soon as I can.