asyncapi / jasyncapi

/jay-sync-api/ is a Java code-first tool for AsyncAPI specification
Apache License 2.0
67 stars 23 forks source link

Unable to parse a spec with an nullable attribute #164

Closed jaydeepk closed 4 months ago

jaydeepk commented 7 months ago

Description

When we try to parse a spec with a 'nullable' attribute, it throws an error.

How to Reproduce

Given a spec with the following message schema:

  messages:
    product:
      name: product
      title: An inventory product
      summary: Product representing items in inventory
      contentType: application/json
      payload:
        type: object
        properties:
          name:
            description: Every product has a name
            type: string
          inventory:
            description: Count of items in inventory
            type: number
            nullable: true
          id:
            description: Unique identifier of the product
            type: number

Note: The inventory property has a 'nullable' attribute.

When we try to parse the spec :

val specFilePath ="path to spec file"
val specFileContents = File(specFilePath).readText()
val asyncAPISpec= ObjectMapper(YAMLFactory()).readValue(specFileContents, AsyncAPI::class.java)

It throws this error:

com.fasterxml.jackson.databind.JsonMappingException: "nullable" is not valid extension property (through reference chain: com.asyncapi.v2._6_0.model.channel.message.Message["payload"]->com.asyncapi.v2.schema.Schema["properties"]->java.util.LinkedHashMap["inventory"]->com.asyncapi.v2.schema.Schema["nullable"])
    at com.fasterxml.jackson.databind.deser.SettableAnyProperty._throwAsIOE(SettableAnyProperty.java:246)
    at com.fasterxml.jackson.databind.deser.SettableAnyProperty.set(SettableAnyProperty.java:209)
    at com.fasterxml.jackson.databind.deser.SettableAnyProperty.deserializeAndSet(SettableAnyProperty.java:179)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1765)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:316)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:623)
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:449)
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:32)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:310)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
Pakisan commented 7 months ago

@jaydeepk this is incorrect example:

See this reply: https://github.com/asyncapi/spec/issues/1031#issuecomment-1943605614

Reason: nullable is not present in Schema

upd:

Need time to discuss what to do with this fields: https://github.com/asyncapi/spec/issues/1031#issuecomment-1943749870

Pakisan commented 6 months ago

Right scenario is to use schemaFormat to be able to use schemas from OpenAPI - https://github.com/asyncapi/spec/issues/1037

Pakisan commented 4 months ago

Implemented in 1.0.0-RC